20 lines
1.3 KiB
PowerShell
20 lines
1.3 KiB
PowerShell
# CUST-WP-0073 r4 — attended only. Creates the NEW distro custodian-agents; touches no existing distro.
|
|
param([switch]$IAmAttended)
|
|
$ErrorActionPreference = 'Stop'
|
|
if (-not $IAmAttended) { throw 'REFUSED: run with -IAmAttended in an attended window.' }
|
|
$DistroName = 'custodian-agents'
|
|
$Url = 'https://releases.ubuntu.com/24.04.5/ubuntu-24.04.5-wsl-amd64.wsl'
|
|
$Expected = 'bb415d824822c4b878125729af451a5d18fb13d1cf5cbed9a7393ad64ac6039e'
|
|
$Base = Join-Path $env:LOCALAPPDATA 'Custodian\WSL'
|
|
$Store = Join-Path $Base $DistroName
|
|
$Image = Join-Path $Base 'ubuntu-24.04.5-wsl-amd64.wsl'
|
|
$Existing = ((& wsl.exe --list --quiet) -replace "`0", '') -split "`r?`n" | ForEach-Object { $_.Trim() }
|
|
if ($Existing -contains $DistroName) { throw 'Distribution already exists' }
|
|
if (Test-Path -LiteralPath $Store) { throw 'Destination already exists' }
|
|
New-Item -ItemType Directory -Force -Path $Base | Out-Null
|
|
if (-not (Test-Path -LiteralPath $Image)) { Invoke-WebRequest -Uri $Url -OutFile $Image -UseBasicParsing }
|
|
$Actual = (Get-FileHash -Algorithm SHA256 -LiteralPath $Image).Hash.ToLower()
|
|
if ($Actual -ne $Expected) { throw "Rootfs digest mismatch: $Actual" }
|
|
& wsl.exe --import $DistroName $Store $Image --version 2
|
|
if ($LASTEXITCODE -ne 0) { throw 'Import failed; retain evidence, do not unregister' }
|
|
Write-Output "imported $DistroName sha256=$Actual store=$Store"
|