Skip to content

Commit 5108d3d

Browse files
fix install.ps1 for PowerShell 5.1 compatibility
- Join-Path only accepts two arguments before PS 7; nest calls - if-expression assignments need $() wrapper in PS 5.1 - Use $env:PROCESSOR_ARCHITECTURE instead of .NET RuntimeInformation (unavailable in .NET Framework / PS 5.1)
1 parent bb18d2f commit 5108d3d

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

install.ps1

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ $ErrorActionPreference = 'Stop'
88

99
$repo = "shrug-labs/aipack"
1010
$binaryName = "aipack"
11-
$requestedVersion = if ($env:AIPACK_VERSION) { $env:AIPACK_VERSION } else { "latest" }
11+
$requestedVersion = $(if ($env:AIPACK_VERSION) { $env:AIPACK_VERSION } else { "latest" })
1212

1313
function Normalize-Tag([string]$version) {
1414
if (-not $version -or $version -eq "latest") {
@@ -26,7 +26,7 @@ function Get-LatestVersion {
2626
}
2727

2828
function Get-InstallDir {
29-
$dir = Join-Path $env:LOCALAPPDATA "aipack" "bin"
29+
$dir = Join-Path (Join-Path $env:LOCALAPPDATA "aipack") "bin"
3030
if (-not (Test-Path $dir)) {
3131
New-Item -ItemType Directory -Path $dir -Force | Out-Null
3232
}
@@ -43,7 +43,7 @@ function Install-Aipack {
4343
Write-Host "Using requested version: $tag" -ForegroundColor Cyan
4444
}
4545

46-
$arch = if ([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture -eq 'X64') { 'amd64' } else { 'arm64' }
46+
$arch = $(if ($env:PROCESSOR_ARCHITECTURE -eq 'AMD64') { 'amd64' } else { 'arm64' })
4747
$asset = "$binaryName-windows-$arch.exe"
4848
$url = "https://github.com/$repo/releases/download/$tag/$asset"
4949
$sumsUrl = "https://github.com/$repo/releases/download/$tag/SHA256SUMS"
@@ -57,8 +57,14 @@ function Install-Aipack {
5757

5858
# Verify checksum
5959
Write-Host "Verifying checksum..." -ForegroundColor Cyan
60-
$sums = (Invoke-WebRequest -Uri $sumsUrl -UseBasicParsing).Content
61-
$expectedHash = ($sums -split "`n" | Where-Object { $_ -match $asset } | ForEach-Object { ($_ -split '\s+')[0] })
60+
$resp = Invoke-WebRequest -Uri $sumsUrl -UseBasicParsing
61+
# .Content may be byte[] in PS 5.1 depending on content-type; coerce to string.
62+
if ($resp.Content -is [byte[]]) {
63+
$sums = [System.Text.Encoding]::UTF8.GetString($resp.Content)
64+
} else {
65+
$sums = $resp.Content
66+
}
67+
$expectedHash = ($sums -split '[\r\n]+' | Where-Object { $_ -like "*$asset*" } | ForEach-Object { ($_ -split '\s+')[0] })
6268
if (-not $expectedHash) {
6369
Remove-Item $tmpFile -Force
6470
throw "No checksum found for $asset"

0 commit comments

Comments
 (0)