feat: add and align uninstall flow for newbie setup
This commit is contained in:
@@ -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 ""
|
||||
|
||||
Reference in New Issue
Block a user