summaryrefslogtreecommitdiffstats
path: root/libexec/container
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xlibexec/container/update80
1 files changed, 45 insertions, 35 deletions
diff --git a/libexec/container/update b/libexec/container/update
index 7eed2c3..7bf5e5f 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,15 +161,15 @@ 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)
;;
*)
# usefull use of grep to de-colorize apt output
- 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)"
+ 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)
@@ -140,41 +180,11 @@ do
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)"
-
- # logfile
- echo "${DATE} ${HOST} ${CONTAINER_USER} ${NAME} ${UPDATES} update(s): ${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${UPDATES} update(s)\x03: ${PACKAGES}"
- done
- fi
- fi
- fi
-
case "${AUTOREMOVE}" in
true)
container run -n ${NAME} -- "apt ${YES} autoremove ${PURGE}"