Files
ZYZ/pushdist.sh
2023-05-08 15:20:49 +08:00

102 lines
2.5 KiB
Bash
Executable File

#!/bin/sh
if [ $# != 1 ] ; then
echo "需要1个参数"
exit 1;
fi
port=22
env=${1}
sshAddr=()
buildAddr=''
if [ ${1} == 'alpha' ] ; then
sshAddr=( "zyzalpha")
buildAddr="zyzdev"
port=22
env='alpha'
elif [ ${1} == 'zy' ] ; then
sshAddr=( "yjz-zy-game1" "yjz-zy-game2" "yjz-zy-game3" "yjz-zy-game4" "yjz-zy-game5" "yjz-zy-game6" "yjz-zy-game7" "yjz-zy-game8" "yjz-zy-game9" "yjz-zy-game10")
buildAddr="yjz-zy-web1"
port=22
env='zy1'
elif [ ${1} == 'ch' ] ; then
sshAddr=("yjz-ch-game1" "yjz-ch-game2" "yjz-ch-game3" "yjz-ch-game4" "yjz-ch-game5" "yjz-ch-game6")
buildAddr="yjz-ch-web1"
port=22
env='ch1'
else
echo "需要一个参数指明服务器"
exit 1;
fi
echo "|*********************|\n"
if branch=$(git symbolic-ref --short -q HEAD)
then
echo "git on branch $branch \n"
else
echo "git not on any branch \n"
fi
echo "|*********************|\n"
echo "and config.json is: \n"
node ./config.js ${env} ${1}
cat './game-server/config.json'
echo "\n"
echo "|*********************|\n"
echo "and server_const is \n"
cat './shared/resource/jsons/server_const.json' | grep DEBUG_PAY
cat './shared/resource/jsons/server_const.json' | grep DEBUG_TIME
cat './shared/resource/jsons/server_const.json' | grep CHECK_WORD
cat './shared/resource/jsons/server_const.json' | grep CAN_PAY
cat './shared/resource/jsons/server_const.json' | grep SKIP_ENCODE
echo "\n"
echo "|*********************|"
read -r -p "Are You Sure? [Y/n]" input
case $input in
[yY][eE][sS]|[yY])
destUrl='root@'${buildAddr}':/root/zyz/'
echo $destUrl
rsync -av --include '.babelrc' --include '.eslintrc.js' --exclude-from='exclude-file.txt' --progress --inplace --no-owner --no-group --rsh='ssh -p'${port} . ${destUrl}
ssh $buildAddr "
cd /root/zyz/game-server
npm run build
tar -zcvf dist.tar.gz dist
exit
"
mkdir ~/pushdist
scp root@$buildAddr:/root/zyz/game-server/dist.tar.gz ~/pushdist/dist.tar.gz
length=${#sshAddr[@]}
int=1
while(( $int<=$length ))
do
addr=${sshAddr[$int-1]}
scp ~/pushdist/dist.tar.gz root@$addr:/root/zyz/game-server/dist.tar.gz
ssh $addr "
cd /root/zyz/game-server
tar -zxvf dist.tar.gz
exit
"
let "int++"
done
;;
[nN][oO]|[nN])
echo "No"
;;
*)
echo "Invalid input"
;;
esac
git checkout ./game-server/config.json
git checkout ./gm-server/config/env
git checkout ./web-server/config/env
git checkout ./web-server/config/sshHost.ts