Files
coredesktop/updates.d/99-reboot-check.sh
T
davidandClaude Opus 5.5 1e2581dcc5
shellcheck / shellcheck (push) Successful in 48s
Keep the running kernel's modules after a kernel upgrade
install.sh failed whenever its upgrade replaced the kernel (Arch installed
a few days earlier): pacman deletes the running kernel's modules, so Docker
and then the firewall couldn't load theirs. The smoketest found it.

kernel-modules-hook keeps them until the next reboot, and its cleanup
service removes them after. install.sh installs it with archlinux-keyring,
in a transaction of its own so its hooks run for the upgrade; packages.conf
lists it and the service, so update adds them to existing machines.

With the modules kept, a missing modules folder no longer means a newer
kernel was installed, so newer_kernel_installed (utils.sh) also counts a
folder no package owns, and the reboot check, version and finish-install
use it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 18:41:50 -07:00

39 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
source "$HOME/.local/share/coredesktop/utils.sh"
# Tells update to offer a reboot at the end
REBOOT_NEEDED="$HOME/.local/state/coredesktop/reboot-needed"
# Packages whose upgrade only fully takes effect after a reboot: the kernel and
# firmware, the NVIDIA driver (the loaded module must match the installed
# one), CPU microcode, and the core libraries every running program uses
REBOOT_PACKAGES='linux|linux-lts|linux-zen|linux-hardened|linux-firmware.*|nvidia.*|.*-ucode|systemd|glibc'
if initramfs_build_failed; then
echo -e "\e[31mDon't reboot yet: the initramfs failed to rebuild (see $PACMAN_UPDATE_LOG).\e[0m"
exit 0
fi
reasons=()
if newer_kernel_installed; then
reasons+=("a newer kernel was installed")
fi
# Packages upgraded by this update's pacman -Su (see updates.d/10-pacman.sh)
if [ -f "$PACMAN_UPDATE_LOG" ]; then
mapfile -t upgraded < <(tr '\r' '\n' < "$PACMAN_UPDATE_LOG" \
| grep -oP 'upgrading \K[^ ]+' | sort -u | grep -xE "$REBOOT_PACKAGES")
if (( ${#upgraded[@]} > 0 )); then
reasons+=("${upgraded[*]} upgraded")
fi
fi
if (( ${#reasons[@]} > 0 )); then
reason="$(printf '%s; ' "${reasons[@]}")"
echo -e "\e[33mPlease reboot when convenient to finish this update (${reason%; }).\e[0m"
# update offers to reboot once it's done; it removes this file before its hooks run
mkdir -p "$(dirname "$REBOOT_NEEDED")" && echo "${reason%; }" > "$REBOOT_NEEDED"
fi