openclawsetup 1.0.4 → 1.0.6

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.
Files changed (2) hide show
  1. package/bin/cli.mjs +129 -19
  2. package/package.json +1 -1
package/bin/cli.mjs CHANGED
@@ -173,26 +173,42 @@ function detectExistingInstall() {
173
173
  const openclawDir = join(home, '.openclaw');
174
174
  const clawdbotDir = join(home, '.clawdbot');
175
175
 
176
+ let result = { installed: false };
177
+
176
178
  if (existsSync(openclawDir) || existsSync(clawdbotDir)) {
177
- return {
179
+ result = {
178
180
  installed: true,
179
181
  configDir: existsSync(openclawDir) ? openclawDir : clawdbotDir,
180
182
  name: existsSync(openclawDir) ? 'openclaw' : 'clawdbot',
181
183
  };
184
+ } else {
185
+ // 检查命令是否存在
186
+ const openclawResult = safeExec('openclaw --version');
187
+ if (openclawResult.ok) {
188
+ result = { installed: true, name: 'openclaw', version: openclawResult.output, configDir: openclawDir };
189
+ } else {
190
+ const clawdbotResult = safeExec('clawdbot --version');
191
+ if (clawdbotResult.ok) {
192
+ result = { installed: true, name: 'clawdbot', version: clawdbotResult.output, configDir: clawdbotDir };
193
+ }
194
+ }
182
195
  }
183
196
 
184
- // 检查命令是否存在
185
- const openclawResult = safeExec('openclaw --version');
186
- if (openclawResult.ok) {
187
- return { installed: true, name: 'openclaw', version: openclawResult.output };
188
- }
189
-
190
- const clawdbotResult = safeExec('clawdbot --version');
191
- if (clawdbotResult.ok) {
192
- return { installed: true, name: 'clawdbot', version: clawdbotResult.output };
197
+ // 如果已安装,尝试读取配置获取 token 和 port
198
+ if (result.installed && result.configDir) {
199
+ const configPath = join(result.configDir, result.name === 'openclaw' ? 'openclaw.json' : 'clawdbot.json');
200
+ if (existsSync(configPath)) {
201
+ try {
202
+ const config = JSON.parse(readFileSync(configPath, 'utf8'));
203
+ result.token = config.gateway?.auth?.token;
204
+ result.port = config.gateway?.port || 18789;
205
+ } catch (e) {
206
+ // 忽略解析错误
207
+ }
208
+ }
193
209
  }
194
210
 
195
- return { installed: false };
211
+ return result;
196
212
  }
197
213
 
198
214
  // 带进度动画的命令执行
@@ -519,6 +535,23 @@ function startService(cliName) {
519
535
  return false;
520
536
  }
521
537
 
538
+ // 检测是否在云服务器/VPS 上运行
539
+ function detectVPS() {
540
+ // 检查常见的云服务器特征
541
+ const indicators = [
542
+ existsSync('/etc/cloud'), // cloud-init
543
+ existsSync('/var/lib/cloud'), // cloud-init data
544
+ existsSync('/sys/hypervisor'), // 虚拟化
545
+ process.env.CLOUD_SHELL === 'true', // Google Cloud Shell
546
+ ];
547
+
548
+ // 检查是否有公网 IP(简单检测)
549
+ const result = safeExec('hostname -I 2>/dev/null || hostname -i 2>/dev/null');
550
+ const hasPublicIP = result.ok && result.output && !result.output.startsWith('127.');
551
+
552
+ return indicators.some(Boolean) || hasPublicIP;
553
+ }
554
+
522
555
  // 主函数
523
556
  async function main() {
524
557
  const options = parseArgs();
@@ -533,16 +566,69 @@ async function main() {
533
566
  // 检测现有安装
534
567
  const existing = detectExistingInstall();
535
568
  if (existing.installed) {
536
- console.log(colors.yellow('\n检测到已有安装:'));
569
+ console.log(colors.bold(colors.green('\n========================================')));
570
+ console.log(colors.bold(colors.green('✅ OpenClaw 已安装')));
571
+ console.log(colors.bold(colors.green('========================================')));
572
+
537
573
  if (existing.configDir) {
538
- log.detail(`配置目录: ${existing.configDir}`);
574
+ console.log(colors.cyan('\n配置信息:'));
575
+ console.log(` 配置目录: ${colors.yellow(existing.configDir)}`);
539
576
  }
540
577
  if (existing.version) {
541
- log.detail(`版本: ${existing.version}`);
578
+ console.log(` 版本: ${colors.yellow(existing.version)}`);
542
579
  }
543
- console.log(colors.cyan('\n如需重新安装,请先卸载:'));
544
- console.log(` npm uninstall -g ${existing.name}`);
545
- console.log(` rm -rf ~/.openclaw ~/.clawdbot`);
580
+ if (existing.port) {
581
+ console.log(` Gateway 端口: ${colors.yellow(existing.port)}`);
582
+ }
583
+ if (existing.token) {
584
+ console.log(` Gateway Token: ${colors.yellow(existing.token)}`);
585
+ }
586
+
587
+ // 检测是否在 VPS 上
588
+ const isVPS = detectVPS();
589
+ const port = existing.port || 18789;
590
+ const token = existing.token || '<你的token>';
591
+
592
+ // 显示访问说明
593
+ if (isVPS) {
594
+ console.log(colors.cyan('\n📡 Dashboard 访问 (云服务器):'));
595
+ console.log(colors.gray(' Gateway 默认绑定 127.0.0.1,外部无法直接访问(安全设计)'));
596
+ console.log('');
597
+ console.log(colors.yellow(' 方式一:SSH 隧道(推荐,安全)'));
598
+ console.log(colors.gray(' 在本地电脑执行以下命令,保持终端窗口打开:'));
599
+ console.log(` ssh -N -L ${port}:127.0.0.1:${port} root@<服务器IP>`);
600
+ console.log(colors.gray(' 然后在本地浏览器访问:'));
601
+ console.log(` ${colors.green(`http://127.0.0.1:${port}/?token=${token}`)}`);
602
+ console.log('');
603
+ console.log(colors.yellow(' 方式二:直接暴露端口(不推荐,有安全风险)'));
604
+ console.log(colors.gray(' 1. 修改配置文件 ~/.openclaw/openclaw.json'));
605
+ console.log(colors.gray(' 将 "bind": "loopback" 改为 "bind": "all"'));
606
+ console.log(colors.gray(' 2. 在云服务器控制台开放端口 ' + port));
607
+ console.log(colors.gray(' - 腾讯云:安全组 → 入站规则 → 添加 TCP ' + port));
608
+ console.log(colors.gray(' - 阿里云:安全组 → 配置规则 → 添加 TCP ' + port));
609
+ console.log(colors.gray(' 3. 重启 Gateway:' + existing.name + ' gateway restart'));
610
+ console.log(colors.gray(' 4. 访问:http://<服务器IP>:' + port + '/?token=...'));
611
+ } else {
612
+ console.log(colors.cyan('\nDashboard 访问:'));
613
+ console.log(` ${colors.yellow(`http://127.0.0.1:${port}/?token=${token}`)}`);
614
+ }
615
+
616
+ console.log(colors.cyan('\n常用命令:'));
617
+ console.log(` 查看状态: ${colors.yellow(`${existing.name} status`)}`);
618
+ console.log(` 查看日志: ${colors.yellow(`${existing.name} gateway logs`)}`);
619
+ console.log(` 重启服务: ${colors.yellow(`${existing.name} gateway restart`)}`);
620
+ console.log(` 诊断问题: ${colors.yellow(`${existing.name} doctor`)}`);
621
+
622
+ console.log(colors.cyan('\n配置 AI 模型:'));
623
+ console.log(` ${colors.yellow('npx openclawapi@latest preset-claude')}`);
624
+
625
+ console.log(colors.cyan('\n配置聊天渠道:'));
626
+ console.log(` Discord: ${colors.yellow('npx openclawdc')}`);
627
+ console.log(` 飞书: ${colors.yellow('npx openclawfs')}`);
628
+
629
+ console.log(colors.gray('\n如需重新安装,请先卸载:'));
630
+ console.log(colors.gray(` npm uninstall -g ${existing.name}`));
631
+ console.log(colors.gray(` rm -rf ~/.openclaw ~/.clawdbot`));
546
632
  console.log('');
547
633
  process.exit(0);
548
634
  }
@@ -567,6 +653,9 @@ async function main() {
567
653
  log.info('跳过服务启动 (--skip-start)');
568
654
  }
569
655
 
656
+ // 检测是否在 VPS 上
657
+ const isVPS = detectVPS();
658
+
570
659
  // 完成
571
660
  console.log(colors.bold(colors.green('\n========================================')));
572
661
  console.log(colors.bold(colors.green('✅ OpenClaw 安装完成!')));
@@ -577,8 +666,29 @@ async function main() {
577
666
  console.log(` Gateway 端口: ${colors.yellow(config.port)}`);
578
667
  console.log(` Gateway Token: ${colors.yellow(config.token)}`);
579
668
 
580
- console.log(colors.cyan('\nDashboard 访问:'));
581
- console.log(` ${colors.yellow(`http://127.0.0.1:${config.port}/?token=${config.token}`)}`);
669
+ // 根据环境显示不同的访问说明
670
+ if (isVPS) {
671
+ console.log(colors.cyan('\n📡 Dashboard 访问 (云服务器):'));
672
+ console.log(colors.gray(' Gateway 默认绑定 127.0.0.1,外部无法直接访问(安全设计)'));
673
+ console.log('');
674
+ console.log(colors.yellow(' 方式一:SSH 隧道(推荐,安全)'));
675
+ console.log(colors.gray(' 在本地电脑执行以下命令,保持终端窗口打开:'));
676
+ console.log(` ssh -N -L ${config.port}:127.0.0.1:${config.port} root@<服务器IP>`);
677
+ console.log(colors.gray(' 然后在本地浏览器访问:'));
678
+ console.log(` ${colors.green(`http://127.0.0.1:${config.port}/?token=${config.token}`)}`);
679
+ console.log('');
680
+ console.log(colors.yellow(' 方式二:直接暴露端口(不推荐,有安全风险)'));
681
+ console.log(colors.gray(' 1. 修改配置文件 ~/.openclaw/openclaw.json'));
682
+ console.log(colors.gray(' 将 "bind": "loopback" 改为 "bind": "all"'));
683
+ console.log(colors.gray(' 2. 在云服务器控制台开放端口 ' + config.port));
684
+ console.log(colors.gray(' - 腾讯云:安全组 → 入站规则 → 添加 TCP ' + config.port));
685
+ console.log(colors.gray(' - 阿里云:安全组 → 配置规则 → 添加 TCP ' + config.port));
686
+ console.log(colors.gray(' 3. 重启 Gateway:' + cliName + ' gateway restart'));
687
+ console.log(colors.gray(' 4. 访问:http://<服务器IP>:' + config.port + '/?token=...'));
688
+ } else {
689
+ console.log(colors.cyan('\nDashboard 访问:'));
690
+ console.log(` ${colors.yellow(`http://127.0.0.1:${config.port}/?token=${config.token}`)}`);
691
+ }
582
692
 
583
693
  console.log(colors.cyan('\n下一步 - 配置 AI 模型:'));
584
694
  console.log(` ${colors.yellow('npx openclawapi@latest preset-claude')}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclawsetup",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "一键安装 OpenClaw - 自动完成基础部署,无需交互",
5
5
  "type": "module",
6
6
  "bin": {