Maven打包部署脚本

时间:2024-01-13 16:29:26
#!/bin/sh

SVN_USER_NAME=
SVN_PASSWORD=

ROOT_PATH
PROJECT_NAME
ACTION
SVN_LIB_ROOT

USER_ACCOUNT
PASSWORD
HOST
PORT
COMMAND

netty_common='netty-common'
netty_common_server='netty-common-server'
netty_common_client='netty-common-client'
netty_chat_common='netty-chat-common'

tip () {
echo "usage: deploy_base.sh ROOT_PATH PROJECT_NAME ACTION SVN_LIB_ROOT USER_ACCOUNT PASSWORD HOST COMMAND"
}

#update_src () {
#if [ -d $1 ]; then
#cd $
#svn update
#else
#svn co svn: --username $2 --password $3 $1
#cd $
#fi
#}

mvn_pkg(){
mvn package
}

mvn_install(){
mvn install
}

update_lib () {
path-lib"
if [ -d $path ]; then
cd $path
svn update
else
svn co $/lib --username $2 --password $3 $path
cd $path
fi

}

cp_lib () {
cp target/lib/*.jar "$1-lib"
cp target/*.jar "$1-lib"
}

commit_lib () {
cd "$1-lib"
svn add *.jar
svn commit -m "package & deploy $1"
}

restart(){
auto_login_ssh $1 $2@$3 $4 $COMMAND
}

auto_login_ssh () {

expect -c "set timeout -1;
spawn -noecho ssh -p $3 -o StrictHostKeyChecking=no $2 ${@:4};
expect *assword:*;
send -- $1\r;
interact;";
}

if [ $# -lt 8 ];then
tip
exit 0;
fi

case "$ACTION" in

restart)
restart $PASSWORD $USER_ACCOUNT $HOST $PORT
;;

deploy | deploy_delete)

cd $ROOT_PATH

if [ -d "../$netty_common/" ];then
cd ../$netty_common/
mvn_install
fi

if [ -d "../$netty_common_server/" ];then
cd ../$netty_common_server/
mvn_install
fi

if [ -d "../$netty_common_client/" ];then
cd ../$netty_common_client/
mvn_install
fi

if [ -d "../$netty_chat_common/" ];then
cd ../$netty_chat_common/
mvn_install
fi

if [ -d "../$netty_common/" ];then
cd ../$PROJECT_NAME/
fi

mvn_pkg

update_lib $PROJECT_NAME $SVN_USER_NAME $SVN_PASSWORD $SVN_LIB_ROOT
cd ../

cp_lib $PROJECT_NAME

commit_lib $PROJECT_NAME
cd ../

restart $PASSWORD $USER_ACCOUNT $HOST $PORT
;;
*)
tip
esac

exit 1