source /etc/profile

context_name=report
base_dir=/mnt/report/tomcat
tmp_dir=/data/reports/tmp
version=0.0.1
wf=$context_name.war

cd $base_dir/webapps

function install() {
    rm -rf backup/$wf.bak
    if [ -f $wf ]
    then
        mv $wf backup/$wf.bak
    fi
    rm -rf $context_name
    echo 'Downloading war file...'
    wget -q http://113.105.74.141:8081/artifactory/libs-release/com/uas/report/$context_name/$version/$context_name-$version.war
    echo 'Download succeeded'
    mv $context_name-$version.war $wf
}

function run() {
    ps -ef | grep $base_dir | grep java | awk '{print $2}' | xargs kill -9
    ../bin/catalina.sh start
    tail -f ../logs/catalina.out
}

install

run

