Repository navigation
Hibernate laptops on critical battery once hibernation is set up #13540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stevederico
wants to merge
10
commits into
omacom:quattro
Choose a base branch
from
stevederico:fix/critical-battery-hibernate
base: quattro
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0219577
Hibernate laptops on critical battery once hibernation is set up
stevederico 4e49925
Give laptops set up before the critical battery hibernate
stevederico 8734928
Say how to pick another critical battery level
stevederico d69b993
Hibernate on critical battery only once resume works
stevederico f7a0b8d
Date the critical battery migration after the ones quattro has run
stevederico 61e8ccf
Keep the critical battery test off the host's resume rebuild marker
stevederico 81f8c2e
Keep the critical battery test off the host's sleep setting
stevederico 625f72c
Drop the critical battery migration test
stevederico 39a39b2
Stub the Apple Silicon check in the critical battery test
stevederico 2f4445a
Fold the critical battery checks into the hibernation setup test
stevederico File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Installed by omarchy-hibernation-setup on laptops. UPower's Auto action is | ||
| # logind's Sleep(), which is suspend-then-hibernate: at the last few percent the | ||
| # suspend can drain the battery before the hibernate ever runs. Hibernate | ||
| # directly, early enough for the image to be written on battery. | ||
| # | ||
| # To pick another level, put PercentageAction under [UPower] in a later drop-in, | ||
| # such as /etc/UPower/UPower.conf.d/99-local.conf, and keep it below | ||
| # PercentageCritical. Setup leaves that file alone. | ||
| [UPower] | ||
| CriticalPowerAction=Hibernate | ||
| PercentageCritical=8.0 | ||
| PercentageAction=5.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| echo "Hibernate on critical battery on laptops that already set up hibernation" | ||
|
|
||
| # omarchy-hibernation-setup now installs a UPower drop-in that hibernates on | ||
| # critical battery, but only when it runs. A laptop set up before keeps UPower's | ||
| # Auto action, which suspends into a dying battery (#13256). On a machine that | ||
| # already has hibernation, setup skips the swap and boot steps and only adds | ||
| # what is missing, and it leaves an installed drop-in alone. | ||
| resume_conf="${OMARCHY_RESUME_CONF:-/etc/mkinitcpio.conf.d/omarchy_resume.conf}" | ||
|
|
||
| if [[ -f $resume_conf ]] && grep -q "^HOOKS+=(resume)$" "$resume_conf" && omarchy-battery-present; then | ||
| omarchy-hibernation-setup | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| #!/bin/bash | ||
| # | ||
| # Hibernation setup makes a laptop hibernate on critical battery, and removing | ||
| # hibernation takes that back. /etc paths are redirected into a scratch root; | ||
| # sudo runs the file operations there and records service restarts. | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| set -euo pipefail | ||
|
|
||
| source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" | ||
|
|
||
| scratch=$(mktemp -d) | ||
| trap 'rm -rf "$scratch"' EXIT | ||
| mkdir -p "$scratch/bin" "$scratch/etc/mkinitcpio.conf.d" "$scratch/etc/limine-entry-tool.d" | ||
| : > "$scratch/image_size" | ||
| export CALL_LOG="$scratch/calls" | ||
| export OMARCHY_PATH="$ROOT" | ||
| # omarchy-sleep-disabled reads this, so a host with sleep turned off doesn't skip setup. | ||
| export OMARCHY_SLEEP_CONFIG_DIR="$scratch/etc/systemd/sleep.conf.d" | ||
| export PATH="$scratch/bin:$ROOT/bin:$PATH" | ||
|
|
||
| cat > "$scratch/bin/sudo" <<'STUB' | ||
| #!/bin/bash | ||
| case "$1" in | ||
| systemctl) echo "systemctl ${*:2}" >> "$CALL_LOG" ;; | ||
| /usr/bin/install) | ||
| args=() | ||
| while (($# > 1)); do | ||
| shift | ||
| case "$1" in -o | -g) shift ;; *) args+=("$1") ;; esac | ||
| done | ||
| exec /usr/bin/install "${args[@]}" | ||
| ;; | ||
| *) exec "$@" ;; | ||
| esac | ||
| STUB | ||
| printf '#!/bin/bash\n[[ ${BATTERY:-1} == 1 ]]\n' > "$scratch/bin/omarchy-battery-present" | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
| printf '#!/bin/bash\nexit 0\n' > "$scratch/bin/gum" | ||
| # Setup skips Apple Silicon, so the test must not ask the host's hardware. | ||
| printf '#!/bin/bash\nexit 1\n' > "$scratch/bin/omarchy-hw-aarch64-apple" | ||
| printf '#!/bin/bash\necho "btrfs $*" >> "$CALL_LOG"\nexit 1\n' > "$scratch/bin/btrfs" | ||
| chmod +x "$scratch/bin/"* | ||
|
|
||
| redirect() { | ||
| sed -e "s|/etc/|$scratch/etc/|g" -e "s|/var/lib/omarchy/|$scratch/var/lib/omarchy/|g" -e "s|\"/swap|\"$scratch/swap|g" \ | ||
| -e "s|/sys/power/image_size|$scratch/image_size|g" "$ROOT/bin/$1" > "$scratch/$1" | ||
| } | ||
| redirect omarchy-hibernation-setup | ||
| redirect omarchy-hibernation-remove | ||
|
|
||
| drop_in="$scratch/etc/UPower/UPower.conf.d/70-omarchy-critical-hibernate.conf" | ||
| resume_params="$scratch/etc/limine-entry-tool.d/resume.conf" | ||
| echo "HOOKS+=(resume)" > "$scratch/etc/mkinitcpio.conf.d/omarchy_resume.conf" | ||
|
|
||
| # Without a resume offset the kernel cannot restore the image, so a dying | ||
| # battery would power off a session for good. The action waits for the offset. | ||
| echo 'KERNEL_CMDLINE[default]+=" resume=/dev/root resume_offset="' > "$resume_params" | ||
| bash "$scratch/omarchy-hibernation-setup" --no-rebuild > "$scratch/out" 2>&1 || | ||
| fail "setup without a resume offset still succeeds" "$(<"$scratch/out")" | ||
| [[ ! -e $drop_in ]] || fail "a laptop without a resume offset gets no critical battery action" | ||
| rm -f "$resume_params" | ||
| bash "$scratch/omarchy-hibernation-setup" --no-rebuild > "$scratch/out" 2>&1 | ||
| [[ ! -e $drop_in ]] || fail "a laptop without resume parameters gets no critical battery action" | ||
| pass "the critical battery action waits until resume can restore the session" | ||
|
|
||
| echo 'KERNEL_CMDLINE[default]+=" resume=/dev/root resume_offset=533760"' > "$resume_params" | ||
|
|
||
| : > "$CALL_LOG" | ||
| bash "$scratch/omarchy-hibernation-setup" --no-rebuild > "$scratch/out" 2>&1 || | ||
| fail "setup on an already-hibernating laptop succeeds" "$(<"$scratch/out")" | ||
| cmp -s "$ROOT/default/upower/omarchy-critical-hibernate.conf" "$drop_in" || | ||
| fail "a laptop set up earlier gets the critical battery action" "$(<"$scratch/out")" | ||
| grep -qx 'systemctl try-restart upower.service' "$CALL_LOG" || fail "UPower is restarted to read the new action" | ||
| pass "rerunning setup on a laptop installs the critical battery hibernate action" | ||
|
|
||
| grep -qx 'CriticalPowerAction=Hibernate' "$drop_in" || fail "the critical action is Hibernate" | ||
| pass "the critical battery action is Hibernate, not suspend-then-hibernate" | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| : > "$CALL_LOG" | ||
| bash "$scratch/omarchy-hibernation-setup" --no-rebuild > "$scratch/out" 2>&1 | ||
| [[ ! -s $CALL_LOG ]] || fail "an unchanged drop-in does not restart UPower" "$(<"$CALL_LOG")" | ||
| pass "an installed action is left alone" | ||
|
|
||
| rm -rf "$scratch/etc/UPower" | ||
| BATTERY=0 bash "$scratch/omarchy-hibernation-setup" --no-rebuild > "$scratch/out" 2>&1 | ||
| [[ ! -e $drop_in ]] || fail "a desktop gets no battery action" | ||
| pass "a machine without a battery gets no battery action" | ||
|
|
||
| # The migration runs setup on laptops set up before; a failed install has to | ||
| # fail setup so the migration runs again instead of being marked done. | ||
| mkdir -p "$scratch/etc/UPower" && touch "$scratch/etc/UPower/UPower.conf.d" | ||
| if bash "$scratch/omarchy-hibernation-setup" --no-rebuild > "$scratch/out" 2>&1; then | ||
| fail "setup reports a failed install of the critical battery action" "$(<"$scratch/out")" | ||
| fi | ||
| rm -rf "$scratch/etc/UPower" | ||
| pass "a failed install fails setup so the migration retries" | ||
|
|
||
| bash "$scratch/omarchy-hibernation-setup" --no-rebuild > /dev/null 2>&1 | ||
| printf '#!/bin/bash\nexit 0\n' > "$scratch/bin/limine-mkinitcpio" | ||
| printf '#!/bin/bash\nexit 1\n' > "$scratch/bin/swapon" | ||
| chmod +x "$scratch/bin/limine-mkinitcpio" "$scratch/bin/swapon" | ||
| : > "$CALL_LOG" | ||
| bash "$scratch/omarchy-hibernation-remove" > "$scratch/out" 2>&1 || fail "remove succeeds" "$(<"$scratch/out")" | ||
| [[ ! -e $drop_in ]] || fail "removing hibernation removes the critical battery action" | ||
| grep -qx 'systemctl try-restart upower.service' "$CALL_LOG" || fail "UPower is restarted after the action is removed" | ||
| pass "removing hibernation removes the critical battery action" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.