#!/usr/bin/env bash # =========================================================================== # Stage 08: User Systemd Services # Deploys and enables Julian's custom user systemd services. # =========================================================================== # Custom user services: # - porridge.service : Zoom meeting transcriber daemon # - porridge-dictate.service : Push-to-talk transcription # - pi-overview.service : Session dashboard on port 3000 # - bw-ssh-keys.service : Load Bitwarden SSH keys into ssh-agent # - empty_downloads.service : Clear Downloads folder at login # =========================================================================== CONFIG_DIR="${SCRIPT_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}/config" SERVICES_DIR="${CONFIG_DIR}/systemd" UNIT_DIR="$HOME/.config/systemd/user" mkdir -p "$UNIT_DIR" # =========================================================================== # 0. SSH Agent setup — ensure OpenSSH ssh-agent is the active agent # =========================================================================== # Enable ssh-agent.socket and disable/mask the GCR SSH agent so that # bw-ssh-keys.service (below) loads keys into the same agent the user's # terminal sees. Must run BEFORE enabling bw-ssh-keys.service. if [ "$DISTRO_FAMILY" = "fedora" ]; then info "Setting up OpenSSH ssh-agent..." systemctl --user enable --now ssh-agent.socket 2>/dev/null && \ ok "ssh-agent.socket enabled." || \ warn "ssh-agent.socket not available." if systemctl --user list-unit-files gcr-ssh-agent.service &>/dev/null 2>&1; then systemctl --user disable --now gcr-ssh-agent.socket gcr-ssh-agent.service 2>/dev/null || true systemctl --user mask --now gcr-ssh-agent.socket gcr-ssh-agent.service 2>/dev/null && \ ok "gcr-ssh-agent disabled (masked)." || \ warn "Could not mask gcr-ssh-agent." fi fi info "Deploying user systemd services..." # ---- Helper: install service file ---- install_service_file() { local src="$1" local name="$2" if [ -f "$src" ]; then cp "$src" "$UNIT_DIR/$name" ok "Installed: $name" else warn "Service file not found: $src (skipping)" fi } # ---- 1. porridge.service — Zoom transcriber daemon ---- install_service_file "$SERVICES_DIR/porridge.service" "porridge.service" # ---- 2. porridge-dictate.service — Push-to-talk transcription ---- install_service_file "$SERVICES_DIR/porridge-dictate.service" "porridge-dictate.service" # ---- 3. pi-overview.service — Session dashboard ---- install_service_file "$SERVICES_DIR/pi-overview.service" "pi-overview.service" # ---- 4. bw-ssh-keys.service — Load Bitwarden SSH keys into ssh-agent ---- install_service_file "$SERVICES_DIR/bw-ssh-keys.service" "bw-ssh-keys.service" # ---- 6. empty_downloads.service — Clear Downloads at login ---- install_service_file "$SERVICES_DIR/empty_downloads.service" "empty_downloads.service" # ---- Enable and start services ---- info "Enabling and starting services..." # Services that should start automatically (enabled) systemctl --user daemon-reload if [ -x "$HOME/.local/bin/porridge" ]; then systemctl --user enable --now porridge.service 2>/dev/null && ok "porridge.service enabled" else warn "porridge.service skipped (binary not found — run stage 06 first)." fi if [ -x "$HOME/.local/bin/porridge" ]; then systemctl --user enable --now porridge-dictate.service 2>/dev/null && ok "porridge-dictate.service enabled" else warn "porridge-dictate.service skipped (binary not found — run stage 06 first)." fi if [ -x "$HOME/.local/bin/pi-overview" ]; then systemctl --user enable --now pi-overview.service 2>/dev/null && ok "pi-overview.service enabled" else warn "pi-overview.service skipped (binary not found — run stage 07 first)." fi if [ -f "$HOME/.local/bin/bw-load-ssh.sh" ]; then systemctl --user enable bw-ssh-keys.service 2>/dev/null && ok "bw-ssh-keys.service enabled" else warn "bw-ssh-keys.service skipped (bw-load-ssh.sh not found — run stage 06 first)." fi systemctl --user enable --now empty_downloads.service 2>/dev/null && ok "empty_downloads.service enabled" || warn "empty_downloads.service not started." info "===== Service Status =====" systemctl --user list-units --type=service --state=running 2>/dev/null | grep -E "(porridge|pi-overview|bw-ssh|empty)" || true ok "Stage 08 complete: user systemd services deployed."