forked from runxhq/runx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
55 lines (49 loc) · 2.41 KB
/
Copy pathinstall.ps1
File metadata and controls
55 lines (49 loc) · 2.41 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
# runx installer for Windows.
#
# irm runx.ai/install.ps1 | iex
#
# Downloads the prebuilt binary from the GitHub Release, verifies its sha256, and
# installs it. Honors $env:RUNX_VERSION (default: latest cli-v* release) and
# $env:RUNX_INSTALL_DIR (default: %LOCALAPPDATA%\runx\bin).
$ErrorActionPreference = "Stop"
$repo = "runxhq/runx"
$arch = $env:PROCESSOR_ARCHITECTURE
if ($arch -ne "AMD64") { throw "unsupported architecture: $arch (only x64 is published)" }
$target = "x86_64-pc-windows-msvc"
$version = $env:RUNX_VERSION
if (-not $version) {
Write-Host "runx: resolving latest release..."
$releases = Invoke-RestMethod "https://api.github.com/repos/$repo/releases"
$tag = ($releases | Where-Object { $_.tag_name -like "cli-v*" } | Select-Object -First 1).tag_name
if (-not $tag) { throw "could not resolve latest cli-v* release; set `$env:RUNX_VERSION" }
$version = $tag
}
$version = $version -replace '^cli-v','' -replace '^v',''
$archive = "runx-$version-$target.zip"
$base = if ($env:RUNX_BASE_URL) { $env:RUNX_BASE_URL } else { "https://github.com/$repo/releases/download/cli-v$version" }
$tmp = Join-Path $env:TEMP ("runx-" + [guid]::NewGuid())
New-Item -ItemType Directory -Path $tmp | Out-Null
try {
Write-Host "runx: downloading $version ($target)"
Invoke-WebRequest "$base/$archive" -OutFile "$tmp\$archive"
try {
Invoke-WebRequest "$base/$archive.sha256" -OutFile "$tmp\$archive.sha256"
$expected = (Get-Content "$tmp\$archive.sha256").Split(" ")[0]
$actual = (Get-FileHash "$tmp\$archive" -Algorithm SHA256).Hash.ToLower()
if ($expected -ne $actual) { throw "checksum mismatch (expected $expected, got $actual)" }
Write-Host "runx: checksum verified"
} catch { Write-Warning "runx: skipping checksum verification ($_)" }
Expand-Archive "$tmp\$archive" -DestinationPath $tmp -Force
$dir = $env:RUNX_INSTALL_DIR
if (-not $dir) { $dir = Join-Path $env:LOCALAPPDATA "runx\bin" }
New-Item -ItemType Directory -Path $dir -Force | Out-Null
Copy-Item "$tmp\runx-$version-$target\runx.exe" "$dir\runx.exe" -Force
Write-Host "runx: installed to $dir\runx.exe"
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($userPath -notlike "*$dir*") {
[Environment]::SetEnvironmentVariable("Path", "$userPath;$dir", "User")
Write-Host "runx: added $dir to your user PATH (restart your shell)"
}
} finally {
Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue
}