-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
59 lines (46 loc) · 1.98 KB
/
Copy pathinstall.ps1
File metadata and controls
59 lines (46 loc) · 1.98 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
# gp-cli Windows installer (PowerShell)
# Usage: irm https://raw.githubusercontent.com/noaa/patent-cli/main/install.ps1 | iex
$ErrorActionPreference = "Stop"
$Repo = "noaa/patent-cli"
$Binary = "gp-cli"
$Asset = "gp-cli-windows-amd64.exe"
$InstDir = "$env:LOCALAPPDATA\gp-cli"
Write-Host ">> Fetching latest release..." -ForegroundColor Cyan
$Release = Invoke-RestMethod "https://api.github.com/repos/$Repo/releases/latest"
$Tag = $Release.tag_name
if (-not $Tag) {
Write-Error "Could not find latest release. Check https://github.com/$Repo/releases"
}
Write-Host ">> Installing $Binary $Tag for Windows/amd64" -ForegroundColor Cyan
$ZipName = "$Asset.zip"
$Url = "https://github.com/$Repo/releases/download/$Tag/$ZipName"
$TmpDir = [System.IO.Path]::GetTempPath() + [System.Guid]::NewGuid()
New-Item -ItemType Directory -Path $TmpDir | Out-Null
try {
$ZipPath = "$TmpDir\$ZipName"
Write-Host ">> Downloading $Url"
Invoke-WebRequest -Uri $Url -OutFile $ZipPath -UseBasicParsing
Expand-Archive -Path $ZipPath -DestinationPath $TmpDir -Force
New-Item -ItemType Directory -Force -Path $InstDir | Out-Null
Copy-Item "$TmpDir\$Asset" "$InstDir\$Binary.exe" -Force
Write-Host ""
Write-Host ">> Installed: $InstDir\$Binary.exe" -ForegroundColor Green
Write-Host ""
} finally {
Remove-Item -Recurse -Force $TmpDir -ErrorAction SilentlyContinue
}
# Add to user PATH if not already there
$UserPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($UserPath -notlike "*$InstDir*") {
[Environment]::SetEnvironmentVariable(
"PATH",
"$UserPath;$InstDir",
"User"
)
Write-Host ">> Added $InstDir to your PATH." -ForegroundColor Yellow
Write-Host ">> Please restart your terminal (or PowerShell) to use gp-cli." -ForegroundColor Yellow
} else {
Write-Host ">> PATH already contains $InstDir" -ForegroundColor Gray
}
Write-Host ""
Write-Host ">> Done! Open a new terminal and run: $Binary --help" -ForegroundColor Green