码迷,mamicode.com
首页 > 其他好文 > 详细

git-自动化脚本

时间:2017-09-26 10:45:14      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:git自动化脚本 git-版本回滚

首先我们要从https://github.com/github 上申请一个GitHub仓库。(过程就不介绍了)

现在我们来写个git的自动回滚脚本-通过版本号来回滚代码。

cat /usr/local/src/git.sh

#!/bin/bash

#author:xiaozhagn

mail_user="1179570cab@qq.com"

WORK_DIR=/learngit/

REPLOY="zrh"

SRC_DIR=/data  #已存在

IP=172.25.0.31

GITHUB=git@github.com:xiaozhagn/zrh.git

send_mail () {

   echo "$1" | mail -s "Gits current version" $mail_user

}


git_pull(){

    if [ ! -d $WORK_DIR ];then

        mkdir $WORK_DIR

    fi

}

git_add_tag(){

   git_pull

   tag_num=$(($(git tag | wc -l)+1))

   tag_deploy="v$tag_num.0"

   git tag -a $tag_deploy -m "$tag_deploy"

   git push -f

   git push --tag

}


git_deploy(){

   rsync -vzrtopg --progress $WORK_DIR/$REPLOY/* $IP:$SRC_DIR

   cd $WORK_DIR/$REPLOY

   tag_status=$(git tag | tail -n 1)

   echo "$tag_status" 

   send_mail $tag_status

   ssh 172.25.0.31 ln -s $SRC_DIR /web/

}

git_reset(){

    PS3="Select a number: "

    cd $WORK_DIR/$REPLOY

    while true ; do

    read -p "Does  reset your version yes/no": input

        if [ $input == yes ]; then

           select rollback in  "quick rollback" "rollback you need version"; do

                case $rollback in


                   "quick rollback")

                      git   reset --hard HEAD^

                      git   push -f

                      tag1_status=$(git tag | tail -n 1)

                      send_mail  $tag1_status

                      echo  $tag1_status

                   

 quit

                      ;;

                   "rollback you need version" )

                      list_version=$(git tag)

                      select  version  in $list_version ; do

                      gti reset --hart $version

                      git push -f

                      tag2_status=$(git tag | tail -n 1)

                      send_mail  $tag2_status

                      echo  $tag2_status

                      break

                      done ;;


                  esac

           done

 else

               if [ $input == no ]; then

                exit

               fi

               if [ $input == * ] ; then

               echo "Please  yes or on"

               fi

        fi

done


}

line(){

 echo "Please echo \"main\""  

 echo "If you check your script file please input \"git_add_tag/git_deploy/git_reset again\" " 


 }

line

main(){

   git_add_tag

   git_deploy

   git_reset

}

$1



本文出自 “我的运维” 博客,谢绝转载!

git-自动化脚本

标签:git自动化脚本 git-版本回滚

原文地址:http://xiaozhagn.blog.51cto.com/13264135/1968620

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!