-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.ps1
More file actions
75 lines (63 loc) · 2.31 KB
/
Copy pathinstall.ps1
File metadata and controls
75 lines (63 loc) · 2.31 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
72
73
74
75
# install.ps1 — download and install gitkit on Windows
# Usage: irm https://raw.githubusercontent.com/UniverLab/gitkit/main/scripts/install.ps1 | iex
#
# Options (set as env vars before running):
# $env:VERSION = "0.1.0" # pin a specific version
# $env:INSTALL_DIR = "C:\my\bin" # custom install directory
$ErrorActionPreference = "Stop"
$Repo = "UniverLab/gitkit"
$Binary = "gitkit.exe"
$Target = "x86_64-pc-windows-msvc"
$InstallDir = if ($env:INSTALL_DIR) { $env:INSTALL_DIR } else { "$env:USERPROFILE\.local\bin" }
function Info($label, $msg) {
Write-Host " " -NoNewline
Write-Host $label -ForegroundColor Blue -NoNewline
Write-Host " $msg"
}
function Fail($msg) {
Write-Host " error: $msg" -ForegroundColor Red
exit 1
}
# --- resolve version ---
if ($env:VERSION) {
$Tag = "v$($env:VERSION)"
Info "version" "$Tag (pinned)"
} else {
$latest = Invoke-RestMethod "https://api.github.com/repos/$Repo/releases/latest"
$Tag = $latest.tag_name
if (-not $Tag) { Fail "Could not resolve latest release tag" }
Info "version" "$Tag (latest)"
}
# --- download ---
$Archive = "gitkit-$Tag-$Target.zip"
$Url = "https://github.com/$Repo/releases/download/$Tag/$Archive"
$Tmp = Join-Path $env:TEMP "gitkit-install"
New-Item -ItemType Directory -Force -Path $Tmp | Out-Null
Info "download" $Url
try {
Invoke-WebRequest -Uri $Url -OutFile "$Tmp\$Archive" -UseBasicParsing
} catch {
Fail "Download failed: $_`nURL: $Url"
}
# --- extract ---
Expand-Archive -Path "$Tmp\$Archive" -DestinationPath $Tmp -Force
$extracted = Join-Path $Tmp $Binary
if (-not (Test-Path $extracted)) { Fail "Binary not found in archive" }
# --- install ---
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
Copy-Item $extracted "$InstallDir\$Binary" -Force
Info "installed" "$InstallDir\$Binary"
# --- ensure PATH ---
$userPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($userPath -notlike "*$InstallDir*") {
[Environment]::SetEnvironmentVariable("PATH", "$InstallDir;$userPath", "User")
$env:PATH = "$InstallDir;$env:PATH"
Info "updated" "User PATH"
}
# --- cleanup ---
Remove-Item $Tmp -Recurse -Force
# --- verify ---
$ver = & "$InstallDir\$Binary" --version 2>$null
Info "done" $ver
Write-Host ""
Info "ready" "Run 'gitkit init' to get started!"