diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-11-16 06:00:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-11-16 06:00:51 +0000 |
commit | 902f8aaf5115f62e26fc7e8dd2f1c67dcee4508a (patch) | |
tree | bd95e580b5098d6b2417f193002070f48953b2e0 /libexec/container | |
parent | Adding upstream version 20211115. (diff) | |
download | open-infrastructure-compute-tools-upstream/20211116.tar.xz open-infrastructure-compute-tools-upstream/20211116.zip |
Adding upstream version 20211116.upstream/20211116
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-x | libexec/container/update | 96 |
1 files changed, 60 insertions, 36 deletions
diff --git a/libexec/container/update b/libexec/container/update index 80f154a..de76942 100755 --- a/libexec/container/update +++ b/libexec/container/update @@ -93,6 +93,46 @@ Usage () Parameters "${@}" +Notification () +{ + TYPE="${1}" + NUMBER="${2}" + PACKAGES="${3}" + + if [ -z "${PACKAGES}" ] + then + return + fi + + CONTAINER_USER="${SUDO_USER:-${USER}}" + + DATE="$(date +%Y-%m-%d\ %H:%M:%S)" + HOST="$(hostname -f 2> /dev/null || hostname)" + + # logfile + echo "${DATE} ${HOST} ${CONTAINER_USER} ${NAME} ${NUMBER} ${TYPE}: ${PACKAGES}" >> "/var/log/${SOFTWARE}/${PROGRAM}.log" + + # irc + if [ -e /usr/bin/irk ] + then + for FILE in "/etc/${SOFTWARE}/${PROGRAM}.conf" "/etc/${SOFTWARE}/${PROGRAM}.conf.d"/*.conf + do + if [ -e "${FILE}" ] + then + . "${FILE}" + fi + done + + if [ -n "${IRK_TARGETS}" ] + then + for TARGET in ${IRK_TARGETS} + do + irk "${TARGET}" "\x0300${CONTAINER_USER}\x03@\x0312${HOST}:\x03 \x0303${NAME}\x03 \x0307${NUMBER} ${TYPE}\x03: ${PACKAGES}" + done + fi + fi +} + case "${NAME}" in ALL) NAMES="$(container list --started --format shell)" @@ -121,62 +161,46 @@ do container run -n ${NAME} -- "apt update" - UPDATES="$(container run -n ${NAME} -- "apt \-\-simulate full-upgrade" | awk '/^[0-9]* upgraded, / { print $1 }')" + UPDATE_NUMBER="$(container run -n ${NAME} -- "apt \-\-simulate full-upgrade" | awk '/^[0-9]* upgraded, / { print $1 }')" - case "${UPDATES}" in + case "${UPDATE_NUMBER}" in 0) ;; *) - PACKAGES="$(for PACKAGE in $(container run -n ${NAME} -- "apt list \-\-upgradable 2>/dev/null | grep '\/'" | awk -F/ '{ print $1 }'); do echo -n "${PACKAGE} "; done | sed -e 's| $||'; echo)" + # usefull use of grep to de-colorize apt output + UPDATE_PACKAGES="$(for PACKAGE in $(container run -n ${NAME} -- "apt list \-\-upgradable 2>/dev/null | grep '\/'" | awk -F/ '{ print $1 }'); do echo -n "${PACKAGE} "; done | sed -e 's| $||'; echo)" case "${FULL_UPGRADE}" in true) - container run -n ${NAME} -- "apt ${YES} full-upgrade" + container run -n ${NAME} -- "DEBCONF_FRONTEND='noninteractive' DEBCONF_PRIORITY='critical' apt \-o Dpkg::Options::=\-\-force-confold ${YES} full-upgrade" ;; *) - container run -n ${NAME} -- "apt ${YES} upgrade" + container run -n ${NAME} -- "DEBCONF_FRONTEND='noninteractive' DEBCONF_PRIORITY='critical' apt \-o Dpkg::Options::=\-\-force-confold ${YES} upgrade" ;; esac + + Notification "update(s)" "${UPDATE_NUMBER}" "${UPDATE_PACKAGES}" ;; esac - # Notification - if [ -n "${PACKAGES}" ] - then - CONTAINER_USER="${SUDO_USER:-${USER}}" - - DATE="$(date +%Y-%m-%d\ %H:%M:%S)" - HOST="$(hostname -f 2> /dev/null || hostname)" + case "${AUTOREMOVE}" in + true) + REMOVE_NUMBER="$(container run -n ${NAME} -- "apt \-\-simulate autoremove" | awk '/^[0-9]* upgraded, / { print $6 }')" - # logfile - echo "${DATE} ${HOST} ${CONTAINER_USER} ${NAME} ${UPDATES} upgraded: ${PACKAGES}" >> "/var/log/${SOFTWARE}/${PROGRAM}.log" + case "${REMOVE_NUMBER}" in + 0) + ;; - # irc - if [ -e /usr/bin/irk ] - then - for FILE in "/etc/${SOFTWARE}/${PROGRAM}.conf" "/etc/${SOFTWARE}/${PROGRAM}.conf.d"/*.conf - do - if [ -e "${FILE}" ] - then - . "${FILE}" - fi - done + *) + REMOVE_PACKAGES="$(for LINE in $(container run -n ${NAME} -- "apt \-\-simulate autoremove" | grep '^ '); do echo ${LINE}; done | sed -e 's|^ ||' -e 's|
$||'; echo)" - if [ -n "${IRK_TARGETS}" ] - then - for TARGET in ${IRK_TARGETS} - do - irk "${TARGET}" "\x0300${CONTAINER_USER}\x03@\x0312${HOST}:\x03 \x0303${NAME}\x03 \x0307${UPDATES} upgraded\x03: ${PACKAGES}" - done - fi - fi - fi + container run -n ${NAME} -- "apt ${YES} autoremove ${PURGE}" - case "${AUTOREMOVE}" in - true) - container run -n ${NAME} -- "apt ${YES} autoremove ${PURGE}" + Notification "removal(s)" "${REMOVE_NUMBER}" "$(echo ${REMOVE_PACKAGES})" + ;; + esac ;; esac |