Don't manage files with SIMULATE_MODE enabled

This commit is contained in:
Jeremy Gardais 2020-06-24 15:54:53 +02:00
parent 1c6a8fcbc6
commit b7a369ae90
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 45 additions and 14 deletions

View File

@ -42,7 +42,7 @@ readonly MACO_TMP_URGENT_FILE="/tmp/.maco.urgent.upgrade"
usage() { # {{{ usage() { # {{{
cat <<- EOF 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 Compare current version of Maco script with the latest and
the urgent versions then try to prepare the host by: 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: EXAMPLES:
- Verify Maco's upgrade and prepare the current host - Verify Maco's upgrade and prepare the current host
${PROGNAME} ${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})." 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})." message "Urgent Maco upgrade is available (from version ${CURRENT_MACO_VERSION} to ${URGENT_MACO_VERSION})."
return_urgent_upgrade="0" return_urgent_upgrade="0"
## Also create an urgent temp file that can be monitored
## touch and append to keep existing content ## If SIMULATE_MODE is not enable
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}" -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 else
debug_message "is_maco_urgent_upgrade_require \ debug_message "is_maco_urgent_upgrade_require \
Local Maco (${CURRENT_MACO_VERSION}) is newer than urgent upgrade (${URGENT_MACO_VERSION})." Local Maco (${CURRENT_MACO_VERSION}) is newer than urgent upgrade (${URGENT_MACO_VERSION})."
return_urgent_upgrade="1" return_urgent_upgrade="1"
## Ensure urgent temp file is not present ## If SIMULATE_MODE is not enable
rm -f -- "${MACO_TMP_URGENT_FILE}" if [ ! "${SIMULATE_MODE}" -eq 0 ]; then
## Ensure urgent temp file is not present
rm -f -- "${MACO_TMP_URGENT_FILE}"
fi
fi fi
return "${return_urgent_upgrade}" 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})." 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})." message "Latest Maco upgrade is available (from version ${CURRENT_MACO_VERSION} to ${LATEST_MACO_VERSION})."
return_upgrade="0" return_upgrade="0"
## Also create a temp file that can be monitored
## touch and append to keep existing content ## If SIMULATE_MODE is not enable
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}" -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 else
debug_message "is_maco_upgrade_require \ debug_message "is_maco_upgrade_require \
Local Maco (${CURRENT_MACO_VERSION}) seems up to date (latest: ${LATEST_MACO_VERSION})." Local Maco (${CURRENT_MACO_VERSION}) seems up to date (latest: ${LATEST_MACO_VERSION})."
return_upgrade="1" return_upgrade="1"
## Ensure temp file is not present ## If SIMULATE_MODE is not enable
rm -f -- "${MACO_TMP_FILE}" if [ ! "${SIMULATE_MODE}" -eq 0 ]; then
## Ensure temp file is not present
rm -f -- "${MACO_TMP_FILE}"
fi
fi fi
return "${return_upgrade}" return "${return_upgrade}"
@ -159,8 +186,11 @@ is_maco_uptodate() { # {{{
Local Maco (${CURRENT_MACO_VERSION}) is up to date (latest: ${LATEST_MACO_VERSION})." 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})." message "Local Maco (${CURRENT_MACO_VERSION}) is up to date (latest: ${LATEST_MACO_VERSION})."
return_uptodate="0" return_uptodate="0"
## Ensure to remove temp files ## If SIMULATE_MODE is not enable
rm -f -- "${MACO_TMP_FILE}" "${MACO_TMP_URGENT_FILE}" if [ ! "${SIMULATE_MODE}" -eq 0 ]; then
## Ensure to remove temp files
rm -f -- "${MACO_TMP_FILE}" "${MACO_TMP_URGENT_FILE}"
fi
else else
debug_message "is_maco_uptodate \ debug_message "is_maco_uptodate \
Local Maco version (${CURRENT_MACO_VERSION}) is different from latest version (${LATEST_MACO_VERSION})." 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" sge_disable_host_queue_script="${PROGDIR}/sge.disable.host.queue.sh"
## If SIMULATE_MODE is enable
if [ "${SIMULATE_MODE}" -eq 0 ]; then if [ "${SIMULATE_MODE}" -eq 0 ]; then
return 0 return 0
else else