Keep a closed lid from suspending during install and update
shellcheck / shellcheck (push) Successful in 19s

logind ignores sleep locks when the lid closes (LidSwitchIgnoreInhibited),
so install.sh and update now also take a handle-lid-switch lock. It's a
separate systemd-inhibit, since polkit refuses that lock outside a local
session and that mustn't cost the sleep lock too. After a long sleep, a
pacman upgrade can be cut off part way and sudo's cached password expires.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-29 21:25:39 -07:00
co-authored by Claude Opus 5.5
parent af853b7d72
commit 06fff0d777
3 changed files with 20 additions and 8 deletions
+10 -4
View File
@@ -153,11 +153,17 @@ SUDO_KEEPALIVE_PID=$!
trap 'kill "$SUDO_KEEPALIVE_PID" 2>/dev/null' EXIT
# Keep the computer from suspending, from idle or a closed lid, until update
# exits: a pacman upgrade cut off part way can leave it unbootable. tail exits
# with update, and that ends the inhibitor.
# exits: a pacman upgrade cut off part way can leave it unbootable, and after a
# long sleep sudo's cached password has expired, so the next sudo times out.
# logind ignores sleep locks when the lid closes (LidSwitchIgnoreInhibited), so
# the lid takes its own lock; it's kept apart because polkit refuses it outside
# a local session, and that mustn't lose the sleep lock too. tail exits with
# update, and that ends the inhibitors.
if command -v systemd-inhibit > /dev/null; then
systemd-inhibit --what=sleep:idle --who=CoreDesktop --why="Updating CoreDesktop" --mode=block \
tail --pid=$$ -f /dev/null > /dev/null 2>&1 &
for what in sleep:idle handle-lid-switch; do
systemd-inhibit --what="$what" --who=CoreDesktop --why="Updating CoreDesktop" --mode=block \
tail --pid=$$ -f /dev/null > /dev/null 2>&1 &
done
fi
rm -f "$REBOOT_NEEDED"