Watch for temp APT file if APT upgrade is available

This commit is contained in:
Jeremy Gardais 2020-06-18 11:51:48 +02:00
parent 6a84224f8a
commit 27ef7256a0
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 24 additions and 36 deletions

View File

@ -16,6 +16,9 @@ readonly NBARGS="${#}"
## Export DEBUG for sub-script ## Export DEBUG for sub-script
export DEBUG export DEBUG
# 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'
@ -65,24 +68,16 @@ debug_message() { # {{{
# }}} # }}}
is_apt_upgrade_absent() { # {{{ is_apt_upgrade_absent() { # {{{
## Count the number of upgradable packages and substract 1 for the header ## Check if temp APT upgrade file is absent
#local_apt_upgrade_number="$(apt list --upgradable \ if [ ! -f "${APT_TMP_FILE}" ]; then
#| wc -l \
#| awk '{print $1-1}')"
local_apt_upgrade_number="5"
case "${local_apt_upgrade_number}" in
0 ) ## No available upgrade
return_apt_upgrade_absent="0" return_apt_upgrade_absent="0"
;;
* ) ## Upgrade seems available
return_apt_upgrade_absent="1"
;;
esac
## Simple debug message to valid current variable
debug_message "is_apt_upgrade_absent \ debug_message "is_apt_upgrade_absent \
APT upgrade available for this system: ${RED}${local_apt_upgrade_number:=/dev/null}${COLOR_DEBUG}." NO APT upgrade available for this system."
else
return_apt_upgrade_absent="1"
debug_message "is_apt_upgrade_absent \
APT upgrade seems available for this system."
fi
return "${return_apt_upgrade_absent}" return "${return_apt_upgrade_absent}"
@ -90,23 +85,16 @@ APT upgrade available for this system: ${RED}${local_apt_upgrade_number:=/dev/nu
# }}} # }}}
is_apt_upgrade_present() { # {{{ is_apt_upgrade_present() { # {{{
## Count the number of upgradable packages and substract 1 for the header ## Check if temp APT upgrade file exists
local_apt_upgrade_number="$(apt list --upgradable \ if [ -f "${APT_TMP_FILE}" ]; then
| wc -l \
| awk '{print $1-1}')"
case "${local_apt_upgrade_number}" in
0 ) ## No available upgrade
return_apt_upgrade_present="1"
;;
* ) ## Upgrade seems available
return_apt_upgrade_present="0" return_apt_upgrade_present="0"
;; debug_message "is_apt_upgrade_absent \
esac APT upgrade seems available for this system."
else
## Simple debug message to valid current variable return_apt_upgrade_present="1"
debug_message "is_apt_upgrade_present \ debug_message "is_apt_upgrade_absent \
APT upgrade available for this system: ${RED}${local_apt_upgrade_number:=/dev/null}${COLOR_DEBUG}." NO APT upgrade available for this system."
fi
return "${return_apt_upgrade_present}" return "${return_apt_upgrade_present}"
@ -221,7 +209,7 @@ main() { # {{{
is_job_running "${sge_hostname}" \ is_job_running "${sge_hostname}" \
&& exit 0 && exit 0
## If anything to maco is currently running ## If anything related to maco is currently running
### Exit ### Exit
is_proc_running "${maco_proc_pattern}" \ is_proc_running "${maco_proc_pattern}" \
&& exit 0 && exit 0