Tomcat安裝指令碼

weixin_33716557發表於2017-05-09

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

相關文章