-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_watcher.sh
More file actions
executable file
·87 lines (73 loc) · 2.58 KB
/
install_watcher.sh
File metadata and controls
executable file
·87 lines (73 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
# install_watcher.sh — Install or uninstall the plexwatcher launchd agent
#
# USAGE:
# ./install_watcher.sh # install and start
# ./install_watcher.sh uninstall # stop and remove
# ./install_watcher.sh status # show current status
# ./install_watcher.sh restart # reload agent
set -euo pipefail
LABEL="com.mproadmin.plexwatcher"
PLIST_SRC="$(cd "$(dirname "$0")" && pwd)/com.mproadmin.plexwatcher.plist"
PLIST_DST="$HOME/Library/LaunchAgents/${LABEL}.plist"
LOG_DIR="$(cd "$(dirname "$0")" && pwd)/results"
case "${1:-install}" in
install)
echo "=== Installing plexwatcher launchd agent ==="
echo " Plist source : $PLIST_SRC"
echo " Plist dest : $PLIST_DST"
# Ensure results dir exists for log files
mkdir -p "$LOG_DIR"
# Unload existing agent if present
if launchctl list | grep -q "$LABEL" 2>/dev/null; then
echo " Unloading existing agent..."
launchctl unload "$PLIST_DST" 2>/dev/null || true
fi
# Copy plist to LaunchAgents
cp "$PLIST_SRC" "$PLIST_DST"
echo " Copied plist to LaunchAgents"
# Validate plist syntax
plutil -lint "$PLIST_DST" && echo " Plist syntax: OK"
# Load and start
launchctl load "$PLIST_DST"
echo " Agent loaded. First run will start within seconds."
echo ""
echo " launchctl list | grep plexwatcher"
launchctl list | grep "$LABEL" || echo " (not listed yet — give it a moment)"
echo ""
echo " Watch live output:"
echo " tail -f \"$LOG_DIR/watcher_launchd_stdout.log\""
;;
uninstall)
echo "=== Uninstalling plexwatcher ==="
launchctl unload "$PLIST_DST" 2>/dev/null && echo " Agent unloaded" || echo " Agent was not loaded"
rm -f "$PLIST_DST" && echo " Plist removed" || echo " Plist not found"
;;
restart)
echo "=== Restarting plexwatcher ==="
launchctl unload "$PLIST_DST" 2>/dev/null || true
sleep 1
launchctl load "$PLIST_DST"
echo " Reloaded."
;;
status)
echo "=== plexwatcher status ==="
launchctl list | grep "$LABEL" || echo " Not loaded"
echo ""
echo " Last 20 log lines:"
tail -20 "$LOG_DIR/watcher_launchd_stdout.log" 2>/dev/null || echo " (no log yet)"
echo ""
echo " Stderr (errors):"
tail -5 "$LOG_DIR/watcher_launchd_stderr.log" 2>/dev/null || echo " (no errors)"
;;
run-now)
echo "=== Triggering immediate run ==="
launchctl start "$LABEL"
sleep 2
tail -20 "$LOG_DIR/watcher_launchd_stdout.log" 2>/dev/null
;;
*)
echo "Usage: $0 [install|uninstall|restart|status|run-now]"
exit 1
;;
esac