From ff9383f59774b02ac93be18d0dc7ec9ef5addab3 Mon Sep 17 00:00:00 2001 From: openclaw Date: Mon, 9 Mar 2026 21:43:24 +0800 Subject: [PATCH] feat: merge install/uninstall into one interactive entrypoint --- README.md | 10 ++++++++-- install-macos.sh | 18 ++++++++++++++++++ install-windows-en.ps1 | 42 ++++++++++++++++++++++++++++++++++++++++++ install-windows.ps1 | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 86e8be1..e4479af 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,12 @@ --- -## 快速安装 +## 统一入口(安装 / 卸载) + +> 运行脚本后会先弹出菜单,让用户选择: +> 1) 安装 / 更新 +> 2) 卸载 + ### macOS @@ -106,7 +111,8 @@ iwr -useb https://github.carrydelahaye.work/openclaw/openclaw-setup-cn/raw/branc ## 卸载 -> 已对齐当前安装方式:Windows 卸载脚本会按“原生 Windows 安装”路径执行卸载。 +> 推荐直接运行上面的“统一入口”脚本,然后选择 **2) 卸载**。 +> 下面保留独立卸载命令,方便自动化或批量操作。 ### macOS diff --git a/install-macos.sh b/install-macos.sh index 374bc46..02801c9 100755 --- a/install-macos.sh +++ b/install-macos.sh @@ -28,6 +28,24 @@ header() { header +echo -e "${BOLD}请选择操作:${NC}" +echo " 1) 安装 / 更新 OpenClaw" +echo " 2) 卸载 OpenClaw" +read -r -p "请输入选项 [1/2](默认 1): " ACTION +ACTION=${ACTION:-1} + +if [[ "$ACTION" == "2" ]]; then + info "你选择了:卸载 OpenClaw" + if command -v openclaw &>/dev/null; then + openclaw uninstall --all --yes --non-interactive + else + warn "在 PATH 中未找到 openclaw,尝试使用 npx 卸载..." + npx -y openclaw uninstall --all --yes --non-interactive + fi + success "OpenClaw 已卸载。" + exit 0 +fi + # ───────────────────────────────────────────── # 步骤 1: 检查 / 安装 Node 22+ # ───────────────────────────────────────────── diff --git a/install-windows-en.ps1 b/install-windows-en.ps1 index 983e55a..c0fd3de 100644 --- a/install-windows-en.ps1 +++ b/install-windows-en.ps1 @@ -20,6 +20,48 @@ try { Write-Header +Write-Host "Choose an action:" -ForegroundColor White +Write-Host " 1) Install / Update OpenClaw" -ForegroundColor Gray +Write-Host " 2) Uninstall OpenClaw" -ForegroundColor Gray +$action = Read-Host "Enter [1/2] (default: 1)" +if ([string]::IsNullOrWhiteSpace($action)) { $action = "1" } + +if ($action -eq "2") { + Write-Info "You chose: uninstall OpenClaw" + + $uninstalled = $false + + if (Get-Command openclaw -ErrorAction SilentlyContinue) { + try { + openclaw uninstall --all --yes --non-interactive + $uninstalled = $true + } catch { + Write-Warn "openclaw uninstall failed, trying npx..." + } + } + + if (-not $uninstalled -and (Get-Command npx -ErrorAction SilentlyContinue)) { + try { + npx -y openclaw uninstall --all --yes --non-interactive + $uninstalled = $true + } catch { + Write-Warn "npx uninstall failed." + } + } + + if (Get-Command npm -ErrorAction SilentlyContinue) { + try { npm uninstall -g openclaw 2>$null | Out-Null } catch {} + } + + if ($uninstalled) { + Write-Ok "OpenClaw uninstalled." + } else { + Write-Err "Failed to uninstall OpenClaw. Please ensure Node.js/npm is available and retry." + } + + return +} + # ───────────────────────────────────────────── # Step 1: Check / Install Node.js 22+ # ───────────────────────────────────────────── diff --git a/install-windows.ps1 b/install-windows.ps1 index 2a9dc99..2ea515f 100644 --- a/install-windows.ps1 +++ b/install-windows.ps1 @@ -20,6 +20,48 @@ try { Write-Header +Write-Host "请选择操作:" -ForegroundColor White +Write-Host " 1) 安装 / 更新 OpenClaw" -ForegroundColor Gray +Write-Host " 2) 卸载 OpenClaw" -ForegroundColor Gray +$action = Read-Host "请输入选项 [1/2](默认 1)" +if ([string]::IsNullOrWhiteSpace($action)) { $action = "1" } + +if ($action -eq "2") { + Write-Info "你选择了:卸载 OpenClaw" + + $uninstalled = $false + + if (Get-Command openclaw -ErrorAction SilentlyContinue) { + try { + openclaw uninstall --all --yes --non-interactive + $uninstalled = $true + } catch { + Write-Warn "openclaw 卸载失败,尝试 npx 方式..." + } + } + + if (-not $uninstalled -and (Get-Command npx -ErrorAction SilentlyContinue)) { + try { + npx -y openclaw uninstall --all --yes --non-interactive + $uninstalled = $true + } catch { + Write-Warn "npx 卸载失败。" + } + } + + if (Get-Command npm -ErrorAction SilentlyContinue) { + try { npm uninstall -g openclaw 2>$null | Out-Null } catch {} + } + + if ($uninstalled) { + Write-Ok "OpenClaw 已卸载。" + } else { + Write-Err "未能完成 OpenClaw 卸载。请确认 Node.js/npm 可用后重试。" + } + + return +} + # ───────────────────────────────────────────── # 步骤 1: 检查 / 安装 Node.js 22+ # ─────────────────────────────────────────────