Repository navigation
Enable first-run user units one at a time #10582
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
Changes from all commits
e46ddfb
557f303
7a38fc8
7aa223d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" | ||
|
|
||
| # first-run must not abort the whole unit list when one unit is missing | ||
| # (issue #10484). systemctl enable with multiple names validates the full list | ||
| # first; a single missing name enables nothing. | ||
|
|
||
| script="$ROOT/install/user/first-run/enable-user-units.sh" | ||
| [[ -f $script ]] || fail "enable-user-units.sh exists" | ||
|
|
||
| grep -F 'for unit in' "$script" >/dev/null || | ||
| fail "enable-user-units enables units one at a time" | ||
| grep -F 'could not enable' "$script" >/dev/null || | ||
| fail "enable-user-units warns when a unit fails" | ||
| # Must not keep the multi-arg enable that aborts the whole list under set -e. | ||
| if grep -E 'enable --now[[:space:]]+\\$' "$script" >/dev/null; then | ||
| fail "enable-user-units must not multi-arg enable under one set -e line" | ||
| fi | ||
| pass "enable-user-units enables units one at a time" | ||
|
|
||
| test_tmp=$(mktemp -d) | ||
| trap 'rm -rf "$test_tmp"' EXIT | ||
| mock_bin="$test_tmp/bin" | ||
| log="$test_tmp/systemctl.log" | ||
| mkdir -p "$mock_bin" | ||
|
|
||
| cat >"$mock_bin/systemctl" <<'SH' | ||
| #!/bin/bash | ||
| printf '%s\n' "$*" >>"$OMARCHY_TEST_SYSTEMCTL_LOG" | ||
| # daemon-reload always succeeds. | ||
| [[ $1 == "--user" && $2 == "daemon-reload" ]] && exit 0 | ||
| # enable --now: fail the injected missing unit, or every unit. | ||
| if [[ $1 == "--user" && $2 == "enable" && $3 == "--now" ]]; then | ||
| unit=$4 | ||
| if [[ $unit == "${OMARCHY_TEST_MISSING_UNIT:-}" || -n ${OMARCHY_TEST_ALL_MISSING:-} ]]; then | ||
|
Comment on lines
+35
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
| echo "Failed to enable unit: Unit $unit does not exist" >&2 | ||
| exit 1 | ||
| fi | ||
| exit 0 | ||
| fi | ||
| exit 0 | ||
| SH | ||
| chmod +x "$mock_bin/systemctl" | ||
|
|
||
| # The real one would write into $HOME and fail where OWE is not installed. | ||
| cat >"$mock_bin/omarchy-hook-install" <<'SH' | ||
| #!/bin/bash | ||
| printf 'omarchy-hook-install %s\n' "$*" >>"$OMARCHY_TEST_SYSTEMCTL_LOG" | ||
| SH | ||
| chmod +x "$mock_bin/omarchy-hook-install" | ||
|
|
||
| # Missing unit in the middle must not stop later units. | ||
| : >"$log" | ||
| export OMARCHY_TEST_SYSTEMCTL_LOG="$log" | ||
| export OMARCHY_TEST_MISSING_UNIT="omarchy-sleep-lock.service" | ||
| PATH="$mock_bin:/usr/bin:/bin" bash "$script" >"$test_tmp/out" 2>"$test_tmp/err" || status=$? | ||
| status=${status:-0} | ||
| (( status == 0 )) || fail "enable-user-units exits 0 when some units still enable" "status=$status err=$(cat "$test_tmp/err")" | ||
|
|
||
| grep -F 'enable --now bt-agent.service' "$log" >/dev/null || | ||
| fail "enable-user-units still tries bt-agent" "$(cat "$log")" | ||
| grep -F 'enable --now omarchy-sleep-lock.service' "$log" >/dev/null || | ||
| fail "enable-user-units still tries the missing unit" "$(cat "$log")" | ||
| grep -F 'enable --now omarchy-crash-watch.service' "$log" >/dev/null || | ||
| fail "enable-user-units continues after a missing unit" "$(cat "$log")" | ||
| grep -F 'could not enable omarchy-sleep-lock.service' "$test_tmp/err" >/dev/null || | ||
| fail "enable-user-units warns about the missing unit" "$(cat "$test_tmp/err")" | ||
| grep -Fx 'omarchy-hook-install theme-set /usr/share/owe/10-owe-sync' "$log" >/dev/null || | ||
| fail "enable-user-units installs the OWE hook after a missing unit" "$(cat "$log")" | ||
| pass "enable-user-units continues after a missing unit" | ||
|
|
||
| # Prove the old multi-arg failure mode for contrast (documentation of the bug). | ||
| : >"$log" | ||
| cat >"$mock_bin/systemctl-atomic" <<'SH' | ||
| #!/bin/bash | ||
| printf '%s\n' "$*" >>"$OMARCHY_TEST_SYSTEMCTL_LOG" | ||
| if [[ $* == *enable* && $* == *does-not-exist* ]]; then | ||
| echo "Failed to enable unit: Unit does-not-exist.service does not exist" >&2 | ||
| exit 1 | ||
| fi | ||
| exit 0 | ||
| SH | ||
| chmod +x "$mock_bin/systemctl-atomic" | ||
| if PATH="$mock_bin:$PATH" systemctl-atomic --user enable --now bt-agent.service does-not-exist.service 2>/dev/null; then | ||
| fail "multi-arg enable should fail when one unit is missing" | ||
| fi | ||
| # No partial enables recorded as separate lines for the good unit alone — the | ||
| # atomic call is one line that failed entirely. | ||
| lines=$(grep -c 'enable --now' "$log" || true) | ||
| (( lines == 1 )) || fail "atomic multi-arg enable is a single failed call" "$(cat "$log")" | ||
| pass "multi-arg enable fails the whole list when one unit is missing" | ||
|
|
||
| # All units present → clean success, no warnings. | ||
| : >"$log" | ||
| : >"$test_tmp/err" | ||
| unset OMARCHY_TEST_MISSING_UNIT | ||
| PATH="$mock_bin:/usr/bin:/bin" bash "$script" >"$test_tmp/out" 2>"$test_tmp/err" | ||
| [[ ! -s $test_tmp/err ]] || fail "enable-user-units is quiet when every unit enables" "$(cat "$test_tmp/err")" | ||
| for unit in bt-agent.service owed.service omarchy-recover-internal-monitor.service omarchy-sleep-lock.service \ | ||
| omarchy-migrate-notify.service omarchy-fcitx5.service omarchy-crash-watch.service; do | ||
| grep -F "enable --now $unit" "$log" >/dev/null || | ||
| fail "enable-user-units enables $unit" "$(cat "$log")" | ||
| done | ||
| pass "enable-user-units enables every shipped unit when all exist" | ||
|
|
||
| # No unit enables → first-run must see the step fail. | ||
| : >"$log" | ||
| status=0 | ||
| OMARCHY_TEST_ALL_MISSING=1 PATH="$mock_bin:/usr/bin:/bin" bash "$script" >"$test_tmp/out" 2>"$test_tmp/err" || status=$? | ||
| (( status != 0 )) || fail "enable-user-units fails when no unit could be enabled" "$(cat "$test_tmp/err")" | ||
| grep -F 'no omarchy user units could be enabled' "$test_tmp/err" >/dev/null || | ||
| fail "enable-user-units says why it failed" "$(cat "$test_tmp/err")" | ||
| pass "enable-user-units fails when no unit could be enabled" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
omarchy-sleep-lock.servicefails to enable while another unit succeeds, this script reports success. First-run is then marked complete, so later logins do not retry the failed unit. The service starts the monitor that locks the session before general suspend; without it, the session can remain unlocked after waking, even if the missing unit is later restored. Preserve the partial enablement, but keep failed units eligible for retry.How this was verified: The sleep-lock unit starts the suspend-event monitor, while the first-run completion marker prevents another enable attempt.