From 5d3ee97df0e7db29e914d178a9d2b703d63d3e2d Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 18 Apr 2026 21:31:26 +0000 Subject: [PATCH] All paths into sky-cam.conf; install.sh generates systemd units sky-cam.conf - Add SCRIPT_DIR (install location) and CAM_NAME (camera/folder name) - These are the only values that change when deploying to a new machine install.sh (new) - Sources sky-cam.conf, generates all systemd .service and .timer units with correct ExecStart paths, then enables and starts the timers - Run once after editing sky-cam.conf; run again if paths change - Supports --system flag for system-wide install All .sh scripts + sunrise2mm.py - No hardcoded paths remain - script_name=$(basename ...) derivation replaced by $CAM_NAME from conf - sunrise_video.10s.sh now sources sky-cam.conf for BASE_DIR, CAM_NAME, and SCRIPT_DIR (replaces all /home/motion/... references) - sunrise2mm.py builds video path from BASE_DIR + CAM_NAME in conf systemd/ template files kept as reference but no longer need editing https://claude.ai/code/session_01C4jbd3waXG3eKZYbGUjLUQ --- 4-seasons.sh | 5 +- fullday-video.sh | 5 +- install.sh | 115 +++++++++++++++++++++++++++++++++++++++++++ montage-mvt.sh | 3 +- sky-cam.conf | 22 ++++++--- sunrise2mm.py | 4 +- sunrise_video.10s.sh | 20 ++++---- year-end-join.sh | 10 ++-- 8 files changed, 151 insertions(+), 33 deletions(-) create mode 100755 install.sh diff --git a/4-seasons.sh b/4-seasons.sh index 54a903e..0109c1f 100755 --- a/4-seasons.sh +++ b/4-seasons.sh @@ -43,8 +43,7 @@ target_per_clip=$(echo "scale=6; $music_duration / $DAYS_IN_MVT" | bc) echo "Target clip duration: $target_per_clip s ($DAYS_IN_MVT days in movement)" # ── Locate yesterday's images ───────────────────────────────────────────────── -script_name=$(basename "$SCRIPT_DIR" | cut -d'-' -f1) -image_dir="$base_dir/$script_name/$yesterday" +image_dir="$base_dir/$CAM_NAME/$yesterday" if [ ! -d "$image_dir" ]; then echo "WARNING: Image directory $image_dir not found — skipping $yesterday." @@ -59,7 +58,7 @@ fi echo "Images found: $total_images" # ── Prepare output directory ────────────────────────────────────────────────── -output_dir="$base_dir/movies/$script_name/$ASTRO_YEAR/$SEASON/Mvt$MVT_NUM" +output_dir="$base_dir/movies/$CAM_NAME/$ASTRO_YEAR/$SEASON/Mvt$MVT_NUM" mkdir -p "$output_dir" # ── Build sorted image list ─────────────────────────────────────────────────── diff --git a/fullday-video.sh b/fullday-video.sh index be9fcf2..25d0ac6 100755 --- a/fullday-video.sh +++ b/fullday-video.sh @@ -17,9 +17,8 @@ RETENTION_DAYS=10 # full-day videos older than this are deleted # ── Date / paths ────────────────────────────────────────────────────────────── yesterday=$(date --date="yesterday" +%Y-%m-%d) -script_name=$(basename "$SCRIPT_DIR" | cut -d'-' -f1) -image_dir="$base_dir/$script_name/$yesterday" -output_dir="$base_dir/movies/$script_name/fullday" +image_dir="$base_dir/$CAM_NAME/$yesterday" +output_dir="$base_dir/movies/$CAM_NAME/fullday" mkdir -p "$output_dir" # ── Purge old full-day videos ───────────────────────────────────────────────── diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..b3e16d8 --- /dev/null +++ b/install.sh @@ -0,0 +1,115 @@ +#!/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" <