欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

shell Deploy Java with one click

程序员文章站 2023-12-30 13:03:46
...

shell Deploy Java with one click

vim /root/java_install.sh
#!/bin/sh
# -*- coding: utf-8 -*-
# Author: CIAS
# 2020-12-14

LogFile="/var/log/install_$(date +'%Y%m%d')".log

echo -e '\E[32m' "Check to see if the Java environment variables were previously configured"
sleep 3
sed -i '/export JAVA_HOME=/'d /etc/profile 2>&1 | tee -a $LogFile
sed -i '/export CLASSPATH=/'d /etc/profile 2>&1 | tee -a $LogFile
sed -i '/export PATH=/'d /etc/profile 2>&1 | tee -a $LogFile
sed -i '/export JRE_HOME=/'d /etc/profile 2>&1 | tee -a $LogFile

echo "Install download tool"
sleep 3
yum install wget -y 2>&1 | tee -a $LogFile

echo "shutdown selinux"
sleep 3
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config 2>&1 | tee -a $LogFile

echo "Download the JDK installation package"
sleep 3
wget -N -P /opt/ https://repo.huaweicloud.com/java/jdk/8u151-b12/jdk-8u151-linux-x64.tar.gz 2>&1 | tee -a $LogFile

echo "Unpack the JDK" >> $LogFile
sleep 3
tar -xvf /opt/jdk-8u151-linux-x64.tar.gz -C /opt/ 2>&1 | tee -a $LogFile

echo "Configuring the JDK environment"
sleep 3
sed -i '$aexport JAVA_HOME=/opt/jdk1.8.0_151' /etc/profile 2>&1 | tee -a $LogFile
sed -i '$aexport JRE_HOME=/opt/jdk1.8.0_151/jre' /etc/profile 2>&1 | tee -a $LogFile
sed -i '$aexport CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:\$JRE_HOME/lib:\$CLASSPATH' /etc/profile 2>&1 | tee -a $LogFile
sed -i '$aexport PATH=\$JAVA_HOME/bin:\$PATH' /etc/profile 2>&1 | tee -a $LogFile

echo "flash file"
sleep 3
source /etc/profile 2>&1 | tee -a $LogFile

echo "Remove installation package"
sleep 3
rm -rf /opt/jdk-8u151-linux-x64.tar.gz 2>&1 | tee -a $LogFile

 

相关标签: shell Java

上一篇:

下一篇: