wake-alarm/uninstall.sh
Krzysztof kuhy Rudnicki c3c129b068 Make the morning session the carrot: earn 11:00 by finishing it in time
On 2026-09-19 the phone was powered off after the bathroom tag and nothing
on the PC noticed: every finished session was published and nothing read
it. Now wake-alarm distils the phone's morning into an HMAC-signed
~/.local/state/wake_alarm/morning_session.json (wake-alarm-session.timer,
07:00-11:00 every 2 min) that screen-locker and leetcode-guard read to
defer their locks -- provisionally until min(start + 90 min, 09:30) while
the session is live, until 11:00 once it completed inside that cutoff,
and not at all for a session finished later (the phone switched on at
noon completes the legs then; that must un-lock nothing).

The phone publishes the session at start as well as at finish
(current_session, cleared with the finish stamp), so the PC can tell
"started, not finished" from "never started". A required 1-5 energy tap
joins the weigh-in and ships as latest_energy with a PC reader mirroring
_weight (the shared half is _field_reader).

Also fixes the vmbox harness, red since the 2026-09-11 home-tidy: the
guest tree lives at ~/wake-alarm, and the INSTALL-OK grep matched vm's
echo of the command line. Takes Flutter 3.47.5.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tp54ewdXRLaimUuT8LgYyn
2026-09-19 16:40:51 +02:00

104 lines
3.5 KiB
Bash
Executable File

#!/bin/bash
# Remove the PC's waking machinery.
#
# Usage:
# bash uninstall.sh # remove everything this repo installed
# bash uninstall.sh --retired-only # remove only the retired waking pieces
#
# WHY THIS SCRIPT EXISTS, AND WHY `rm -rf` ON THE REPO IS NOT ENOUGH:
# `/usr/local/bin/shutdown` is root-owned and shadows `/usr/bin/shutdown` via
# PATH order. Deleting the repo does NOT remove it, and with the alarm cache
# gone it falls through to `sudo rtcwake ... ; exec systemctl hibernate` --
# so `shutdown now` would silently stop being a poweroff, every day, forever.
#
# `/etc/sudoers.d/wake-alarm` is deliberately LEFT IN PLACE even by a full
# uninstall: screen-locker's own _wake_alarm.py:_schedule_rtcwake still shells
# out to `sudo rtcwake`, and removing the entry here would break a live feature
# in another repo with no error message anywhere.
set -euo pipefail
readonly SLEEP_HOOK_DST="/usr/lib/systemd/system-sleep/wake-alarm.sh"
readonly SHUTDOWN_WRAPPER_DST="/usr/local/bin/shutdown"
readonly SYSTEMD_USER_DIR="$HOME/.config/systemd/user"
RETIRED_ONLY=0
usage() {
echo "Usage: $(basename "$0") [--retired-only]"
exit 0
}
while [[ $# -gt 0 ]]; do
case $1 in
--retired-only) RETIRED_ONLY=1; shift ;;
-h|--help) usage ;;
*) echo "Unknown option: $1" >&2; exit 1 ;;
esac
done
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
exit 1
fi
remove_retired() {
# The shutdown wrapper. Checked by content, not just existence, so this
# never deletes an unrelated /usr/local/bin/shutdown someone else put there.
if [[ -f "$SHUTDOWN_WRAPPER_DST" ]] \
&& grep -q 'wake-alarm\|rtcwake' "$SHUTDOWN_WRAPPER_DST"; then
echo " Removing $SHUTDOWN_WRAPPER_DST (restores real /usr/bin/shutdown)"
sudo rm -f "$SHUTDOWN_WRAPPER_DST"
else
echo " $SHUTDOWN_WRAPPER_DST: not ours or already gone"
fi
if [[ -f "$SLEEP_HOOK_DST" ]]; then
echo " Removing $SLEEP_HOOK_DST"
sudo rm -f "$SLEEP_HOOK_DST"
else
echo " $SLEEP_HOOK_DST: already gone"
fi
# wake-alarm.service is gone from the repo; clear any stale installed copy
# and its enable symlink.
if [[ -f "$SYSTEMD_USER_DIR/wake-alarm.service" ]]; then
echo " Removing stale wake-alarm.service"
systemctl --user disable wake-alarm.service >/dev/null 2>&1 || true
rm -f "$SYSTEMD_USER_DIR/wake-alarm.service"
else
echo " wake-alarm.service: already gone"
fi
}
remove_trigger() {
echo " Disabling the trigger timer"
systemctl --user disable --now wake-alarm-trigger.timer >/dev/null 2>&1 || true
systemctl --user disable --now wake-alarm-session.timer >/dev/null 2>&1 || true
rm -f "$SYSTEMD_USER_DIR/wake-alarm-trigger.service" \
"$SYSTEMD_USER_DIR/wake-alarm-trigger.timer" \
"$SYSTEMD_USER_DIR/wake-alarm-session.service" \
"$SYSTEMD_USER_DIR/wake-alarm-session.timer"
}
main() {
echo "=== Removing the PC's waking machinery ==="
remove_retired
if [[ $RETIRED_ONLY -eq 0 ]]; then
remove_trigger
echo " Note: the workout lock no longer starts at the phone's alarm time."
fi
systemctl --user daemon-reload
echo
echo "Left in place on purpose:"
echo " /etc/sudoers.d/wake-alarm — screen-locker's own rtcwake path needs it."
echo
echo "Verify: command -v shutdown # expect /usr/bin/shutdown"
}
main "$@"