Rewrite Windows scripts: drop WSL, run natively

- install-windows.ps1: install Node.js via winget/choco (fallback
  to nodejs.cn manual download), then npm install openclaw. No WSL.
- configure-aws-bedrock.ps1: full native PowerShell port with
  SecureString input, user-level env vars, config backup.
- README: update Windows instructions to reflect native install.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Rick Mu
2026-02-13 18:49:49 +11:00
parent 0108f7fa2f
commit 68c1bee826
3 changed files with 304 additions and 182 deletions

View File

@@ -1,6 +1,6 @@
# ─────────────────────────────────────────────
# OpenClaw 一键部署安装脚本 (Windows)
# 安装 WSL2 + Ubuntu然后在 WSL 中设置 OpenClaw
# 安装 Node.js + OpenClaw原生 Windows 运行
# ─────────────────────────────────────────────
$ErrorActionPreference = "Stop"
@@ -21,151 +21,111 @@ function Write-Header {
Write-Header
# ─────────────────────────────────────────────
# 步骤 1: 检查 / 安装 WSL2
# 步骤 1: 检查 / 安装 Node.js 22+
# ─────────────────────────────────────────────
Write-Info "正在检查 WSL2 安装..."
Write-Info "正在检查 Node.js..."
$wslInstalled = $false
try {
$wslOutput = wsl --status 2>&1
if ($LASTEXITCODE -eq 0) {
$wslInstalled = $true
}
} catch {
$wslInstalled = $false
}
# 检查 WSL 中是否有 Ubuntu
$ubuntuAvailable = $false
if ($wslInstalled) {
$distros = wsl --list --quiet 2>&1
if ($distros -match "Ubuntu") {
$ubuntuAvailable = $true
}
}
if (-not $wslInstalled -or -not $ubuntuAvailable) {
Write-Info "正在安装 WSL2 和 Ubuntu 24.04..."
Write-Warn "可能需要重启。重启后请再次运行此脚本。"
wsl --install -d Ubuntu-24.04
if ($LASTEXITCODE -ne 0) {
Write-Err "WSL2 安装失败。请手动安装wsl --install -d Ubuntu-24.04"
}
Write-Ok "WSL2 + Ubuntu 24.04 安装完成。"
Write-Warn "如果提示重启,请重启计算机后再次运行此脚本。"
# 检查是否需要重启
$restartNeeded = $false
try {
wsl --status 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) { $restartNeeded = $true }
} catch {
$restartNeeded = $true
}
if ($restartNeeded) {
Write-Host ""
Write-Warn "需要重启才能完成 WSL2 安装。"
Write-Host "重启后,请再次运行此脚本。" -ForegroundColor Yellow
Write-Host ""
Read-Host "按 Enter 键退出"
exit 0
}
} else {
Write-Ok "已找到 WSL2 和 Ubuntu。"
}
# ─────────────────────────────────────────────
# 步骤 2: 在 WSL 中启用 systemd
# ─────────────────────────────────────────────
Write-Info "正在配置 WSL 中的 systemd..."
$checkSystemd = wsl -d Ubuntu-24.04 -- bash -c "cat /etc/wsl.conf 2>/dev/null || echo ''"
if ($checkSystemd -notmatch "systemd=true") {
wsl -d Ubuntu-24.04 -- bash -c "echo '[boot]' | sudo tee /etc/wsl.conf > /dev/null && echo 'systemd=true' | sudo tee -a /etc/wsl.conf > /dev/null"
Write-Ok "已在 /etc/wsl.conf 中启用 systemd"
# ─────────────────────────────────────────
# 步骤 3: 重启 WSL
# ─────────────────────────────────────────
Write-Info "正在重启 WSL 以应用 systemd..."
wsl --shutdown
Start-Sleep -Seconds 3
Write-Ok "WSL 已重启。"
} else {
Write-Ok "systemd 已启用。"
}
# ─────────────────────────────────────────────
# 步骤 4: 在 WSL 中安装 Node 22+
# ─────────────────────────────────────────────
Write-Info "正在检查 WSL 中的 Node.js..."
$nodeCheck = wsl -d Ubuntu-24.04 -- bash -c "command -v node && node -v || echo 'NOT_FOUND'" 2>&1
$needsNode = $true
if ($nodeCheck -notmatch "NOT_FOUND" -and $nodeCheck -match "v(\d+)") {
$nodeVersion = [int]$Matches[1]
if ($nodeVersion -ge 22) {
Write-Ok "WSL 中已找到 Node.js v$nodeVersion (>= 22)。"
$needsNode = $false
} else {
Write-Warn "WSL 中已找到 Node.js v$nodeVersion,但需要 >= 22。正在升级..."
try {
$nodeVersion = (node -v 2>$null)
if ($nodeVersion -match "v(\d+)") {
$major = [int]$Matches[1]
if ($major -ge 22) {
Write-Ok "已找到 Node.js $nodeVersion"
$needsNode = $false
} else {
Write-Warn "已找到 Node.js $nodeVersion,但需要 v22+,正在升级..."
}
}
} else {
Write-Warn "WSL 中未找到 Node.js。"
} catch {
Write-Warn "未找到 Node.js。"
}
if ($needsNode) {
Write-Info "正在通过 NodeSource 在 WSL 中安装 Node.js 22..."
Write-Info "正在安装 Node.js 22..."
$installNodeScript = @'
set -e
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs
node -v
'@
$installed = $false
wsl -d Ubuntu-24.04 -- bash -c $installNodeScript
if ($LASTEXITCODE -ne 0) {
Write-Err "WSL 中 Node.js 安装失败。"
# 方式 1: wingetWindows 11 / Windows 10 自带)
if (-not $installed -and (Get-Command winget -ErrorAction SilentlyContinue)) {
Write-Info "使用 winget 安装..."
winget install OpenJS.NodeJS.LTS --accept-package-agreements --accept-source-agreements
if ($LASTEXITCODE -eq 0) {
$installed = $true
Write-Ok "Node.js 已通过 winget 安装"
}
}
Write-Ok "WSL 中 Node.js 22 安装完成。"
}
# ─────────────────────────────────────────────
# 步骤 5: 在 WSL 中安装 OpenClaw
# ─────────────────────────────────────────────
Write-Info "正在在 WSL 中安装 OpenClaw..."
$openclawCheck = wsl -d Ubuntu-24.04 -- bash -c "command -v openclaw || echo 'NOT_FOUND'" 2>&1
if ($openclawCheck -match "NOT_FOUND") {
wsl -d Ubuntu-24.04 -- bash -c "curl -fsSL https://openclaw.ai/install.sh | bash -s -- --no-onboard"
if ($LASTEXITCODE -ne 0) {
Write-Err "WSL 中 OpenClaw 安装失败。"
# 方式 2: Chocolatey
if (-not $installed -and (Get-Command choco -ErrorAction SilentlyContinue)) {
Write-Info "使用 Chocolatey 安装..."
choco install nodejs-lts -y
if ($LASTEXITCODE -eq 0) {
$installed = $true
Write-Ok "Node.js 已通过 Chocolatey 安装"
}
}
# 方式 3: 手动下载提示
if (-not $installed) {
Write-Host ""
Write-Err "无法自动安装 Node.js。请手动安装后重新运行此脚本`n`n 下载地址https://nodejs.cn/download/`nhttps://nodejs.org/en/download/`n`n 安装完成后重新打开 PowerShell 运行此脚本。"
}
# 刷新 PATH
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
# 验证安装
try {
$nodeVersion = (node -v 2>$null)
Write-Ok "Node.js $nodeVersion 安装成功"
} catch {
Write-Err "Node.js 安装后验证失败。请关闭 PowerShell 重新打开后再试。"
}
Write-Ok "WSL 中 OpenClaw 安装完成。"
} else {
Write-Ok "WSL 中已安装 OpenClaw。"
}
# ─────────────────────────────────────────────
# 步骤 6: 安装 OpenClaw 网关守护进程
# 步骤 2: 安装 OpenClaw
# ─────────────────────────────────────────────
Write-Info "正在安装 OpenClaw 网关守护进程..."
Write-Info "正在检查 OpenClaw..."
wsl -d Ubuntu-24.04 -- bash -c 'export PATH="$HOME/.openclaw/bin:$PATH" && openclaw gateway install'
if ($LASTEXITCODE -ne 0) {
Write-Warn "网关守护进程安装遇到问题。您可以稍后使用以下命令安装openclaw gateway install"
} else {
Write-Ok "网关守护进程安装完成"
$needsInstall = $true
try {
$null = Get-Command openclaw -ErrorAction Stop
Write-Ok "已找到 OpenClaw"
$needsInstall = $false
} catch {
Write-Info "正在安装 OpenClaw..."
}
if ($needsInstall) {
npm install -g openclaw@latest
if ($LASTEXITCODE -ne 0) {
Write-Err "OpenClaw 安装失败。请手动运行npm install -g openclaw@latest"
}
# 刷新 PATH
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
# 把 npm global bin 加到 PATH
try {
$npmPrefix = (npm config get prefix 2>$null).Trim()
if ($npmPrefix) {
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if (-not ($userPath -split ";" | Where-Object { $_ -ieq $npmPrefix })) {
[Environment]::SetEnvironmentVariable("Path", "$userPath;$npmPrefix", "User")
$env:Path += ";$npmPrefix"
}
}
} catch {}
Write-Ok "OpenClaw 安装完成。"
}
# ─────────────────────────────────────────────
# 步骤 7: 启动交互式配置
# 步骤 3: 启动交互式配置
# ─────────────────────────────────────────────
Write-Host ""
Write-Host "========================================" -ForegroundColor Green
@@ -177,7 +137,7 @@ Write-Host " 选择 MiniMax 可获得 7天免费试用 - 无需信用卡。" -F
Write-Host " 注册地址https://platform.minimax.io" -ForegroundColor Cyan
Write-Host ""
wsl -d Ubuntu-24.04 -- bash -c 'export PATH="$HOME/.openclaw/bin:$PATH" && openclaw onboard --accept-risk --flow quickstart --node-manager npm --skip-skills < /dev/tty'
openclaw onboard --accept-risk --flow quickstart --node-manager npm --skip-skills
Write-Host ""
Write-Host "========================================" -ForegroundColor Green
@@ -185,7 +145,8 @@ Write-Host " 配置完成!" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
Write-Host ""
Write-Host " 接下来:" -ForegroundColor White
Write-Host " 1. 开始使用 OpenClawopenclaw在 WSL 中)" -ForegroundColor Gray
Write-Host " 2. 添加技能可选openclaw configure --section skills" -ForegroundColor Gray
Write-Host " 3. 浏览可用技能openclaw skills" -ForegroundColor Gray
Write-Host " 1. 进入项目目录cd 你的项目路径" -ForegroundColor Gray
Write-Host " 2. 开始使用 OpenClawopenclaw" -ForegroundColor Gray
Write-Host " 3. 添加技能(可选)openclaw configure --section skills" -ForegroundColor Gray
Write-Host " 4. 浏览可用技能openclaw skills" -ForegroundColor Gray
Write-Host ""