blob: b58ab97807d00ab849ab562690322f7ec8fb5321 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#! /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 <https://www.gnu.org/licenses/>.
set -e
CHECK_LISTBUGS=false
SBINDIR=/usr/local/sbin
UPDATE_SYMLINK="/system-update"
UPDATE_TARGET="${SBINDIR}/adu-upgrade"
apt-get -qq update
upgradeable=$(apt -qq list --upgradeable 2>/dev/null)
upgrades=$(echo "$upgradeable" | grep -c . | cat)
if [ "$upgrades" -eq 0 ]; then
exit 0
fi
if $CHECK_LISTBUGS && command -v apt-listbugs >/dev/null; then
# Sed script to change format of `apt list --upgradeable` to `apt-listbugs`
#sed_upg_lb='s:^\([^/]\+\)/[^ ]\+ \([^ ]\+\) .*:\1:'
sed_upg_lb='s:^\([^/]\+\)/[^ ]\+ \([^ ]\+\) .*:\1/\2:'
#echo "Checking for bugs in: $(echo "$upgradeable" | sed -e "$sed_upg_lb")"
bugs=$(echo "$upgradeable" \
| sed -e "$sed_upg_lb" \
| xargs apt-listbugs -q list \
| grep -E -- "- #[[:digit:]]+ -")
if [ -n "$bugs" ]; then
#echo "$bugs"
echo "$upgrades upgrades available, but $(echo "$bugs" | wc -l) bugs exist - ignoring upgrade"
if [ x"$(realpath -- "${UPDATE_SYMLINK}")" = x"${UPDATE_TARGET}" ]; then
rm -f -- "${UPDATE_SYMLINK}"
fi
exit 0
fi
fi
apt-get -q -y --with-new-pkgs --download-only upgrade | grep "^Get:" | cat
ln -s -- "${UPDATE_TARGET}" "${UPDATE_SYMLINK}" 2>/dev/null || true
# Take a list on standard input, and output them all together separated by $1
listify() {
sep=""
while read -r line; do
printf "%s" "${sep}${line}"
sep="$1"
done
printf "\\n"
}
# Notify logged-in users that updates are available
if command -v notify-send >/dev/null; then
sources="$(echo "$upgradeable" \
| cut -d / -f 1 \
| xargs -n 1 apt-cache showsrc 2>/dev/null \
| grep ^Package: \
| cut -d " " -f 2 \
| sort -u \
| listify ", ")"
# 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" \
"To install them, reboot when it is convenient\\nUpdates from $sources"
done
fi
echo "$upgrades updates available"
|