Manage a temp file if upgrade is required

This commit is contained in:
Jeremy Gardais 2020-06-17 16:01:25 +02:00
parent 965fc3dd0e
commit ee91922764
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 15 additions and 0 deletions

View File

@ -3,6 +3,7 @@
# This script will check if Maco require an upgrade and # This script will check if Maco require an upgrade and
# will prepare the host in order to apply upgrade: # will prepare the host in order to apply upgrade:
# 1. Disable SGE queue # 1. Disable SGE queue
# 2. Create a temp file (/tmp/.maco.upgrade or /tmp/.maco.urgent.upgrade)
# This script can be call by a cronjob (eg. weekly) # This script can be call by a cronjob (eg. weekly)
# Another script should try to apply upgrades also with cron (eg. hourly) # Another script should try to apply upgrades also with cron (eg. hourly)
@ -34,6 +35,8 @@ readonly COLOR_DEBUG="${PURPLE}"
## Maco ## Maco
readonly MACO_LOCAL_DIR="/opt/maco" readonly MACO_LOCAL_DIR="/opt/maco"
readonly MACO_INSTALL_DIR="/mnt/store.ipr/InstallProgs/ipr/maco" readonly MACO_INSTALL_DIR="/mnt/store.ipr/InstallProgs/ipr/maco"
readonly MACO_TMP_FILE="/tmp/.maco.upgrade"
readonly MACO_TMP_URGENT_FILE="/tmp/.maco.urgent.upgrade"
# }}} # }}}
usage() { # {{{ usage() { # {{{
@ -108,10 +111,15 @@ 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
touch "${MACO_TMP_URGENT_FILE}" && echo "Urgent Maco upgrade is available (from version ${CURRENT_MACO_VERSION} to ${URGENT_MACO_VERSION})." >> "${MACO_TMP_URGENT_FILE}"
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
rm -f -- "${MACO_TMP_URGENT_FILE}"
fi fi
return "${return_urgent_upgrade}" return "${return_urgent_upgrade}"
@ -127,10 +135,15 @@ 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
touch "${MACO_TMP_FILE}" && echo "Latest Maco upgrade is available (from version ${CURRENT_MACO_VERSION} to ${LATEST_MACO_VERSION})." >> "${MACO_TMP_FILE}"
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
rm -f -- "${MACO_TMP_FILE}"
fi fi
return "${return_upgrade}" return "${return_upgrade}"
@ -146,6 +159,8 @@ 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
rm -f -- "${MACO_TMP_FILE}" "${MACO_TMP_URGENT_FILE}"
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})."