YJ的博客
个人生活、工作的随笔

本站部分文章、资源来自互联网,版权归原作者及网站所有,如侵犯了您的权利,请及时致信告知我

粤ICP备15050546号-1

网站地图

一键安装JDK7与Tomcat7脚本

#!/bin/bash
echo "这是一个一键安装Java7+Tomcat7环境的脚本,哈哈,是不是很方便?"
echo "现在帮你安装JAVA环境,注意:由于一些默认规则下载的安装包请放置于/usr/local/src目录下,安装的软件路径会放置于/usr/local下加对应的软件名。"
sleep 2

read -p "请输入JDK安装包的绝对路径加包名如/home/jdk7.rpm,只支持rpm包哦:" jdkpackagepath
rpm -ivh $jdkpackagepath
echo -e "\033[31m安装的jdk版本信息如下:\033[0m"
java -version
sleep 2

echo -e "\033[31m开始配置环境变量。\033[0m"
echo "JAVA_HOME=/usr/java/jdk1.7.0_79
JRE_HOME=/usr/java/jdk1.7.0_79/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH" >> /etc/profile
source /etc/profile
echo -e "\033[31m开始测试环境变量设置情况。\033[0m"
java &>/dev/null
if [ $? -ne 0 ]
then
  echo -e "\033[31mJAVA命令正常可运行\033[0m"
fi

javac &>/dev/null
if [ $? -ne 0 ]
then
  echo -e "\033[31mJAVAC命令正常可运行\033[0m"
fi

echo "你是否要继续安装tomcat?"
select goon in yes no
do
  case $goon in
  yes) echo "你选择了"$goon",现在继续安装tomcat。" && break;;
  no) echo "你选择了"$goon",现在退出脚本,再见!" && exit 1;;
  *) echo "你选错了,没有此选项,请重选哦,看清楚,就1跟2.";;
  esac
done

read -p "请输入Tomcat的tar包绝对路径加包名如/home/tomcat.tar:" tomcattarpath
unzip -n $tomcattarpath -d /home &>/dev/null
tomcatdirpath=`find /home -type d -name "*tomcat*"`
tomcatpath=`find /home -type d -name "*tomcat*" | awk -F/ '{print $NF}'`
cp -rf $tomcatdirpath /usr/local/$tomcatpath
echo "tomcat程序路径为/usr/local/$tomcatpath"

echo "是否要修改tomcat的web端口?"
select tomcatport in yes no
do
  case $tomcatport in
  yes) read -p "请问你想把tomcat的web端口修改为:" port && sed -i 's/port="8080"/port="'${port}'"/' /usr/local/$tomcatpath/conf/server.xml && echo "Tomcat的web端口已修改为"$port"" && break;;
  no) break;;
  *) echo "没有此选项,请重新选择。";;
  esac
done

chmod +x /usr/local/$tomcatpath/bin/startup.sh /usr/local/$tomcatpath/bin/shutdown.sh /usr/local/$tomcatpath/bin/catalina.sh
echo "是否需要帮你启动tomcat?"
select tomcaton in yes no
do
  case $tomcaton in
  yes) /usr/local/$tomcatpath/bin/startup.sh && echo "tomcat启动完毕,请打开浏览器输入http://tomcat server ip测试访问tomcat,安装脚本到此结束,退出脚本" && exit 1;;
  no) echo "安装脚本到此结束,退出脚本" && exit 1;;
  *) echo "没有此选项,请重新输入。";;
  esac
done
2016-05-12
243 views
暂无评论

发表评论