關於shell指令碼函數、數組、字串截取、svn更新發布執行個體

來源:互聯網
上載者:User

標籤:login   eof   [1]   ati   svn add   /tmp   檔案   bin   sed   

#/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_NAME=$1

      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 ()

{

LOG_PATH="/code/svnlog"

      #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 $1

                      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 $1

               commit

                ;;

           *)

                      usage

                      ;;

           esac

fi

 

關於shell指令碼函數、數組、字串截取、svn更新發布執行個體

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.