1 #!/bin/bash 2 # Author : standby 3 # Date : 2017-05-12 4 # Description : Deploy something. 5 6 . /etc/init.d/functions 7 8 # Usage... 9 function Usage() 10 { 11 echo -e "Usage: /bin/sh $0 arg1 arg2 12 - arg1 like this : data1 | data2 ... 13 - arg2 like this : tag" 14 exit 2 15 } 16 # The core deploy code block here... 17 function deploy() 18 { 19 # Prepare something... 20 # ... 21 # Deploy some crontab and script... 22 # ... 23 } 24 # Verificate the arguments. 25 function verificate() 26 { 27 result=0 28 available=`df -m |grep $1$ |awk '{print $4}'` 29 [[ $available -lt 1000000 ]] && result=1 30 [[ $2 == x* ]] || result=2 31 #[ $2 == x* ] || result=2 32 echo $result 33 } 34 # Start something processes. 35 function start_work() 36 { 37 if [ $1 -eq 1 ] 38 then 39 echo -e " " 40 action "Deploy something successful." /bin/true 41 echo -e " Begin to start something process... " 42 # start something cmd here ... 43 if [ $? -eq 0 ] 44 then 45 action "Start something successful." /bin/true 46 else 47 action "Start something failed." /bin/false 48 fi 49 elif [ $1 -eq 2 ] 50 then 51 action "Deploy something failed." /bin/false 52 exit -1 53 else 54 action "You are not expected to undestand this code block ->_->" /bin/true 55 fi 56 } 57 # Main code body. 58 function main() 59 { 60 [[ $1 == dat* ]] || Usage 61 result=`verificate $1 $2` 62 #echo $result 63 if [ $result -eq 0 ] 64 then 65 #echo "Hello world!" 66 deploy $1 $2 67 [ $? -eq 0 ] && start_work 1 || start_work 2 68 elif [ $result -eq 1 ] 69 then 70 echo "$1 have less than 1T space left" 71 exit 1 72 elif [ $result -eq 2 ] 73 then 74 echo "The arg2 must start with 'x', not $2" 75 exit 2 76 fi 77 } 78 # Start here... 79 if [ $# -ne 2 ] 80 then 81 Usage 82 else 83 main $1 $2 84 fi