#!/bin/bash
# EAA AirVenture Oshkosh — 10-second wallpaper installer (macOS) — double-click me
# Real camera frames pulled straight from YouTube to YOUR Mac + composited locally.
# Needs Homebrew (brew.sh) for ffmpeg + yt-dlp, and python3 + pillow.
# Restores your wallpaper + removes itself on July 27. Uninstall early:
#   python3 ~/Library/Application\ Support/OshkoshWallpaper/oshkosh-grid.py uninstall
set -e
DIR="$HOME/Library/Application Support/OshkoshWallpaper"; BASE="https://dizydiz.com/oshkosh"
PLIST="$HOME/Library/LaunchAgents/com.dizydiz.oshkosh.plist"
mkdir -p "$DIR" "$HOME/Library/LaunchAgents"

need() { command -v "$1" >/dev/null 2>&1; }
echo "Checking dependencies…"
if ! need brew; then
  echo "Homebrew is required (free): https://brew.sh — install it, then run this again."
  read -r -p "Press Enter to close…"; exit 1
fi
need ffmpeg || brew install ffmpeg
need yt-dlp || brew install yt-dlp
need python3 || brew install python
python3 -c "import PIL" 2>/dev/null || python3 -m pip install --user --quiet pillow

curl -s -o "$DIR/oshkosh-grid.py" "$BASE/oshkosh-grid.py"

PY="$(command -v python3)"
cat > "$PLIST" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
  <key>Label</key><string>com.dizydiz.oshkosh</string>
  <key>ProgramArguments</key><array><string>$PY</string><string>$DIR/oshkosh-grid.py</string></array>
  <key>RunAtLoad</key><true/>
  <key>KeepAlive</key><true/>
</dict></plist>
EOF
launchctl unload "$PLIST" 2>/dev/null || true
launchctl load "$PLIST"

echo
echo " ============================================================"
echo "  Oshkosh Camera Wallpaper is ON (real frames from YouTube)."
echo "  First time: allow 'System Events' control if macOS asks."
echo "  Restores your wallpaper + removes itself on July 27."
echo "  Uninstall early:  python3 \"$DIR/oshkosh-grid.py\" uninstall"
echo " ============================================================"
read -r -p "Press Enter to close…"
