From 138aecfb477b41d5bcda7a1965fabb1a0bcb9597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Mon, 22 Jun 2020 12:22:01 +0200 Subject: [PATCH] Exit if pending upgrades --- cluster/sge.enable.host.queue.sh | 80 ++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/cluster/sge.enable.host.queue.sh b/cluster/sge.enable.host.queue.sh index 8c9f8a0..1d16aca 100755 --- a/cluster/sge.enable.host.queue.sh +++ b/cluster/sge.enable.host.queue.sh @@ -8,6 +8,13 @@ readonly NBARGS="${#}" ## Test if DEBUG is already defined (by parent script,…) [ -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 readonly PURPLE='\033[1;35m' readonly RED='\033[0;31m' @@ -20,9 +27,13 @@ manage_args() { # {{{ case "${NBARGS}" in 0 ) sge_hostname="$(hostname -f)" + ## Ensure there is no pending upgrades on the local host + CHECK_UPGRADE="0" ;; 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}" @@ -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_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_name="${2}" @@ -151,7 +213,7 @@ is_all_queue_enable() { # {{{ } # }}} -enable_sge_queue() { # {{{ +enable_sge_queue() { # {{{ local_sge_hostname="${1}" local_sge_queue_name="${2}" @@ -180,6 +242,18 @@ main() { # {{{ | cut -d"'" -f2 \ | 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 debug_message "main − Try to manage \ SGE queue(s): ${RED}${sge_queues_name_print:=/dev/null}${COLOR_DEBUG}\