scplt预生产更新发布

scplt预生产更新发布

#!/bin/bash
# Author  : royoy
# Version : v0.0.1
# Date	  : 2016/02
# Desc	  : update code for scplt pre
 
# Source font file
. /etc/rc.d/init.d/font

stty erase ^H
Host_IP="10.10.10.10"
set -e

usage(){
	echo -e "\nUsage:\n\t`basename $0` [ -u update | -c clear | -a autoload | -v version ]"
	exit
}

# update codes, include all machines
rsync(){
	font -purple "start to exec $OPTARG ..." -reset -n
	/data/shell/code_sync.sh && ssh $Host_IP "/data/shell/code_sync.sh" && font -t -green "rsync done" -reset -n && ssh 10.10.11.154 "/data/shell/code_sync.sh" && font -t -green "mmc rsync done" -reset -n
}

# clear cache, only web, not include other machines
clear(){
	font -purple "start to exec $OPTARG ..." -reset -n
	cd /data/codes/preproduct && composer clear-tplcache && ssh 10.10.11.154 "cd /data/codes/preproduct && composer clear-tplcache" && font -t -green "clear done" -n -t "mmc clear done" -reset -n
}

# composer dump-autoload code, include all machines
autoload(){
	font -purple "start to exec $OPTARG ..." -reset -n
	cd /data/codes/preproduct && composer dump-autoload && ssh $Host_IP "cd /data/codes/preproduct && composer dump-autoload" && ssh 10.10.11.154 "cd /data/codes/preproduct && composer dump-autoload" && font -t -green "\tautoload done" -reset -n
}

# update the version of the static resources, include all machines
version(){
	font -purple "start to exec $OPTARG ..." -reset -n
	cd /data/codes/preproduct && composer update-version && ssh $Host_IP "cd /data/codes/preproduct && composer update-version" && font -t -green "version done" -reset -n && ssh 10.10.11.154 "cd /data/codes/preproduct && composer update-version" && font -t -green "mmc version done" -reset -n
}

# Interactive mode
while [[ $# -eq 0 ]]
do
	echo "Please input option clear|update|autoload|version|exit"
	read OPTARG
	case $OPTARG in
		update|u)
			rsync
			;;	
		clear|c)
			clear
			;;
		autoload|a)
			autoload
			;;
		version|v)
			version
			;;
		exit|quit|q|e)
			exit
	esac
done

# Auto mode
while getopts ":u:c:a:v:" opt; do
	case $opt in
		u)
			rsync
			;;
		c)
			clear
			;;
		a)
			autoload
			;;
		v)
			version
			;;
		\?)
			font "Invalid option: -$OPTARG" -n
			usage
			;;
	esac
done