aboutsummaryrefslogtreecommitdiffstats
path: root/systemd/pacman-offline
blob: 9471bfce0af1592a81e19b204cee85279e3cc7a7 (plain) (blame)
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
#!/bin/sh

# (C) 2017-2024 by Christian Hesse <mail@eworm.de>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

set -e

# verify this is for us or exit gracefully
if [ "$(readlink '/system-update')" != '/var/cache/pacman/pkg' ]; then
	exit 0
fi

# exclude /etc/pacman.d/offline.conf
function finish { rm -f /run/pacman.conf; }
trap finish EXIT
sed '/^Include *= *\/etc\/pacman\.d\/offline\.conf$/s|^|#|' < /etc/pacman.conf > /run/pacman.conf

# remove triggering symlink and (soft-)reboot override
rm -f /system-update
rm -f /run/systemd/system/systemd-reboot.service

# install updates
if [ "$(pacman --sync  --print --needed archlinux-keyring | wc -l)" -gt 0 ]; then
	pacman --sync --noconfirm archlinux-keyring
fi
pacman --config /run/pacman.conf --sync --noconfirm --sysupgrade

# clean up package cache
pacman --sync --noconfirm --clean

# reboot
if [ -s "/usr/lib/modules/$(uname -r)/pkgbase" ] && systemctl --dry-run soft-reboot 2>/dev/null; then
	systemctl soft-reboot
else
	systemctl reboot
fi