openclawsetup 2.4.6 → 2.4.7

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 (3) hide show
  1. package/bin/cli.mjs +19 -0
  2. package/install.sh +20 -0
  3. package/package.json +1 -1
package/bin/cli.mjs CHANGED
@@ -187,6 +187,23 @@ function needsSudo() {
187
187
  return true;
188
188
  }
189
189
 
190
+ function fixNpmCacheOwnership() {
191
+ // sudo npm install 会把 ~/.npm 的文件 owner 改成 root
192
+ // 导致后续普通用户的 npx 无法写缓存(EACCES)
193
+ if (platform() === 'win32') return;
194
+ const npmCacheDir = join(homedir(), '.npm');
195
+ if (!existsSync(npmCacheDir)) return;
196
+ try {
197
+ accessSync(npmCacheDir, fsConstants.W_OK);
198
+ } catch {
199
+ const user = process.env.USER || process.env.LOGNAME;
200
+ if (user) {
201
+ log.hint('修复 npm 缓存目录权限...');
202
+ safeExec(`sudo chown -R ${user} "${npmCacheDir}"`);
203
+ }
204
+ }
205
+ }
206
+
190
207
  function detectExistingInstall() {
191
208
  const home = homedir();
192
209
  const openclawDir = join(home, '.openclaw');
@@ -436,6 +453,7 @@ async function installOpenClaw() {
436
453
  process.exit(1);
437
454
  }
438
455
  log.success(`OpenClaw 已安装: ${check.output}`);
456
+ fixNpmCacheOwnership();
439
457
  return 'openclaw';
440
458
  }
441
459
 
@@ -460,6 +478,7 @@ async function installOpenClaw() {
460
478
  shell: true,
461
479
  });
462
480
  if (sudoResult.status === 0) {
481
+ fixNpmCacheOwnership();
463
482
  log.success('OpenClaw CLI 安装完成(sudo)');
464
483
  return 'openclaw';
465
484
  }
package/install.sh CHANGED
@@ -258,6 +258,7 @@ install_node() {
258
258
  # 验证安装
259
259
  if command -v node &> /dev/null; then
260
260
  log_success "Node.js 安装完成: $(node -v)"
261
+ fix_npm_cache_ownership
261
262
  else
262
263
  log_error "Node.js 安装失败"
263
264
  echo ""
@@ -401,6 +402,22 @@ show_installed_info() {
401
402
  echo " 飞书: npx openclaw-chat-cn@latest feishu"
402
403
  }
403
404
 
405
+ # 修复 npm 缓存目录权限(sudo 安装后 ~/.npm 可能被 root 占用)
406
+ fix_npm_cache_ownership() {
407
+ local npm_cache="$HOME/.npm"
408
+ if [ -d "$npm_cache" ]; then
409
+ local current_user
410
+ current_user=$(whoami 2>/dev/null || echo "")
411
+ if [ -n "$current_user" ] && [ "$current_user" != "root" ]; then
412
+ # 检查是否有 root 拥有的文件
413
+ if find "$npm_cache" -maxdepth 1 -user root 2>/dev/null | grep -q .; then
414
+ log_info "修复 npm 缓存目录权限..."
415
+ sudo chown -R "$current_user" "$npm_cache" 2>/dev/null || true
416
+ fi
417
+ fi
418
+ fi
419
+ }
420
+
404
421
  # 显示菜单并获取选择
405
422
  show_menu() {
406
423
  local choice=""
@@ -541,6 +558,9 @@ install_openclaw() {
541
558
  log_info "开始安装 OpenClaw..."
542
559
  echo ""
543
560
 
561
+ # 修复 npm 缓存权限(防止之前 sudo 导致的 EACCES)
562
+ fix_npm_cache_ownership
563
+
544
564
  # 清除 npm 缓存确保获取最新版本
545
565
  log_info "清除 npm 缓存..."
546
566
  npm cache clean --force 2>/dev/null || true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclawsetup",
3
- "version": "2.4.6",
3
+ "version": "2.4.7",
4
4
  "description": "OpenClaw 安装向导 - 智能安装、诊断、自动修复",
5
5
  "type": "module",
6
6
  "bin": {