| 1 | $ErrorActionPreference = 'Stop' |
| 2 | |
| 3 | if ([string]::IsNullOrWhiteSpace($env:RUNNER_TEMP)) { |
| 4 | throw 'RUNNER_TEMP is required to provision NSIS.' |
| 5 | } |
| 6 | |
| 7 | $version = '3.13' |
| 8 | $sha256 = 'DB9A1038BBC0E53FEF24F423FD609979BD578E942F1BE1198DB186D1C42652A3' |
| 9 | $installer = Join-Path $env:RUNNER_TEMP "nsis-$version-setup.exe" |
| 10 | $url = "https://sourceforge.net/projects/nsis/files/NSIS%203/$version/nsis-$version-setup.exe/download" |
| 11 | |
| 12 | try { |
| 13 | & curl.exe --fail --location --silent --show-error --proto '=https' --proto-redir '=https' --connect-timeout 15 --max-time 60 --retry 2 --retry-delay 5 --output $installer $url |
| 14 | if ($LASTEXITCODE -ne 0) { throw "NSIS download failed with exit code $LASTEXITCODE." } |
| 15 | if ((Get-FileHash -LiteralPath $installer -Algorithm SHA256).Hash -ne $sha256) { |
| 16 | throw 'NSIS installer checksum mismatch.' |
| 17 | } |
| 18 | |
| 19 | $process = Start-Process -FilePath $installer -ArgumentList '/S' -Wait -PassThru |
| 20 | if ($process.ExitCode -ne 0) { throw "NSIS setup failed with exit code $($process.ExitCode)." } |
| 21 | $makensis = @("${env:ProgramFiles(x86)}\NSIS\makensis.exe", "$env:ProgramFiles\NSIS\makensis.exe") | |
| 22 | Where-Object { Test-Path -LiteralPath $_ -PathType Leaf } | Select-Object -First 1 |
| 23 | if (!$makensis) { throw 'makensis.exe was not found after NSIS setup.' } |
| 24 | $installedVersion = (& $makensis '/VERSION').Trim() |
| 25 | if ($LASTEXITCODE -ne 0 -or $installedVersion -ne "v$version") { |
| 26 | throw "Expected NSIS v$version, found $installedVersion." |
| 27 | } |
| 28 | Write-Host "NSIS $version verified at $makensis" |
| 29 | } finally { |
| 30 | Remove-Item -LiteralPath $installer -Force -ErrorAction SilentlyContinue |
| 31 | } |
| 32 |