-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
214 lines (177 loc) · 5.72 KB
/
Copy pathinstall.ps1
File metadata and controls
214 lines (177 loc) · 5.72 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# GitHub Package Manager (ghpm) Windows Installer
# This script sets up ghpm for Windows with all dependencies
param(
[switch]$SkipDependencyCheck = $false
)
$ErrorActionPreference = "Stop"
Write-Host "🚀 GitHub Package Manager (ghpm) Installer" -ForegroundColor Cyan
Write-Host "==========================================" -ForegroundColor Cyan
Write-Host ""
# Color helpers
function Write-Success {
param([string]$Message)
Write-Host "✓ $Message" -ForegroundColor Green
}
function Write-Error-Custom {
param([string]$Message)
Write-Host "✗ $Message" -ForegroundColor Red
}
function Write-Info {
param([string]$Message)
Write-Host "ℹ $Message" -ForegroundColor Blue
}
# Check if running as administrator
function Test-Administrator {
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
# Check Go installation
function Test-Go {
try {
$output = go version 2>&1
Write-Success "Go is installed: $output"
return $true
}
catch {
Write-Error-Custom "Go is not installed or not in PATH"
Write-Host "Download from: https://golang.org/dl/" -ForegroundColor Yellow
return $false
}
}
# Check Git installation
function Test-Git {
try {
$output = git --version 2>&1
Write-Success "Git is installed: $output"
return $true
}
catch {
Write-Error-Custom "Git is not installed or not in PATH"
Write-Host "Download from: https://git-scm.com/download/win" -ForegroundColor Yellow
return $false
}
}
# Build the project
function Build-Project {
Write-Info "Building ghpm..."
try {
& go build -o ghpm.exe -v
if ($LASTEXITCODE -eq 0) {
Write-Success "Build completed successfully"
return $true
}
else {
Write-Error-Custom "Build failed with exit code $LASTEXITCODE"
return $false
}
}
catch {
Write-Error-Custom "Build error: $_"
return $false
}
}
# Setup binary location
function Setup-BinaryLocation {
$installDir = "$env:USERPROFILE\AppData\Local\ghpm"
Write-Info "Setting up installation directory: $installDir"
# Create directory if it doesn't exist
if (-not (Test-Path $installDir)) {
New-Item -ItemType Directory -Path $installDir -Force | Out-Null
Write-Success "Created directory: $installDir"
}
# Copy binary
Copy-Item -Path ".\ghpm.exe" -Destination "$installDir\ghpm.exe" -Force
Write-Success "Copied ghpm.exe to $installDir"
return $installDir
}
# Add to PATH
function Add-ToPath {
param([string]$BinaryPath)
Write-Info "Adding ghpm to PATH..."
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($userPath -like "*$BinaryPath*") {
Write-Success "ghpm is already in PATH"
return $true
}
try {
$newPath = "$userPath;$BinaryPath"
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
Write-Success "Added ghpm to user PATH"
Write-Info "PATH changes will take effect in new terminal windows"
return $true
}
catch {
Write-Error-Custom "Failed to update PATH: $_"
Write-Info "You can manually add '$BinaryPath' to your PATH"
return $false
}
}
# Verify installation
function Verify-Installation {
Write-Info "Verifying installation..."
# Refresh PATH for current session
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
try {
$output = & ghpm 2>&1
if ($output -like "*Usage: ghpm*") {
Write-Success "ghpm is working correctly!"
Write-Host ""
Write-Host "Usage examples:" -ForegroundColor Cyan
Write-Host " ghpm install owner/repo - Install from GitHub"
Write-Host " ghpm list - List installed packages"
Write-Host " ghpm remove repo-name - Remove a package"
return $true
}
}
catch {
Write-Error-Custom "Verification failed: $_"
return $false
}
}
# Main installation flow
function Main {
Write-Host ""
# Check dependencies
if (-not $SkipDependencyCheck) {
Write-Info "Checking dependencies..."
Write-Host ""
$goInstalled = Test-Go
Write-Host ""
$gitInstalled = Test-Git
Write-Host ""
if (-not $goInstalled -or -not $gitInstalled) {
Write-Host ""
Write-Error-Custom "Required dependencies are missing. Please install them first."
Write-Host "After installing Go and Git, run this script again." -ForegroundColor Yellow
exit 1
}
}
Write-Host ""
# Build
Write-Info "Building project..."
Write-Host ""
if (-not (Build-Project)) {
exit 1
}
Write-Host ""
# Setup installation
Write-Info "Setting up installation..."
Write-Host ""
$installDir = Setup-BinaryLocation
Write-Host ""
# Add to PATH
Write-Info "Configuring PATH..."
Write-Host ""
Add-ToPath $installDir
Write-Host ""
# Verify
Verify-Installation
Write-Host ""
Write-Host "==========================================" -ForegroundColor Cyan
Write-Success "Installation complete! 🎉"
Write-Host "✨ You can now use 'ghpm' from any terminal window" -ForegroundColor Cyan
Write-Host ""
}
# Run main installation
Main