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
+2 -2
View File
@@ -66,7 +66,7 @@ wget -qO- https://federated.sh | bash
First it checks the machine. It stops if this isn't Arch, if you run it as root, if your user can't use sudo, or if there's no internet. It asks before going on if there's less than about 60 GB free, or if / isn't on btrfs (then there are no snapshots before updates, and only reinstalling Arch with btrfs changes that). If the login screen isn't GNOME's, or sound goes through PulseAudio, it offers to switch to GNOME's login screen and to PipeWire. First it checks the machine. It stops if this isn't Arch, if you run it as root, if your user can't use sudo, or if there's no internet. It asks before going on if there's less than about 60 GB free, or if / isn't on btrfs (then there are no snapshots before updates, and only reinstalling Arch with btrfs changes that). If the login screen isn't GNOME's, or sound goes through PulseAudio, it offers to switch to GNOME's login screen and to PipeWire.
3) At the end, it offers to run `configure`, which connects to your Federated Core, sets up backups and signs you in to the AI agents (see "Configure" below). If the install brought in a newer kernel, it asks you to reboot first; run `configure` after the reboot. 3) At the end, it offers to run `configure`, which connects to your Federated Core, sets up backups and signs you in to the AI agents (see "Configure" below). If the install brought in a newer kernel, it asks you to reboot first, and offers to reboot now; run `configure` after the reboot.
4) If something fails, just run the command again. It skips what's already done. 4) If something fails, just run the command again. It skips what's already done.
@@ -214,7 +214,7 @@ Each run's full output is saved in ~/.local/state/coredesktop/logs/, so you can
If an install or update fails, it offers to send its log to the CoreDesktop team so we can find and fix the problem. Nothing is sent unless you say yes, and you can read exactly what would be sent first: your user name, host name, home folder, email addresses, IP addresses and Tailscale names are taken out. Along with the log go CoreDesktop's version, the kernel's, the names of the steps that failed and your sibling projects' versions. You get a report ID to mention if you contact us. To send a log later, run `report` (the newest log) or `report <file>`; `report --view` shows what would be sent without sending anything. If an install or update fails, it offers to send its log to the CoreDesktop team so we can find and fix the problem. Nothing is sent unless you say yes, and you can read exactly what would be sent first: your user name, host name, home folder, email addresses, IP addresses and Tailscale names are taken out. Along with the log go CoreDesktop's version, the kernel's, the names of the steps that failed and your sibling projects' versions. You get a report ID to mention if you contact us. To send a log later, run `report` (the newest log) or `report <file>`; `report --view` shows what would be sent without sending anything.
It is a good idea to reboot after an update especially if you see you have a new Linux kernel installed (and that happens frequently enough for Arch). If the update installed a newer kernel, or upgraded firmware, CPU microcode, the NVIDIA driver, systemd or glibc, it says so at the end and asks whether to reboot now. The answer is no unless you type y.
Note: sometimes, for whatever reason, the update barfs. Take a look at [https://archlinux.org](https://archlinux.org) in the "Latest News" section for fixes. Note: sometimes, for whatever reason, the update barfs. Take a look at [https://archlinux.org](https://archlinux.org) in the "Latest News" section for fixes.
+7 -1
View File
@@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# #
# Purpose : The end of install.sh: say the install worked, say whether to # Purpose : The end of install.sh: say the install worked, say whether to
# reboot, and offer configure if something is still to do. refresh # reboot and offer to, and offer configure if something is still to do. refresh
# runs install.sh too, so it may all be done already; the install # runs install.sh too, so it may all be done already; the install
# still ends by saying it worked, so it can't be taken for a failure. # still ends by saying it worked, so it can't be taken for a failure.
@@ -19,6 +19,12 @@ echo -e "\e[32mCoreDesktop is installed.\e[0m"
if [ ! -d "/usr/lib/modules/$(uname -r)" ]; then if [ ! -d "/usr/lib/modules/$(uname -r)" ]; then
echo "A newer kernel has been installed. Reboot, then run: configure" echo "A newer kernel has been installed. Reboot, then run: configure"
echo "$CONFIGURE_HINT" echo "$CONFIGURE_HINT"
# The same as the system menu's restart: an active desktop session needs no password
if { : < "$TTY"; } 2> /dev/null && read -rp "Reboot now? [y/N] " answer < "$TTY" \
&& [[ "$answer" == [yY]* ]]; then
echo "Rebooting..."
systemctl reboot || echo "Couldn't reboot. Restart from the system menu instead."
fi
exit 0 exit 0
fi fi
echo "Kernel is up to date, no reboot needed. You may want to consider a reboot if other significant software was updated or installed." echo "Kernel is up to date, no reboot needed. You may want to consider a reboot if other significant software was updated or installed."
+29
View File
@@ -69,3 +69,32 @@ answer() {
[[ "$output" == *"CoreDesktop is installed."* ]] [[ "$output" == *"CoreDesktop is installed."* ]]
called configure called configure
} }
@test "finish-install reboots after a new kernel when told yes" {
KERNEL=0.0.0-not-installed
stub systemctl
answer y
run bash "$REPO/system/finish-install.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"Reboot, then run: configure"*"Rebooting..."* ]]
called systemctl reboot
}
@test "finish-install doesn't reboot unless told yes" {
KERNEL=0.0.0-not-installed
stub systemctl
answer ""
run bash "$REPO/system/finish-install.sh"
[ "$status" -eq 0 ]
not_called systemctl
}
@test "finish-install doesn't ask about a reboot when the kernel is up to date" {
needs_modules
stub systemctl
answer y
run bash "$REPO/system/finish-install.sh"
[ "$status" -eq 0 ]
[[ "$output" != *"Reboot now?"* ]]
not_called systemctl
}
+81
View File
@@ -237,3 +237,84 @@ ran() {
[[ "$output" == *"Done."* ]] [[ "$output" == *"Done."* ]]
ran a 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" ]
}
+33 -1
View File
@@ -44,6 +44,31 @@ clean_log() {
s/\x1b[()][0-9A-Za-z]//g; s/\x1b[=>]//g; s/\r+$//; s/.*\r//' "$1" s/\x1b[()][0-9A-Za-z]//g; s/\x1b[=>]//g; s/\r+$//; s/.*\r//' "$1"
} }
# Set by updates.d/99-reboot-check.sh when this update needs a reboot
REBOOT_NEEDED="$HOME/.local/state/coredesktop/reboot-needed"
# The same as the system menu's restart: an active desktop session needs no
# password. (sudo's cached password belongs to script(1)'s terminal, see below.)
reboot_now() {
echo "Rebooting..."
systemctl reboot || echo "Couldn't reboot. Restart from the system menu instead."
}
# If this update needs a reboot, ask on the terminal whether to reboot now. Under
# script(1), leave it to the copy outside, so the log is cleaned up first.
offer_reboot() {
local tty="${COREDESKTOP_TTY:-/dev/tty}" answer
[ -e "$REBOOT_NEEDED" ] || return 0
{ : < "$tty"; } 2> /dev/null || return 0
read -rp "Reboot now? [y/N] " answer < "$tty" || return 0
[[ "$answer" == [yY]* ]] || return 0
if [ -n "$UPDATE_IN_SCRIPT" ]; then
touch "$UPDATE_LOG.reboot"
else
reboot_now
fi
}
# Log each update to ~/.local/state/coredesktop/logs (95-cleanup.sh deletes # Log each update to ~/.local/state/coredesktop/logs (95-cleanup.sh deletes
# old ones). In a terminal, run under script(1), so everything still sees a # old ones). In a terminal, run under script(1), so everything still sees a
# terminal and colors, menus and prompts work as before; otherwise use tee. # terminal and colors, menus and prompts work as before; otherwise use tee.
@@ -52,9 +77,13 @@ if [[ -z "$UPDATE_LOG" ]] && mkdir -p -m 700 "$HOME/.local/state/coredesktop/log
UPDATE_LOG="$HOME/.local/state/coredesktop/logs/update-$(date +%Y-%m-%d-%H%M%S).log" UPDATE_LOG="$HOME/.local/state/coredesktop/logs/update-$(date +%Y-%m-%d-%H%M%S).log"
export UPDATE_LOG export UPDATE_LOG
if [ -t 0 ] && [ -t 1 ] && command -v script > /dev/null; then if [ -t 0 ] && [ -t 1 ] && command -v script > /dev/null; then
SHELL=/bin/bash script -q -e -f -c "$(printf '%q ' "$0" "$@")" "$UPDATE_LOG" SHELL=/bin/bash UPDATE_IN_SCRIPT=1 script -q -e -f -c "$(printf '%q ' "$0" "$@")" "$UPDATE_LOG"
status=$? status=$?
clean_log "$UPDATE_LOG" clean_log "$UPDATE_LOG"
if [ -e "$UPDATE_LOG.reboot" ]; then
rm -f "$UPDATE_LOG.reboot"
reboot_now
fi
exit "$status" exit "$status"
fi fi
exec > >(tee -a "$UPDATE_LOG") 2>&1 exec > >(tee -a "$UPDATE_LOG") 2>&1
@@ -118,6 +147,7 @@ while kill -0 $$ 2>/dev/null; do sudo -n -v; sleep 60; done > /dev/null 2>&1 &
SUDO_KEEPALIVE_PID=$! SUDO_KEEPALIVE_PID=$!
trap 'kill "$SUDO_KEEPALIVE_PID" 2>/dev/null' EXIT trap 'kill "$SUDO_KEEPALIVE_PID" 2>/dev/null' EXIT
rm -f "$REBOOT_NEEDED"
FAILED=() FAILED=()
[[ -n "$UPDATE_PULL_FAILED" ]] && FAILED+=("git pull") [[ -n "$UPDATE_PULL_FAILED" ]] && FAILED+=("git pull")
@@ -150,9 +180,11 @@ if (( ${#FAILED[@]} > 0 )); then
# Ask, on the terminal if there is one, whether to send it to us # Ask, on the terminal if there is one, whether to send it to us
[ -x ~/.local/bin/report ] && ~/.local/bin/report --offer "$UPDATE_LOG" "${FAILED[@]}" [ -x ~/.local/bin/report ] && ~/.local/bin/report --offer "$UPDATE_LOG" "${FAILED[@]}"
fi fi
offer_reboot
exit 1 exit 1
fi fi
echo "Done." echo "Done."
offer_reboot
exit 0 exit 0
} }
+5
View File
@@ -2,6 +2,9 @@
source "$HOME/.local/share/coredesktop/utils.sh" 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 # Packages whose upgrade only fully takes effect after a reboot: the kernel and
# firmware, the NVIDIA driver (the loaded module must match the installed # firmware, the NVIDIA driver (the loaded module must match the installed
# one), CPU microcode, and the core libraries every running program uses # one), CPU microcode, and the core libraries every running program uses
@@ -31,4 +34,6 @@ fi
if (( ${#reasons[@]} > 0 )); then if (( ${#reasons[@]} > 0 )); then
reason="$(printf '%s; ' "${reasons[@]}")" reason="$(printf '%s; ' "${reasons[@]}")"
echo -e "\e[33mPlease reboot when convenient to finish this update (${reason%; }).\e[0m" 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 fi