-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
67 lines (56 loc) · 2.78 KB
/
install.ps1
File metadata and controls
67 lines (56 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#Requires -Version 5.1
$ErrorActionPreference = 'Stop'
$Repo = "operator-kit/ghapp-cli"
$InstallDir = if ($env:INSTALL_DIR) { $env:INSTALL_DIR } else { Join-Path $env:USERPROFILE ".local\bin" }
# Detect arch
$Arch = switch ([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) {
'X64' { 'amd64' }
default { Write-Error "Unsupported architecture: $_"; exit 1 }
}
# Resolve version
$Version = $env:GHAPP_VERSION
if (-not $Version) {
$response = Invoke-WebRequest -Uri "https://github.com/$Repo/releases/latest" -MaximumRedirection 0 -ErrorAction SilentlyContinue -UseBasicParsing
$Version = ($response.Headers.Location -split '/tag/')[-1]
if (-not $Version) {
Write-Error "Could not determine latest version. Set GHAPP_VERSION manually."
exit 1
}
}
$VersionNum = $Version -replace '^v', ''
$Archive = "ghapp_${VersionNum}_windows_${Arch}.zip"
$Url = "https://github.com/$Repo/releases/download/$Version/$Archive"
$ChecksumsUrl = "https://github.com/$Repo/releases/download/$Version/checksums.txt"
Write-Host "Installing ghapp $Version (windows/$Arch)..."
# Download to temp
$TmpDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
New-Item -ItemType Directory -Path $TmpDir -Force | Out-Null
try {
$archivePath = Join-Path $TmpDir $Archive
$checksumsPath = Join-Path $TmpDir "checksums.txt"
Invoke-WebRequest -Uri $Url -OutFile $archivePath -UseBasicParsing
Invoke-WebRequest -Uri $ChecksumsUrl -OutFile $checksumsPath -UseBasicParsing
# Verify checksum
$expected = (Get-Content $checksumsPath | Where-Object { $_ -match $Archive }) -split '\s+' | Select-Object -First 1
$actual = (Get-FileHash -Path $archivePath -Algorithm SHA256).Hash.ToLower()
if ($expected -ne $actual) {
Write-Error "Checksum mismatch! Expected: $expected, Got: $actual"
exit 1
}
# Extract and install
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
Expand-Archive -Path $archivePath -DestinationPath $TmpDir -Force
Copy-Item (Join-Path $TmpDir "ghapp.exe") (Join-Path $InstallDir "ghapp.exe") -Force
Copy-Item (Join-Path $TmpDir "ghapp-gh.exe") (Join-Path $InstallDir "ghapp-gh.exe") -Force
# Add to user PATH if not already present
$userPath = [Environment]::GetEnvironmentVariable('Path', 'User')
if ($userPath -notlike "*$InstallDir*") {
[Environment]::SetEnvironmentVariable('Path', "$InstallDir;$userPath", 'User')
$env:Path = "$InstallDir;$env:Path"
Write-Host "Added $InstallDir to user PATH (restart terminal for other sessions)"
}
Write-Host "Installed ghapp and ghapp-gh to $InstallDir"
& (Join-Path $InstallDir "ghapp.exe") version
} finally {
Remove-Item -Path $TmpDir -Recurse -Force -ErrorAction SilentlyContinue
}