#/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

关于shell脚本函数、数组、字符串截取、svn更新发布实例的更多相关文章

  1. Shell脚本8种字符串截取方法总结

    Linux 的字符串截取很有用.有八种方法. 假设有变量 var=http://www.aaa.com/123.htm. 1. # 号截取,删除左边字符,保留右边字符. 代码如下: echo ${va ...

  2. shell 脚本获取数组字符串长度

    #!/bin/sh source /etc/init.d/functions funOne() { array=(I am dfh kjlhfjksdf sdfj jdkfhaskl mjjoldfu ...

  3. 学习Linux shell脚本中连接字符串的方法

    这篇文章主要介绍了Linux shell脚本中连接字符串的方法,如果想要在变量后面添加一个字符,可以用一下方法: 代码如下: $value1=home $value2=${value1}"= ...

  4. shell脚本函数与数组

    前言 之前写过一篇关于shell脚本流程控制总结,这次继续写关于shell脚本的问题.本篇文章主要包含shell脚本中的函数以及数组的用法介绍.同时也涵盖了一些字符串处理以及shell脚本比较使用的小 ...

  5. Shell基础(四):字符串截取及切割、字符串初值的处理、基使用Shell数组、expect预期交互、使用正则表达式

    一.字符串截取及切割 目标: 使用Shell完成各种Linux运维任务时,一旦涉及到判断.条件测试等相关操作时,往往需要对相关的命令输出进行过滤,提取出符合要求的字符串. 本案例要求熟悉字符串的常见处 ...

  6. shell脚本函数及数组

    函数介绍: 函数function是由若干条shell命令组成的语句块,实现代码重用和模块话编程. 它与shell程序形式上是相似的,不同的是它不是一个单独的进程,不能独立运行,而是shell程序的一部 ...

  7. PHP 函数(数组字符串)

    函数四要素:  参数  变量   返回值  函数体 函数分类: 1.有参数的函数: function Show() { echo "hello"; } Show(); 2. 有返回 ...

  8. shell脚本--函数

    shell的函数和Javacript和php的函数声明一样,只不过shell在调用函数的时候,只需要写函数名就可以调用函数,注意不要在函数名后面加括号 创建并使用函数 #!/bin/bash #文件名 ...

  9. Thinkphp 模板中直接对数据处理 模板中使用函数 中文字符串截取

    1.Thinkphp 模板中直接对数据处理:{$data.name|substr=0,3} 2.中文字符串截取函数:mb_substr=0,14,'utf-8' 3.中文字符串统计:iconv_str ...

随机推荐

  1. js与jQuery对象相互转换

    // jQuery-->JavaScript 两种方法: $(selector).get(index) ; $(selector)[index]; // JavaScript-->jQue ...

  2. Range Modular Queries

    Range Modular Queries 题意 给出一个数列,q个查询,问查询区间内有几个数 a[i] % x == y. 分析 其实裸的分块就能过了,跑的还特别快. 这里分块的作用就是排序. 在x ...

  3. 邪恶改装:TPYBoard制作廉价WIFI干扰器

    转载请注明:@小五义http://www.cnblogs.com/xiaowuyi 0X01 引言 想不想搞个WIFI干扰器?网上搜集了一下资料,发现用esp8266可以实现简单的干扰功能,包括断网. ...

  4. nodeJS实战:自定义模块与引入,不同模块的函数传递及回调处理,exports与module.exports(基于nodejs6.2.0)

    前言:本文基于上一篇文章中的源代码进行改写,地址:http://blog.csdn.net/eguid_1/article/details/52182386 注意:为什么不用module.export ...

  5. Elasticsearch文档查询

    简单数据集 到目前为止,已经了解了基本知识,现在我们尝试用更逼真的数据集,这儿已经准备好了一份虚构的JSON,关于客户银行账户信息的.每个文档的结构如下: { , , "firstname& ...

  6. asp.net web api实现图片点击式图片验证码

    现在验证码的形式越来越丰富,今天要实现的是在点击图片中的文字来进行校验的验证码,如图 这种验证码验证是验证鼠标是否选中了图片中文字的位置,以及选择的顺序,产生验证码的时候可以提供一组底图,然后随机获取 ...

  7. jQuery淡入淡出的轮播图

    html结构: <div class="banna">            <ul class="img">              ...

  8. [leetcode-573-Squirrel Simulation]

    There's a tree, a squirrel, and several nuts. Positions are represented by the cells in a 2D grid. Y ...

  9. C++ inline函数与编译器设置

    1. 经过测试#define与inline的速度几乎没有区别. 2. inline函数更为安全,有效避免了#define二义性问题.inline是真正的函数,而#define只是在字符串意义上的宏替换 ...

  10. Spring+SpringMVC+MyBatis深入学习及搭建(十七)——SpringMVC拦截器

    转载请注明出处:http://www.cnblogs.com/Joanna-Yan/p/7098753.html 前面讲到:Spring+SpringMVC+MyBatis深入学习及搭建(十六)--S ...