-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathinstall-daemon.sh
More file actions
executable file
Β·135 lines (113 loc) Β· 3.72 KB
/
install-daemon.sh
File metadata and controls
executable file
Β·135 lines (113 loc) Β· 3.72 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
# ============================================================
# Auto Company β Install/Uninstall launchd Daemon (macOS)
# ============================================================
# Generates a launchd plist dynamically based on current paths,
# installs it to ~/Library/LaunchAgents/, and loads it.
#
# Usage:
# ./install-daemon.sh # Install and start
# ./install-daemon.sh --uninstall # Stop and remove
# ============================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
LABEL="com.autocompany.loop"
PLIST_PATH="$HOME/Library/LaunchAgents/${LABEL}.plist"
PAUSE_FLAG="${SCRIPT_DIR}/.auto-loop-paused"
# --- Uninstall ---
if [ "${1:-}" = "--uninstall" ]; then
echo "Uninstalling Auto Company daemon..."
if launchctl list | grep -q "$LABEL"; then
launchctl unload "$PLIST_PATH" 2>/dev/null || true
echo "Service unloaded."
fi
if [ -f "$PLIST_PATH" ]; then
rm -f "$PLIST_PATH"
echo "Plist removed: $PLIST_PATH"
fi
echo "Done. Daemon uninstalled."
exit 0
fi
# --- Install ---
# Check dependencies
if ! command -v claude &>/dev/null; then
echo "Error: 'claude' CLI not found. Install Claude Code first."
exit 1
fi
CLAUDE_PATH="$(command -v claude)"
CLAUDE_DIR="$(dirname "$CLAUDE_PATH")"
# Detect node path (for wrangler/npx)
NODE_DIR=""
if command -v node &>/dev/null; then
NODE_DIR="$(dirname "$(command -v node)")"
fi
# Build PATH: include all tool directories
DAEMON_PATH="${CLAUDE_DIR}"
[ -n "$NODE_DIR" ] && DAEMON_PATH="${DAEMON_PATH}:${NODE_DIR}"
DAEMON_PATH="${DAEMON_PATH}:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
echo "Installing Auto Company daemon..."
echo " Project: $SCRIPT_DIR"
echo " Claude: $CLAUDE_PATH"
echo " PATH: $DAEMON_PATH"
mkdir -p "$HOME/Library/LaunchAgents" "$SCRIPT_DIR/logs"
# Install implies active running state
rm -f "$PAUSE_FLAG"
# Unload existing if running
if launchctl list 2>/dev/null | grep -q "$LABEL"; then
launchctl unload "$PLIST_PATH" 2>/dev/null || true
fi
# Generate plist
cat > "$PLIST_PATH" << 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>/bin/bash</string>
<string>${SCRIPT_DIR}/auto-loop.sh</string>
<string>--daemon</string>
</array>
<key>WorkingDirectory</key>
<string>${SCRIPT_DIR}</string>
<key>KeepAlive</key>
<dict>
<key>PathState</key>
<dict>
<key>${PAUSE_FLAG}</key>
<false/>
</dict>
</dict>
<key>RunAtLoad</key>
<true/>
<key>StandardOutPath</key>
<string>${SCRIPT_DIR}/logs/launchd-stdout.log</string>
<key>StandardErrorPath</key>
<string>${SCRIPT_DIR}/logs/launchd-stderr.log</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>${DAEMON_PATH}</string>
<key>HOME</key>
<string>${HOME}</string>
</dict>
<key>ThrottleInterval</key>
<integer>30</integer>
</dict>
</plist>
EOF
echo "Plist written: $PLIST_PATH"
# Load
launchctl load "$PLIST_PATH"
echo ""
echo "Daemon installed and started!"
echo ""
echo "Commands:"
echo " ./monitor.sh # Watch live logs"
echo " ./monitor.sh --status # Check status"
echo " ./stop-loop.sh # Stop the loop (daemon will restart it)"
echo " ./stop-loop.sh --pause-daemon # Pause daemon (no auto-restart)"
echo " ./stop-loop.sh --resume-daemon # Resume daemon"
echo " ./install-daemon.sh --uninstall # Remove daemon completely"