Add -a parameter to only run after_upgrade() function
Benjamin Renard

Benjamin Renard commited on 2015-01-26 09:11:51
Showing 1 changed files, with 29 additions and 8 deletions.

... ...
@@ -22,6 +22,7 @@ NAGIOS=0
22 22
 UPGRADE=0
23 23
 EXTRACT=0
24 24
 JUST_DISP=0
25
+JUST_AFTER_UPGRADE=0
25 26
 
26 27
 function usage() {
27 28
 	echo "Usage : $0 [-v] [-n] [-d] [-u]"
... ...
@@ -29,11 +30,12 @@ function usage() {
29 30
 	echo "  -n   Nagios mode"
30 31
 	echo "  -d   Download new release"
31 32
 	echo "  -u   Upgrade installation"
33
+	echo "  -a   Just run after_upgrade function"
32 34
 	echo "  -j   Just display current stable version"
33 35
 	echo "  -h   Display this help"
34 36
 }
35 37
 
36
-while getopts ":dvnhuj" opt; do
38
+while getopts ":dvnhuaj" opt; do
37 39
 	case $opt in
38 40
 		v)
39 41
 			DEBUG=1
... ...
@@ -50,6 +52,9 @@ while getopts ":dvnhuj" opt; do
50 52
 			DEBUG=1
51 53
 			EXTRACT=1
52 54
 		;;
55
+		a)
56
+			JUST_AFTER_UPGRADE=1
57
+		;;
53 58
 		j)
54 59
 			JUST_DISP=1
55 60
 		;;
... ...
@@ -75,6 +80,28 @@ done
75 80
 
76 81
 [ -f "$0.local" ] && source "$0.local" && [ $DEBUG -eq 1 ] && echo "Import local config file : $0.local"
77 82
 
83
+function run_after_upgrade() {
84
+	RC_NEW_HOME="$1"
85
+	type after_upgrade > /dev/null 2>&1
86
+	if [ $? -eq 0 ]
87
+	then
88
+		echo "Execution de la fonction custom after_upgrade() :"
89
+		after_upgrade "$RC_NEW_HOME"
90
+		res=$?
91
+		echo "Fin de la fonction after_upgrade() (Retour : $res)"
92
+		return $res
93
+	else
94
+		echo "La fonction 'after_upgrade' n'est pas définie. On passe."
95
+		return 0
96
+	fi
97
+}
98
+
99
+if [ $JUST_AFTER_UPGRADE -eq 1 ]
100
+then
101
+	run_after_upgrade "$RC_HOME"
102
+	exit $?
103
+fi
104
+
78 105
 for i in `seq 1 $MAX_CHECK`
79 106
 do
80 107
 	tmpfile=`mktemp`
... ...
@@ -246,13 +273,7 @@ then
246 273
 		cd "$src"
247 274
 		./bin/installto.sh "$to"
248 275
 
249
-		type after_upgrade > /dev/null 2>&1
250
-		if [ $? -eq 0 ]
251
-		then
252
-			echo "Execution de la fonction custom after_upgrade() :"
253
-			after_upgrade "$to"
254
-			echo "Fin de la fonction after_upgrade()"
255
-		fi
276
+		run_after_upgrade "$to"
256 277
 
257 278
 		if [ -L "$RC_HOME" ]
258 279
 		then
259 280