Tomcat安装脚本
#!/bin/bash
# Author: joj
# Version 1.0
#Change:模块化
# Description 安装包放在/tmp目录下
#设置初始的信息(jdk包,tomcat包)
JDK="jdk-8u40-linux-x64.tar.gz"
Tomcat="apache-tomcat-8.0.20.tar.gz"
InretllPath="/usr/local"
#解压软件包到指定位置的函数
function Tar(){
soft=$1
echo "tar $soft ---解压安装包到指定位置"
tar xf "/tmp/${soft}" -C $InretllPath &>/dev/null
ret=$?
#查看是否生成
echo 'ls /usr/local' | bash >>/tmp/inretll.log
if [ "$ret" == "0" ]
then
echo "tar ${JDk} ok !!!"
return $ret
else
echo "wrong,please check the soft if it exise in /tmp !!!"
return $ret
exit 99
fi
}
# 解压软件包
function ForTar(){
for i in $JDK $Tomcat
do
#调用函数解开压缩
Tar $i
#获取执行的返回状态
ret=$?
echo $ret
done
}
#安装jdk
function Install_Jdk(){
JdkName=`ls $InretllPath |grep 'jdk'`
echo $TomcatName
ln -s "$InretllPath/$JdkName" "$InretllPath/jdk"
echo 'ln -s jdk'
cat>>/etc/profile.d/java.sh<
export JAVA_HOME=/usr/local/jdk
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
EOF
source /etc/profile
if [ `java -version` ]
then
echo "install jdk sucess!"
else
echo "error ,install jdk falt!"
fi
}
#安装tomcat
function Install_Tomcat(){
TomcatName=`echo $Tomcat | sed 's/.tar.gz$/''/'`
echo $TomcatName
ln -s "$InretllPath/$TomcatName" "$InretllPath/tomcat"
echo 'ln -s tomcat'
cd "$InretllPath/tomcat"/bin
echo `ls`
#删除默认的项目
rm -rf /usr/local/tomcat/webapps
/usr/local/tomcat/bin/catalina.sh start &
echo "/usr/local/tomcat/bin/catalina.sh start">>/etc/rc.local
}
function main(){
#解压软件包
ForTar
#安装jdk
Install_Jdk
#安装tomcat
Install_Tomcat
}
main