Files
aeternalis/tools/bootstrap-go.ps1
T

13 lines
869 B
PowerShell

$ErrorActionPreference = 'Stop'
$toolsDir = Join-Path $PSScriptRoot '..\.tools'
New-Item -ItemType Directory -Force -Path $toolsDir | Out-Null
$releases = Invoke-RestMethod 'https://go.dev/dl/?mode=json'
$release = $releases | Where-Object stable | Select-Object -First 1
$archive = $release.files | Where-Object { $_.os -eq 'windows' -and $_.arch -eq 'amd64' -and $_.kind -eq 'archive' } | Select-Object -First 1
if (-not $archive) { throw 'No stable Windows Go archive found.' }
$destination = Join-Path $toolsDir $archive.filename
Invoke-WebRequest ('https://go.dev/dl/' + $archive.filename) -OutFile $destination
if ((Get-FileHash $destination -Algorithm SHA256).Hash.ToLowerInvariant() -ne $archive.sha256) { throw 'Go checksum mismatch.' }
Expand-Archive -LiteralPath $destination -DestinationPath $toolsDir -Force
& (Join-Path $toolsDir 'go\bin\go.exe') version