From 842543d62fe645f6dec04d674bbc4dfcf727f57a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Fri, 12 Jun 2020 15:23:28 +0200 Subject: [PATCH] Add information messages and silent mode --- cluster/maco.check.update.sh | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/cluster/maco.check.update.sh b/cluster/maco.check.update.sh index ceedb03..1f432fb 100755 --- a/cluster/maco.check.update.sh +++ b/cluster/maco.check.update.sh @@ -12,10 +12,15 @@ readonly PROGNAME=$(basename "${0}") readonly PROGDIR=$(readlink -m $(dirname "${0}")) readonly ARGS="${*}" readonly NBARGS="${#}" + [ -z "${DEBUG}" ] && DEBUG=1 ## Export DEBUG for sub-script export DEBUG +[ -z "${OUTPUT_MESSAGE}" ] && OUTPUT_MESSAGE=0 +## Export OUTPUT_MESSAGE for sub-script +export OUTPUT_MESSAGE + ## Colors readonly PURPLE='\033[1;35m' readonly RED='\033[0;31m' @@ -45,10 +50,21 @@ EXAMPLES : # }}} debug_message() { # {{{ - local_message="${1}" + local_debug_message="${1}" ## Print message if DEBUG is enable (=0) - [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG − ${PROGNAME} : ${local_message}" + [ "${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' "${local_message}" + + return 0 } # }}} @@ -59,6 +75,7 @@ is_maco_urgent_upgrade_require() { if [ "${URGENT_TIMESTAMP}" -gt "${CURRENT_TIMESTAMP}" ]; then debug_message "is_maco_urgent_upgrade_require − \ Urgent Maco upgrade is available (from version ${CURRENT_MACO_VERSION} to ${URGENT_MACO_VERSION})." + message "Urgent Maco upgrade is available (from version ${CURRENT_MACO_VERSION} to ${URGENT_MACO_VERSION})." return_urgent_upgrade="0" else debug_message "is_maco_urgent_upgrade_require − \ @@ -77,6 +94,7 @@ is_maco_upgrade_require() { # {{{ if [ "${LATEST_TIMESTAMP}" -gt "${CURRENT_TIMESTAMP}" ]; then debug_message "is_maco_upgrade_require − \ Latest Maco upgrade is available (from version ${CURRENT_MACO_VERSION} to ${LATEST_MACO_VERSION})." + message "Latest Maco upgrade is available (from version ${CURRENT_MACO_VERSION} to ${LATEST_MACO_VERSION})." return_upgrade="0" else debug_message "is_maco_upgrade_require − \ @@ -95,6 +113,7 @@ is_maco_uptodate() { # {{{ if [ "${CURRENT_TIMESTAMP}" = "${LATEST_TIMESTAMP}" ]; then debug_message "is_maco_uptodate − \ Local Maco (${CURRENT_MACO_VERSION}) is up to date (latest : ${LATEST_MACO_VERSION})." + message "Local Maco (${CURRENT_MACO_VERSION}) is up to date (latest : ${LATEST_MACO_VERSION})." return_uptodate="0" else debug_message "is_maco_uptodate − \ @@ -152,6 +171,14 @@ if [ ! "${NBARGS}" -eq "0" ]; then ## Re-export new DEBUG value export DEBUG ;; + -q|--quiet ) ## Silent mode + ## Avoid to display any message on standard output + OUTPUT_MESSAGE=1 + ;; + -s|--silent ) ## Silent mode + ## Avoid to display any message on standard output + OUTPUT_MESSAGE=1 + ;; -- ) ## End of options list ## End the while loop break