-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstaller.ps1
More file actions
111 lines (85 loc) · 3.55 KB
/
installer.ps1
File metadata and controls
111 lines (85 loc) · 3.55 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
# EndGit Installer for Windows
param(
[string]$InstallPath = "$env:LOCALAPPDATA\endgit"
)
$ErrorActionPreference = "Stop"
$repo = "two-tech-dev/endgit-cli"
$apiUrl = "https://api.github.com/repos/$repo/releases/latest"
Write-Host "EndGit Installer" -ForegroundColor Cyan
Write-Host "================" -ForegroundColor Cyan
Write-Host ""
try {
Write-Host "Fetching latest release information..." -ForegroundColor Yellow
$response = Invoke-RestMethod -Uri $apiUrl -Headers @{
"User-Agent" = "endgit-installer"
}
if (-not $response -or -not $response.tag_name) {
Write-Host "Error: Failed to fetch release information." -ForegroundColor Red
exit 1
}
$version = $response.tag_name
Write-Host "Latest version: $version" -ForegroundColor Green
# Find Windows asset
$asset = $response.assets | Where-Object { $_.name -eq "endgit-windows-amd64.exe" }
if (-not $asset) {
$asset = $response.assets | Where-Object {
$_.name -like "*windows*.exe" -or $_.name -like "*win*.exe"
}
}
if (-not $asset) {
$asset = $response.assets | Where-Object { $_.name -like "*.exe" }
}
if (-not $asset) {
Write-Host "Error: No Windows executable found in latest release." -ForegroundColor Red
Write-Host "Available assets:" -ForegroundColor Yellow
$response.assets | ForEach-Object { Write-Host " - $($_.name)" }
exit 1
}
$downloadUrl = $asset.browser_download_url
$fileName = $asset.name
Write-Host "Found asset: $fileName" -ForegroundColor Green
Write-Host ""
if (-not (Test-Path $InstallPath)) {
Write-Host "Creating installation directory: $InstallPath" -ForegroundColor Yellow
New-Item -ItemType Directory -Path $InstallPath -Force | Out-Null
}
$exePath = Join-Path $InstallPath "endgit.exe"
Write-Host "Downloading $fileName..." -ForegroundColor Yellow
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $downloadUrl -OutFile $exePath -UseBasicParsing
$ProgressPreference = 'Continue'
Write-Host "Downloaded successfully!" -ForegroundColor Green
if (-not (Test-Path $exePath)) {
Write-Host "Error: Download failed." -ForegroundColor Red
exit 1
}
$fileSize = (Get-Item $exePath).Length
if ($fileSize -eq 0) {
Write-Host "Error: Downloaded file is empty." -ForegroundColor Red
Remove-Item $exePath -Force
exit 1
}
Write-Host "Installed to: $exePath ($([math]::Round($fileSize/1KB, 2)) KB)" -ForegroundColor Green
Write-Host ""
Write-Host "Adding to user PATH..." -ForegroundColor Yellow
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($userPath -notlike "*$InstallPath*") {
$newPath = "$userPath;$InstallPath"
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
Write-Host "Added $InstallPath to PATH" -ForegroundColor Green
Write-Host "Restart terminal to apply changes." -ForegroundColor Yellow
} else {
Write-Host "Already in PATH" -ForegroundColor Green
}
Write-Host ""
Write-Host "Installation complete!" -ForegroundColor Green
Write-Host ""
Write-Host "Usage:" -ForegroundColor Cyan
Write-Host " endgit search <plugin>" -ForegroundColor White
Write-Host " endgit install <plugin>" -ForegroundColor White
Write-Host " endgit init" -ForegroundColor White
} catch {
Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
Write-Host "Installation failed." -ForegroundColor Red
exit 1
}