返回 DeepSeek-Reasonix
install-nsis.ps1
根目录 / scripts / install-nsis.ps1
1 $ErrorActionPreference = "Stop"
2 Set-StrictMode -Version Latest
3
4 # Keep Windows packaging independent from Chocolatey's package-index availability.
5 # The portable archive is pinned and checksum-verified before it reaches PATH.
6 $version = "3.12"
7 $url = "https://sourceforge.net/projects/nsis/files/NSIS%203/$version/nsis-$version.zip/download"
8 $expectedSha256 = "56581f90db321581c5381193d796fffcf2d24b2f8fed2160a6c6a3baa67f2c4f"
9 $tempRoot = if ($env:RUNNER_TEMP) { $env:RUNNER_TEMP } else { [IO.Path]::GetTempPath() }
10 $archive = Join-Path $tempRoot "nsis-$version.zip"
11 $extractRoot = Join-Path $tempRoot "reasonix-nsis"
12 $nsisDir = Join-Path $extractRoot "nsis-$version"
13
14 for ($attempt = 1; $attempt -le 3; $attempt++) {
15 try {
16 Remove-Item -LiteralPath $archive -Force -ErrorAction SilentlyContinue
17 & curl.exe --fail --location --silent --show-error --connect-timeout 30 --max-time 120 --output $archive $url
18 if ($LASTEXITCODE -ne 0) {
19 throw "curl failed with exit code $LASTEXITCODE"
20 }
21 break
22 }
23 catch {
24 if ($attempt -eq 3) {
25 throw
26 }
27 Write-Warning "NSIS download attempt $attempt failed; retrying in $($attempt * 5) seconds"
28 Start-Sleep -Seconds ($attempt * 5)
29 }
30 }
31
32 $actualSha256 = (Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash.ToLowerInvariant()
33 if ($actualSha256 -ne $expectedSha256) {
34 throw "NSIS archive checksum mismatch: expected $expectedSha256, got $actualSha256"
35 }
36
37 Remove-Item -LiteralPath $extractRoot -Recurse -Force -ErrorAction SilentlyContinue
38 Expand-Archive -LiteralPath $archive -DestinationPath $extractRoot
39 Remove-Item -LiteralPath $archive -Force
40
41 $makensis = Join-Path $nsisDir "makensis.exe"
42 if (-not (Test-Path -LiteralPath $makensis -PathType Leaf)) {
43 throw "NSIS extraction did not produce $makensis"
44 }
45 if ([string]::IsNullOrWhiteSpace($env:GITHUB_PATH)) {
46 throw "GITHUB_PATH is not set"
47 }
48
49 Add-Content -LiteralPath $env:GITHUB_PATH -Value $nsisDir -Encoding utf8
50 & $makensis /VERSION
51 if ($LASTEXITCODE -ne 0) {
52 throw "makensis version check failed with exit code $LASTEXITCODE"
53 }
54
54 lines Plain Text