From b7a369ae90ad1ca45c9f6c459f684bfb4966b803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Wed, 24 Jun 2020 15:54:53 +0200 Subject: [PATCH] Don't manage files with SIMULATE_MODE enabled --- cluster/maco.check.update.sh | 59 +++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/cluster/maco.check.update.sh b/cluster/maco.check.update.sh index b851980..1516764 100755 --- a/cluster/maco.check.update.sh +++ b/cluster/maco.check.update.sh @@ -42,7 +42,7 @@ readonly MACO_TMP_URGENT_FILE="/tmp/.maco.urgent.upgrade" usage() { # {{{ cat <<- EOF -usage: $PROGNAME [-h,--help|-d,--debug|-s,--simulate] +usage: $PROGNAME [-d|-h|-s] Compare current version of Maco script with the latest and the urgent versions then try to prepare the host by: @@ -51,7 +51,18 @@ Compare current version of Maco script with the latest and EXAMPLES: - Verify Maco's upgrade and prepare the current host ${PROGNAME} - EOF + +OPTIONS : + -d,--debug + Enable debug messages. + + -h,--help + Print this help message. + + -s,--simulate + Only display messages and don't manage temp files. +EOF + } # }}} @@ -111,15 +122,23 @@ 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" - ## Also create an urgent temp file that can be monitored - ## touch and append to keep existing content - touch "${MACO_TMP_URGENT_FILE}" && echo "Urgent Maco upgrade is available (from version ${CURRENT_MACO_VERSION} to ${URGENT_MACO_VERSION})." >> "${MACO_TMP_URGENT_FILE}" + + ## If SIMULATE_MODE is not enable + if [ ! "${SIMULATE_MODE}" -eq 0 ]; then + ### Also create an urgent temp file that can be monitored + ### touch and append to keep existing content + touch "${MACO_TMP_URGENT_FILE}" && echo "Urgent Maco upgrade is available (from version ${CURRENT_MACO_VERSION} to ${URGENT_MACO_VERSION})." >> "${MACO_TMP_URGENT_FILE}" + fi + else debug_message "is_maco_urgent_upgrade_require − \ Local Maco (${CURRENT_MACO_VERSION}) is newer than urgent upgrade (${URGENT_MACO_VERSION})." return_urgent_upgrade="1" - ## Ensure urgent temp file is not present - rm -f -- "${MACO_TMP_URGENT_FILE}" + ## If SIMULATE_MODE is not enable + if [ ! "${SIMULATE_MODE}" -eq 0 ]; then + ## Ensure urgent temp file is not present + rm -f -- "${MACO_TMP_URGENT_FILE}" + fi fi return "${return_urgent_upgrade}" @@ -135,15 +154,23 @@ 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" - ## Also create a temp file that can be monitored - ## touch and append to keep existing content - touch "${MACO_TMP_FILE}" && echo "Latest Maco upgrade is available (from version ${CURRENT_MACO_VERSION} to ${LATEST_MACO_VERSION})." >> "${MACO_TMP_FILE}" + + ## If SIMULATE_MODE is not enable + if [ ! "${SIMULATE_MODE}" -eq 0 ]; then + ### Also create a temp file that can be monitored + ### touch and append to keep existing content + touch "${MACO_TMP_FILE}" && echo "Latest Maco upgrade is available (from version ${CURRENT_MACO_VERSION} to ${LATEST_MACO_VERSION})." >> "${MACO_TMP_FILE}" + fi + else debug_message "is_maco_upgrade_require − \ Local Maco (${CURRENT_MACO_VERSION}) seems up to date (latest: ${LATEST_MACO_VERSION})." return_upgrade="1" - ## Ensure temp file is not present - rm -f -- "${MACO_TMP_FILE}" + ## If SIMULATE_MODE is not enable + if [ ! "${SIMULATE_MODE}" -eq 0 ]; then + ## Ensure temp file is not present + rm -f -- "${MACO_TMP_FILE}" + fi fi return "${return_upgrade}" @@ -159,8 +186,11 @@ 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" - ## Ensure to remove temp files - rm -f -- "${MACO_TMP_FILE}" "${MACO_TMP_URGENT_FILE}" + ## If SIMULATE_MODE is not enable + if [ ! "${SIMULATE_MODE}" -eq 0 ]; then + ## Ensure to remove temp files + rm -f -- "${MACO_TMP_FILE}" "${MACO_TMP_URGENT_FILE}" + fi else debug_message "is_maco_uptodate − \ Local Maco version (${CURRENT_MACO_VERSION}) is different from latest version (${LATEST_MACO_VERSION})." @@ -175,6 +205,7 @@ prepare_host_for_upgrade() { # {{{ sge_disable_host_queue_script="${PROGDIR}/sge.disable.host.queue.sh" + ## If SIMULATE_MODE is enable if [ "${SIMULATE_MODE}" -eq 0 ]; then return 0 else