Exit if pending upgrades

This commit is contained in:
Jeremy Gardais 2020-06-22 12:22:01 +02:00
parent 270c1eb3fb
commit 138aecfb47
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 77 additions and 3 deletions

View File

@ -8,6 +8,13 @@ readonly NBARGS="${#}"
## Test if DEBUG is already defined (by parent script,…) ## Test if DEBUG is already defined (by parent script,…)
[ -z "${DEBUG}" ] && readonly DEBUG=0 [ -z "${DEBUG}" ] && readonly DEBUG=0
# Maco temp file
readonly MACO_TMP_FILE="/tmp/.maco.upgrade"
readonly MACO_TMP_URGENT_FILE="/tmp/.maco.urgent.upgrade"
# APT temp file to monitor
readonly APT_TMP_FILE="/tmp/.apt.upgrade"
## Colors ## Colors
readonly PURPLE='\033[1;35m' readonly PURPLE='\033[1;35m'
readonly RED='\033[0;31m' readonly RED='\033[0;31m'
@ -20,9 +27,13 @@ manage_args() { # {{{
case "${NBARGS}" in case "${NBARGS}" in
0 ) 0 )
sge_hostname="$(hostname -f)" sge_hostname="$(hostname -f)"
## Ensure there is no pending upgrades on the local host
CHECK_UPGRADE="0"
;; ;;
1 ) 1 )
sge_hostname="${1}" sge_hostname="${1}"
## No way to monitor pending upgrades on a remote host
CHECK_UPGRADE="1"
;; ;;
* ) * )
printf '%b\n' "${RED}Expect 1 or 0 argument.${RESET}" printf '%b\n' "${RED}Expect 1 or 0 argument.${RESET}"
@ -61,7 +72,58 @@ debug_message() { # {{{
} }
# }}} # }}}
is_queue_enable() { # {{{ is_apt_upgrade_present() { # {{{
## No pending upgrade by default
return_apt_upgrade_present="1"
## If we need to watch for upgrades
if [ "${CHECK_UPGRADE}" -eq "0" ]; then
### Check if temp APT upgrade file exists
if [ -f "${APT_TMP_FILE}" ]; then
return_apt_upgrade_present="0"
debug_message "is_apt_upgrade_absent \
APT upgrade seems available for this system."
else
return_apt_upgrade_present="1"
debug_message "is_apt_upgrade_absent \
NO APT upgrade available for this system."
fi
fi
return "${return_apt_upgrade_present}"
}
# }}}
is_maco_upgrade_present() { # {{{
## No pending upgrades by default
return_maco_upgrade_present="1"
## If we need to watch for upgrades
if [ "${CHECK_UPGRADE}" -eq "0" ]; then
## Check if temp Maco upgrade file is present
if [ -f "${MACO_TMP_FILE}" ]; then
return_maco_upgrade_present="0"
debug_message "is_maco_upgrade_present \
Maco upgrade seems available."
## Check if temp Maco urgent upgrade file is present
elif [ -f "${MACO_TMP_URGENT_FILE}" ]; then
return_maco_upgrade_present="0"
debug_message "is_maco_upgrade_present \
Maco urgent upgrade seems available."
else
debug_message "is_maco_upgrade_present \
No Maco upgrade require."
fi
fi
return "${return_maco_upgrade_present}"
}
# }}}
is_queue_enable() { # {{{
local_queue_enable_hostname="${1}" local_queue_enable_hostname="${1}"
local_queue_enable_name="${2}" local_queue_enable_name="${2}"
@ -129,7 +191,7 @@ state is: ${RED}${local_sge_queue_state:=/dev/null}${COLOR_DEBUG}."
} }
# }}} # }}}
is_all_queue_enable() { # {{{ is_all_queue_enable() { # {{{
local_all_queue_enable_hostname="${1}" local_all_queue_enable_hostname="${1}"
local_all_queue_enable_name="${2}" local_all_queue_enable_name="${2}"
@ -151,7 +213,7 @@ is_all_queue_enable() { # {{{
} }
# }}} # }}}
enable_sge_queue() { # {{{ enable_sge_queue() { # {{{
local_sge_hostname="${1}" local_sge_hostname="${1}"
local_sge_queue_name="${2}" local_sge_queue_name="${2}"
@ -180,6 +242,18 @@ main() { # {{{
| cut -d"'" -f2 \ | cut -d"'" -f2 \
| tr -s '\n' ' ' )" | tr -s '\n' ' ' )"
## If APT package upgrade is available
### Exit (wait for APT upgrade to be applied)
is_apt_upgrade_present \
&& exit 0
## If Maco upgrade is present
### Exit (wait for Maco upgrade to be applied)
is_maco_upgrade_present \
&& exit 0
## Simple debug message with color to valid current variables ## Simple debug message with color to valid current variables
debug_message "main Try to manage \ debug_message "main Try to manage \
SGE queue(s): ${RED}${sge_queues_name_print:=/dev/null}${COLOR_DEBUG}\ SGE queue(s): ${RED}${sge_queues_name_print:=/dev/null}${COLOR_DEBUG}\