-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathinstall_cli.ps1
More file actions
50 lines (40 loc) · 1.6 KB
/
Copy pathinstall_cli.ps1
File metadata and controls
50 lines (40 loc) · 1.6 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
$ErrorActionPreference = "Stop"
$Repo = "MichaelCurrin/auto-commit-msg"
$Binaries = @("acm", "gacm", "auto_commit_msg")
$InstallDir = "$HOME\AppData\Local\bin"
$RepoUrl = "https://github.com/$Repo/releases/latest/download"
# Ensure install directory exists.
if (!(Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir | Out-Null
}
# Create a temporary workspace.
$TempDir = Join-Path $env:TEMP ([Guid]::NewGuid().ToString())
New-Item -ItemType Directory -Path $TempDir | Out-Null
try {
foreach ($Bin in $Binaries) {
$Filename = "${Bin}-windows-amd64.exe"
$DownloadUrl = "${RepoUrl}/${Filename}"
$DestPath = Join-Path $InstallDir "${Bin}.exe"
$TempPath = Join-Path $TempDir $Filename
Write-Host "Installing $Bin..."
# Download
Invoke-WebRequest -Uri $DownloadUrl -OutFile $TempPath -UseBasicParsing
# Move to destination
Move-Item -Path $TempPath -Destination $DestPath -Force
}
# Verify PATH.
$UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($UserPath -notlike "*$InstallDir*") {
Write-Host "Adding $InstallDir to User PATH..." -ForegroundColor Cyan
[Environment]::SetEnvironmentVariable("Path", "$UserPath;$InstallDir", "User")
$env:Path += ";$InstallDir"
}
Write-Host "Successfully installed $($Binaries -join ', ') to $InstallDir" -ForegroundColor Green
Write-Host "Please restart your terminal to refresh the PATH." -ForegroundColor Yellow
}
finally {
# Cleanup.
if (Test-Path $TempDir) {
Remove-Item -Path $TempDir -Recurse -Force
}
}