-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·198 lines (169 loc) · 6.49 KB
/
setup.sh
File metadata and controls
executable file
·198 lines (169 loc) · 6.49 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
#!/bin/bash
set -euo pipefail
echo "================================================"
echo " openclaw-tunnel setup wizard"
echo " Run Claude Code from Docker-hosted OpenClaw"
echo "================================================"
echo ""
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# ── Pre-flight checks ──────────────────────────────
echo "🔍 Pre-flight checks..."
# Docker
if ! command -v docker &>/dev/null; then
echo "❌ Docker not found. Install Docker first: https://docs.docker.com/get-docker/"
exit 1
fi
if ! docker info &>/dev/null 2>&1; then
echo "❌ Docker is not running. Start Docker Desktop first."
exit 1
fi
echo " ✅ Docker"
# Node.js
if ! command -v node &>/dev/null; then
echo "❌ Node.js not found. Install Node.js ≥ 22.5: https://nodejs.org/"
exit 1
fi
NODE_MAJOR=$(node -e "console.log(parseInt(process.versions.node))")
NODE_MINOR=$(node -e "console.log(parseInt(process.versions.node.split('.')[1]))")
if [[ "$NODE_MAJOR" -lt 22 ]] || { [[ "$NODE_MAJOR" -eq 22 ]] && [[ "$NODE_MINOR" -lt 5 ]]; }; then
echo "❌ Node.js $(node -v) is too old. Need ≥ 22.5 for node:sqlite support."
exit 1
fi
echo " ✅ Node.js $(node -v)"
# Claude Code CLI
DEFAULT_CLAUDE="claude"
read -rp " Claude Code CLI path [${DEFAULT_CLAUDE}]: " CLAUDE_PATH
CLAUDE_PATH="${CLAUDE_PATH:-$DEFAULT_CLAUDE}"
if ! command -v "$CLAUDE_PATH" &>/dev/null; then
echo " ⚠️ '${CLAUDE_PATH}' not found in PATH. Make sure it's installed and authenticated."
read -rp " Continue anyway? [y/N]: " CONTINUE
[[ "$CONTINUE" =~ ^[Yy] ]] || exit 1
else
echo " ✅ Claude Code CLI (${CLAUDE_PATH})"
fi
# Codex CLI
DEFAULT_CODEX="codex"
read -rp " Codex CLI path [${DEFAULT_CODEX}] (skip to disable): " CODEX_PATH
CODEX_PATH="${CODEX_PATH:-$DEFAULT_CODEX}"
if [[ "$CODEX_PATH" != "skip" ]] && command -v "$CODEX_PATH" &>/dev/null; then
echo " ✅ Codex CLI (${CODEX_PATH})"
elif [[ "$CODEX_PATH" == "skip" ]]; then
CODEX_PATH=""
echo " ⏭️ Codex disabled"
else
echo " ⚠️ '${CODEX_PATH}' not found — Codex will fail until installed"
fi
# Gemini CLI
DEFAULT_GEMINI="gemini"
read -rp " Gemini CLI path [${DEFAULT_GEMINI}] (skip to disable): " GEMINI_PATH
GEMINI_PATH="${GEMINI_PATH:-$DEFAULT_GEMINI}"
if [[ "$GEMINI_PATH" != "skip" ]] && command -v "$GEMINI_PATH" &>/dev/null; then
echo " ✅ Gemini CLI (${GEMINI_PATH})"
elif [[ "$GEMINI_PATH" == "skip" ]]; then
GEMINI_PATH=""
echo " ⏭️ Gemini disabled"
else
echo " ⚠️ '${GEMINI_PATH}' not found — Gemini will fail until installed"
fi
echo ""
# ── Configuration ───────────────────────────────────
echo "📝 Configuration"
echo ""
# Port
read -rp " task-api port [3456]: " PORT
PORT="${PORT:-3456}"
# Check port
if lsof -i ":${PORT}" &>/dev/null 2>&1; then
echo " ⚠️ Port ${PORT} is in use."
read -rp " Continue anyway? [y/N]: " CONTINUE
[[ "$CONTINUE" =~ ^[Yy] ]] || exit 1
fi
# Bot token
echo ""
echo " Callback bot token is used to deliver results back to your chat."
echo " For Discord: your bot's token from https://discord.com/developers"
read -rp " Callback bot token: " CALLBACK_BOT_TOKEN
if [[ -z "$CALLBACK_BOT_TOKEN" ]]; then
echo "❌ Bot token is required for callback delivery."
exit 1
fi
# Callback channel
echo ""
echo " Fallback channel ID for result delivery."
echo " (The plugin normally uses the channel where /cc was invoked)"
read -rp " Fallback callback channel ID [skip]: " CALLBACK_CHANNEL
CALLBACK_CHANNEL="${CALLBACK_CHANNEL:-}"
# Generate token
WORKER_TOKEN=$(openssl rand -hex 8)
echo ""
echo " 🔑 Generated WORKER_TOKEN: ${WORKER_TOKEN}"
echo ""
# ── Write .env ──────────────────────────────────────
ENV_FILE="${SCRIPT_DIR}/.env"
cat > "$ENV_FILE" <<ENV
# Generated by setup.sh on $(date -u +"%Y-%m-%dT%H:%M:%SZ")
# === task-api (runs in Docker) ===
WORKER_TOKEN=${WORKER_TOKEN}
PORT=${PORT}
CALLBACK_BOT_TOKEN=${CALLBACK_BOT_TOKEN}
CALLBACK_API_BASE_URL=https://discord.com/api/v10
# === runner (runs on host) ===
WORKER_URL=http://localhost:${PORT}
CLAUDE_PATH=${CLAUDE_PATH}
CODEX_PATH=${CODEX_PATH}
GEMINI_PATH=${GEMINI_PATH}
CC_TIMEOUT=1200000
ENV
echo " 📄 Written: .env"
# ── Write plugin config ────────────────────────────
PLUGIN_CONFIG="${SCRIPT_DIR}/plugin/openclaw.plugin.json"
if [[ -f "$PLUGIN_CONFIG" ]]; then
# Update the existing config with our values
# Use node to do JSON manipulation safely
node -e "
const fs = require('fs');
const config = JSON.parse(fs.readFileSync('${PLUGIN_CONFIG}', 'utf8'));
if (!config.config) config.config = {};
config.config.apiUrl = 'http://host.docker.internal:${PORT}';
config.config.apiToken = '${WORKER_TOKEN}';
config.config.callbackChannel = '${CALLBACK_CHANNEL}';
config.config.discordBotToken = '${CALLBACK_BOT_TOKEN}';
fs.writeFileSync('${PLUGIN_CONFIG}', JSON.stringify(config, null, 2) + '\n');
"
echo " 📄 Updated: plugin/openclaw.plugin.json"
else
echo " ⚠️ plugin/openclaw.plugin.json not found, skipping"
fi
# ── Runner LaunchAgent ──────────────────────────────
echo ""
if [[ "$(uname)" == "Darwin" ]]; then
read -rp " Install macOS LaunchAgent for runner auto-start? [Y/n]: " INSTALL_LA
INSTALL_LA="${INSTALL_LA:-Y}"
if [[ "$INSTALL_LA" =~ ^[Yy] ]]; then
bash "${SCRIPT_DIR}/runner/install.sh"
else
echo " Skipped. Run manually: cd runner && npm start"
fi
else
echo " ℹ️ Linux detected. Run the runner manually:"
echo " cd runner && WORKER_URL=http://localhost:${PORT} WORKER_TOKEN=${WORKER_TOKEN} node worker.js"
fi
# ── Done ────────────────────────────────────────────
echo ""
echo "================================================"
echo " ✅ Setup complete!"
echo "================================================"
echo ""
echo " 1. Start task-api:"
echo " docker-compose up -d"
echo ""
echo " 2. Start runner (if not using LaunchAgent):"
echo " cd runner && npm start"
echo ""
echo " 3. Install plugin into your OpenClaw instance:"
echo " Copy the plugin/ directory into your OpenClaw plugins folder"
echo " or add it to your openclaw.json plugins config"
echo ""
echo " 4. Try it out:"
echo " /cc hello"
echo ""