mirror of
https://github.com/kuhyx/wake-alarm.git
synced 2026-11-11 13:27:32 +01:00
The PC no longer wakes anyone -- the phone does. This deletes the alarm window, the audio escalation, the sink/reactivation machinery, the power-key inhibitor, the escape hatch, the curtains, the smart plug, the brightness and DDC/CI control, the hibernate path (shutdown wrapper + rtcwake + sleep hook) and the challenge set: 30 modules, 34 test files, ~5k lines. What stays is the part that still earns its keep: the per-minute trigger reads the alarm the phone published and starts morning-routine.service, so the workout lock still runs at the right time. THE ONE LOAD-BEARING BEHAVIOUR CHANGE. Deleting _alarm.py orphaned the only writer of wake_state.json, and _trigger gated on it via was_alarm_dismissed_today(). With that gone -- and was_workout_logged_today() already permanently False, since WORKOUT_LOG_FILE does not exist -- both gates would have been dead and the routine restarted on every tick for the rest of the 60-minute catch-up window. The unit is Type=simple, so a start while it runs is a no-op, but the moment the workout lock finished the next tick would relaunch it on top of the user. So _trigger now writes its own once-per-day latch (save_trigger_fired / was_trigger_fired_today) and gates on that. Collapsing the catch-up window instead was rejected: that window is the entire reason a suspended or just-booted machine still fires. It also replaces the deleted sleep hook, via Persistent=true. _trigger also imported should_refire from _alarm_session, which was on the delete list. Since start_session lived only in _alarm.py, no session record is ever written again and the branch was unreachable, not merely unused. WAKE_STATE_FILE is now redirected in tests/conftest.py rather than per-file. The trigger tests never redirected it, because until this commit nothing on that path wrote anything -- and a per-file redirect is exactly the kind that gets forgotten when a new writer appears, with a silent failure: a green suite that quietly stamped the live state file. Verified by mtime that it did not. Cross-repo, same change: morning_routine._orchestrator loses its alarm leg and its --with-alarm flag. Leaving an orchestrator pointing at a deleted module caused a month-long silent failure once already. uninstall.sh is new, and matters more than it looks. /usr/local/bin/shutdown is root-owned and shadows /usr/bin/shutdown; deleting this repo would leave it in place, and with the alarm cache gone it falls through to rtcwake + hibernate -- so "shutdown now" would silently stop being a poweroff, every day, forever. /etc/sudoers.d/wake-alarm is deliberately NOT removed: screen-locker's own _wake_alarm.py still needs passwordless rtcwake. 159 tests pass at 100% branch coverage; all 26 pre-commit hooks green. Verified by running it: _sync --show and _trigger --dry-run both resolve. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PcdngP688mW6rJye3LRkSN
72 lines
3.2 KiB
Bash
Executable File
72 lines
3.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# Install the wake-alarm trigger timer.
|
|
#
|
|
# Usage: bash install.sh
|
|
#
|
|
# The PC no longer wakes anyone -- the phone does. All this installs is the
|
|
# per-minute trigger that starts morning-routine.service (and therefore the
|
|
# workout lock) at the time the phone last synced.
|
|
#
|
|
# What it does:
|
|
# 1. Installs wake_alarm + dependencies for /usr/bin/python
|
|
# 2. Installs the systemd user units and enables the per-minute trigger timer
|
|
# 3. Removes the retired waking machinery from earlier installs
|
|
#
|
|
# Deliberately NOT done any more, and why:
|
|
# - no shutdown wrapper, no rtcwake, no sleep hook: the PC does not wake you
|
|
# - the /etc/sudoers.d/wake-alarm entry is left ALONE. screen-locker's own
|
|
# _wake_alarm.py still shells out to `sudo rtcwake`, so removing it here
|
|
# would silently break a live feature in another repo.
|
|
|
|
set -euo pipefail
|
|
|
|
# Refuse to run under sudo. This script must run as the logged-in user: it
|
|
# installs *user* systemd units and calls `sudo` itself for the few root-owned
|
|
# pieces. Under sudo, XDG_RUNTIME_DIR and DBUS_SESSION_BUS_ADDRESS are stripped,
|
|
# so `systemctl --user` fails and later steps are silently skipped while the
|
|
# earlier pip output still looks like success. It also runs pip as root, which
|
|
# leaves root-owned files in ~/.cache/pip. Failing loudly beats half-finishing.
|
|
if [[ -n "${SUDO_USER:-}" || $EUID -eq 0 ]]; then
|
|
echo "Error: do not run this script with sudo." >&2
|
|
echo "Run it as your normal user: bash $0" >&2
|
|
echo "It will prompt for sudo itself where root is actually needed." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Split declare/assign so the command-substitution exit code is not masked (SC2155).
|
|
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
|
readonly SCRIPT_DIR
|
|
readonly REPO_DIR="$SCRIPT_DIR"
|
|
readonly TRIGGER_SERVICE_SRC="$SCRIPT_DIR/wake-alarm-trigger.service"
|
|
readonly TRIGGER_TIMER_SRC="$SCRIPT_DIR/wake-alarm-trigger.timer"
|
|
readonly SYSTEMD_USER_DIR="$HOME/.config/systemd/user"
|
|
|
|
echo "=== Wake Alarm Trigger Installer ==="
|
|
|
|
echo "[1/3] Installing wake_alarm for /usr/bin/python..."
|
|
# Editable, and from this clone: a later `git pull` here then updates the
|
|
# running production code with no reinstall. A non-editable snapshot taken
|
|
# from a scratch directory silently stops tracking this repo.
|
|
/usr/bin/python3 -m pip install --user --break-system-packages -e "$REPO_DIR"
|
|
echo " Installed. Verifying import..."
|
|
/usr/bin/python3 -c "import wake_alarm; import gatelock"
|
|
echo " wake_alarm and gatelock import under /usr/bin/python."
|
|
|
|
echo "[2/3] Installing systemd user units..."
|
|
mkdir -p "$SYSTEMD_USER_DIR"
|
|
cp "$TRIGGER_SERVICE_SRC" "$TRIGGER_TIMER_SRC" "$SYSTEMD_USER_DIR/"
|
|
systemctl --user daemon-reload
|
|
systemctl --user enable --now wake-alarm-trigger.timer
|
|
echo " Trigger timer enabled and started (ticks once a minute)."
|
|
|
|
echo "[3/3] Removing retired waking machinery from earlier installs..."
|
|
bash "$SCRIPT_DIR/uninstall.sh" --retired-only
|
|
echo
|
|
|
|
echo "=== Installation complete ==="
|
|
echo "The timer ticks once a minute and starts morning-routine.service at the"
|
|
echo "time the phone last synced."
|
|
echo "Check what it resolves right now: python -m wake_alarm._sync --show"
|
|
echo "Check what the next tick would do: python -m wake_alarm._trigger --dry-run"
|
|
echo "Watch it live: journalctl --user -fu wake-alarm-trigger.service"
|