jdk一键部署的功能与优势

请把JDK安装包与脚本放在同一目录,以便脚本识别JDK版本, 请在脚本首字段jdk_path变量设置好安装路径, 然后运行脚本即可完成一键部署, 完成部署后请手动输入source /etc/profile命令以便新环境生效。–[新增进度条功能]

如何获取离线jdk包

https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

shell脚本

#*************************************************************************
#         > File Name: jdk.sh
#         > Author: chenglee
#         > Main : chengkenlee@sina.com
#         > Blog : http://www.cnblogs.com/chenglee/
#         > Created Time : 2019年03月07日 星期四 18时08分59秒
#*************************************************************************
#!/bin/bash
jdk_path="/usr/local"
jdk_targ=`basename *jdk-*`

function Cheng_flash(){
    i=0;
    str=""
    arr=("|" "/" "-" "\\")
    while [ $i -le 100 ]
    do
    let index=i%4
    let indexcolor=i%8
    let color=30+indexcolor
    printf "\e[0;$color;1m[%-100s][%d%%]%c\r" "$str" "$i" "${arr[$index]}"
    sleep ${sleeptime2}
    let i++
    str+='='
    done
    printf "\n"
}
function Time_test(){
    echo "please wait a moment ... "
    starttime=`date +'%Y-%m-%d %H:%M:%S'`
    tar tvvf ${jdk_targ} > /dev/null
    endtime=`date +'%Y-%m-%d %H:%M:%S'`
    start_seconds=$(date --date="$starttime" +%s);
    end_seconds=$(date --date="$endtime" +%s);
    sleeptime=$((end_seconds-start_seconds))
    sleeptime2=`awk 'BEGIN{printf "%0.2f",'${sleeptime}'/100}'`
}
function tar_gz(){
    Time_test
    tar xvvf ${jdk_targ} -C ${jdk_path} > /dev/null | Cheng_flash
}
function profile(){
    jdk_Path=`find ${jdk_path} -maxdepth 1 | grep jdk`
(
cat <<EOF
#java jdk
export JAVA_HOME=${jdk_Path}
export JRE_HOME=\${JAVA_HOME}/jre
export CLASSPATH=.:\${JAVA_HOME}/lib:\${JRE_HOME}/lib
export PATH=\${JAVA_HOME}/bin:\$PATH
EOF
) >> /etc/profile
}
function Source(){
    source /etc/profile 
}

function main(){
    tar_gz
    profile
    Source
}
main

文档更新时间: 2019-03-08 11:09   作者:杭州-雪翊寒|深圳-夏天