#!/usr/bin/env bash # run_all_timelapses.sh # # Run timelapse creation for a fixed set of webcams, # collect public URLs, update HTML index, and send one combined ntfy notification. # # Requirements: make_timelapse.sh in same folder or PATH set -euo pipefail # --- Settings --- BASE_DIR="/media/photos/misc/webcams" INDEX_FILE="$BASE_DIR/timelapses.html" WEBCAMS=( "frontyard" "basement_table" "mailbox" "basement_extension" "backyard_low" "backyard_north" "basement_cape" "basement_tv" "backyard" "bulkhead" "barn" "garage" "birds" "porch" "garden" "diningroom" ) TIMELAPSE_SCRIPT="/usr/local/bin/make_timelapse" NTFY_URL="https://ntfy.unbl.ink/timelapse" WEB_PREFIX="https://files.lab.unbl.ink" # ---------------- # Yesterday's date if date -d "yesterday" +%Y >/dev/null 2>&1; then # GNU date (Linux) YESTERDAY=$(date -d "yesterday" +"%Y/%m/%d") else # BSD date (macOS) YESTERDAY=$(date -v-1d +"%Y/%m/%d") fi LINKS=() for cam in "${WEBCAMS[@]}"; do TARGET_DIR="$BASE_DIR/$cam/$YESTERDAY" if [[ -d "$TARGET_DIR" ]]; then echo "📷 Processing $cam ($TARGET_DIR)" OUTPUT=$("$TIMELAPSE_SCRIPT" "$TARGET_DIR") echo "$OUTPUT" LINK="$WEB_PREFIX/$cam/$YESTERDAY/timelapse.mp4" if [[ -f "$TARGET_DIR/timelapse.mp4" ]]; then LINKS+=("[$cam] $LINK") fi else echo "⚠️ Skipping $cam (no folder for $YESTERDAY)" fi done # --- Update HTML index --- mkdir -p "$BASE_DIR" if [[ ! -f "$INDEX_FILE" ]]; then cat >"$INDEX_FILE" < Webcam Timelapses

Webcam Timelapses

EOF fi # Insert new section for yesterday at the top TMP=$(mktemp) { echo "

$YESTERDAY

" echo "" echo "
" } >"$TMP" # Place new block after

line awk -v block="$(cat "$TMP")" ' /

/ { print; getline; print; print block; next } { print } ' "$INDEX_FILE" >"$INDEX_FILE.new" mv "$INDEX_FILE.new" "$INDEX_FILE" rm "$TMP" echo "📄 Updated HTML index: $INDEX_FILE" # --- Send combined notification --- if [[ -n "$NTFY_URL" ]] && [[ ${#LINKS[@]} -gt 0 ]]; then MSG="Timelapses for $YESTERDAY:\n$(printf '%s\n' "${LINKS[@]}")" curl -s -H "Title: Timelapses complete" \ -H "Priority: high" \ -d "$MSG" \ "$NTFY_URL" >/dev/null || true echo "📢 Combined notification sent to ntfy." fi