diff options
author | Adam Spragg <adam@spra.gg> | 2022-03-17 10:59:49 +0000 |
---|---|---|
committer | Adam Spragg <adam@spra.gg> | 2022-03-17 10:59:49 +0000 |
commit | 8ae543fa8d3fdf08bcc61dcb27cafd987344ada2 (patch) | |
tree | 0eb649ae48c7d0df14132f0ca896aa3b9afb7555 | |
parent | eaab1334258f9c3813fba68b806f0ef4d14e1bc7 (diff) |
Notify logged-in users when updates are availble.
-rw-r--r-- | README.md | 5 | ||||
-rwxr-xr-x | adu-download | 16 |
2 files changed, 21 insertions, 0 deletions
@@ -36,6 +36,11 @@ updates for packages which have bugs (or remove already-downloaded updates). So, look into a way of doing that. +### Notifying users about updates + +Find a better way of getting a list of logged in users and their DBus session +bus address than `find /run/user -type s -name bus`. + ## License diff --git a/adu-download b/adu-download index 7c9a08c..574eeae 100755 --- a/adu-download +++ b/adu-download @@ -35,4 +35,20 @@ fi apt-get -q -y --with-new-pkgs --download-only upgrade | grep "^Get:" ln -s -- "${UPDATE_TARGET}" "${UPDATE_SYMLINK}" 2>/dev/null || true + +# Notify logged-in users that updates are available +if command -v notify-send >/dev/null; then + # Disable shellcheck's "For loops over find output are fragile" warning here + # because filenames in `/run/user` are safe, and doing it The Right Way is a + # pain because of the environment variable. + # shellcheck disable=SC2044 + for addr in $(find /run/user -type s -name bus 2>/dev/null); do + export DBUS_SESSION_BUS_ADDRESS="unix:path=$addr"; + runuser -u "$(stat -c "%U" "$addr")" -- \ + notify-send --app-name=apt-desktop-upgrades \ + "$upgrades system updates available" \ + "Reboot when it is convenient to install them" + done +fi + echo "$upgrades updates available" |