-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
88 lines (75 loc) · 2.78 KB
/
install.ps1
File metadata and controls
88 lines (75 loc) · 2.78 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
$ErrorActionPreference = "Stop" # stops the script if any error occurs (Write-Error)
$Repo = "andrearcaina/goforge"
$BinName = "goforge"
$BinNameExe = "$BinName.exe"
# get the latest tag from GitHub
Write-Host "Fetching latest release tag..."
$LatestReleaseUrl = "https://api.github.com/repos/$Repo/releases/latest"
try {
$Response = Invoke-RestMethod -Uri $LatestReleaseUrl -Method Get
$Tag = $Response.tag_name
} catch {
Write-Error "Failed to fetch latest release tag."
exit 1
}
# add "v" if missing (though github usually includes it, just in case logic differs)
if (-not $Tag.StartsWith("v")) {
$Tag = "v$Tag"
}
# detect architecture
$ArchInput = $env:PROCESSOR_ARCHITECTURE
if ($ArchInput -eq "AMD64") {
$Arch = "x86_64"
} elseif ($ArchInput -eq "ARM64") {
$Arch = "arm64"
} elseif ($ArchInput -eq "x86") {
if ([System.Environment]::Is64BitOperatingSystem) {
$Arch = "x86_64"
} else {
$Arch = "i386"
}
} else {
Write-Error "Unsupported architecture: $ArchInput"
exit 1
}
$Os = "Windows"
$Ext = "zip"
$DownloadName = "${BinName}_${Os}_${Arch}.${Ext}"
$DownloadUrl = "https://github.com/$Repo/releases/download/$Tag/$DownloadName"
Write-Host "Downloading goforge $Tag for Windows ($Arch)..."
$TempZip = Join-Path $env:TEMP "$BinName.zip"
try {
Invoke-WebRequest -Uri $DownloadUrl -OutFile $TempZip
} catch {
Write-Error "Failed to download release from $DownloadUrl"
exit 1
}
# install directory (this is where the binary will be installed)
# will be installed in $USERPROFILE/.pathfinder/bin
$InstallDir = Join-Path $env:USERPROFILE ".pathfinder/bin"
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
}
# extract (extract the zip file downloaded from GitHub)
Expand-Archive -Path $TempZip -DestinationPath $env:TEMP -Force
$ExtractedBin = Join-Path $env:TEMP $BinNameExe
if (Test-Path $ExtractedBin) {
Move-Item -Path $ExtractedBin -Destination (Join-Path $InstallDir $BinNameExe) -Force
Write-Host "Installed to $InstallDir\$BinNameExe"
} else {
Write-Error "Could not find $BinNameExe after extraction."
exit 1
}
# then cleanup (remove temp zip)
Remove-Item $TempZip -Force
# check USER PATH and add pathfinder bin directory if not present
$UserPath = [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::User)
if ($UserPath -notlike "*$InstallDir*") {
Write-Host "Adding $InstallDir to User PATH..."
[Environment]::SetEnvironmentVariable("Path", "$UserPath;$InstallDir", [EnvironmentVariableTarget]::User)
$env:PATH = "$env:PATH;$InstallDir"
Write-Host "Added to PATH. You may need to restart your shell for changes to take full effect."
} else {
Write-Host "$InstallDir is already in your User PATH."
}
Write-Host "Installation complete."