| 1 |
[CmdletBinding()] |
| 2 |
param ( |
| 3 |
[Parameter(Mandatory = $true)] |
| 4 |
[string] $Destination |
| 5 |
) |
| 6 |
|
| 7 |
$version = "4.13.6" |
| 8 |
$folder="ccache-$version-windows-x86_64" |
| 9 |
$url = "https://github.com/ccache/ccache/releases/download/v$version/$folder.zip" |
| 10 |
$expectedSha256 = "3D7CEBB05850AD704E197B3F1D3F0F924AB6C9FDFC561578E146184FE9D89380" |
| 11 |
|
| 12 |
$ErrorActionPreference = "Stop" |
| 13 |
Set-StrictMode -Version Latest |
| 14 |
$PSNativeCommandUseErrorActionPreference = $true |
| 15 |
|
| 16 |
try { |
| 17 |
New-Item -Path "$Destination" -ItemType Container -ErrorAction SilentlyContinue |
| 18 |
|
| 19 |
Write-Host "Download CCache" |
| 20 |
$zipFilePath = Join-Path "$env:TEMP" "$folder.zip" |
| 21 |
Invoke-WebRequest -Uri $url -UseBasicParsing -OutFile "$zipFilePath" -MaximumRetryCount 3 |
| 22 |
|
| 23 |
$hash = Get-FileHash $zipFilePath -Algorithm "sha256" |
| 24 |
if ($hash.Hash -ne $expectedSha256) { |
| 25 |
throw "File $Path hash $hash.Hash did not match expected hash $expectedHash" |
| 26 |
} |
| 27 |
|
| 28 |
Write-Host "Unzip CCache" |
| 29 |
Expand-Archive -Path "$zipFilePath" -DestinationPath "$env:TEMP" |
| 30 |
|
| 31 |
Write-Host "Move CCache" |
| 32 |
Move-Item -Force "$env:TEMP/$folder/ccache.exe" "$Destination" |
| 33 |
Remove-Item "$zipFilePath" |
| 34 |
Remove-Item -Recurse "$env:TEMP/$folder" |
| 35 |
} |
| 36 |
catch { |
| 37 |
Write-Host "Installation failed with an error" |
| 38 |
$_.Exception | Format-List |
| 39 |
exit -1 |
| 40 |
} |