Files
coredesktop/updates.d/99-reboot-check.sh
T
davidandClaude Opus 5.5 5d7db2cdc8
shellcheck / shellcheck (push) Failing after 13s
Offer to reboot at the end of an install or update that needs one
update already said "Please reboot when convenient" after a new kernel,
firmware, microcode, NVIDIA driver, systemd or glibc. It now ends by
asking "Reboot now? [y/N]", after the offer to send a failed step's
log. 99-reboot-check.sh records that a reboot is needed, and update
clears that before its steps run, so an earlier update's reboot isn't
offered. Under script(1), the copy outside reboots once the log is
cleaned up. Never asked without a terminal, or when the initramfs
failed to rebuild.

install asks the same when it brought in a newer kernel.

Both reboot with systemctl, like the system menu's restart: sudo's
cached password belongs to another terminal by then.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 06:17:53 -07:00

40 lines
1.5 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 the running kernel's modules are gone, a newer kernel was installed
if [ ! -d "/usr/lib/modules/$(uname -r)" ]; 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