#!/bin/bash
# Filename: install_jdk.sh
# Revision: 1.0
# Date: 2019/07/12
# Author: sdhzdtwhm
# Website: no
# Description: centos7 install jdk
# Usage:
# ./install_jdk.sh /home/test/java
base_dir=$1
down_url=http://192.168.2.253/file/jdk-8u192-linux-x64.tar.gz
package_name=jdk-8u192-linux-x64.tar.gz
username=$(whoami)
function down_software(){
cd /tmp/
curl -s -O $down_url
}
function unzip_jdk(){
mkdir -p $base_dir
tar -zxf /tmp/$package_name -C $base_dir
}
function config_root_path(){
cat >> /etc/profile << EOF
export JAVA_HOME=$base_dir/jdk1.8.0_192
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH
EOF
}
function config_user_path(){
cat >> ~/.bashrc << EOF
export JAVA_HOME=$base_dir/jdk1.8.0_192
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH
EOF
}
function main(){
down_software;
unzip_jdk;
if [ $? = 0 ];then
if [ $username = 'root' ]; then
config_root_path;
else
config_user_path;
fi
else
echo "unzip_jdk is error!"
fi
}
main