45 lines
1.3 KiB
Bash
Executable File
45 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
fail() {
|
|
printf 'Panama action IPC contract: %s\n' "$1" >&2
|
|
exit 1
|
|
}
|
|
|
|
restore_target() {
|
|
local target="$1" expected="$2" current
|
|
current="$(qs ipc call "$target" status 2>/dev/null || true)"
|
|
if [[ $current != "$expected" && ( $expected == true || $expected == false ) ]]; then
|
|
qs ipc call "$target" toggle >/dev/null 2>&1 || true
|
|
fi
|
|
}
|
|
|
|
exercise_toggle() {
|
|
local target="$1" before after restored
|
|
before="$(qs ipc call "$target" status)"
|
|
trap 'restore_target "$target" "$before"' RETURN
|
|
|
|
[[ $before == true || $before == false ]] \
|
|
|| fail "$target returned a non-boolean status: $before"
|
|
|
|
after="$(qs ipc call "$target" toggle)"
|
|
[[ $after != "$before" ]] \
|
|
|| fail "$target did not change state: before=$before after=$after"
|
|
|
|
restored="$(qs ipc call "$target" toggle)"
|
|
[[ $restored == "$before" ]] \
|
|
|| fail "$target did not restore its original state: before=$before restored=$restored"
|
|
|
|
trap - RETURN
|
|
}
|
|
|
|
ipc="$(qs ipc show)"
|
|
rg -q '^target caffeine$' <<<"$ipc" || fail 'caffeine IPC target is missing'
|
|
rg -q '^target night-light$' <<<"$ipc" || fail 'night-light IPC target is missing'
|
|
|
|
exercise_toggle caffeine
|
|
exercise_toggle night-light
|
|
|
|
printf 'Panama action IPC contract: PASS\n'
|