-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·188 lines (159 loc) · 6.83 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·188 lines (159 loc) · 6.83 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
#!/usr/bin/env bash
set -euo pipefail
# ── Clawbox — First-Run Setup ────────────────────────────────
# This script gets you from zero to running in one command.
COMPOSE_FILE="docker-compose.yml"
ENV_FILE=".env"
VOLUME_NAME="clawbox_clawbox-work-state"
# Colors (disabled if not a terminal)
if [ -t 1 ]; then
BOLD='\033[1m' DIM='\033[2m' GREEN='\033[32m' YELLOW='\033[33m' RED='\033[31m' RESET='\033[0m'
else
BOLD='' DIM='' GREEN='' YELLOW='' RED='' RESET=''
fi
info() { echo -e "${GREEN}▶${RESET} $*"; }
warn() { echo -e "${YELLOW}⚠${RESET} $*"; }
error() { echo -e "${RED}✗${RESET} $*" >&2; }
die() { error "$@"; exit 1; }
# ── Gateway port configuration ──────────────────────────────────────
GATEWAY_PORT="${GATEWAY_PORT:-18790}"
# ── Preflight checks ────────────────────────────────────────────────
info "Checking prerequisites..."
# Docker installed?
if ! command -v docker &>/dev/null; then
die "Docker is not installed. Get it at https://docs.docker.com/get-docker/"
fi
# Docker daemon running?
if ! docker info &>/dev/null; then
die "Docker daemon is not running. Start Docker Desktop (or systemctl start docker) and try again."
fi
# docker compose available?
if ! docker compose version &>/dev/null; then
die "docker compose (v2) not found. Update Docker Desktop or install the compose plugin."
fi
info "Docker is ready."
# ── Environment file ────────────────────────────────────────────────
if [ -f "$ENV_FILE" ]; then
info "Found existing .env — not overwriting."
set -a; source "$ENV_FILE"; set +a
else
info "Creating .env file..."
# Anthropic API key
if [ -n "${ANTHROPIC_API_KEY:-}" ]; then
info "Using ANTHROPIC_API_KEY from environment."
else
echo ""
echo -e "${BOLD}Anthropic API Key${RESET}"
echo " Get one at https://console.anthropic.com/settings/keys"
echo ""
read -rp " Enter your Anthropic API key: " ANTHROPIC_API_KEY
if [ -z "$ANTHROPIC_API_KEY" ]; then
die "API key is required."
fi
fi
# Write .env
cat > "$ENV_FILE" <<EOF
ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
EOF
chmod 600 "$ENV_FILE"
info ".env created (permissions: 600)."
fi
# ── Port conflict detection ─────────────────────────────────────────
info "Checking for port conflicts..."
check_port_available() {
local port="$1"
if command -v lsof &>/dev/null; then
local pid
pid=$(lsof -ti tcp:"$port" 2>/dev/null | head -1)
if [ -n "$pid" ]; then
# Check if it's our own clawbox container
local container_pid
container_pid=$(docker inspect clawbox-work --format '{{.State.Pid}}' 2>/dev/null || echo "")
if [ -n "$container_pid" ] && [ "$container_pid" != "0" ] && [ "$pid" = "$container_pid" ]; then
return 0 # Our own container — skip
fi
local proc
proc=$(ps -p "$pid" -o comm= 2>/dev/null || echo "pid $pid")
warn "Port $port is in use by: $proc (PID $pid)"
return 1
fi
elif nc -z 127.0.0.1 "$port" 2>/dev/null; then
warn "Port $port is already in use."
return 1
fi
return 0
}
PORT_CONFLICT=0
if ! check_port_available "$GATEWAY_PORT"; then
PORT_CONFLICT=1
fi
if [ "$PORT_CONFLICT" = "1" ]; then
echo ""
warn "Port conflict detected on gateway port $GATEWAY_PORT."
echo ""
echo " Option 1: Stop whatever is using port $GATEWAY_PORT and re-run setup.sh"
echo " Option 2: Run on a different port:"
echo " GATEWAY_PORT=18791 bash setup.sh"
echo ""
echo " Multiple clawbox instances can run simultaneously using different ports."
echo " Set GATEWAY_PORT in your shell to target a specific instance:"
echo " export GATEWAY_PORT=18791"
echo " clawbox run \"hello\""
echo ""
die "Cannot start: port conflict on $GATEWAY_PORT"
fi
info "Port $GATEWAY_PORT is available."
# ── Build and start ─────────────────────────────────────────────────
info "Building container image..."
GATEWAY_PORT="$GATEWAY_PORT" docker compose build --quiet
info "Starting clawbox-work..."
GATEWAY_PORT="$GATEWAY_PORT" docker compose up -d
# ── Wait for container to be healthy ────────────────────────────────
echo ""
info "Waiting for gateway to become healthy (up to 60s)..."
for i in $(seq 1 30); do
STATUS=$(docker inspect --format='{{.State.Health.Status}}' clawbox-work 2>/dev/null || echo "unknown")
if [ "$STATUS" = "healthy" ]; then
info "Gateway is healthy!"
break
fi
sleep 2
done
STATUS=$(docker inspect --format='{{.State.Health.Status}}' clawbox-work 2>/dev/null || echo "unknown")
if [ "$STATUS" != "healthy" ]; then
warn "Container not yet healthy (status: $STATUS). Check: docker compose logs -f"
fi
# ── Print next steps ────────────────────────────────────────────────
echo ""
echo -e "${BOLD}═══════════════════════════════════════════════════${RESET}"
echo -e "${BOLD} Clawbox is ready!${RESET}"
echo -e "${BOLD}═══════════════════════════════════════════════════${RESET}"
echo ""
echo -e " Gateway: ${GREEN}ws://localhost:18790${RESET}"
echo -e " Auth: ${DIM}none (loopback-only, host access only)${RESET}"
echo ""
echo -e "${BOLD}Connect the CLI:${RESET}"
echo ""
echo " export OPENCLAW_GATEWAY_URL=ws://localhost:18790"
echo " export OPENCLAW_GATEWAY_TOKEN=clawbox"
echo " openclaw agent --agent main -m \"hello\""
echo ""
echo -e " ${DIM}(OPENCLAW_GATEWAY_TOKEN is required by the CLI when overriding the URL;"
echo -e " the value doesn't matter — auth=none on the gateway)${RESET}"
echo ""
echo -e "${BOLD}Or add to ~/.zshrc for convenience:${RESET}"
echo ""
echo " export OPENCLAW_GATEWAY_URL=ws://localhost:18790"
echo " export OPENCLAW_GATEWAY_TOKEN=clawbox"
echo " alias owc=\"openclaw agent --agent main\""
echo ""
echo -e "${BOLD}Useful commands:${RESET}"
echo ""
echo " make status — check gateway status"
echo " make logs — tail gateway logs"
echo " make stop — stop the container"
echo " make shell — shell into the container"
echo " make chat — open openclaw TUI"
echo ""
echo -e "${DIM}Run 'make help' for all available targets.${RESET}"
echo ""