-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
路249 lines (214 loc) 路 5.85 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
路249 lines (214 loc) 路 5.85 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PORT="${PORT:-3333}"
HOST="${HOST:-127.0.0.1}"
SERVICE_NAME="openclaw-dashboard"
NO_SERVICE=0
DEV_MODE=0
while [[ $# -gt 0 ]]; do
case "$1" in
--no-service)
NO_SERVICE=1
shift
;;
--dev)
DEV_MODE=1
shift
;;
--port)
PORT="${2:-}"
shift 2
;;
--host)
HOST="${2:-}"
shift 2
;;
-h|--help)
cat <<EOF
Mission Control setup
Usage:
./setup.sh [--port 3333] [--host 127.0.0.1] [--dev] [--no-service]
Defaults:
PORT=${PORT}
HOST=${HOST}
Behavior:
1) Installs dependencies
2) Builds the dashboard (unless --dev)
3) Starts it as a background service (unless --no-service)
Service support:
- macOS: launchd user agent
- Linux: systemd --user service
EOF
exit 0
;;
*)
echo "Unknown argument: $1" >&2
exit 1
;;
esac
done
log() {
printf "\033[1;36m[setup]\033[0m %s\n" "$*"
}
warn() {
printf "\033[1;33m[warn]\033[0m %s\n" "$*" >&2
}
require_cmd() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "Required command not found: $1" >&2
exit 1
fi
}
require_cmd node
require_cmd npm
if [[ "${EUID:-$(id -u)}" -eq 0 ]]; then
warn "Running setup as root/sudo can cause permission and native dependency issues. Prefer a normal user shell."
fi
if ! command -v openclaw >/dev/null 2>&1; then
warn "openclaw CLI was not found in PATH. Mission Control can still start, but data loading may fail."
fi
if [[ ! "$PORT" =~ ^[0-9]+$ ]]; then
echo "Invalid port: ${PORT}" >&2
exit 1
fi
cd "$ROOT_DIR"
check_lightningcss() {
node -e 'require("lightningcss")' >/dev/null 2>&1
}
log "Installing dependencies..."
if [[ -f package-lock.json ]]; then
npm ci --include=optional --no-audit --no-fund
else
npm install --include=optional --no-audit --no-fund
fi
if ! check_lightningcss; then
warn "lightningcss native package was not detected. Retrying install with optional dependencies..."
npm install --include=optional --no-audit --no-fund --no-save lightningcss
fi
if ! check_lightningcss; then
cat >&2 <<'EOF'
[error] lightningcss native dependency is missing (required by Tailwind/Next build).
Try:
1) rm -rf node_modules package-lock.json
2) npm install --include=optional
3) rerun ./setup.sh (without sudo)
EOF
exit 1
fi
if [[ "$DEV_MODE" -eq 0 ]]; then
log "Building production bundle..."
npm run build
fi
start_foreground() {
if [[ "$DEV_MODE" -eq 1 ]]; then
log "Starting in development mode (foreground)..."
exec npm run dev -- -H "$HOST" -p "$PORT"
else
log "Starting in production mode (foreground)..."
exec npm run start -- -H "$HOST" -p "$PORT"
fi
}
install_launchd_service() {
local plist_dir="$HOME/Library/LaunchAgents"
local plist_path="${plist_dir}/com.openclaw.dashboard.plist"
mkdir -p "$plist_dir"
local run_cmd
if [[ "$DEV_MODE" -eq 1 ]]; then
run_cmd="cd \"$ROOT_DIR\" && PORT=\"$PORT\" HOST=\"$HOST\" npm run dev -- -H \"$HOST\" -p \"$PORT\""
else
run_cmd="cd \"$ROOT_DIR\" && PORT=\"$PORT\" HOST=\"$HOST\" npm run start -- -H \"$HOST\" -p \"$PORT\""
fi
cat >"$plist_path" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.openclaw.dashboard</string>
<key>ProgramArguments</key>
<array>
<string>/bin/zsh</string>
<string>-lc</string>
<string>${run_cmd}</string>
</array>
<key>WorkingDirectory</key>
<string>${ROOT_DIR}</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>${ROOT_DIR}/.dashboard.log</string>
<key>StandardErrorPath</key>
<string>${ROOT_DIR}/.dashboard.err.log</string>
</dict>
</plist>
EOF
launchctl unload "$plist_path" >/dev/null 2>&1 || true
launchctl load -w "$plist_path"
}
install_systemd_user_service() {
require_cmd systemctl
local service_dir="$HOME/.config/systemd/user"
local service_path="${service_dir}/${SERVICE_NAME}.service"
mkdir -p "$service_dir"
local exec_line
if [[ "$DEV_MODE" -eq 1 ]]; then
exec_line="/usr/bin/env bash -lc 'cd \"$ROOT_DIR\" && PORT=\"$PORT\" HOST=\"$HOST\" npm run dev -- -H \"$HOST\" -p \"$PORT\"'"
else
exec_line="/usr/bin/env bash -lc 'cd \"$ROOT_DIR\" && PORT=\"$PORT\" HOST=\"$HOST\" npm run start -- -H \"$HOST\" -p \"$PORT\"'"
fi
cat >"$service_path" <<EOF
[Unit]
Description=OpenClaw Mission Control Dashboard
After=network.target
[Service]
Type=simple
WorkingDirectory=${ROOT_DIR}
ExecStart=${exec_line}
Restart=always
RestartSec=2
Environment=PORT=${PORT}
Environment=HOST=${HOST}
[Install]
WantedBy=default.target
EOF
systemctl --user daemon-reload
systemctl --user enable --now "${SERVICE_NAME}.service"
}
start_with_nohup() {
log "Starting without service manager (nohup fallback)..."
mkdir -p "${ROOT_DIR}/.run"
local log_path="${ROOT_DIR}/.run/dashboard.out.log"
if [[ "$DEV_MODE" -eq 1 ]]; then
nohup npm run dev -- -H "$HOST" -p "$PORT" >"$log_path" 2>&1 &
else
nohup npm run start -- -H "$HOST" -p "$PORT" >"$log_path" 2>&1 &
fi
echo $! > "${ROOT_DIR}/.run/dashboard.pid"
}
if [[ "$NO_SERVICE" -eq 1 ]]; then
start_foreground
fi
log "Configuring background service..."
if [[ "$(uname -s)" == "Darwin" ]]; then
install_launchd_service
elif [[ "$(uname -s)" == "Linux" ]] && command -v systemctl >/dev/null 2>&1; then
if systemctl --user status >/dev/null 2>&1; then
install_systemd_user_service
else
warn "systemd --user is not available in this session."
start_with_nohup
fi
else
warn "No supported service manager detected."
start_with_nohup
fi
echo
log "Mission Control is ready."
echo "URL: http://${HOST}:${PORT}"
echo
echo "Remote tunnel example:"
echo "ssh -N -L ${PORT}:127.0.0.1:${PORT} user@your-server"
echo