diff --git a/scripts/vps_bootstrap.ps1 b/scripts/vps_bootstrap.ps1 index 2051bd2..482cfb6 100644 --- a/scripts/vps_bootstrap.ps1 +++ b/scripts/vps_bootstrap.ps1 @@ -30,14 +30,15 @@ if (-not (Test-Path $envSrc)) { # --- 1. WSL2 + Ubuntu 22.04 ---------------------------------- Step "WSL state" -$wslList = @() -try { - $raw = wsl --list --quiet 2>$null - if ($raw) { - $wslList = ($raw -split "`n") | ForEach-Object { ($_ -replace "`0","").Trim() } | Where-Object { $_ } - } -} catch {} -$ubuntu = $wslList | Where-Object { $_ -match "Ubuntu" } | Select-Object -First 1 +# Probe properly: 'wsl -l -q' on a system without any distro PRINTS HELP and exits non-zero. +# Use -v (verbose) and check exit code; only valid distro lines are accepted. +$ubuntu = $null +$probe = & wsl.exe -l -q 2>&1 +$probeExit = $LASTEXITCODE +if ($probeExit -eq 0 -and $probe) { + $candidates = ($probe -join "`n") -split "`n" | ForEach-Object { ($_ -replace "[`0`r]","").Trim() } | Where-Object { $_ -and ($_ -notmatch '^[-= ]+$') -and ($_ -notmatch '(?i)usage|help|wsl\.exe|--install|argument|distribution') } + $ubuntu = $candidates | Where-Object { $_ -match '(?i)^Ubuntu' } | Select-Object -First 1 +} if (-not $ubuntu) { Step "Installing WSL2 + Ubuntu-22.04 (REBOOT REQUIRED)"