diff --git a/README.md b/README.md index e4479af..8c30d93 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ iwr -useb https://github.carrydelahaye.work/openclaw/openclaw-setup-cn/raw/branc - 默认跳过搜索提供商配置(`--skip-search`) - 默认跳过渠道配置(`--skip-channels`) - 默认跳过 Skills 配置(`--skip-skills`) +- OpenClaw 安装优先走 `npmmirror`,失败后回退 `npmjs`(更适合国内网络) --- diff --git a/install-macos.sh b/install-macos.sh index 02801c9..a0734c0 100755 --- a/install-macos.sh +++ b/install-macos.sh @@ -89,14 +89,31 @@ fi # ───────────────────────────────────────────── # 步骤 2: 安装 / 更新 OpenClaw +# 国内网络优先:npmmirror → npmjs(必要时) # ───────────────────────────────────────────── info "正在安装 / 更新 OpenClaw..." -curl -fsSL https://openclaw.ai/install.sh | bash -s -- --no-onboard -success "OpenClaw 安装 / 更新完成。" +install_openclaw_with_registry() { + local registry="$1" + info "尝试通过 npm 安装 OpenClaw($registry)..." + npm install -g openclaw@latest --registry="$registry" +} + +if install_openclaw_with_registry "https://registry.npmmirror.com"; then + success "已通过 npmmirror 安装 / 更新 OpenClaw。" +elif install_openclaw_with_registry "https://registry.npmjs.org"; then + success "已通过 npm 官方源安装 / 更新 OpenClaw。" +else + error "OpenClaw 安装失败:npmmirror 与 npm 官方源均不可用。" +fi # 确保 openclaw 在 PATH 中 -export PATH="$HOME/.openclaw/bin:$PATH" +NPM_PREFIX=$(npm config get prefix 2>/dev/null || true) +if [[ -n "$NPM_PREFIX" ]]; then + export PATH="$NPM_PREFIX/bin:$HOME/.openclaw/bin:$PATH" +else + export PATH="$HOME/.openclaw/bin:$PATH" +fi if ! command -v openclaw &>/dev/null; then error "OpenClaw 安装失败 — 在 PATH 中找不到 'openclaw'。请尝试重启终端后再次运行此脚本。" diff --git a/install-windows-en.ps1 b/install-windows-en.ps1 index c0fd3de..38f9e96 100644 --- a/install-windows-en.ps1 +++ b/install-windows-en.ps1 @@ -186,12 +186,27 @@ if (Get-Command git -ErrorAction SilentlyContinue) { # ───────────────────────────────────────────── # Step 3: Install / Update OpenClaw +# China-first path: npmmirror → npmjs (if needed) # ───────────────────────────────────────────── Write-Info "Installing / updating OpenClaw..." -npm install -g openclaw@latest 2>&1 | Write-Host -if ($LASTEXITCODE -ne 0) { - Write-Err "OpenClaw installation failed. Please run manually: npm install -g openclaw@latest" +function Install-OpenClawByRegistry($registry) { + Write-Info "Trying npm install via $registry ..." + npm install -g openclaw@latest --registry=$registry 2>&1 | Write-Host + return ($LASTEXITCODE -eq 0) +} + +$installedOpenClaw = $false +if (Install-OpenClawByRegistry "https://registry.npmmirror.com") { + Write-Ok "OpenClaw installed / updated via npmmirror." + $installedOpenClaw = $true +} elseif (Install-OpenClawByRegistry "https://registry.npmjs.org") { + Write-Ok "OpenClaw installed / updated via npm registry." + $installedOpenClaw = $true +} + +if (-not $installedOpenClaw) { + Write-Err "OpenClaw installation failed: both npmmirror and npm registry are unavailable." } # Refresh PATH diff --git a/install-windows.ps1 b/install-windows.ps1 index 2ea515f..f9264c5 100644 --- a/install-windows.ps1 +++ b/install-windows.ps1 @@ -187,12 +187,27 @@ if (Get-Command git -ErrorAction SilentlyContinue) { # ───────────────────────────────────────────── # 步骤 3: 安装 / 更新 OpenClaw +# 国内网络优先:npmmirror → npmjs(必要时) # ───────────────────────────────────────────── Write-Info "正在安装 / 更新 OpenClaw..." -npm install -g openclaw@latest 2>&1 | Write-Host -if ($LASTEXITCODE -ne 0) { - Write-Err "OpenClaw 安装失败。请手动运行:npm install -g openclaw@latest" +function Install-OpenClawByRegistry($registry) { + Write-Info "尝试通过 npm 安装 OpenClaw($registry)..." + npm install -g openclaw@latest --registry=$registry 2>&1 | Write-Host + return ($LASTEXITCODE -eq 0) +} + +$installedOpenClaw = $false +if (Install-OpenClawByRegistry "https://registry.npmmirror.com") { + Write-Ok "已通过 npmmirror 安装 / 更新 OpenClaw。" + $installedOpenClaw = $true +} elseif (Install-OpenClawByRegistry "https://registry.npmjs.org") { + Write-Ok "已通过 npm 官方源安装 / 更新 OpenClaw。" + $installedOpenClaw = $true +} + +if (-not $installedOpenClaw) { + Write-Err "OpenClaw 安装失败:npmmirror 与 npm 官方源均不可用。" } # 刷新 PATH