#! /bin/sh # Copyright © 2022 Adam Spragg # SPDX-License-Identifier: LGPL-3.0-or-later # # This file is part of apt-desktop-upgrades # # apt-desktop-upgrades is free software: you can redistribute it and/or modify # under the terms of the GNU Lesser General Public License as published by the # Free Software Foundation, either version 3 of the License, or (at your option) # any later version. # # apt-desktop-upgrades is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License # for more details. # # You should have received a copy of the GNU Lesser General Public License along # with apt-desktop-upgrades. If not, see . set -e SBINDIR=/usr/local/sbin UPDATE_SYMLINK="/system-update" UPDATE_TARGET="${SBINDIR}/adu-upgrade" apt-get -qq update upgrades=$(apt -qq list --upgradeable 2>/dev/null | wc -l) if [ "$upgrades" -eq 0 ]; then exit 0 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"