抄了一个

#!/bin/bash 
2 
 
3 #Date/Time 
4 CTIME=$(date "+%Y-%m-%d-%H-%M") 
5 
 
6 #Shell 
7 CODE_DIR="/deploy/code/deploy" 
8 CONFIG_DIR="/deploy/config" 
9 TMP_DIR="/deploy/tmp" 
10 TAR_DIR="/deploy/tar" 
11 
 
12 
 
13 usage(){ 
14     echo $"Usage: $0 [ deploy | rollback-list | rollback-pro ver]" 
15 } 
16 
 
17 git_pro(){ 
18   echo "begin git pull" 
19   cd "$CODE_DIR" && git pull 
20   API_VERL=$(git show | grep commit | cut -d ' ' -f2) 
21   API_VER=$(echo ${API_VERL:0:6}) 
22   cp -r "$CODE_DIR" "$TMP_DIR" 
23 } 
24 
 
25 config_pro(){ 
26   echo "copy pro config to dir" 
27   /bin/cp "$CONFIG_DIR"/* $TMP_DIR/deploy/ 
28   TAR_VER="$API_VER"-"$CTIME" 
29   cd $TMP_DIR && mv deploy pro_deploy_"$TAR_VER" 
30 } 
31 
 
32 tar_pro(){ 
33   echo "begin tar" 
34   cd $TMP_DIR && tar czf pro_deploy_"$TAR_VER".tar.gz pro_deploy_"$TAR_VER" 
35   echo "tar end pro_deploy_"$TAR_VER".tar.gz" 
36 } 
37 
 
38 scp_pro(){ 
39   echo "begin scp" 
40   /bin/cp $TMP_DIR/pro_deploy_"$TAR_VER".tar.gz /opt 
41   #scp $TMP_DIR/pro_deploy_"$TAR_VER".tar.gz 192.168.1.2:/opt 
42   #scp $TMP_DIR/pro_deploy_"$TAR_VER".tar.gz 192.168.1.3:/opt 
43   #scp $TMP_DIR/pro_deploy_"$TAR_VER".tar.gz 192.168.1.4:/opt 
44 } 
45 #执行部署操作 
46 deploy_pro(){ 
47   #socat haproxy unix nginx  
48   echo "begin deploy" 
49   cd /opt && tar zxf pro_deploy_"$TAR_VER".tar.gz 
50   rm -f /var/www/html && ln -s /opt/pro_deploy_"$TAR_VER" /var/www/html 
51 } 
52 #测试部署 
53 test_pro(){ 
54   echo "begin test" 
55   #curl --head http://192.168.56.31/index.php | grep xxxx 
56   echo "add cluster" # socat haproxy-nginx+php 
57 } 
58 #回滚列表 
59 rollback_list(){ 
60   ls -l /opt/*.tar.gz 
61 } 
62 #制定版本回滚 
63 rollback_pro(){ 
64   #ssh 192.168.56.31  
65   rm -f /var/www/html && ln -s /opt/$1 /var/www/html 
66 } 
67 #主函数,对之前编写的进行组合 
68 main(){ 
69   case $1 in 
70     deploy) 
71         git_pro; 
72         config_pro; 
73         tar_pro; 
74         scp_pro; 
75         deploy_pro; 
76         test_pro; 
77         ;; 
78     rollback-list) 
79         rollback_list; 
80         ;; 
81     rollback-pro) 
82         rollback_pro $2; 
83         ;; 
84     *) 
85         usage; 
86   esac 
87 } 
88 main $1 $2 
原文地址:https://www.cnblogs.com/gaoyuechen/p/7648466.html