JDK一键部署, 新添加进度条

JDK部署, 脚本与JDK安装包放在同一目录

然后执行

source ./jdk.sh

稍等进度条100%即可

#*************************************************************************
#         > File Name: jdk.sh
#         > Author: chenglee
#         > Main : [email protected]
#         > 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

猜你喜欢

转载自www.cnblogs.com/chenglee/p/10495747.html
今日推荐