-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·116 lines (103 loc) · 3.42 KB
/
start.sh
File metadata and controls
executable file
·116 lines (103 loc) · 3.42 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
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Load .env
if [ -f .env ]; then
set -a
source .env
set +a
echo "[✓] Loaded .env"
else
echo "[!] No .env file found. Copy .env.example → .env and fill in your keys."
exit 1
fi
# Check required env vars
if [ -z "${OPENROUTER_API_KEY:-}" ]; then
echo "[!] OPENROUTER_API_KEY is not set in .env"
exit 1
fi
# Auto-detect Chrome/Chromium if CHROME_PATH not set
if [ -z "${CHROME_PATH:-}" ]; then
for candidate in \
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" \
/snap/chromium/current/usr/lib/chromium-browser/chrome \
/usr/bin/google-chrome-stable \
/usr/bin/google-chrome \
/usr/bin/chromium-browser \
/usr/bin/chromium \
/snap/bin/chromium; do
if [ -x "$candidate" ]; then
export CHROME_PATH="$candidate"
echo "[✓] Auto-detected Chrome at $CHROME_PATH"
break
fi
done
if [ -z "${CHROME_PATH:-}" ]; then
echo "[!] No Chrome/Chromium found. Set CHROME_PATH in .env"
exit 1
fi
else
echo "[✓] Using CHROME_PATH=$CHROME_PATH"
fi
# Build everything
echo "[…] Building workspace…"
cargo build --release 2>&1 | tail -5
# PID file for cleanup
PIDFILE="$SCRIPT_DIR/.webfurl.pids"
> "$PIDFILE"
# Start MongoDB via Docker
MONGO_CONTAINER="webfurl-mongo"
if docker ps --format '{{.Names}}' | grep -q "^${MONGO_CONTAINER}$"; then
echo "[✓] MongoDB container already running"
else
if docker ps -a --format '{{.Names}}' | grep -q "^${MONGO_CONTAINER}$"; then
echo "[…] Starting existing MongoDB container…"
docker start "$MONGO_CONTAINER"
else
echo "[…] Creating MongoDB container…"
docker run -d --name "$MONGO_CONTAINER" \
-p 27017:27017 \
-v webfurl-mongo-data:/data/db \
mongo:7
fi
# Wait for MongoDB to be ready
echo "[…] Waiting for MongoDB…"
for i in $(seq 1 15); do
if docker exec "$MONGO_CONTAINER" mongosh --eval "db.runCommand({ping:1})" --quiet &>/dev/null; then
break
fi
sleep 1
done
echo "[✓] MongoDB is ready"
fi
# Kill any previous webfurl-server on :3001
if lsof -ti:3001 &>/dev/null; then
echo "[…] Killing previous server on :3001…"
kill $(lsof -ti:3001) 2>/dev/null
sleep 0.5
fi
# Start the Axum API server in the background
echo "[…] Starting webfurl-server on :3001…"
RUST_LOG="${RUST_LOG:-info,webfurl_core=debug}" \
./target/release/webfurl-server &
SERVER_PID=$!
echo "$SERVER_PID" >> "$PIDFILE"
echo "[✓] webfurl-server started (PID $SERVER_PID)"
# Wait a moment for server to bind
sleep 1
# Start the agent (interactive, foreground)
echo ""
echo "════════════════════════════════════════"
echo " WebFurl Agent — interactive mode"
echo " Server running on http://localhost:3001"
echo " Type /url <url> to browse a page"
echo " Type /quit to exit"
echo "════════════════════════════════════════"
echo ""
RUST_LOG="${RUST_LOG:-info,webfurl_core=debug,webfurl_agent=debug}" \
./target/release/webfurl-agent
# When agent exits, clean up
echo ""
echo "[…] Agent exited, cleaning up…"
source "$SCRIPT_DIR/stop.sh"