Name no longer implies a fixed duration. Updated all references: install.sh, sky-cam.conf script map, systemd/sky-cam-sunrise.service. https://claude.ai/code/session_01C4jbd3waXG3eKZYbGUjLUQ
116 lines
4.1 KiB
Bash
Executable File
116 lines
4.1 KiB
Bash
Executable File
#!/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" \
|
|
"daily_sunrise_video.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
|