#!/bin/bash
init(){
echo "初始化环境..."
cd /root
tar -xvf tools.tar.xz
echo "解压工具包完成。"
cd /usr/local
mkdir tools
echo "在/usr/local下创建tools目录完成。"
}
install_jdk(){
echo "开始安装JDK..."
cd /root
mv /root/tools/java-1.8.0-openjdk-portable-1.8.0.342.b07-1.portable.jdk.el.x86_64.tar.xz /usr/local/tools
echo "移动JDK压缩包到/usr/local/tools完成。"
cd /usr/local/tools
tar -xvf java-1.8.0-openjdk-portable-1.8.0.342.b07-1.portable.jdk.el.x86_64.tar.xz
echo "解压JDK完成。"
mv java-1.8.0-openjdk-portable-1.8.0.342.b07-1.portable.jdk.el.x86_64 openjdk_342
echo "重命名JDK目录为openjdk_342完成。"
echo "设置环境变量..."
echo "export JAVA_HOME=/usr/local/tools/openjdk_342" >> "/etc/profile"
echo "export PATH=\$JAVA_HOME/bin:\$PATH" >> "/etc/profile"
echo "export CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar" >> "/etc/profile"
source /etc/profile
echo "环境变量设置完成。"
java -version
echo "JDK安装并验证版本完成。"
source /etc/profile
echo "请手动执行如下命令: source /etc/profile"
read HOSTIP1
source /etc/profile
}
#init
install_jdk