#/bin/bash
#功能:QA服根据模板创建区配置文件并提交到svn上。
SOURCE_PATH=/data/source_code
SVN_PATH=/code/psm #svn发布目录,要先推送到这个目录,然后更新提交
dir="/data/source_code/configfiles"
default_conf="config.properties"
default_socket_conf="socket.lp"
LOG_FILE='/tmp/log.log'
usage(){
cat <<EOF
echo_error 使用说明:
sh $0 username create_one_zone_config #根据区参数匹配/data/source_code/configfiles/conf目录下各分区配置信息生成参数指定单个区配置文件
sh $0 username delete_one_zone_config #根据区参数匹配/data/source_code/configfiles/conf目录下各分区配置信息删除参数指定单个区配置文件
EOF
exit 1
}
if [ $# -eq 0 ] ; then
usage
fi
change_config_file(){
#根据/data/source_code/configfiles/conf目录下各分区配置信息生成区配置文件
ZONE_FILE="$1"
yunyingshang=`echo ${ZONE_FILE}|awk -F'_' '{print $2}'`
source ${dir}/conf/${ZONE_FILE} #引用模板文件
[ ! -d ${SOURCE_PATH}/zonefile/${yunyingshang}/${ZONE_FILE}/bin/boot ] && mkdir -p ${SOURCE_PATH}/zonefile/${yunyingshang}/${ZONE_FILE}/bin/boot
####生成和修改区配置文件
cp -rf ${dir}/${default_conf} ${SOURCE_PATH}/zonefile/${yunyingshang}/${ZONE_FILE}/bin/
cp -rf ${dir}/${default_socket_conf} ${SOURCE_PATH}/zonefile/${yunyingshang}/${ZONE_FILE}/bin/boot/
sed -i -e "s#game.serverId=.*#game.serverId=${QA_CONF[0]}#" \
-e "s#game.serverName=.*#game.serverName=${QA_CONF[1]}#" \
-e "s#game.serverIp=.*#game.serverIp=${QA_CONF[2]}#" \
-e "s#game.loginDomain=.*#game.loginDomain=${QA_CONF[3]}#" \
-e "s#redis.host=.*#redis.host=${QA_CONF[6]}#" \
-e "s#mysql.host=.*#mysql.host=${QA_CONF[8]}#" \ ####使用数组功能。
${SOURCE_PATH}/zonefile/${yunyingshang}/${ZONE_FILE}/bin/${default_conf}
sed -i "s#port=.*#port=${QA_CONF[9]}#" ${SOURCE_PATH}/zonefile/${yunyingshang}/${ZONE_FILE}/bin/boot/${default_socket_conf}
echo "one configuration file has been generated"
###从生成目录同步区配置到SVN发布目录。
rsync -avz --exclude=".svn" ${SOURCE_PATH}/zonefile/${yunyingshang}/* ${SVN_PATH}/zonefile/${yunyingshang}/ >> ${LOG_FILE}
###区文件推到GM目录。
rsync -avz --exclude=".svn" ${SOURCE_PATH}/zonefile/${yunyingshang}/${ZONE_FILE}/bin/${default_conf} ${SVN_PATH}/psm_gm/zq/config/subserver/${QA_CONF[0]}.properties >> ${LOG_FILE}
}
change_one_zone_config_file(){
change_config_file "${ZONE_NAME}"
}
delete_one_zone_config_file(){
delete_config_file "${ZONE_NAME}"
}
delete_config_file(){
ZONE_FILE="$1"
yunyingshang=`echo ${ZONE_FILE}|awk -F'_' '{print $2}'`
source ${dir}/conf/${ZONE_FILE}
rm -rf ${dir}/conf/${ZONE_FILE}
rm -rf ${SOURCE_PATH}/zonefile/${yunyingshang}/${ZONE_FILE}
rm -rf ${SVN_PATH}/zonefile/${yunyingshang}/${ZONE_FILE}
rm -rf ${SVN_PATH}/psm_gm/zq/config/subserver/${QA_CONF[0]}.properties
echo "delete_one_zone_config is OK!"
}
update()
{
$SVN update --username ${SVN_NAME}
if [ $? -ne 0 ];then
echo "svn update failed"
exit 1
fi
VERSION=`$SVN info |awk -F"[ ]+" '/Revision/{print $2}'`
TEMP="`date +%Y%m%d`${VERSION}"
NUM=`echo ${TEMP}+1|bc`
echo -e "####################\nsvn update complete"
}
commit ()
{
#svn commit
echo "cd ${1:-${SVN_PATH}}"
cd ${1:-${SVN_PATH}}
[ ! -d ${LOG_PATH} ] && mkdir -p ${LOG_PATH}
mkdir -p ${LOG_PATH}/${VERSION}
$SVN status |awk '{if($1=="!") print $0}' |cut -b 9- >${LOG_PATH}/${VERSION}/svn_del.log
$SVN status |awk '{if($1=="?") print $0}' |cut -b 9- >${LOG_PATH}/${VERSION}/svn_add.log
$SVN status |awk '{if($1=="M") print $0}' |cut -b 9- >${LOG_PATH}/${VERSION}/svn_change.log
while read line ;do $SVN delete "$line" ;done <${LOG_PATH}/${VERSION}/svn_del.log && echo "svn delete complete"
while read line ;do $SVN add "$line" ;done <${LOG_PATH}/${VERSION}/svn_add.log && echo "svn add complete"
$SVN commit -m "`date +%Y%m%d%H%M%S`" --username ${SVN_NAME} && echo "svn commit complete"
#删除认证文件
rm -f /root/.subversion/auth/svn.simple/*
}
if [ -n "$2" ];then
SVN_NAME="$1"
case $2 in
create_one_zone_config)
if [ -n "$3" ];then
change_one_zone_config_file
else
echo -e "Please input zone name parameter for change_one_zone_config_file! For example: \c" && echo -e "\033[40;32;1m create_one_zone_config psm_9wee_s0 \c" && echo -e "\033[0m!"
exit 1
fi
update
commit
;;
delete_one_zone_config)
if [ -n "$3" ];then
delete_one_zone_config_file
else
echo -e "Please input zone name parameter for delete_one_zone_config_file! For example: \c" && echo -e "\033[40;32;1m delete_one_zone_config psm_9wee_s0 \c" && echo -e "\033[0m!"
exit 1
fi
update
commit
;;
*)
usage
;;
esac
fi