#!/usr/bin/bash

#Tate:2022.3.26
#Author:Yingjian
#Function：一键安装java

#判断是否重复安装
if [ -d "/usr/local/java" ];then
echo "java 已安装" 
exit 2
fi
#判断网络是否正常
ping -c 1 www.baidu.com &> /dev/null
if [ ! $? -eq 0 ];then
echo "请检测网络是否正常"
exit 2
fi
#安装
if [ ! -f "/usr/local/src/jdk-8u281-linux-x64.tar.gz" ];then
curl -o /usr/local/src/jdk-8u281-linux-x64.tar.gz -s http://8.210.62.122/java/jdk-8u281-linux-x64.tar.gz
else
echo "java包已安装"
fi
#解压
tar xf /usr/local/src/jdk-8u281-linux-x64.tar.gz -C /usr/local
mv /usr/local/jdk1.8.0_281 /usr/local/java
#环境变量
cat > /etc/profile.d/java.sh <<EOF
export JAVA_HOME=/usr/local/java
export PATH=\$JAVA_HOME/bin:\$PATH
EOF

source /etc/profile.d/java.sh
