New mode that check update if last update failed

This commit is contained in:
Jeremy Gardais 2021-05-21 14:27:57 +02:00
parent fa307a2152
commit 36621b4f62
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 55 additions and 0 deletions

View File

@ -62,6 +62,9 @@ OPTIONS:
-d,--debug
Enable debug messages.
-f,--fail
Check update only if the last Maco update failed.
-h,--help
Print this help message.
@ -231,6 +234,36 @@ Local Maco version (${CURRENT_MACO_VERSION}) is different from latest version ($
return "${return_uptodate}"
}
# }}}
is_maco_status_ok() { # {{{
## Maco status not ok by default
return_maco_status_ok="1"
## Check if Maco status file is present
if [ -f "${MACO_STATUS_FILE}" ]; then
debug_message "is_maco_status_ok \
Maco status file (${MACO_STATUS_FILE}) exists."
local_maco_status=$(grep --max-count=1 -- MacoStatus "${MACO_STATUS_FILE}" | cut --delimiter="=" --fields=2)
## Check current Maco status
if [ "${local_maco_status}" = "last-update-succeeded" ]; then
debug_message "is_maco_status_ok \
Last Maco upgrade succeed (${local_maco_status})."
return_maco_status_ok="0"
else
debug_message "is_maco_status_ok \
Maco require upgrade/maintenance (current state: ${local_maco_status})."
fi
else
debug_message "is_maco_status_ok \
Maco status file (${MACO_STATUS_FILE}) doesn't exists."
fi
return "${return_maco_status_ok}"
}
# }}}
prepare_host_for_upgrade() { # {{{
@ -274,6 +307,13 @@ main() { # {{{
### }}}
## }}}
## If MACO_FAILED_MODE wasn't defined (argument, environment variable,…) {{{
if [ -z "${MACO_FAILED_MODE}" ]; then
### Set False by default
MACO_FAILED_MODE="1"
fi
## }}}
## Get all Maco's versions (date)
readonly CURRENT_MACO_VERSION=$(< "${MACO_LOCAL_DIR}/maco-version.txt" awk -v FS=. '{ print $1 "-" $2 "-" $3 "T" $4 ":" $5 ":" $6 }' )
readonly LATEST_MACO_VERSION=$(< "${MACO_INSTALL_DIR}/maco-version.txt" awk -v FS=. '{ print $1 "-" $2 "-" $3 "T" $4 ":" $5 ":" $6 }' )
@ -282,12 +322,24 @@ main() { # {{{
readonly CURRENT_TIMESTAMP=$(date -d "${CURRENT_MACO_VERSION}" "+%s")
readonly LATEST_TIMESTAMP=$(date -d "${LATEST_MACO_VERSION}" "+%s")
readonly URGENT_TIMESTAMP=$(date -d "${URGENT_MACO_VERSION}" "+%s")
# Maco status file
readonly MACO_STATUS_FILE="/var/fr.univ-rennes1.ipr.maco.machinestate.txt"
## If a variable is empty
## Exit with error code
is_var_empty "${CURRENT_MACO_VERSION}" "${LATEST_MACO_VERSION}" "${URGENT_MACO_VERSION}" "${CURRENT_TIMESTAMP}" "${LATEST_TIMESTAMP}" "${URGENT_TIMESTAMP}" \
&& exit 1
## If MACO_FAILED_MODE is set {{{
### Exit if Maco last-update-succeeded
if [ "${MACO_FAILED_MODE}" -eq "0" ]; then
### If Macostatus=last-update-succeeded
### Exit
is_maco_status_ok \
&& exit 0
fi
## }}}
is_maco_uptodate \
&& exit 0
@ -327,6 +379,9 @@ if [ ! "${NBARGS}" -eq "0" ]; then
while printf -- '%s' "${1}" | grep -q -E -- "^-+"; do
case "${1}" in
-f|--fail ) ## Failed mode
MACO_FAILED_MODE="0"
;;
-h|--help ) ## help
usage
## Exit after help informations