Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
jdk.sh 3.17 KB
Copy Edit Raw Blame History
不失本心 authored 2023-07-06 06:45 . 第一次提交
#!/bin/sh
#
#********************************************************************
#Author: ocean
#QQ: 910853073
#Date: 2019-12-20
#FileName: ocean.sh
#URL: http://www.ocean101.com
#Description: The test script
#Copyright (C): 2023 All rights reserved
#********************************************************************
#ply="6666"
#a="1"
#b="1"
#echo "sss $ply"
#if [ "$a" == "$b" ]; then
# echo "值相同"
#else
# echo "值不同"
#fi
# ANSI颜色序列
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # 恢复默认颜色
# 判断是否为CentOS
systemVersion=""
systemType=""
if [[ -f /etc/redhat-release ]]; then
centos_version=$(grep -oE '[0-9]+\.[0-9]+' /etc/redhat-release)
echo "当前系统是 CentOS $centos_version"
systemVersion="CentOS $centos_version"
systemType="1"
fi
# 判断是否为Debian
if [[ -f /etc/debian_version ]]; then
debian_version=$(cat /etc/debian_version)
#echo "当前系统是 Debian $debian_version"
systemVersion="Debian $debian_version"
systemType="2"
fi
# 判断是否为国产系统(如麒麟、深度等)
if [[ -f /etc/os-release ]]; then
source /etc/os-release
if [[ "$NAME" == *"Kylin"* ]]; then
#echo "当前系统是国产系统 - 麒麟"
systemVersion="国产系统 - 麒麟"
systemType="4"
elif [[ "$NAME" == *"Deepin"* ]]; then
#echo "当前系统是国产系统 - 深度"
systemVersion="国产系统 - 深度"
systemType="5"
else
echo "当前系统是 $NAME"
#systemVersion="$NAME"
#systemType="6"
fi
fi
# 判断是否为Ubuntu
if [[ -f /etc/lsb-release ]]; then
source /etc/lsb-release
if [[ "$DISTRIB_ID" == "Ubuntu" ]]; then
#echo "当前系统是 Ubuntu $DISTRIB_RELEASE"
systemVersion="Ubuntu $DISTRIB_RELEASE"
systemType="3"
fi
fi
# 其他未知系统类型
#echo "无法确定当前系统类型"
function installCentos() {
mkdir -p /usr/java
cp jdk-8u371-linux-x64.tar.gz /usr/java/
cd /usr/java
tar -xvf jdk-8u371-linux-x64.tar.gz
sh -c 'echo " " >> /etc/profile'
sh -c 'echo "export JAVA_HOME=/usr/java/jdk1.8.0_371" >> /etc/profile'
sh -c 'echo "export CLASSPATH=\$CLASSPATH:\$JAVA_HOME/lib/" >> /etc/profile'
sh -c 'echo "export PATH=\$PATH:\$JAVA_HOME/bin" >> /etc/profile'
source /etc/profile
if [[ "$javaHome" != *openjdk* ]];then
echo -e "${YELLOW}jdk安装成功${NC}"
echo -e "${YELLOW}$(java -version 2>&1)${NC}"
exit 0
else
echo -e "${YELLOW}jdk安装失败${NC}"
fi
}
echo "开始安装JDK"
rpmJava="$(rpm -qa | grep java)"
rpmJdk="$(rpm -qa | grep jdk)"
javaHome="$(java -version 2>&1)"
#echo "$rpmJava"
#echo "$rpmJdk"
#echo "$javaHome"
if [ "$rpmJava" == "" -a "$rpmJdk" == "" ] && [[ "$javaHome" != *version* ]];then
echo "没有安装JDK"
echo -e "${YELLOW}$systemType${NC}"
#echo "$javaHome"
#判断是否为centos系统
if [ "$systemType" == "1" ];then
echo "调用installCentos方法"
installCentos
else
exit 0
fi
else
echo "已安装JDK"
fi
#thisFile="$(pwd)"
#echo "$thisFile"
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化