码迷,mamicode.com
首页 > 其他好文 > 详细

安装jdk1.8

时间:2018-07-21 22:41:46      阅读:320      评论:0      收藏:0      [点我收藏+]

标签:finish   success   exit   inf   port   bee   tar   war   not   

这是很普通的shell的脚本,只需要注意:echo 语句内出现的变量,需要转义!

#!/bin/bash

function get_current_time_stamp()
{
echo `date "+%Y/%m/%d %H:%M:%S"`
}

function send_error()
{
echo -e "\e[1;45m [ Error ] `get_current_time_stamp` - $1 -\e[0m"
}

function send_success()
{
echo -e "\e[1;32m [ Success ] `get_current_time_stamp` - $1 -\e[0m"
}

function send_info()
{
echo -e "\e[1;34m [ Info ] `get_current_time_stamp` - $1 -\e[0m"
}

function send_warn()
{
echo -e "\e[1;33m [ Warn ] `get_current_time_stamp` - $1 -\e[0m"
}

 

check_java=$(rpm -qa|grep -E "^java" | wc -l)

if [ $check_java -gt 0 ];then
send_error "java has been installed, exit..."
exit 1
fi

if [ ! -d /usr/local ];then
mkdir -p /usr/local
chmod 755 /usr/local
fi

if [ ! -e "./jdk-8u181-linux-x64.tar.gz" ];then
send_error "jdk package not found..."
exit 1
fi

tar -zxvf ./jdk-8u181-linux-x64.tar.gz -C /usr/local/

if [ $? -ne 0 ];then
send_error "tar error, Please Check!"
exit 1
fi

cp /etc/profile /etc/profile.bak

echo "JAVA_HOME=/usr/local/jdk1.8.0_181" >> /etc/profile
echo "JRE_HOME=\$JAVA_HOME/jre" >> /etc/profile
echo "PATH=\$PATH:\$JAVA_HOME/bin" >> /etc/profile
echo "CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar" >> /etc/profile

echo "export JAVA_HOME" >> /etc/profile
echo "export JRE_HOME" >> /etc/profile
echo "export PATH" >> /etc/profile
echo "export CLASSPATH" >> /etc/profile

send_info "JDK install finished."

安装jdk1.8

标签:finish   success   exit   inf   port   bee   tar   war   not   

原文地址:https://www.cnblogs.com/ralphdc/p/9348162.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!