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
This commit is contained in:
Executable
+115
@@ -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" <<EOF
|
||||
[Unit]
|
||||
Description=Sky-Cam ($CAM_NAME) — $description
|
||||
${extra}OnFailure=sky-cam-notify-failure@%n.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=$SCRIPT_DIR/$script
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
EOF
|
||||
echo " wrote ${unit}.service"
|
||||
}
|
||||
|
||||
# ── Helper: write a timer unit ───────────────────────────────────────────────
|
||||
write_timer() {
|
||||
local unit="$1" description="$2" calendar="$3"
|
||||
cat > "$UNIT_DIR/${unit}.timer" <<EOF
|
||||
[Unit]
|
||||
Description=Sky-Cam ($CAM_NAME) — $description
|
||||
|
||||
[Timer]
|
||||
OnCalendar=$calendar
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
EOF
|
||||
echo " wrote ${unit}.timer"
|
||||
}
|
||||
|
||||
# ── Failure notification template ────────────────────────────────────────────
|
||||
cat > "$UNIT_DIR/sky-cam-notify-failure@.service" <<EOF
|
||||
[Unit]
|
||||
Description=Sky-Cam notify on failure for %i
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=$SCRIPT_DIR/notify.sh "sky-cam job failed: %i" "systemd unit %i failed — check: journalctl -u %i"
|
||||
EOF
|
||||
echo " wrote sky-cam-notify-failure@.service"
|
||||
|
||||
# ── Three daily jobs ──────────────────────────────────────────────────────────
|
||||
# Sunrise video → Mattermost (run after sunrise window ends)
|
||||
write_service "sky-cam-sunrise" \
|
||||
"daily sunrise video → Mattermost" \
|
||||
"sunrise_video.10s.sh" \
|
||||
"After=network-online.target\nWants=network-online.target\n"
|
||||
write_timer "sky-cam-sunrise" "daily sunrise video" "*-*-* 09:00:00"
|
||||
|
||||
# Four Seasons daily clip (auto-triggers montage + year-end on last days)
|
||||
write_service "sky-cam-4seasons" \
|
||||
"Four Seasons daily clip" \
|
||||
"4-seasons.sh" \
|
||||
"After=network-online.target\nWants=network-online.target\n"
|
||||
write_timer "sky-cam-4seasons" "Four Seasons daily clip" "*-*-* 01:00:00"
|
||||
|
||||
# Full-day timelapse with 10-day retention
|
||||
write_service "sky-cam-fullday" \
|
||||
"full-day timelapse" \
|
||||
"fullday-video.sh"
|
||||
write_timer "sky-cam-fullday" "full-day timelapse" "*-*-* 02:00:00"
|
||||
|
||||
# ── Reload and enable ─────────────────────────────────────────────────────────
|
||||
echo ""
|
||||
$SC daemon-reload
|
||||
|
||||
for timer in sky-cam-sunrise sky-cam-4seasons sky-cam-fullday; do
|
||||
$SC enable --now "${timer}.timer" \
|
||||
&& echo " enabled + started ${timer}.timer" \
|
||||
|| echo " WARNING: could not enable ${timer}.timer"
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "Done. Check status with:"
|
||||
if $SYSTEM_MODE; then
|
||||
echo " sudo systemctl list-timers 'sky-cam-*'"
|
||||
echo " sudo journalctl -u sky-cam-4seasons.service -f"
|
||||
else
|
||||
echo " systemctl --user list-timers 'sky-cam-*'"
|
||||
echo " journalctl --user -u sky-cam-4seasons.service -f"
|
||||
fi
|
||||
Reference in New Issue
Block a user