bm灰度更新shell脚本二

bm灰度更新shell脚本二

#!/bin/bash
# Author  : royoy
# Version : v0.0.2
# Date	  : 2019/05
# Desc	  : update code for bm huidu
 
# Source font file
. /etc/rc.d/init.d/font

salt_bin="/bin/salt"
bm_huidu="bm_huidu_10.5.66.3"
remote_script="/datas/shells/bm_huidu_update.sh"

usage(){
	echo -e "\nUsage:\n\t`basename $0` [ -b bm | -x xytt | -h h5 | -a api ]"
	exit 33
}

# function func
update_func(){
        font -purple "start to exec $1 huidu update..." -reset -n
        $salt_bin "$bm_huidu" cmd.run "$remote_script $1" && font -n -d -purple "$1 huidu update" -reset -t -green "Success" -reset -n \
	|| font -n -d "$1 huidu update" -t -red "Failed" -reset -n
}

# update bm huidu
bm(){
	update_func bmm
}

# update xytt huidu
xytt(){
	update_func xytt
}

# update h5 huidu
h5(){
	update_func bm-mobile-h5
}

# update api huidu
api(){
	update_func bm-mobile-api
}

# Interactive mode
while [[ $# -eq 0 ]]
do
	stty erase ^H
	echo "Please input option: ( b|bm ) ( x|xytt ) ( h|h5 ) ( a|api ) ( q|e|quit|exit )"
	read OPTARG
	case $OPTARG in
		bm|b)
			bm
			;;	
		xytt|x)
			xytt
			;;
		h5|h)
			h5
			;;
		api|a)
			api
			;;
		exit|quit|q|e)
			exit
	esac
done

# Auto mode
while getopts ":b:x:h:a:" opt
do
	case $opt in
		b)
			$OPTARG
			;;
		x)
			$OPTARG
			;;
		h)
			$OPTARG
			;;
		a)
			$OPTARG
			;;
		\?)
			font "Invalid option: -$OPTARG" -n
			usage
			;;
	esac
done