#!/usr/bin/env bash
set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"

cd "$ROOT"

echo "installing session-memory dispatcher user service"
mkdir -p "$HOME/.config/systemd/user"
install -m 0644 "$ROOT/scripts/install-session-memory-dispatcher.service" "$HOME/.config/systemd/user/install-session-memory-dispatcher.service"
systemctl --user daemon-reload
systemctl --user enable --now install-session-memory-dispatcher.service

echo "installing session-memory sweeper timer"
install -m 0644 "$ROOT/scripts/session-memory-sweeper.service" "$HOME/.config/systemd/user/session-memory-sweeper.service"
install -m 0644 "$ROOT/scripts/session-memory-sweeper.timer" "$HOME/.config/systemd/user/session-memory-sweeper.timer"
systemctl --user daemon-reload
systemctl --user enable --now session-memory-sweeper.timer

echo "installing tmp-cleanup cron"
"$ROOT/scripts/install-tmp-cleanup-cron.sh"

echo "installing pi-telegram user service"
"$ROOT/scripts/install-pi-telegram-service.sh"

echo "installing wifi-tracker-api user service"
"$ROOT/scripts/install-wifi-tracker-api-service.sh"

echo "installing codex usage alert timer"
"$ROOT/scripts/install-codex-usage-alert.sh"

echo "installing shell/tmux helper restoration"
"$ROOT/scripts/install-shell-tmux-helpers.sh"

echo "note: nginx kiosk config has a repo-owned installer but still needs sudo/root execution"

echo "service bootstrap ok"
