-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
52 lines (39 loc) · 1.75 KB
/
Copy pathinstall.ps1
File metadata and controls
52 lines (39 loc) · 1.75 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
param(
[string]$InstallDir = "$env:LOCALAPPDATA\gogentoo\bin"
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
Write-Host "Installing GoGentoo to '$InstallDir'..."
if (-not (Test-Path -LiteralPath $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
}
# Build the gogentoo executable
$outputExe = Join-Path $InstallDir "gogentoo.exe"
Write-Host "Building gogentoo.exe..."
& go build -o $outputExe ./cmd/gogentoo
if ($LASTEXITCODE -ne 0 -or -not (Test-Path -LiteralPath $outputExe)) {
throw "go build failed; ensure Go is installed and in PATH, and run this script from the repository root."
}
Write-Host "Built gogentoo at '$outputExe'."
# Add InstallDir to user PATH if not already present
$currentUserPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($null -eq $currentUserPath) {
$currentUserPath = ""
}
$pathParts = $currentUserPath -split ';' | Where-Object { $_ -ne "" }
$alreadyInPath = $pathParts | Where-Object { $_.TrimEnd('\') -ieq $InstallDir.TrimEnd('\') } | ForEach-Object { $true } | Select-Object -First 1
if (-not $alreadyInPath) {
Write-Host "Adding '$InstallDir' to user PATH..."
if ($currentUserPath -and $currentUserPath.Trim() -ne "") {
$newUserPath = "$currentUserPath;$InstallDir"
} else {
$newUserPath = $InstallDir
}
[Environment]::SetEnvironmentVariable("PATH", $newUserPath, "User")
# Also update PATH for the current session
$env:PATH = "$newUserPath"
Write-Host "PATH updated. You may need to open a new terminal for other processes to pick this up."
} else {
Write-Host "'$InstallDir' is already on the user PATH."
}
Write-Host "GoGentoo installation complete. You should now be able to run 'gogentoo' from a new terminal."