Offer to reboot at the end of an install or update that needs one
shellcheck / shellcheck (push) Failing after 13s

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>
This commit is contained in:
2026-11-16 06:17:53 -07:00
co-authored by Claude Opus 5.5
parent 902967f111
commit 5d7db2cdc8
6 changed files with 157 additions and 4 deletions
+81
View File
@@ -237,3 +237,84 @@ ran() {
[[ "$output" == *"Done."* ]]
ran a
}
# needs_reboot NAME: a hook that says this update needs a reboot, as
# updates.d/99-reboot-check.sh does
needs_reboot() {
hook "$1" 'mkdir -p ~/.local/state/coredesktop; echo "a newer kernel was installed" > ~/.local/state/coredesktop/reboot-needed'
}
# answer TEXT: what's typed at update's questions
answer() {
export COREDESKTOP_TTY="$BATS_TEST_TMPDIR/answer"
echo "$1" > "$COREDESKTOP_TTY"
}
@test "update reboots when it needs to and is told yes" {
stub systemctl
needs_reboot 99-reboot-check
answer y
run "$CD/update"
[ "$status" -eq 0 ]
[[ "$output" == *"Done."*"Rebooting..."* ]]
called systemctl reboot
}
@test "update doesn't reboot unless told yes" {
stub systemctl
needs_reboot 99-reboot-check
answer ""
run "$CD/update"
[ "$status" -eq 0 ]
not_called systemctl
}
@test "update doesn't ask about a reboot without a terminal" {
stub systemctl
needs_reboot 99-reboot-check
export COREDESKTOP_TTY="$BATS_TEST_TMPDIR/no-tty/tty"
run "$CD/update"
[ "$status" -eq 0 ]
not_called systemctl
}
@test "update doesn't offer a reboot an earlier update needed" {
stub systemctl
hook 10-a 'true'
mkdir -p "$HOME/.local/state/coredesktop"
touch "$HOME/.local/state/coredesktop/reboot-needed"
answer y
run "$CD/update"
[ "$status" -eq 0 ]
not_called systemctl
}
@test "update offers a reboot after offering to send the log of a failed step" {
printf '#!/bin/bash\necho "Send this log?"\n' > "$CD/report"
chmod +x "$CD/report"
stub systemctl
hook 10-a 'return 1'
needs_reboot 99-reboot-check
answer y
run "$CD/update"
[ "$status" -eq 1 ]
[[ "$output" == *"Send this log?"*"Rebooting..."* ]]
called systemctl reboot
}
@test "under script, the reboot waits for update's log to be cleaned up" {
stub systemctl
needs_reboot 99-reboot-check
answer y
export UPDATE_IN_SCRIPT=1 UPDATE_LOG="$BATS_TEST_TMPDIR/update.log"
run "$CD/update"
[ "$status" -eq 0 ]
not_called systemctl
[ -e "$UPDATE_LOG.reboot" ]
}