#!/bin/bash # install.sh — generate and install sky-cam systemd units from sky-cam.conf. # # Usage: # ./install.sh # installs to ~/.config/systemd/user (no root needed) # ./install.sh --system # installs to /etc/systemd/system (needs sudo) # # Run this once after editing sky-cam.conf, and again whenever sky-cam.conf # changes (e.g. SCRIPT_DIR moves). No other file needs editing. set -euo pipefail HERE="$(dirname "$(realpath "$0")")" source "$HERE/sky-cam.conf" # ── Install target ──────────────────────────────────────────────────────────── SYSTEM_MODE=false [ "${1:-}" = "--system" ] && SYSTEM_MODE=true if $SYSTEM_MODE; then UNIT_DIR="/etc/systemd/system" SC="sudo systemctl" else UNIT_DIR="$HOME/.config/systemd/user" SC="systemctl --user" fi mkdir -p "$UNIT_DIR" echo "Installing systemd units to $UNIT_DIR ..." # ── Helper: write a oneshot service unit ───────────────────────────────────── write_service() { local unit="$1" description="$2" script="$3" extra="${4:-}" cat > "$UNIT_DIR/${unit}.service" < "$UNIT_DIR/${unit}.timer" < "$UNIT_DIR/sky-cam-notify-failure@.service" <