feat: add and align uninstall flow for newbie setup

This commit is contained in:
2026-03-09 21:40:02 +08:00
parent da477378a7
commit 126b19dd7a
5 changed files with 57 additions and 24 deletions

View File

@@ -1,5 +1,6 @@
# ─────────────────────────────────────────────
# OpenClaw 卸载脚本 (Windows / WSL)
# OpenClaw 卸载脚本 (Windows)
# 与当前“原生 Windows 安装”流程对齐
# ─────────────────────────────────────────────
$ErrorActionPreference = "Stop"
@@ -7,6 +8,7 @@ $ErrorActionPreference = "Stop"
function Write-Info($msg) { Write-Host "[信息] $msg" -ForegroundColor Cyan }
function Write-Ok($msg) { Write-Host "[完成] $msg" -ForegroundColor Green }
function Write-Warn($msg) { Write-Host "[警告] $msg" -ForegroundColor Yellow }
function Write-Err($msg) { Write-Host "[错误] $msg" -ForegroundColor Red; throw $msg }
Write-Host ""
Write-Host "========================================" -ForegroundColor White
@@ -14,20 +16,51 @@ Write-Host " OpenClaw 卸载器 (Windows)" -ForegroundColor White
Write-Host "========================================" -ForegroundColor White
Write-Host ""
$uninstallScript = @'
set -e
export PATH="$HOME/.openclaw/bin:$PATH"
if command -v openclaw &>/dev/null; then
echo "[信息] 已找到 openclaw正在运行卸载..."
openclaw uninstall --all --yes --non-interactive
else
echo "[警告] 在 PATH 中未找到 openclaw使用 npx..."
npx -y openclaw uninstall --all --yes --non-interactive
fi
'@
$uninstalled = $false
Write-Info "正在卸载 WSL 中OpenClaw..."
wsl -d Ubuntu-24.04 -- bash -c $uninstallScript
# 1) 优先使用已安装openclaw 命令
if (Get-Command openclaw -ErrorAction SilentlyContinue) {
try {
Write-Info "已找到 openclaw正在卸载--all..."
openclaw uninstall --all --yes --non-interactive
$uninstalled = $true
Write-Ok "OpenClaw 卸载命令执行完成。"
} catch {
Write-Warn "openclaw 卸载失败,尝试 npx 方式..."
}
}
# 2) 回退npx 直接调用
if (-not $uninstalled) {
if (Get-Command npx -ErrorAction SilentlyContinue) {
try {
Write-Info "使用 npx 执行卸载..."
npx -y openclaw uninstall --all --yes --non-interactive
$uninstalled = $true
Write-Ok "OpenClaw 卸载命令执行完成npx"
} catch {
Write-Warn "npx 卸载失败。"
}
} else {
Write-Warn "未找到 npx跳过 npx 卸载。"
}
}
# 3) 清理全局 npm 包(幂等,失败不终止)
if (Get-Command npm -ErrorAction SilentlyContinue) {
try {
Write-Info "尝试移除全局 npm 包 openclaw如存在..."
npm uninstall -g openclaw 2>$null | Out-Null
Write-Ok "全局 npm 包清理完成。"
} catch {
Write-Warn "全局 npm 包清理跳过:$_"
}
}
if (-not $uninstalled) {
Write-Err "未能完成 OpenClaw 卸载。请确认 Node.js/npm 可用后重试。"
}
Write-Host ""
Write-Ok "OpenClaw 已卸载。"
Write-Host ""