jdk_init(){
now_time_num=`date '+%Y%m%d%H%M%S'`
java -version

if [ ? -ne 0 ];then
   jdk_dir="/usr/local/jdk"
   if [ -ejdk_dir ];then
      mv /usr/local/jdk /usr/local/jdk_baknow_time_num
   else
      echo"开始安装"
   fi
   cp /etc/profile /etc/profile_baknow_time_num
   sed -i '/JAVA_/d'  /etc/profile
   tar zxf jdk-*.tar.gz -C /usr/src/
   cp -R /usr/src/jdk*_* /usr/local/jdk
   chmod -R 755 /usr/local/jdk/bin/*

     echo '

export  JAVA_HOME=/usr/local/jdk
export  JAVA_BIN=/usr/local/jdk/bin
export  PATH=JAVA_HOME/bin:PATH
export  CLASSPATH=.:JAVA_HOME/bin/dt.jar:JAVA_HOME/bin/tools.jar
export  JAVA_HOME  JAVA_BIN  PATH  CLASSPATH' >> /etc/profile

        source /etc/profile
   echo '安装成功'
else
   jdk_version=`java -version 2>&1 |awk 'NR==1{ gsub(/"/,""); print 3 }'`
   read -p '当前环境已经安装jdk,版本为 'jdk_version' 是否继续安装(y:继续,n:停止):' jdk_yn
   if [ jdk_yn = 'y' ];then
      if [ -ejdk_dir ];then
         mv /usr/local/jdk /usr/local/jdk_baknow_time_num
      else
         echo"开始安装"
      fi
      cp /etc/profile /etc/profile_baknow_time_num
      sed -i '/JAVA_/d'  /etc/profile
      tar zxf jdk-*.tar.gz -C /usr/src/
      cp -R /usr/src/jdk*_* /usr/local/jdk
      chmod -R 755 /usr/local/jdk/bin/*

      echo '
1
export  JAVA_HOME=/usr/local/jdk
export  JAVA_BIN=/usr/local/jdk/bin
export  PATH=JAVA_HOME/bin:PATH
export  CLASSPATH=.:JAVA_HOME/bin/dt.jar:JAVA_HOME/bin/tools.jar
export  JAVA_HOME  JAVA_BIN  PATH  CLASSPATH' >> /etc/profile

           source /etc/profile
   else
      echo '停止安装'
      exit
   fi
fi

}

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code