Repository navigation
Expand file tree
/
Copy pathinstall.ps1
More file actions
69 lines (55 loc) · 2.11 KB
/
Copy pathinstall.ps1
File metadata and controls
69 lines (55 loc) · 2.11 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
$ErrorActionPreference = "Stop"
$Repo = "thewulf7/localcode"
$BinName = "localcode.exe"
$InstallDir = "$env:USERPROFILE\.localcode\bin"
# Create the install directory if it doesn't exist
if (-not (Test-Path -Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir | Out-Null
}
Write-Host "Fetching latest release from GitHub for $Repo..."
$ApiUrl = "https://api.github.com/repos/$Repo/releases/latest"
try {
$Release = Invoke-RestMethod -Uri $ApiUrl
}
catch {
Write-Error "Failed to fetch latest release. Please verify the repository exists and is public."
Exit 1
}
$DownloadUrl = $null
foreach ($Asset in $Release.assets) {
# Check for windows specific binary
if ($Asset.name -match "windows") {
$DownloadUrl = $Asset.browser_download_url
break
}
}
if (-not $DownloadUrl) {
# Fallback to any .exe file
foreach ($Asset in $Release.assets) {
if ($Asset.name -match "\.exe$") {
$DownloadUrl = $Asset.browser_download_url
break
}
}
}
if (-not $DownloadUrl) {
Write-Error "Could not find a suitable Windows binary (.exe) in the latest release."
Write-Host "You can still install using cargo: cargo install --git https://github.com/$Repo.git"
Exit 1
}
$InstallPath = Join-Path -Path $InstallDir -ChildPath $BinName
Write-Host "Downloading $BinName from $DownloadUrl..."
Invoke-WebRequest -Uri $DownloadUrl -OutFile $InstallPath
Write-Host "✅ $BinName installed successfully to $InstallPath."
# Add to User PATH if not already there
$UserPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($UserPath -notmatch [regex]::Escape($InstallDir)) {
Write-Host "Adding $InstallDir to your PATH..."
$NewPath = "$InstallDir;$UserPath"
[Environment]::SetEnvironmentVariable("PATH", $NewPath, "User")
# Update current session PATH so it works immediately
$env:PATH = "$InstallDir;$env:PATH"
Write-Host "⚠️ You may need to restart your terminal for the PATH changes to take effect in new windows." -ForegroundColor Yellow
}
Write-Host ""
Write-Host "Run 'localcode --help' to get started."