|
1
|
#!/usr/bin/env bash |
|
2
|
# run.sh — scuttlebot dev helper |
|
3
|
# Usage: ./run.sh [command] |
|
4
|
# (no args) build and start scuttlebot |
|
5
|
# stop kill running scuttlebot |
|
6
|
# restart stop + build + start |
|
7
|
# token print the current API token |
|
8
|
# log tail the log (if logging to file is configured) |
|
9
|
# test run Go unit tests |
|
10
|
# e2e run Playwright e2e tests (requires scuttlebot running) |
|
11
|
# clean remove built binaries |
|
12
|
|
|
13
|
set -euo pipefail |
|
14
|
|
|
15
|
BINARY=bin/scuttlebot |
|
16
|
CONFIG=${SCUTTLEBOT_CONFIG:-scuttlebot.yaml} |
|
17
|
TOKEN_FILE=data/ergo/api_token |
|
18
|
PID_FILE=.scuttlebot.pid |
|
19
|
LOG_FILE=.scuttlebot.log |
|
20
|
cmd=${1:-start} |
|
21
|
|
|
22
|
_pid() { cat "$PID_FILE" 2>/dev/null || echo ""; } |
|
23
|
|
|
24
|
_running() { |
|
25
|
local pid; pid=$(_pid) |
|
26
|
[[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null |
|
27
|
} |
|
28
|
|
|
29
|
_stop() { |
|
30
|
if _running; then |
|
31
|
local pid; pid=$(_pid) |
|
32
|
kill "$pid" && rm -f "$PID_FILE" |
|
33
|
echo "stopped (pid $pid)" |
|
34
|
else |
|
35
|
echo "not running" |
|
36
|
fi |
|
37
|
# Kill any stale ergo processes holding IRC/API ports. |
|
38
|
pkill -f "data/ergo/ergo" 2>/dev/null && sleep 1 || true |
|
39
|
} |
|
40
|
|
|
41
|
_build() { |
|
42
|
echo "building..." |
|
43
|
go build -o "$BINARY" ./cmd/scuttlebot |
|
44
|
echo "ok → $BINARY" |
|
45
|
} |
|
46
|
|
|
47
|
_start() { |
|
48
|
if _running; then |
|
49
|
echo "already running (pid $(_pid)) — use ./run.sh restart" |
|
50
|
exit 0 |
|
51
|
fi |
|
52
|
|
|
53
|
if [[ ! -f "$CONFIG" ]]; then |
|
54
|
echo "no $CONFIG found — copying from example" |
|
55
|
cp deploy/standalone/scuttlebot.yaml.example "$CONFIG" |
|
56
|
echo "edit $CONFIG if needed, then re-run" |
|
57
|
fi |
|
58
|
|
|
59
|
mkdir -p bin data/ergo |
|
60
|
|
|
61
|
"$BINARY" -config "$CONFIG" >"$LOG_FILE" 2>&1 & |
|
62
|
echo $! >"$PID_FILE" |
|
63
|
local pid; pid=$(_pid) |
|
64
|
echo "started (pid $pid) — logs: $LOG_FILE" |
|
65
|
|
|
66
|
# wait briefly and print token so it's handy |
|
67
|
sleep 1 |
|
68
|
if [[ -f "$TOKEN_FILE" ]]; then |
|
69
|
echo "token: $(cat "$TOKEN_FILE")" |
|
70
|
fi |
|
71
|
|
|
72
|
echo "ui: http://localhost:8080/ui/" |
|
73
|
} |
|
74
|
|
|
75
|
_token() { |
|
76
|
if [[ -f "$TOKEN_FILE" ]]; then |
|
77
|
cat "$TOKEN_FILE" |
|
78
|
else |
|
79
|
echo "no token file found (is scuttlebot running?)" >&2 |
|
80
|
exit 1 |
|
81
|
fi |
|
82
|
} |
|
83
|
|
|
84
|
|
|
85
|
case "$cmd" in |
|
86
|
start) |
|
87
|
_build |
|
88
|
_start |
|
89
|
;; |
|
90
|
stop) |
|
91
|
_stop |
|
92
|
;; |
|
93
|
restart) |
|
94
|
_stop || true |
|
95
|
_build |
|
96
|
_start |
|
97
|
;; |
|
98
|
build) |
|
99
|
_build |
|
100
|
;; |
|
101
|
token) |
|
102
|
_token |
|
103
|
;; |
|
104
|
log|logs) |
|
105
|
tail -f "$LOG_FILE" |
|
106
|
;; |
|
107
|
test) |
|
108
|
go test ./... |
|
109
|
;; |
|
110
|
e2e) |
|
111
|
SB_TOKEN=$(cat "$TOKEN_FILE" 2>/dev/null) \ |
|
112
|
SB_USERNAME=${SB_USERNAME:-admin} \ |
|
113
|
SB_PASSWORD=${SB_PASSWORD:-} \ |
|
114
|
npx --prefix tests/e2e playwright test "${@:2}" |
|
115
|
;; |
|
116
|
clean) |
|
117
|
_stop || true |
|
118
|
rm -f "$BINARY" bin/scuttlectl "$LOG_FILE" "$PID_FILE" |
|
119
|
echo "clean" |
|
120
|
;; |
|
121
|
*) |
|
122
|
echo "usage: $0 {start|stop|restart|build|token|log|test|e2e|clean}" |
|
123
|
exit 1 |
|
124
|
;; |
|
125
|
esac |
|
126
|
|