2026-05-22 16:01:04 +02:00
|
|
|
#!/bin/bash
|
2026-05-25 18:55:27 +02:00
|
|
|
# systemd-sleep hook: start the unified morning routine after resume.
|
2026-05-22 16:01:04 +02:00
|
|
|
#
|
|
|
|
|
# Installed to /usr/lib/systemd/system-sleep/wake-alarm.sh by install.sh.
|
|
|
|
|
#
|
2026-05-25 18:55:27 +02:00
|
|
|
# When the PC hibernates (rtcwake -m disk) and resumes the next morning, the
|
|
|
|
|
# user session is restored but no morning service is running. This hook starts
|
|
|
|
|
# morning-routine.service, which runs the wake alarm first (it owns the
|
|
|
|
|
# fullscreen until dismissed) and then the workout screen lock - one coherent
|
|
|
|
|
# flow, with the two never fighting for the screen.
|
2026-05-22 16:01:04 +02:00
|
|
|
|
|
|
|
|
if [[ "$1" != "post" ]]; then
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
2026-05-25 18:55:27 +02:00
|
|
|
logger -t wake-alarm-hook "Woke from sleep (type=$2) - starting morning-routine.service for active sessions"
|
2026-05-22 16:01:04 +02:00
|
|
|
|
|
|
|
|
# Start wake-alarm.service for every logged-in user that has a running session
|
|
|
|
|
# bus. Works with systemd >= 219.
|
|
|
|
|
while IFS= read -r uid; do
|
|
|
|
|
runtime_dir="/run/user/$uid"
|
|
|
|
|
[[ -d "$runtime_dir" ]] || continue
|
|
|
|
|
username=$(id -nu "$uid" 2>/dev/null) || continue
|
2026-05-25 18:55:27 +02:00
|
|
|
logger -t wake-alarm-hook "Starting morning-routine.service for user $username (uid=$uid)"
|
2026-05-22 16:01:04 +02:00
|
|
|
XDG_RUNTIME_DIR="$runtime_dir" \
|
|
|
|
|
DBUS_SESSION_BUS_ADDRESS="unix:path=${runtime_dir}/bus" \
|
|
|
|
|
runuser -u "$username" -- \
|
2026-05-25 18:55:27 +02:00
|
|
|
systemctl --user start morning-routine.service 2>/dev/null \
|
|
|
|
|
|| logger -t wake-alarm-hook "Failed to start morning-routine.service for $username (non-fatal)"
|
2026-05-22 16:01:04 +02:00
|
|
|
done < <(loginctl list-sessions --no-legend 2>/dev/null | awk '{print $2}' | sort -u)
|