bm灰度更新shell脚本一

bm灰度更新shell脚本一


[root@huidu-xxxtyt shell]# cat xxxtyt_huidu_update.sh 
#!/bin/bash
# Author : royoy
# Date   : 2019/05
# Desc   : xxxtyt_huidu_update.sh "args"
# Args   : [ xxxtyt | xytt | xxxtyt-mobile-h5 | xxxtyt-mobile-api ]
# Eg     : ./xxxtyt_huidu_update.sh xxxtyt

project_name="xxxtyt xytt xxxtyt-mobile-h5 xxxtyt-mobile-api"
h5_conf_dir="/data/xxxtyt-mobile-h5/src/app/config"
update_log="/var/log/xxxtyt_huidu_update.log"
record_log="tee -a $update_log"
gitlab_host="xx.xx.xx.xx"
tmp_file="/tmp/xxxtyt-mobile-h5.txt"
yarn_log=/tmp/yarn.log
yarn_error_log=/tmp/yarn_error.log

if test -z "$1" || ! [[ $project_name =~ "$1" ]];then font "Usage: ./`basename $0` (xxxtyt|xytt|xxxtyt-mobile-h5|xxxtyt-mobile-api)" -n;exit 3;fi

# update func
cd /data/$1 && {
# start update $1
font -n "============================start HuiDu $1 update============================" -n | $record_log
if [ "xmlxxxtyt-mobile-h5" == "xml$1" ];then
# update h5 huidu
        font -d "Start to execute Git Pull for $1 on Huidu" -n | $record_log
        git pull |& tee $tmp_file |& $record_log && (exit ${PIPESTATUS[0]}) || {
                font -n -d "Git Pull on HuiDu" -t -red "Failed" -reset -n | $record_log
                exit 31
        }
        [ "Already up-to-date" = "`grep -oE '(Already up-to-date|new branch)' $tmp_file`" ] && font -n -d "$1 " -yellow "codes not changed" -reset | $record_log || {
                font -n -d "Git Pull codes on HuiDu" -t -green "OK" -reset -n | $record_log
                cd ${h5_conf_dir} && {
                        /bin/cp -f product.config.ts config.ts && {
                                font -d "Copy product.config.ts to config.ts" -t -green "OK" | $record_log
                                /usr/bin/yarn build  > >(tee $yarn_log) 2> >(tee $yarn_error_log >&2) && {
                                        font -d "yarn build" -t -green "Success" -reset -n | $record_log
                                        font -d "HuiDu $1 update" -t -green "Finish" -reset -n | $record_log
                                } || {
                                        font -d "yarn build" -t -red "ERROR" -reset -n | $record_log ;exit 2
                                }
                        } || {
                                font -d -red "Can not copy product.config.ts to config.ts" -reset -n ;exit 33
                        }
                } || font -d "Not found ${h5_conf_dir}" | $record_log ;exit 33
        }
elif [ "xmlxxxtyt" == "xml$1" ];then
# update xxxtyt huidu
        font -d "start to execute Codes Merge and Push for $1 on Gitlab" -n | $record_log
        ssh ${gitlab_host} "/data/shell/xxxtyt_codes_update.sh" && {
                font -n -d "Gitlab Codes Push" -t -green "OK" -reset -n -n -d -purple "Start git pull on huidu..." -reset -n | $record_log
                git pull |& $record_log && (exit ${PIPESTATUS[0]}) && font -n -d "HuiDu $1 git pull" -t -green "OK" -reset -n -d "HuiDu $1 update" -t -green "Finish" -reset -n | $record_log || {
                        font -d "HuiDu git pull" -t -red "ERROR" reset -n | $record_log ;exit 6
                }
        } || {
                font -d "Merge or Push codes on Gitlab" -t -red "ERROR" -reset -n ;exit 5
        }
else
# update api or xytt
        font -d "Start to execute git pull for $1 on Huidu" -n | $record_log
        git pull |& $record_log && (exit ${PIPESTATUS[0]}) && {
                font -n -d "HuiDu $1 git pull" -t -green "OK" -reset -n | $record_log 
                font -d "HuiDu $1 update" -t -green "Finish" -reset -n | $record_log 
        } || {
                font -d "HuiDu $1 git pull" -t -red "ERROR" -reset -n | $record_log ;exit 6
        }
fi
} || {
        font -d -red "Not found /data/$1 dir" -reset -n ;exit 33
}