Add full banner headers to all scripts across the codebase

Every script now has the established header format: PURPOSE with ─────── separator,
OPERATIONAL MODEL, DESIGN PRINCIPLES, OPERATIONAL SAFEGUARDS, CONFIGURATION, and
RUNTIME MODES — structured with full ====== banner sections throughout.

Orchestrators converted from compact ── inline format to full banners. Stale
emby-fallback and dirty sync references removed from Plugin/user_script_plug-in.sh.
This commit is contained in:
Gmer4Lfe
2026-06-26 18:50:05 -04:00
parent 1003bee72a
commit f92ee4064b
51 changed files with 1822 additions and 563 deletions
+85 -52
View File
@@ -2,68 +2,101 @@
# ==============================================================================================
# ============================= Daily Sync Maintenance =========================================
# ==============================================================================================
# Daily orchestrator — runs the full daily maintenance window in the correct order.
# Schedule: 0 1 * * * (1am daily via User Scripts plugin)
#
# ── EXECUTION ORDER ───────────────────────────────────────────────────────────────────────────
# Pre-sync:
# git_pull_execute.sh — pull latest scripts first, always
# PURPOSE
# ─────────────────────────────────────────────────────────────────────────────
# Daily maintenance window orchestrator — runs the full daily sequence in the
# correct order. Schedule: 0 1 * * * (1am daily via User Scripts plugin)
#
# Arr Sync (arr_sync.sh):
# Syncs Lidarr/Sonarr/Radarr libraries across all nodes bidirectionally.
# All nodes agree on tracked library before any files are transferred.
# Remote nodes that don't have an arr running are skipped gracefully.
# ==============================================================================================
# OPERATIONAL MODEL
# ==============================================================================================
#
# Rsync window (DAILY_SYNC_SHARES per host):
# HOST*_DAILY_SYNC_SHARESmedia shares spread to all nodes (no --delete)
# HOST*_PERSONAL_SHARES — encrypted personal shares
# Pre-sync:
# git_pull_execute.sh pull latest scripts first, always
#
# Post-sync maintenance (DAILY_MAINTENANCE_SCRIPTS):
# media_shares_permissions.sh — fix ownership before arr cleanup
# media_cleaner.sh anime — remove junk from anime shares
# media_cleaner.sh media — remove junk from media shares
# lidarr_cleanup.sh — remove orphaned music files (local arr = truth)
# sonarr_cleanup.sh — remove orphaned TV files (local arr = truth)
# radarr_cleanup.sh — remove orphaned movie files (local arr = truth)
# docker_daily_restart.sh — restart containers needing daily restart
# Arr Sync (arr_sync.sh):
# Syncs Lidarr/Sonarr/Radarr libraries across all nodes bidirectionally.
# All nodes agree on tracked library before any files are transferred.
# Remote nodes that don't have an arr running are skipped gracefully.
#
# ── WHY ORDER MATTERS ─────────────────────────────────────────────────────────────────────────
# git pull first — maintenance runs on latest code, not yesterday's
# arr sync before rsync — all nodes track the same library before files are spread;
# prevents remote arrs from searching for content already owned
# rsync before cleanup — cleanup sees fully spread state, rsync has no --delete
# permissions before arr cleanup — arrs need correct ownership to delete/rename
# arr cleanup after permissions — clean ownership = successful orphan deletion
# docker restart last — containers already processed by cleanup
# Rsync window (DAILY_SYNC_SHARES per host):
# HOST*_DAILY_SYNC_SHARES — media shares spread to all nodes (no --delete)
# HOST*_PERSONAL_SHARES — encrypted personal shares
#
# ── HOST AWARENESS ────────────────────────────────────────────────────────────────────────────
# Bidirectional — same script runs on both servers, correct direction automatic.
# detect_hosts() aliases DAILY_SYNC_SHARES and PERSONAL_SHARES from HOST*_ vars.
# No manual HOST1/HOST2 comparisons — MY_ID routes correctly on any server.
# Post-sync maintenance (DAILY_MAINTENANCE_SCRIPTS):
# media_shares_permissions.sh — fix ownership before arr cleanup
# media_cleaner.sh anime/media — remove junk from media and anime shares
# lidarr/sonarr/radarr_cleanup.sh — remove orphaned files (local arr = truth)
# docker_daily_restart.sh — restart containers needing daily restart
#
# ── DRIVE TEMP HANDLING ───────────────────────────────────────────────────────────────────────
# rsync.sh returns exit codes for temperature issues:
# exit 1 = temp WARN — skip this share, continue to next
# exit 2 = temp CRITICAL — abort ALL remaining syncs in this window
# All other failures — skip share, continue to next
# DRIVE TEMP HANDLING (rsync.sh exit codes):
# exit 1 = temp WARN → skip this share, continue to next
# exit 2 = temp CRITICAL → abort ALL remaining syncs in this window
#
# ── SILENT WHEN HEALTHY ───────────────────────────────────────────────────────────────────────
# Runs daily at 1am — clean run should produce minimal output.
# Each job reports log() on success (silent), warn()/error() on failure (visible).
# Summary always shown — gives window timing and share/job counts.
# Notify only on failure — successful daily maintenance doesn't need notification.
# ==============================================================================================
# DESIGN PRINCIPLES
# ==============================================================================================
#
# ── CONFIGURATION (master.conf + host*.conf) ───────────────────────────────────────────
# HOST*_DAILY_SYNC_SHARES — shares pushed to mirror each day
# HOST*_PERSONAL_SHARES — encrypted personal shares
# DAILY_MAINTENANCE_SCRIPTS — maintenance jobs (permissions, cleanup, restart)
# DAILY_RSYNC_ENABLED — enable/disable rsync section
# Order Is Load-Bearing
# git pull first — maintenance runs on latest code, not yesterday's. Arr sync
# before rsync — all nodes track the same library before files are spread,
# preventing remote arrs from searching for content already owned. Rsync before
# cleanup — cleanup sees fully spread state. Permissions before arr cleanup —
# arrs need correct ownership to delete/rename. Docker restart last — containers
# already processed by cleanup.
#
# Host-Aware Routing
# Bidirectional — same script runs on both servers, correct direction automatic.
# detect_hosts() aliases DAILY_SYNC_SHARES and PERSONAL_SHARES from HOST*_ vars.
# No manual HOST1/HOST2 comparisons needed.
#
# Silent When Healthy
# Runs daily at 1am — clean runs produce minimal output. Each job logs silently
# on success; failures surface to warn()/error(). Notify only on failure.
#
# ==============================================================================================
# OPERATIONAL SAFEGUARDS
# ==============================================================================================
#
# Root check — rsync and docker operations require root
# acquire_lock — prevents concurrent daily windows
# detect_hosts() — aliases correct per-host share lists
# check_connectivity — verified before any rsync
# check_remote_rootfs — aborts rsync if remote rootfs nearly full
# Non-fatal jobs — a failed job logs and continues; remaining jobs still run
# notify on failure — successful daily run produces no notification
#
# ==============================================================================================
# CONFIGURATION
# ==============================================================================================
#
# host*.conf
#
# HOST*_DAILY_SYNC_SHARES — shares pushed to mirror each day
# HOST*_PERSONAL_SHARES — encrypted personal shares
#
# master.conf
#
# DAILY_MAINTENANCE_SCRIPTS — maintenance jobs (permissions, cleanup, restart)
# DAILY_RSYNC_ENABLED — enable/disable rsync section
#
# ==============================================================================================
# RUNTIME MODES
# ==============================================================================================
#
# daily_sync_maintenance.sh
# Normal run.
#
# daily_sync_maintenance.sh --dry-run
# Preview without syncing or changing.
#
# daily_sync_maintenance.sh --log
# Verbose per-share/per-job output.
#
# daily_sync_maintenance.sh --status
# Show configured shares and jobs.
#
# ── USAGE ─────────────────────────────────────────────────────────────────────────────────────
# daily_sync_maintenance.sh — normal run
# daily_sync_maintenance.sh --dry-run — preview without syncing or changing
# daily_sync_maintenance.sh --log — verbose per-share/per-job output
# daily_sync_maintenance.sh --status — show configured shares and jobs
# ==============================================================================================
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"