get-wsl-msi.ps1 (1627B)
1 # Downloads Microsoft's official Windows Subsystem for Linux installer. 2 # 3 # This file is part of GNU Taler. 4 # Copyright (C) 2026 Taler Systems SA 5 # 6 # The in-box wsl.exe in System32 is only a stub: on a machine with no WSL 7 # runtime it answers "The Windows Subsystem for Linux is not installed" to 8 # --update, to a bare --install and to every flagged form, so it cannot be 9 # relied on to bootstrap itself. The MSI installs silently with msiexec. 10 # 11 # Usage: get-wsl-msi.ps1 <output-path> 12 param([Parameter(Mandatory=$true)][string]$OutFile) 13 14 $ErrorActionPreference = 'Stop' 15 $ProgressPreference = 'SilentlyContinue' 16 17 try { 18 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 19 } catch { } 20 21 try { 22 $release = Invoke-RestMethod -UseBasicParsing -TimeoutSec 120 ` 23 -Uri 'https://api.github.com/repos/microsoft/WSL/releases/latest' ` 24 -Headers @{ 'User-Agent' = 'taler-windows-installer' } 25 26 $asset = $null 27 foreach ($a in $release.assets) { 28 if ($a.name -like 'wsl.*.x64.msi') { $asset = $a; break } 29 } 30 if ($null -eq $asset) { 31 Write-Output "No x64 MSI in WSL release $($release.tag_name)" 32 exit 2 33 } 34 35 Write-Output "Downloading $($asset.name) ($([math]::Round($asset.size/1MB)) MB)" 36 Invoke-WebRequest -UseBasicParsing -TimeoutSec 1800 ` 37 -Uri $asset.browser_download_url -OutFile $OutFile 38 39 if (-not (Test-Path $OutFile)) { exit 3 } 40 if ((Get-Item $OutFile).Length -lt 1MB) { exit 4 } 41 42 Write-Output "Saved to $OutFile" 43 exit 0 44 } 45 catch { 46 Write-Output "WSL MSI download failed: $($_.Exception.Message)" 47 exit 1 48 }