-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinstall.ps1
More file actions
138 lines (114 loc) · 4.92 KB
/
Copy pathinstall.ps1
File metadata and controls
138 lines (114 loc) · 4.92 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# Orbit local CLI (`orbit`) installation script for Windows.
# Supports Windows on x86_64.
#
# Usage (one-liner, in PowerShell):
# irm https://gitlab.com/gitlab-org/orbit/knowledge-graph/-/raw/main/install.ps1 | iex
#
# Usage (with options):
# irm https://gitlab.com/gitlab-org/orbit/knowledge-graph/-/raw/main/install.ps1 -OutFile install.ps1
# .\install.ps1 -Version v0.58.0
# .\install.ps1 -Force
# .\install.ps1 -InstallDir "C:\Tools\orbit"
[CmdletBinding()]
param(
[string]$Version = "",
[string]$InstallDir = "$env:LOCALAPPDATA\Programs\orbit",
[switch]$Force,
[switch]$Help
)
$ErrorActionPreference = "Stop"
$BinaryName = "orbit"
$Platform = "windows"
$Arch = "x86_64"
$ProjectId = "77960826"
function Write-Info { Write-Host $args -ForegroundColor Cyan }
function Write-OK { Write-Host $args -ForegroundColor Green }
function Write-Warn { Write-Host $args -ForegroundColor Yellow }
function Write-Err { Write-Host $args -ForegroundColor Red }
if ($Help) {
@"
Usage: install.ps1 [OPTIONS]
OPTIONS:
-Version VERSION Install specific version (e.g., v0.58.0). Defaults to latest.
-InstallDir INSTALL_DIR Install to a custom directory (default: $env:LOCALAPPDATA\Programs\orbit).
-Force Reinstall even if orbit already exists.
-Help Show this help message.
"@
return
}
Write-Info "=== Orbit local CLI installation ==="
Write-Host ""
# Normalize version (allow "0.58.0" -> "v0.58.0").
if ($Version -and $Version -notmatch '^v') { $Version = "v$Version" }
if ($Version -and $Version -notmatch '^v\d+\.\d+\.\d+(-[A-Za-z0-9.]+)?$') {
throw "Invalid version format: $Version (expected vX.Y.Z or vX.Y.Z-suffix)"
}
$binaryPath = Join-Path $InstallDir "$BinaryName.exe"
if ((Test-Path $binaryPath) -and -not $Force) {
Write-Warn "Orbit local CLI is already installed at $binaryPath"
Write-Host "Re-run with -Force to reinstall, or -Version vX.Y.Z to switch versions."
return
}
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
}
if (-not $Version) {
Write-Host "Resolving the latest Orbit release..."
$permalink = "https://gitlab.com/api/v4/projects/$ProjectId/releases/permalink/latest"
try {
$release = Invoke-RestMethod -UseBasicParsing -Uri $permalink
} catch {
throw "Failed to resolve latest release from $permalink : $_"
}
$Version = $release.tag_name
if (-not $Version) { throw "Latest release returned no tag_name." }
}
Write-Host "Installing the Orbit local CLI $Version..."
$pkgVersion = $Version.TrimStart('v')
$artifact = "orbit-local-$Platform-$Arch.zip"
$pkgBase = "https://gitlab.com/api/v4/projects/$ProjectId/packages/generic/orbit-local/$pkgVersion"
$downloadUrl = "$pkgBase/$artifact"
$checksumUrl = "$pkgBase/$artifact.sha256"
$tempDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
New-Item -ItemType Directory -Path $tempDir -Force | Out-Null
try {
$zipPath = Join-Path $tempDir $artifact
$checksumPath = "$zipPath.sha256"
Write-Host "Downloading $artifact..."
Invoke-WebRequest -UseBasicParsing -Uri $downloadUrl -OutFile $zipPath
Write-Host "Downloading checksum..."
Invoke-WebRequest -UseBasicParsing -Uri $checksumUrl -OutFile $checksumPath
Write-Host "Verifying checksum..."
$expected = ((Get-Content $checksumPath -Raw).Trim() -split '\s+')[0].ToLower()
$actual = (Get-FileHash -Path $zipPath -Algorithm SHA256).Hash.ToLower()
if ($expected -ne $actual) {
throw "Checksum mismatch.`nExpected: $expected`nActual: $actual"
}
Write-OK "Checksum verified."
Write-Host "Extracting..."
$extractDir = Join-Path $tempDir "extract"
New-Item -ItemType Directory -Path $extractDir -Force | Out-Null
Expand-Archive -Path $zipPath -DestinationPath $extractDir -Force
$exe = Get-ChildItem -Path $extractDir -Recurse -Filter "$BinaryName.exe" | Select-Object -First 1
if (-not $exe) { throw "$BinaryName.exe not found in archive." }
Write-Host "Installing to $InstallDir..."
Copy-Item -Path $exe.FullName -Destination $binaryPath -Force
}
finally {
Remove-Item -Recurse -Force $tempDir -ErrorAction SilentlyContinue
}
# Add to User PATH (per-user, no admin required).
$userPath = [Environment]::GetEnvironmentVariable("PATH", "User")
$paths = if ($userPath) { $userPath.Split(';') } else { @() }
if ($paths -notcontains $InstallDir) {
Write-Host "Adding $InstallDir to user PATH..."
$newPath = if ($userPath) { "$InstallDir;$userPath" } else { $InstallDir }
[Environment]::SetEnvironmentVariable("PATH", $newPath, "User")
Write-Warn "PATH updated. Open a new terminal for the change to take effect."
} else {
Write-Host "$InstallDir is already in user PATH."
}
$env:PATH = "$InstallDir;$env:PATH"
Write-OK "Orbit local CLI installed at $binaryPath"
Write-Host ""
Write-Host "Verify with: orbit --help"