From d7f6ae73e1a7d564f01839173d2920c9e1e53308 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Mon, 26 Jan 2015 10:11:31 +0100 Subject: [PATCH] Add -a parameter to only run after_upgrade() function --- check_rc_upgrade.sh | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/check_rc_upgrade.sh b/check_rc_upgrade.sh index 9d2a226..ff2cbdd 100755 --- a/check_rc_upgrade.sh +++ b/check_rc_upgrade.sh @@ -22,6 +22,7 @@ NAGIOS=0 UPGRADE=0 EXTRACT=0 JUST_DISP=0 +JUST_AFTER_UPGRADE=0 function usage() { echo "Usage : $0 [-v] [-n] [-d] [-u]" @@ -29,11 +30,12 @@ function usage() { echo " -n Nagios mode" echo " -d Download new release" echo " -u Upgrade installation" + echo " -a Just run after_upgrade function" echo " -j Just display current stable version" echo " -h Display this help" } -while getopts ":dvnhuj" opt; do +while getopts ":dvnhuaj" opt; do case $opt in v) DEBUG=1 @@ -50,6 +52,9 @@ while getopts ":dvnhuj" opt; do DEBUG=1 EXTRACT=1 ;; + a) + JUST_AFTER_UPGRADE=1 + ;; j) JUST_DISP=1 ;; @@ -75,6 +80,28 @@ done [ -f "$0.local" ] && source "$0.local" && [ $DEBUG -eq 1 ] && echo "Import local config file : $0.local" +function run_after_upgrade() { + RC_NEW_HOME="$1" + type after_upgrade > /dev/null 2>&1 + if [ $? -eq 0 ] + then + echo "Execution de la fonction custom after_upgrade() :" + after_upgrade "$RC_NEW_HOME" + res=$? + echo "Fin de la fonction after_upgrade() (Retour : $res)" + return $res + else + echo "La fonction 'after_upgrade' n'est pas définie. On passe." + return 0 + fi +} + +if [ $JUST_AFTER_UPGRADE -eq 1 ] +then + run_after_upgrade "$RC_HOME" + exit $? +fi + for i in `seq 1 $MAX_CHECK` do tmpfile=`mktemp` @@ -246,13 +273,7 @@ then cd "$src" ./bin/installto.sh "$to" - type after_upgrade > /dev/null 2>&1 - if [ $? -eq 0 ] - then - echo "Execution de la fonction custom after_upgrade() :" - after_upgrade "$to" - echo "Fin de la fonction after_upgrade()" - fi + run_after_upgrade "$to" if [ -L "$RC_HOME" ] then