-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
71 lines (59 loc) · 2.44 KB
/
install.ps1
File metadata and controls
71 lines (59 loc) · 2.44 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
68
69
70
71
#Requires -Version 5.1
[CmdletBinding()]
param(
[string]$InstallDir = "$env:USERPROFILE\.local\bin"
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$Repo = '23prime/backlog-cli'
$AssetName = 'bl-x86_64-pc-windows-msvc.zip'
# Get latest release tag
Write-Host 'Fetching latest release...'
try {
$release = Invoke-RestMethod "https://api.github.com/repos/$Repo/releases/latest"
} catch {
Write-Error "Failed to fetch release info from GitHub API: $_"
}
$tag = $release.tag_name
if (-not $tag) {
Write-Error 'Failed to fetch latest release tag.'
}
Write-Host "Latest version: $tag"
# Download binary and checksum
$baseUrl = "https://github.com/$Repo/releases/download/$tag"
$zipUrl = "$baseUrl/$AssetName"
$sha256Url = "$zipUrl.sha256"
$tmpDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
New-Item -ItemType Directory -Path $tmpDir | Out-Null
try {
$zipPath = Join-Path $tmpDir $AssetName
$sha256Path = "$zipPath.sha256"
Write-Host "Downloading $zipUrl..."
Invoke-WebRequest $zipUrl -OutFile $zipPath -UseBasicParsing
Invoke-WebRequest $sha256Url -OutFile $sha256Path -UseBasicParsing
# Verify checksum
Write-Host 'Verifying checksum...'
$expected = (Get-Content $sha256Path -Raw).Trim().Split()[0].ToLower()
$actual = (Get-FileHash $zipPath -Algorithm SHA256).Hash.ToLower()
if ($expected -ne $actual) {
Write-Error "Checksum mismatch!`n expected: $expected`n actual: $actual"
}
# Extract and install
Expand-Archive -Path $zipPath -DestinationPath $tmpDir -Force
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir | Out-Null
}
Copy-Item (Join-Path $tmpDir 'bl.exe') (Join-Path $InstallDir 'bl.exe') -Force
Write-Host "Installed bl to $InstallDir\bl.exe"
# PATH hint
$effectivePathEntries = ($env:PATH -split ';') | Where-Object { $_ }
if ($effectivePathEntries -notcontains $InstallDir) {
$userPath = [System.Environment]::GetEnvironmentVariable('PATH', 'User')
$newUserPath = if ([string]::IsNullOrWhiteSpace($userPath)) { $InstallDir } else { "$InstallDir;$userPath" }
Write-Host ""
Write-Host "Note: $InstallDir is not in your PATH. Add it with:"
Write-Host " [System.Environment]::SetEnvironmentVariable('PATH', `"$newUserPath`", 'User')"
}
} finally {
Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue
}