utils/gatelock/install_evening_gates.sh
Krzysztof kuhy Rudnicki 115e050110 gatelock 0.15.0: evening gate chain
Add gatelock.evening_chain: `pending` lists the unpaid rungs (book,
tutor, LeetCode), `run` runs each gate in order before night lockdown.
Also RANK_EVENING_GATE = 150, systemd/evening-gates.service and
install_evening_gates.sh (never enables or starts the unit).

Failure paths:
- pending: unreadable ledger or key, reader error, any exception ->
  exit 2 on stderr. FAIL CLOSED (root enters lockdown).
- pending: free day, sick day, 23:00 or later -> exit 1 (stands down).
- run: a rung it cannot check is unpaid, its gate stays up (closed).
- run: gate fails, or exits 0 with the rung unpaid -> skipped; two in
  a row -> exit 1, never a spin (stops, root enters lockdown: closed).
- run: gate exit 10 -> exit 0; exit 3 (no X) -> exit 3; gate still up
  at 23:00 is killed -> exit 0 (the hard time wins).
- earned_time/freedays/sickdays are an optional `evening` extra, so a
  locker never fails to start over them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWYGbnVt12uFXKgNYm8
2026-11-17 21:24:26 +01:00

29 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
# Install the evening-gates user unit. Idempotent; never enables or starts it:
# root's shutdown check starts it on demand (see evening_chain.py).
set -euo pipefail
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly REPO_DIR
readonly UNIT_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user"
readonly SYSTEM_PYTHON="/usr/bin/python3"
fail() {
echo "install_evening_gates: $*" >&2
exit 1
}
main() {
[[ $EUID -ne 0 ]] || fail "run as kuhy, not root (it is a user unit)"
"$SYSTEM_PYTHON" -c "import gatelock.evening_chain, earned_time, freedays, sickdays" \
|| fail "the system python cannot import gatelock.evening_chain and its readers"
mkdir -p "$UNIT_DIR"
install -m 644 "$REPO_DIR/systemd/evening-gates.service" "$UNIT_DIR/"
systemctl --user daemon-reload
systemd-analyze --user verify "$UNIT_DIR/evening-gates.service" \
|| fail "evening-gates.service does not verify"
echo "installed $UNIT_DIR/evening-gates.service (not enabled, not started)"
}
main "$@"