Exit if pending upgrades
This commit is contained in:
parent
270c1eb3fb
commit
138aecfb47
|
@ -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}"
|
||||||
|
@ -59,6 +70,57 @@ debug_message() { # {{{
|
||||||
## Print message if DEBUG is enable (=0)
|
## Print message if DEBUG is enable (=0)
|
||||||
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG − ${PROGNAME} : ${local_debug_message}"
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG − ${PROGNAME} : ${local_debug_message}"
|
||||||
|
|
||||||
|
}
|
||||||
|
# }}}
|
||||||
|
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() { # {{{
|
is_queue_enable() { # {{{
|
||||||
|
@ -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}\
|
||||||
|
|
Loading…
Reference in New Issue