openclawsetup 2.1.3 → 2.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.mjs +58 -16
- package/install.ps1 +1 -1
- package/install.sh +35 -8
- package/package.json +6 -1
- package//344/275/277/347/224/250/350/257/264/346/230/216.md +94 -0
package/bin/cli.mjs
CHANGED
|
@@ -16,6 +16,32 @@ import { homedir, platform } from 'os';
|
|
|
16
16
|
import { join } from 'path';
|
|
17
17
|
import { createInterface } from 'readline';
|
|
18
18
|
|
|
19
|
+
// ============ 错误码定义 ============
|
|
20
|
+
|
|
21
|
+
const ERROR_CODES = {
|
|
22
|
+
NODE_VERSION: { code: 1, message: 'Node.js 版本过低' },
|
|
23
|
+
OPENCLAW_NOT_FOUND: { code: 2, message: '未检测到 OpenClaw 安装' },
|
|
24
|
+
NPM_INSTALL_FAILED: { code: 3, message: 'npm 安装失败' },
|
|
25
|
+
ONBOARD_FAILED: { code: 4, message: 'onboard 执行失败' },
|
|
26
|
+
GATEWAY_RESTART_FAILED: { code: 5, message: 'Gateway 重启失败' },
|
|
27
|
+
INVALID_INPUT: { code: 6, message: '输入无效' },
|
|
28
|
+
PERMISSION_DENIED: { code: 7, message: '权限不足' },
|
|
29
|
+
NETWORK_ERROR: { code: 8, message: '网络错误' },
|
|
30
|
+
PTY_UNAVAILABLE: { code: 9, message: '自动模式不可用' },
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function exitWithError(errorType, details = '') {
|
|
34
|
+
const err = ERROR_CODES[errorType] || { code: 99, message: '未知错误' };
|
|
35
|
+
console.log('\n' + '='.repeat(40));
|
|
36
|
+
console.log(`\x1b[31m❌ 错误: ${err.message}\x1b[0m`);
|
|
37
|
+
console.log('='.repeat(40));
|
|
38
|
+
if (details) {
|
|
39
|
+
console.log(details);
|
|
40
|
+
}
|
|
41
|
+
console.log(`\n错误码: ${err.code}`);
|
|
42
|
+
process.exit(err.code);
|
|
43
|
+
}
|
|
44
|
+
|
|
19
45
|
// ============ 工具函数 ============
|
|
20
46
|
|
|
21
47
|
const colors = {
|
|
@@ -91,11 +117,14 @@ function checkNodeVersion() {
|
|
|
91
117
|
const version = process.version;
|
|
92
118
|
const major = parseInt(version.slice(1).split('.')[0], 10);
|
|
93
119
|
if (major < 18) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
120
|
+
exitWithError('NODE_VERSION', `
|
|
121
|
+
当前版本: ${version},需要 18+
|
|
122
|
+
|
|
123
|
+
解决方案:
|
|
124
|
+
1. 访问 https://nodejs.org/ 下载最新版本
|
|
125
|
+
2. 或使用 nvm: nvm install 22
|
|
126
|
+
3. 或使用一键脚本(自动安装 Node.js):
|
|
127
|
+
curl -fsSL https://unpkg.com/openclawsetup@latest/install.sh | bash`);
|
|
99
128
|
}
|
|
100
129
|
return true;
|
|
101
130
|
}
|
|
@@ -161,9 +190,9 @@ function getConfigInfo() {
|
|
|
161
190
|
} catch {
|
|
162
191
|
try {
|
|
163
192
|
const raw = readFileSync(configPath, 'utf8');
|
|
164
|
-
const tokenMatch = raw.match(/"token"
|
|
165
|
-
const portMatch = raw.match(/"port"
|
|
166
|
-
const bindMatch = raw.match(/"bind"
|
|
193
|
+
const tokenMatch = raw.match(/"token"\s*:\s*"([^"]+)"/i);
|
|
194
|
+
const portMatch = raw.match(/"port"\s*:\s*(\d+)/i);
|
|
195
|
+
const bindMatch = raw.match(/"bind"\s*:\s*"([^"]+)"/i);
|
|
167
196
|
return {
|
|
168
197
|
configDir: cfg.dir,
|
|
169
198
|
configPath,
|
|
@@ -382,11 +411,15 @@ async function installOpenClaw() {
|
|
|
382
411
|
return 'clawdbot';
|
|
383
412
|
}
|
|
384
413
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
414
|
+
exitWithError('NPM_INSTALL_FAILED', `
|
|
415
|
+
解决方案:
|
|
416
|
+
1. 检查网络连接
|
|
417
|
+
2. 清除 npm 缓存后重试:
|
|
418
|
+
npm cache clean --force
|
|
419
|
+
npx openclawsetup@latest
|
|
420
|
+
3. 手动安装:
|
|
421
|
+
npm install -g openclaw@latest
|
|
422
|
+
openclaw onboard --install-daemon`);
|
|
390
423
|
}
|
|
391
424
|
|
|
392
425
|
// ============ 运行 Onboard ============
|
|
@@ -426,9 +459,18 @@ async function runOnboard(cliName) {
|
|
|
426
459
|
log.hint('如果配置未完成,可以手动运行: ' + cliName + ' onboard');
|
|
427
460
|
}
|
|
428
461
|
} else if (options.auto) {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
462
|
+
exitWithError('PTY_UNAVAILABLE', `
|
|
463
|
+
原因: ${autoResult.reason || '未能启用自动应答'}
|
|
464
|
+
|
|
465
|
+
解决方案:
|
|
466
|
+
1. 使用手动模式:
|
|
467
|
+
npx openclawsetup@latest --manual
|
|
468
|
+
2. 在 Linux 服务器上补齐编译依赖后再试:
|
|
469
|
+
sudo apt-get install -y build-essential python3 make g++
|
|
470
|
+
npx openclawsetup@latest --auto
|
|
471
|
+
3. 或直接运行官方命令:
|
|
472
|
+
npm install -g openclaw@latest
|
|
473
|
+
openclaw onboard --install-daemon`);
|
|
432
474
|
} else {
|
|
433
475
|
log.warn('自动模式不可用,已切换为手动模式');
|
|
434
476
|
log.hint(autoResult.reason || '未能启用自动应答');
|
package/install.ps1
CHANGED
package/install.sh
CHANGED
|
@@ -190,25 +190,52 @@ install_node() {
|
|
|
190
190
|
nvm alias default 22
|
|
191
191
|
fi
|
|
192
192
|
elif [ "$OS" == "linux" ]; then
|
|
193
|
+
# 检查是否需要 sudo
|
|
194
|
+
local need_sudo=false
|
|
195
|
+
if [ "$(id -u)" -ne 0 ]; then
|
|
196
|
+
case "$PM" in
|
|
197
|
+
apt|dnf|yum|pacman|apk)
|
|
198
|
+
need_sudo=true
|
|
199
|
+
;;
|
|
200
|
+
esac
|
|
201
|
+
fi
|
|
202
|
+
|
|
203
|
+
if [ "$need_sudo" = true ] && ! command -v sudo &> /dev/null; then
|
|
204
|
+
log_error "需要 root 权限安装 Node.js"
|
|
205
|
+
echo ""
|
|
206
|
+
echo "请使用以下方式之一:"
|
|
207
|
+
echo " 1. 以 root 用户运行此脚本"
|
|
208
|
+
echo " 2. 安装 sudo 后重试"
|
|
209
|
+
echo " 3. 手动安装 Node.js: https://nodejs.org/"
|
|
210
|
+
echo ""
|
|
211
|
+
exit 7
|
|
212
|
+
fi
|
|
213
|
+
|
|
214
|
+
local SUDO_CMD=""
|
|
215
|
+
if [ "$need_sudo" = true ]; then
|
|
216
|
+
SUDO_CMD="sudo"
|
|
217
|
+
log_warn "需要 sudo 权限安装 Node.js,可能会提示输入密码"
|
|
218
|
+
fi
|
|
219
|
+
|
|
193
220
|
case "$PM" in
|
|
194
221
|
apt)
|
|
195
222
|
log_info "使用 NodeSource 安装..."
|
|
196
|
-
curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
|
|
197
|
-
apt-get install -y nodejs
|
|
223
|
+
curl -fsSL https://deb.nodesource.com/setup_22.x | $SUDO_CMD bash -
|
|
224
|
+
$SUDO_CMD apt-get install -y nodejs
|
|
198
225
|
;;
|
|
199
226
|
dnf)
|
|
200
|
-
curl -fsSL https://rpm.nodesource.com/setup_22.x | bash -
|
|
201
|
-
dnf install -y nodejs
|
|
227
|
+
curl -fsSL https://rpm.nodesource.com/setup_22.x | $SUDO_CMD bash -
|
|
228
|
+
$SUDO_CMD dnf install -y nodejs
|
|
202
229
|
;;
|
|
203
230
|
yum)
|
|
204
|
-
curl -fsSL https://rpm.nodesource.com/setup_22.x | bash -
|
|
205
|
-
yum install -y nodejs
|
|
231
|
+
curl -fsSL https://rpm.nodesource.com/setup_22.x | $SUDO_CMD bash -
|
|
232
|
+
$SUDO_CMD yum install -y nodejs
|
|
206
233
|
;;
|
|
207
234
|
pacman)
|
|
208
|
-
pacman -Sy --noconfirm nodejs npm
|
|
235
|
+
$SUDO_CMD pacman -Sy --noconfirm nodejs npm
|
|
209
236
|
;;
|
|
210
237
|
apk)
|
|
211
|
-
apk add --no-cache nodejs npm
|
|
238
|
+
$SUDO_CMD apk add --no-cache nodejs npm
|
|
212
239
|
;;
|
|
213
240
|
*)
|
|
214
241
|
log_info "使用 nvm 安装..."
|
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openclawsetup",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.5",
|
|
4
4
|
"description": "OpenClaw 安装向导 - 带中文指引的官方安装流程",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"openclawsetup": "bin/cli.mjs"
|
|
8
8
|
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/anthropics/openclaw-tools.git",
|
|
12
|
+
"directory": "packages/openclawsetup"
|
|
13
|
+
},
|
|
9
14
|
"optionalDependencies": {
|
|
10
15
|
"node-pty": "^1.0.0"
|
|
11
16
|
},
|
|
@@ -233,6 +233,100 @@ rm ~/.config/systemd/user/openclaw.service
|
|
|
233
233
|
systemctl --user daemon-reload
|
|
234
234
|
```
|
|
235
235
|
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
### 错误:权限不足
|
|
239
|
+
**现象**:提示 "permission denied" 或 "EACCES"
|
|
240
|
+
**原因**:npm 全局安装目录没有写入权限
|
|
241
|
+
**解决**:
|
|
242
|
+
1. Linux 用户使用 sudo:
|
|
243
|
+
```bash
|
|
244
|
+
sudo npm install -g openclaw@latest
|
|
245
|
+
```
|
|
246
|
+
2. 或修复 npm 权限(推荐):
|
|
247
|
+
```bash
|
|
248
|
+
mkdir -p ~/.npm-global
|
|
249
|
+
npm config set prefix '~/.npm-global'
|
|
250
|
+
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
|
|
251
|
+
source ~/.bashrc
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
错误码: 7
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
### 错误:网络连接失败
|
|
259
|
+
**现象**:提示 "ETIMEDOUT"、"ECONNREFUSED" 或下载超时
|
|
260
|
+
**原因**:网络问题或 npm 源不可达
|
|
261
|
+
**解决**:
|
|
262
|
+
1. 检查网络连接
|
|
263
|
+
2. 尝试使用国内镜像源:
|
|
264
|
+
```bash
|
|
265
|
+
npm config set registry https://registry.npmmirror.com
|
|
266
|
+
npx openclawsetup@latest
|
|
267
|
+
```
|
|
268
|
+
3. 恢复官方源:
|
|
269
|
+
```bash
|
|
270
|
+
npm config set registry https://registry.npmjs.org
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
错误码: 8
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
### 错误:node-pty 编译失败
|
|
278
|
+
**现象**:安装时提示 "gyp ERR!" 或 "node-pty" 相关错误
|
|
279
|
+
**原因**:缺少 C++ 编译工具链
|
|
280
|
+
**解决**:
|
|
281
|
+
|
|
282
|
+
**Ubuntu/Debian:**
|
|
283
|
+
```bash
|
|
284
|
+
sudo apt-get update
|
|
285
|
+
sudo apt-get install -y build-essential python3 make g++ pkg-config
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
**CentOS/RHEL:**
|
|
289
|
+
```bash
|
|
290
|
+
sudo yum groupinstall -y "Development Tools"
|
|
291
|
+
sudo yum install -y python3
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
**macOS:**
|
|
295
|
+
```bash
|
|
296
|
+
xcode-select --install
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
**Windows:**
|
|
300
|
+
```powershell
|
|
301
|
+
npm install -g windows-build-tools
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
安装依赖后重试:
|
|
305
|
+
```bash
|
|
306
|
+
npx openclawsetup@latest
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
如果仍然失败,可以使用手动模式(不需要 node-pty):
|
|
310
|
+
```bash
|
|
311
|
+
npx openclawsetup@latest --manual
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
## 错误码速查表
|
|
317
|
+
|
|
318
|
+
| 错误码 | 含义 | 常见原因 |
|
|
319
|
+
|--------|------|----------|
|
|
320
|
+
| 1 | Node.js 版本过低 | 需要 Node.js 18+ |
|
|
321
|
+
| 2 | 未检测到 OpenClaw | 安装未完成 |
|
|
322
|
+
| 3 | npm 安装失败 | 网络问题或权限问题 |
|
|
323
|
+
| 4 | onboard 执行失败 | 配置过程中断 |
|
|
324
|
+
| 5 | Gateway 重启失败 | 服务异常 |
|
|
325
|
+
| 6 | 输入无效 | 参数错误 |
|
|
326
|
+
| 7 | 权限不足 | 需要 sudo 或修复 npm 权限 |
|
|
327
|
+
| 8 | 网络错误 | 检查网络或更换镜像源 |
|
|
328
|
+
| 9 | 自动模式不可用 | 缺少编译依赖,使用 --manual |
|
|
329
|
+
|
|
236
330
|
## 获取帮助
|
|
237
331
|
|
|
238
332
|
```bash
|