Files
ProdDash/modules/resi-studio-cues/install-agent.command
T

67 lines
2.4 KiB
Bash
Raw Normal View History

#!/bin/bash
# Install (or refresh) the login agent that keeps the Resi -> ProPresenter bridge running.
# Double-click this file. Safe to run again after a git pull.
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SOURCE="$HERE/resi_to_propresenter.py"
LABEL="org.waterschurch.resi-propresenter"
PLIST="$HOME/Library/LaunchAgents/$LABEL.plist"
CONFIG_DIR="$HOME/Library/Application Support/ResiCues"
LOG="$HOME/Library/Logs/resi-propresenter.log"
[ -f "$SOURCE" ] || { echo "Cannot find $SOURCE"; exit 1; }
mkdir -p "$HOME/Library/LaunchAgents" "$CONFIG_DIR" "$(dirname "$LOG")"
# A login agent cannot read ~/Documents (and ~/Desktop, ~/Downloads) without Full Disk
# Access — macOS answers "Operation not permitted". Rather than ask for that, run from
# a copy in Application Support, which is not gated. Re-run this after a git pull.
SCRIPT="$CONFIG_DIR/resi_to_propresenter.py"
cp "$SOURCE" "$SCRIPT"
if [ ! -f "$CONFIG_DIR/config.json" ]; then
cp "$HERE/config.example.json" "$CONFIG_DIR/config.json"
echo "Made a starter config at $CONFIG_DIR/config.json — set resi_user and player in it."
fi
cat > "$PLIST" <<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>$LABEL</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/python3</string>
<string>$SCRIPT</string>
</array>
<key>EnvironmentVariables</key>
<dict>
<key>RESI_PP_CONFIG</key><string>$CONFIG_DIR/config.json</string>
</dict>
<key>WorkingDirectory</key><string>$CONFIG_DIR</string>
<key>RunAtLoad</key><true/>
<key>KeepAlive</key><true/>
<key>ThrottleInterval</key><integer>30</integer>
<key>ProcessType</key><string>Background</string>
<key>StandardOutPath</key><string>$LOG</string>
<key>StandardErrorPath</key><string>$LOG</string>
</dict>
</plist>
PLIST_EOF
launchctl bootout "gui/$UID/$LABEL" 2>/dev/null || true
launchctl bootstrap "gui/$UID" "$PLIST"
launchctl enable "gui/$UID/$LABEL" 2>/dev/null || true
echo
echo "Installed. It starts at login and restarts itself if it stops."
echo " script $SCRIPT (a copy — re-run this after a git pull)"
echo " config $CONFIG_DIR/config.json"
echo " log $LOG"
echo
echo "Watch it with: tail -f \"$LOG\""
echo "Stop it with: launchctl bootout gui/$UID/$LABEL"
echo "Start it again: launchctl bootstrap gui/$UID \"$PLIST\""