From 04946977d99e3379a31ea7fd26827b537ee18163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Mon, 22 Jun 2020 14:04:57 +0200 Subject: [PATCH] Add message on stdout and quiet mode --- cluster/sge.enable.host.queue.sh | 40 +++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/cluster/sge.enable.host.queue.sh b/cluster/sge.enable.host.queue.sh index 30c140c..b35a725 100755 --- a/cluster/sge.enable.host.queue.sh +++ b/cluster/sge.enable.host.queue.sh @@ -8,6 +8,9 @@ readonly NBARGS="${#}" ## Test if DEBUG is already defined (by parent script,…) [ -z "${DEBUG}" ] && DEBUG=1 +# If output message should be displayed +[ -z "${OUTPUT_MESSAGE}" ] && OUTPUT_MESSAGE=0 + # Maco temp file readonly MACO_TMP_FILE="/tmp/.maco.upgrade" readonly MACO_TMP_URGENT_FILE="/tmp/.maco.urgent.upgrade" @@ -28,10 +31,11 @@ readonly COLOR_DEBUG="${PURPLE}" usage() { # {{{ cat <<- EOF -usage: $PROGNAME [--help|-d,--debug] [hostname] +usage: $PROGNAME [--help|-d,--debug|-q,--quiet] [hostname] -Try to enable all SGE queues of the current host (default) -or the one passed as first argument. +Try to enable all SGE queues of the current host (default), +if no pending upgrades (Maco, APT) are present, +or to the one passed as first argument (no upgrades checking). EXAMPLES : - Enable SGE's queue(s) of the current host @@ -39,6 +43,17 @@ EXAMPLES : - Enable SGE's queue(s) of "marvin.domain.tld" host ${PROGNAME} marvin.domain.tld + +OPTIONS : + --help + Print this help message. + + -d,--debug + Enable debug messages. + + -q,--quiet + Disable messages on standard output (except for error). + EOF } @@ -50,6 +65,17 @@ debug_message() { # {{{ ## Print message if DEBUG is enable (=0) [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG − ${PROGNAME} : ${local_debug_message}" +} +# }}} +message() { # {{{ + + local_message="${1}" + + ## Print message if OUTPUT_MESSAGE is enable (=0) + [ "${OUTPUT_MESSAGE}" -eq "0" ] && printf '%b\n' "${local_message}" + + return 0 + } # }}} is_apt_upgrade_present() { # {{{ @@ -208,7 +234,7 @@ Try to enable SGE queue: ${RED}${local_sge_queue_name:=/dev/null}@${local_sge_ho qmod --enable "${local_sge_queue_name}@${local_sge_hostname}" \ && return_enable_queue="${?}" else - debug_message "SGE queue: ${RED}${local_sge_queue_name:=/dev/null}@${local_sge_hostname:=/dev/null}${RESET} was manually disabled, please re-enable it ${RED}manually${RESET}." + message "SGE queue: ${RED}${local_sge_queue_name:=/dev/null}@${local_sge_hostname:=/dev/null}${RESET} was manually disabled, please re-enable it ${RED}manually${RESET}." return_enable_queue="1" fi @@ -302,8 +328,10 @@ if [ ! "${NBARGS}" -eq "0" ]; then ;; -d|--debug ) ## debug DEBUG=0 - ## Re-export new DEBUG value - export DEBUG + ;; + -q|--quiet ) ## Silent mode + ## Avoid to display any message on standard output + OUTPUT_MESSAGE=1 ;; -- ) ## End of options list ## End the while loop