2026-04-12 20:45:24 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
# Install the weekend wake alarm systemd user service and sudoers entry.
|
|
|
|
|
#
|
|
|
|
|
# Usage: bash install.sh
|
|
|
|
|
#
|
|
|
|
|
# What it does:
|
2026-06-22 12:31:40 +02:00
|
|
|
# 1. Installs wake_alarm + dependencies for /usr/bin/python
|
|
|
|
|
# 2. Installs system dependencies (alsa-utils, ddcutil)
|
|
|
|
|
# 3. Copies wake-alarm.service to ~/.config/systemd/user/ and enables it
|
|
|
|
|
# 4. Installs the systemd-sleep hook (restarts alarm after hibernate resume)
|
|
|
|
|
# 5. Adds a sudoers entry for passwordless rtcwake
|
|
|
|
|
# 6. Installs shutdown wrapper so "shutdown now" also hibernates on alarm nights
|
|
|
|
|
# 7. Installs fan-control script so alarm can max fans on wake
|
|
|
|
|
# 8. Installs python-kasa (AUR) so the alarm can toggle a Tapo P110 smart plug
|
|
|
|
|
# 9. Installs ddcutil and grants /dev/i2c-* access for DDC/CI monitor control
|
2026-04-12 20:45:24 +02:00
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
2026-06-22 12:31:40 +02:00
|
|
|
# Split declare/assign so the command-substitution exit code is not masked (SC2155).
|
2026-04-12 20:45:24 +02:00
|
|
|
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
2026-06-22 12:31:40 +02:00
|
|
|
readonly SCRIPT_DIR
|
|
|
|
|
readonly REPO_DIR="$SCRIPT_DIR"
|
2026-04-12 20:45:24 +02:00
|
|
|
SERVICE_FILE="$SCRIPT_DIR/wake-alarm.service"
|
2026-05-22 16:01:04 +02:00
|
|
|
SLEEP_HOOK_SRC="$SCRIPT_DIR/sleep-hook.sh"
|
|
|
|
|
SHUTDOWN_WRAPPER_SRC="$SCRIPT_DIR/shutdown-wrapper.sh"
|
2026-05-23 19:51:26 +02:00
|
|
|
FANS_SCRIPT_SRC="$SCRIPT_DIR/wake-alarm-fans.sh"
|
|
|
|
|
FANS_SCRIPT_DST="/usr/local/bin/wake-alarm-fans.sh"
|
2026-04-12 20:45:24 +02:00
|
|
|
SYSTEMD_USER_DIR="$HOME/.config/systemd/user"
|
2026-05-22 16:01:04 +02:00
|
|
|
SLEEP_HOOK_DST="/usr/lib/systemd/system-sleep/wake-alarm.sh"
|
|
|
|
|
SHUTDOWN_WRAPPER_DST="/usr/local/bin/shutdown"
|
2026-04-12 20:45:24 +02:00
|
|
|
SUDOERS_FILE="/etc/sudoers.d/wake-alarm"
|
|
|
|
|
RTCWAKE_BIN="/usr/sbin/rtcwake"
|
|
|
|
|
|
|
|
|
|
echo "=== Weekend Wake Alarm Installer ==="
|
|
|
|
|
|
2026-06-22 12:31:40 +02:00
|
|
|
# 1. Install this package + its dependencies into system Python -------------
|
|
|
|
|
echo "[1/9] Installing wake_alarm + dependencies for /usr/bin/python..."
|
|
|
|
|
/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 cleanly from the system interpreter."
|
|
|
|
|
|
|
|
|
|
# 2. Install system dependencies
|
|
|
|
|
echo "[2/9] Checking system dependencies..."
|
2026-05-22 22:48:28 +02:00
|
|
|
if ! command -v speaker-test &>/dev/null; then
|
|
|
|
|
echo " Installing alsa-utils (required for speaker-test)..."
|
|
|
|
|
sudo pacman -S --noconfirm alsa-utils
|
|
|
|
|
else
|
|
|
|
|
echo " alsa-utils already installed"
|
|
|
|
|
fi
|
|
|
|
|
|
2026-06-22 12:31:40 +02:00
|
|
|
# 3. Install systemd user service
|
|
|
|
|
echo "[3/9] Installing systemd user service..."
|
2026-04-12 20:45:24 +02:00
|
|
|
mkdir -p "$SYSTEMD_USER_DIR"
|
|
|
|
|
cp "$SERVICE_FILE" "$SYSTEMD_USER_DIR/wake-alarm.service"
|
|
|
|
|
systemctl --user daemon-reload
|
|
|
|
|
echo " Installed to $SYSTEMD_USER_DIR/wake-alarm.service"
|
|
|
|
|
systemctl --user enable wake-alarm.service
|
|
|
|
|
echo " Service enabled (will start on next boot)"
|
|
|
|
|
|
2026-06-22 12:31:40 +02:00
|
|
|
# 4. Install systemd-sleep hook (restarts alarm after hibernate resume)
|
|
|
|
|
echo "[4/9] Installing systemd-sleep hook..."
|
2026-05-22 16:01:04 +02:00
|
|
|
sudo cp "$SLEEP_HOOK_SRC" "$SLEEP_HOOK_DST"
|
|
|
|
|
sudo chmod 0755 "$SLEEP_HOOK_DST"
|
|
|
|
|
echo " Installed to $SLEEP_HOOK_DST"
|
|
|
|
|
|
2026-06-22 12:31:40 +02:00
|
|
|
# 5. Add sudoers entry for rtcwake (requires root)
|
|
|
|
|
echo "[5/9] Setting up sudoers for rtcwake..."
|
2026-04-12 20:45:24 +02:00
|
|
|
SUDOERS_LINE="$USER ALL=(root) NOPASSWD: $RTCWAKE_BIN"
|
|
|
|
|
if [[ -f "$SUDOERS_FILE" ]] && grep -qF "$SUDOERS_LINE" "$SUDOERS_FILE"; then
|
|
|
|
|
echo " Sudoers entry already exists"
|
|
|
|
|
else
|
|
|
|
|
echo " Adding sudoers entry (requires sudo)..."
|
|
|
|
|
echo "$SUDOERS_LINE" | sudo tee "$SUDOERS_FILE" > /dev/null
|
|
|
|
|
sudo chmod 0440 "$SUDOERS_FILE"
|
|
|
|
|
echo " Added: $SUDOERS_LINE"
|
|
|
|
|
fi
|
|
|
|
|
|
2026-06-22 12:31:40 +02:00
|
|
|
# 6. Install shutdown wrapper (/usr/local/bin/shutdown shadows /usr/bin/shutdown)
|
|
|
|
|
echo "[6/9] Installing shutdown wrapper..."
|
2026-05-22 16:01:04 +02:00
|
|
|
sudo cp "$SHUTDOWN_WRAPPER_SRC" "$SHUTDOWN_WRAPPER_DST"
|
|
|
|
|
sudo chmod 0755 "$SHUTDOWN_WRAPPER_DST"
|
|
|
|
|
echo " Installed to $SHUTDOWN_WRAPPER_DST"
|
|
|
|
|
echo " 'shutdown now' will now hibernate (not poweroff) on alarm nights."
|
|
|
|
|
|
2026-06-22 12:31:40 +02:00
|
|
|
# 7. Install fan-control script and its sudoers entry
|
|
|
|
|
echo "[7/9] Installing fan-control script..."
|
2026-05-23 19:51:26 +02:00
|
|
|
sudo cp "$FANS_SCRIPT_SRC" "$FANS_SCRIPT_DST"
|
|
|
|
|
sudo chmod 0755 "$FANS_SCRIPT_DST"
|
|
|
|
|
FANS_SUDOERS_LINE="$USER ALL=(root) NOPASSWD: $FANS_SCRIPT_DST"
|
|
|
|
|
if [[ -f "$SUDOERS_FILE" ]] && grep -qF "$FANS_SUDOERS_LINE" "$SUDOERS_FILE"; then
|
|
|
|
|
echo " Fan sudoers entry already exists"
|
|
|
|
|
else
|
|
|
|
|
# Append to existing file (or create)
|
|
|
|
|
echo "$FANS_SUDOERS_LINE" | sudo tee -a "$SUDOERS_FILE" > /dev/null
|
|
|
|
|
sudo chmod 0440 "$SUDOERS_FILE"
|
|
|
|
|
echo " Added fan sudoers entry"
|
|
|
|
|
fi
|
|
|
|
|
|
2026-06-22 12:31:40 +02:00
|
|
|
# 8. Install python-kasa (AUR) for TP-Link Tapo P110 smart-plug control
|
|
|
|
|
echo "[8/9] Installing python-kasa (AUR)..."
|
2026-05-23 19:51:26 +02:00
|
|
|
if python -c 'import kasa' 2>/dev/null; then
|
|
|
|
|
echo " python-kasa already installed"
|
|
|
|
|
elif command -v yay &>/dev/null; then
|
|
|
|
|
yay -S --noconfirm --needed python-kasa
|
|
|
|
|
else
|
|
|
|
|
echo " WARNING: yay not found; install python-kasa manually for smart-plug support" >&2
|
|
|
|
|
fi
|
|
|
|
|
if [[ ! -f "$HOME/.config/wake_alarm/tapo.json" ]]; then
|
|
|
|
|
echo " NOTE: ~/.config/wake_alarm/tapo.json not found — smart-plug control is disabled."
|
|
|
|
|
echo " Create it (mode 0600) with keys: host, email, password."
|
|
|
|
|
fi
|
|
|
|
|
|
2026-06-22 12:31:40 +02:00
|
|
|
# 9. Install ddcutil for DDC/CI monitor power control
|
feat: split oversized modules for 500-line limit, fix kasa coverage gap
Split diet_guard/_gatelock.py, wake_alarm/_alarm.py, and the
usage_report.py/_usage_report_parsing.py pair into focused
sub-modules so every Python file is <= 500 lines, satisfying
test_file_length.py. Install python-kasa into .venv (declared in
requirements but missing after the 3.13->3.14 venv upgrade),
fixing 8 failing smart_plug tests and restoring 100% coverage.
Also includes prior in-progress work from the working tree: the
wake_alarm Progress/View/Hardware field-grouping refactor,
brother_printer query module + tests, diet_guard foodbank/state/cli
updates, new shared coerce/logging_setup helpers, morning_routine
orchestrator tweaks, dwm window-manager config, gaming scripts, and
misc maintenance/digital-wellbeing script updates.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-14 07:19:37 +02:00
|
|
|
# ddcutil lets the alarm force the G27Q on via DDC/CI even when the monitor
|
|
|
|
|
# was physically powered off (power button), bypassing DPMS limitations.
|
2026-06-22 12:31:40 +02:00
|
|
|
echo "[9/9] Installing ddcutil (DDC/CI monitor power control)..."
|
feat: split oversized modules for 500-line limit, fix kasa coverage gap
Split diet_guard/_gatelock.py, wake_alarm/_alarm.py, and the
usage_report.py/_usage_report_parsing.py pair into focused
sub-modules so every Python file is <= 500 lines, satisfying
test_file_length.py. Install python-kasa into .venv (declared in
requirements but missing after the 3.13->3.14 venv upgrade),
fixing 8 failing smart_plug tests and restoring 100% coverage.
Also includes prior in-progress work from the working tree: the
wake_alarm Progress/View/Hardware field-grouping refactor,
brother_printer query module + tests, diet_guard foodbank/state/cli
updates, new shared coerce/logging_setup helpers, morning_routine
orchestrator tweaks, dwm window-manager config, gaming scripts, and
misc maintenance/digital-wellbeing script updates.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-14 07:19:37 +02:00
|
|
|
if command -v ddcutil &>/dev/null; then
|
|
|
|
|
echo " ddcutil already installed"
|
|
|
|
|
else
|
|
|
|
|
sudo pacman -S --noconfirm ddcutil
|
|
|
|
|
echo " ddcutil installed"
|
|
|
|
|
fi
|
|
|
|
|
# ddcutil needs access to /dev/i2c-* — add user to i2c group if it exists.
|
|
|
|
|
if getent group i2c &>/dev/null; then
|
|
|
|
|
if ! id -nG "$USER" | grep -qw i2c; then
|
|
|
|
|
sudo usermod -aG i2c "$USER"
|
|
|
|
|
echo " Added $USER to i2c group (re-login required for group to take effect)"
|
|
|
|
|
else
|
|
|
|
|
echo " $USER already in i2c group"
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
echo " i2c group not found — ddcutil will run via sudo"
|
|
|
|
|
fi
|
|
|
|
|
|
2026-04-12 20:45:24 +02:00
|
|
|
echo "=== Installation complete ==="
|
|
|
|
|
echo "The wake alarm will activate on boot for alarm days (Mon, Fri, Sat, Sun)."
|
2026-05-22 16:01:04 +02:00
|
|
|
echo "After hibernate resume the sleep hook will restart the alarm service."
|
2026-05-23 19:51:26 +02:00
|
|
|
echo "Fans will ramp to 100% while the alarm is active, then restore automatically."
|
2026-06-22 12:31:40 +02:00
|
|
|
echo "To test now: python -m wake_alarm._alarm --demo"
|