【Tomcat】shell 部署配置 war包

#!/bin/bash
#-----------------------------------------------
# FileName: configWAR.sh
# Version: 1.5.2
# LastUpdate: 2017/08/24
# Update: 2017/09/05
# Author: zhengwenqiang
# Email: [email protected]
# Description: change the properties of the essential configuration file, it means that before you startup tomcat to run those three apps etc cas,portal,security
#                it's vital to run this script which bring the proccess running normally.
# Notes: If you are going execute this script on linux, you should  run the command "sed -i 's/\r//g' configWAR.sh" 
#         to delete invalid character which cause character error.
# Changes: Use command sed (line:31) to delete BOM header of conf.properties which generated on Windows Notepad. 
# Copyright: 2017(c) zhengwenqiang
# License: GPL
#-----------------------------------------------

# cd `dirname $(readlink -f $0)`

# 默认使用当前目录下的conf.properties来生成变量
conf=`pwd`'/conf.properties'

# 如果 第一个参数不为空,判断时,在 $1 两边加双引号
if [ -n "$1" ] ; then
    conf=$1
fi

# 如果第一个参数是存在的文件
if [ -f $conf ] ; then
    # 删除utf8文件编码的BOM头
    sed -i -e 's/\xef\xbb\xbf//' -e 's/\r//g' $conf
    # 生成变量
    source $conf
else
    # 如果第一个参数存在但不是文件
    echo "conf.properties not found"
    exit 123
fi

# 获得当前操作系统的IP
IP=` which ip &>/dev/null && ip addr show | grep 'brd.*global'| grep -v 'vir' | cut -d '/' -f 1 | sed 's/[^0-9\.]//g'`
# 如果没有在conf.properties中写入 cas_ip
if [ -z "$cas_ip" ] ; then
    cas_ip=$IP
fi

if [ -z "$security_ip" ] ; then
    security_ip=$IP
fi

if [ -z "$portal_ip" ] ; then
    portal_ip=$IP
fi

cd webapps

if [ $casEnable == "true" ] ; then
    [ -d cas ] && rm -rf cas
    cas_war=`ls *.war | egrep 'cas((-[0-9]{2,4}){3})?.war' | tail -n 1`
    if [ -f ${cas_war} ] ; then

        mkdir cas && unzip ${cas_war} -d cas
        
        cas_pros='cas/WEB-INF/cas.properties'
        
        sed -i -r -e "s/\r//g" -e "s/CAS_IP:CAS_PORT/${cas_ip}:${cas_port}/g" -e "s/PORTAL_IP:PORTAL_PORT/${portal_ip}:${portal_port}/g" -e "s/DB_IP:DB_PORT([/:])DB_NAME/${db_ip}:${db_port}\1${db_name}/g" ${cas_pros}
        sed -i "s/SE_IP:SE_PORT/${security_ip}:${security_port}/g"  ${cas_pros} cas/WEB-INF/classes/bonc-security-base.properties
        case $db_type in
            "mysql")
                sed -r -i -e '/MySQLDialect\r?$/s/^#//g' -e '/com.bonc.jdbc.MysqlDriver$/,+3s/^#//g' -e '/com.mysql.jdbc.Driver$/,+3s/^#//g' ${cas_pros}
                ;;
            "oracle")
                sed -r -i -e '/Oracle10gDialect\r?$/s/^#//g' -e '/com.bonc.jdbc.OracleDriver$/,+4s/^#//g' -e '/oracle.jdbc.driver.OracleDriver$/,+4s/^#//g'  -i ${cas_pros}
                ;;
            *)
                ;;
        esac
        sed -i -e "s/DB_USERNAME/${db_username}/g" -e "s/DB_PASSWD/${db_passwd}/g" ${cas_pros}
    fi

    [ ${cas_war} != "cas.war" ] && mv ${cas_war} cas.war
fi

if [ $portalEnable == "true" ] ; then

    # Configure Portal
    [ -d portal ] && rm -rf portal
    portal_war=`ls *.war | egrep 'portal((-[0-9]{2,4}){3})?.war' | tail -n 1`
    if [ -f ${portal_war} ] ; then

        mkdir portal && unzip ${portal_war} -d portal
        
        for portal in 'portal/WEB-INF/web.xml' 'portal/WEB-INF/classes/bonc-security-base.properties' 'portal/WEB-INF/classes/cfg.db.deploy.properties'
        do
            sed -i "s/CAS_IP:CAS_PORT/${cas_ip}:${cas_port}/g"  $portal
            sed -i "s/PORTAL_IP:PORTAL_PORT/${portal_ip}:${portal_port}/g" $portal
            sed -i "s/SE_IP:SE_PORT/${security_ip}:${security_port}/g" $portal
            sed -r "s/DB_IP:DB_PORT([/:])DB_NAME/${db_ip}:${db_port}\1${db_name}/g" -i $portal
            sed -i "s/DB_USERNAME/${db_username}/g" $portal
            sed -i "s/DB_PASSWD/${db_passwd}/g" $portal
        done
        
        
        case $db_type in
            "mysql")
                sed -r '/^#?database.type=mysql$/,+4s/^#//g' -i 'portal/WEB-INF/classes/cfg.db.deploy.properties'
                sed -r '/MySQL5Dialect$/s/^#//g' -i 'portal/WEB-INF/classes/cfg.db.deploy.properties'
                sed -i "s/DB_SCHEMA/${db_name}/g" 'portal/WEB-INF/classes/cfg.db.deploy.properties'
            ;;
            "oracle")
                sed -r '/^#?database.type=oracle$/,+5s/^#//g' -i 'portal/WEB-INF/classes/cfg.db.deploy.properties'
                sed -r '/Oracle10gDialect$/s/^#//g' -i 'portal/WEB-INF/classes/cfg.db.deploy.properties'
                sed -i "s/DB_SCHEMA/${db_username}/g" 'portal/WEB-INF/classes/cfg.db.deploy.properties'
            ;;
            *)
            ;;
        esac
        
        
    fi

fi

# Configure Security
if [ $securityEnable == "true" ] ; then

    [ -d security ] && rm -rf security
    security_war=`ls *.war | egrep 'security((-[0-9]{2,4}){3})?.war' | tail -n 1`
    if [ -f ${security_war} ] ; then

        mkdir security && unzip ${security_war} -d security
        
        for security in 'security/WEB-INF/web.xml' 'security/WEB-INF/classes/bonc-security-base.properties' 'security/WEB-INF/classes/cfg.db.deploy.properties' 'security/WEB-INF/classes/bonc-security.properties'
        do
            sed -i "s/CAS_IP:CAS_PORT/${cas_ip}:${cas_port}/g"  $security
            sed -i "s/SE_IP:SE_PORT/${security_ip}:${security_port}/g" $security
            sed -r "s/DB_IP:DB_PORT([/:])DB_NAME/${db_ip}:${db_port}\1${db_name}/g" -i $security
            sed -i "s/DB_USERNAME/${db_username}/g" $security
            sed -i "s/DB_PASSWD/${db_passwd}/g" $security
        done
        
        case $db_type in
            "mysql")
                sed -r '/^#?database.type=mysql$/,+4s/^#//g' -i 'security/WEB-INF/classes/cfg.db.deploy.properties'
                sed -r '/MySQL5Dialect$/s/^#//g' -i 'security/WEB-INF/classes/cfg.db.deploy.properties'
                sed -r '/^#?database.type=mysql$/,+4s/^#//g' -i 'security/WEB-INF/classes/bonc-security.properties'
                sed -i "s/DB_SCHEMA/${db_name}/g" 'security/WEB-INF/classes/cfg.db.deploy.properties'
            ;;
            "oracle")
                sed -r '/^#?database.type=oracle$/,+5s/^#//g' -i 'security/WEB-INF/classes/cfg.db.deploy.properties'
                sed -r '/Oracle10gDialect$/s/^#//g' -i 'security/WEB-INF/classes/cfg.db.deploy.properties'
                sed -r '/^#?database.type=oracle$/,+4s/^#//g' -i 'security/WEB-INF/classes/bonc-security.properties'
                sed -i "s/DB_SCHEMA/${db_username}/g" 'security/WEB-INF/classes/cfg.db.deploy.properties'
            ;;
            *)
            ;;
        esac
    fi
fi

 

你可能感兴趣的:(【Tomcat】shell 部署配置 war包)