aboutsummaryrefslogtreecommitdiff
path: root/adu-upgrade
blob: e0a25dd960ff13ea67c4adb636350bdba6da20ec (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
#! /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

SBINDIR=/usr/local/sbin

UPDATE_SYMLINK="/system-update"
UPDATE_TARGET="${SBINDIR}/adu-upgrade"

if [ x"$(realpath -- "${UPDATE_SYMLINK}")" != x"${UPDATE_TARGET}" ]; then
	exit 0
fi

# man:systemd.offline-updates(7):
#    "Make sure to remove the /system-update symlink as early as possible in
#    the update script to avoid reboot loops in case the update fails."
rm -f -- "${UPDATE_SYMLINK}"

upgrades=$(apt -qq list --upgradeable 2>/dev/null | wc -l)
if [ "$upgrades" -eq 0 ]; then
	echo "Nothing to do? Rebooting..."
	systemctl reboot
	exit 0
fi

# Disable apt-listbugs, because if the network isn't available then it blocks
# upgrades.
export APT_LISTBUGS_FRONTEND=none

# Do the update
export DEBIAN_FRONTEND=noninteractive
apt-get -q -y --with-new-pkgs --no-download --ignore-missing upgrade

# man:systemd.offline-updates(7):
#    "The update service should now do its job. [...] After completion
#    (regardless whether the update succeeded or failed) the machine must be
#    rebooted, for example by calling `systemctl reboot`."
systemctl reboot