shell脚本系列:一键部署Centos7的Java1.8开发环境
代码
#!/bin/bash
# 一键安装jdk1.8
cd ~
echo "选择安装版本:";
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
echo ">>>1. 部分安装功能不缺(一百兆左右)>>>";
echo ">>>2. 全部安装 (1G左右)>>>>>>>>>>>>>>";
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
read CHIOCE;
if [ $# == 0 ]; then
echo "==> 默认选择 ==> “1”";
yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel -y
else
if [[ $CHIOCE == '1' ]]; then
echo "==> 将开始下载部分版本";
yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel -y
elif [[ $CHINCE == '2' ]]; then
echo "==> 将开始下载完整版本";
yum install java-1.8.0-openjdk* -y
else
echo "==> 默认选择 ==> “1”";
yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel -y
#statements
fi
fi
if [ $? == 0 ]; then
echo "==> 设置环境变量!";
echo "JAVA_HOME=/usr/lib/jvm/java" >> /etc/profile
echo "PATH=$PATH:$JAVA_HOME/bin" >> /etc/profile
echo "CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar" >> /etc/profile
echo "export JAVA_HOME CLASSPATH PATH" >> /etc/profile
else
echo "==> 执行失败!";
eixt;
fi
echo "==> 验证:"
java -version
javac -version
if [ $? -eq 0 ]; then
echo "==> 安装成功!";
else
echo "==> 安装失败!";
fi
创建脚本文件,并执行
vim install_mysql.sh
# 将上面的代码复制进入。保存
chmod +x install_mysql.sh # 添加执行权限
./install_mysql.sh # 执行
ps: 脚本还比较粗糙,只做交流和个人使用!