#!/bin/bash
#wangmo
#20171206
#Update xizang project code
code=/root/code/xizang_PAD_project/PHP_business_server/tfcms
path=/home/seim
#ip=x.x.x.x
ip=x.x.x.x
time=`date +%Y%m%d-%H%M`
upload=/home/seim/upload
upload_ln=/home/seim/tfcms/public/
config=/root/code/xizang_PAD_project/PHP_business_server/tfcms/public/index.php
#Determine the results
result() {
if [ $? != 0 ];then
echo -e "\033[31m$ip $faild\033[0m" && exit 1
else
echo -e "\033[32m$ip $ok\033[0m"
fi
}
#usage: $1 is commit ID
if [ $# -lt 1 ];then
echo -e "\033[31m usage: sh $0 Tag_ID\033[0m"
echo -e "\033[31m example: sh $0 da14fbb1f38000e045f3e350e1e8d543e8b776e1 \033[0m"
echo -e "\033[31m explain: 升级主机要配置ssh免密,可以使用auto_ssh.sh \033[0m" && exit 2
fi
#pull tag code
ok="checkout tag ok !";faild="checkout tag faild !"
if [ -d $code ];then
cd $code
git checkout main_dev
git pull
git reset --hard $1
else
echo -e "\033[31m$code not exist\033[0m" && exit 4
fi
#backup remote code
ok="backup code ok !";faild="backup code faild !"
ping -c 1 $ip
if [ $? == 0 ];then
ssh -t -p 22 root@$ip "cd $path/tfcms"
if [ $? == 0 ];then
ssh -t -p 22 root@$ip "\cp -arf $path/tfcms/ $path/backup/tfcms_$time\_bak"
result
else
echo -e "\033[31m$ip $path not exist !\033[0m" && exit 5
fi
else
echo -e "\033[31m$ip network unreachable !\033[0m" && exit 6
fi
#rsync code to remote
ok="rsync code ok !";faild="rsync code faild !"
rsync -avzp --delete --exclude-from="/root/scripts/xizang/exclude.list" --exclude '.git' $code root@$ip:$path
result
Create soft connections
ok="Create soft connections ok !";faild="Create soft connections faild !"
ssh -t -p 22 root@$ip "ln -s $upload $upload_ln"
result
#set permission
ok="set permission ok !";faild="set permission faild !"
ssh -t -p 22 root@$ip "chmod -R 755 $path"
ssh -t -p 22 root@$ip "chown -R seim.seim $path"
result