|
| 1 | +[CmdletBinding()] |
| 2 | +param( |
| 3 | + [string]$Destination = (Join-Path $env:LOCALAPPDATA ` |
| 4 | + 'MoonCompiler\bootstrap\3.2.2') |
| 5 | +) |
| 6 | + |
| 7 | +$ErrorActionPreference = 'Stop' |
| 8 | +Set-StrictMode -Version Latest |
| 9 | + |
| 10 | +$Version = '3.2.2' |
| 11 | +$Url = 'https://downloads.freepascal.org/fpc/dist/3.2.2/i386-win32/' + ` |
| 12 | + 'fpc-3.2.2.win32.and.win64.exe' |
| 13 | +$ExpectedSha256 = ` |
| 14 | + '8C255390544B051388B577EB61C6191A04883264AFE0E3369B3600A56DAF7BDE' |
| 15 | +$Bin = Join-Path $Destination 'bin\i386-win32' |
| 16 | +$Bootstrap = Join-Path $Bin 'fpc.exe' |
| 17 | +$RequiredTools = @( |
| 18 | + 'make.exe', |
| 19 | + 'fpcmkcfg.exe', |
| 20 | + 'x86_64-win64-ar.exe', |
| 21 | + 'x86_64-win64-as.exe', |
| 22 | + 'x86_64-win64-ld.exe', |
| 23 | + 'x86_64-win64-nm.exe', |
| 24 | + 'x86_64-win64-objcopy.exe', |
| 25 | + 'x86_64-win64-objdump.exe', |
| 26 | + 'x86_64-win64-strip.exe', |
| 27 | + 'x86_64-win64-windres.exe' |
| 28 | +) |
| 29 | + |
| 30 | +function Test-Bootstrap { |
| 31 | + If (-not (Test-Path -LiteralPath $Bootstrap)) { |
| 32 | + return $false |
| 33 | + } |
| 34 | + foreach ($Tool in $RequiredTools) { |
| 35 | + If (-not (Test-Path -LiteralPath (Join-Path $Bin $Tool))) { |
| 36 | + return $false |
| 37 | + } |
| 38 | + } |
| 39 | + return ((& $Bootstrap -iV).Trim() -eq $Version) |
| 40 | +} |
| 41 | + |
| 42 | +If (-not (Test-Bootstrap)) { |
| 43 | + $Installer = Join-Path ([IO.Path]::GetTempPath()) ` |
| 44 | + 'fpc-3.2.2.win32.and.win64.exe' |
| 45 | + $Download = $true |
| 46 | + If (Test-Path -LiteralPath $Installer) { |
| 47 | + $Actual = (Get-FileHash -LiteralPath $Installer -Algorithm SHA256).Hash |
| 48 | + $Download = ($Actual -ne $ExpectedSha256) |
| 49 | + } |
| 50 | + If ($Download) { |
| 51 | + Invoke-WebRequest -UseBasicParsing -Uri $Url -OutFile $Installer |
| 52 | + } |
| 53 | + $Actual = (Get-FileHash -LiteralPath $Installer -Algorithm SHA256).Hash |
| 54 | + If ($Actual -ne $ExpectedSha256) { |
| 55 | + throw "FPC installer checksum mismatch: $Actual" |
| 56 | + } |
| 57 | + |
| 58 | + New-Item -ItemType Directory -Force -Path $Destination | Out-Null |
| 59 | + $Process = Start-Process -FilePath $Installer -ArgumentList @( |
| 60 | + '/verysilent', '/norestart', "/dir=`"$Destination`"") ` |
| 61 | + -Wait -PassThru -WindowStyle Hidden |
| 62 | + If ($Process.ExitCode -ne 0) { |
| 63 | + throw "FPC installer failed with exit code $($Process.ExitCode)" |
| 64 | + } |
| 65 | + If (-not (Test-Bootstrap)) { |
| 66 | + throw "FPC $Version bootstrap installation is incomplete: $Destination" |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +Write-Output $Bootstrap |
0 commit comments