summaryrefslogtreecommitdiffstats
path: root/libexec/container
diff options
context:
space:
mode:
Diffstat (limited to 'libexec/container')
-rwxr-xr-xlibexec/container/update96
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