Skip to content

Commit 2271777

Browse files
author
Kejilion Assistant
committed
fix: installer ASCII-safe + node/npm PATH refresh after winget install
1 parent e5de2a7 commit 2271777

2 files changed

Lines changed: 26 additions & 13 deletions

File tree

windows/openclaw-manager/install.ps1

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
# OpenClaw Windows one-liner installer/bootstrap
1+
# OpenClaw Windows bootstrap (ASCII-safe)
22
# Usage:
3-
# iwr -useb https://openclaw.ai/install.ps1 | iex
4-
# or
5-
# irm https://raw.githubusercontent.com/kejilion/sh/main/windows/openclaw-manager/install.ps1 | iex
3+
# Set-ExecutionPolicy -Scope Process Bypass -Force; iwr -useb https://raw.githubusercontent.com/kejilion/sh/main/windows/openclaw-manager/install.ps1 | iex
64

75
$ErrorActionPreference = 'Stop'
8-
[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()
9-
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
106
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
117

128
$managerUrl = 'https://raw.githubusercontent.com/kejilion/sh/main/windows/openclaw-manager/openclaw-win-manager.ps1'
@@ -18,7 +14,7 @@ Write-Host '[INFO] Preparing directories...' -ForegroundColor Cyan
1814
New-Item -ItemType Directory -Path $targetDir -Force | Out-Null
1915

2016
Write-Host '[INFO] Downloading latest manager script...' -ForegroundColor Cyan
21-
Invoke-WebRequest -UseBasicParsing -Uri $managerUrl -OutFile $targetFile
17+
Invoke-WebRequest -UseBasicParsing -Headers @{ 'Cache-Control'='no-cache' } -Uri $managerUrl -OutFile $targetFile
2218

2319
if ((Get-Item $targetFile).Length -lt 2000) {
2420
throw 'Downloaded file is too small, abort.'

windows/openclaw-manager/openclaw-win-manager.ps1

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#requires -Version 5.1
2+
# OPENCLAW_WIN_MANAGER_CN_V2
23
<#
34
OpenClaw Windows 10/11 独立管理脚本(中文版)
45
运行:
@@ -85,17 +86,33 @@ function ShowMenu {
8586
}
8687

8788
function InstallNodeIfNeeded {
88-
if(HasCmd "node"){ OK "检测到 Node.js: $(& node -v)"; return }
89-
Info "未检测到 Node.js,尝试自动安装"
89+
if(HasCmd "node" -and HasCmd "npm"){ OK "检测到 Node.js: $(& node -v)"; return }
90+
Info "未检测到 Node.js/npm,尝试自动安装"
9091

9192
if(HasCmd "winget"){
9293
& winget install --id OpenJS.NodeJS.LTS -e --accept-package-agreements --accept-source-agreements
93-
return
9494
}
95-
if(HasCmd "choco"){ & choco install nodejs-lts -y; return }
96-
if(HasCmd "scoop"){ & scoop install nodejs-lts; return }
95+
elseif(HasCmd "choco"){ & choco install nodejs-lts -y }
96+
elseif(HasCmd "scoop"){ & scoop install nodejs-lts }
97+
else { throw "未检测到 winget/choco/scoop,请先手动安装 Node.js 20+" }
98+
99+
# 刷新当前会话 PATH(winget 安装后常见 npm 不在当前会话 PATH)
100+
$machinePath = [Environment]::GetEnvironmentVariable('Path','Machine')
101+
$userPath = [Environment]::GetEnvironmentVariable('Path','User')
102+
$env:Path = "$machinePath;$userPath"
103+
104+
$extra = @('C:\Program Files\nodejs','C:\Program Files (x86)\nodejs')
105+
foreach($e in $extra){
106+
if((Test-Path $e) -and ($env:Path -notlike "*$e*")) { $env:Path += ";$e" }
107+
}
97108

98-
throw "未检测到 winget/choco/scoop,请先手动安装 Node.js 20+"
109+
if(-not (HasCmd "npm")){
110+
Warn "已安装 Node.js,但当前会话未找到 npm。将尝试直接使用 npm.cmd。"
111+
$npmCmd = 'C:\Program Files\nodejs\npm.cmd'
112+
if(Test-Path $npmCmd){
113+
Set-Alias -Name npm -Value $npmCmd -Scope Script
114+
}
115+
}
99116
}
100117

101118
function InstallOpenClaw {

0 commit comments

Comments
 (0)