-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
100 lines (83 loc) · 3.79 KB
/
Copy pathinstall.ps1
File metadata and controls
100 lines (83 loc) · 3.79 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
<#
.SYNOPSIS
Lux installer for Windows.
.DESCRIPTION
Downloads the latest Lux release from GitHub and installs it to ~/.lux/bin.
Adds the install directory to the user PATH if not already present.
.LINK
https://github.com/Lux-Python/Lux
#>
$ErrorActionPreference = "Stop"
$LuxRepo = "Lux-Python/Lux"
$LuxBin = "lux.exe"
$InstallDir = Join-Path $env:USERPROFILE ".lux" "bin"
Write-Host ""
Write-Host " Installing Lux from github.com/$LuxRepo ..." -ForegroundColor Cyan
Write-Host ""
# --- Resolve latest release tag ---------------------------------------------------
$ApiUrl = "https://api.github.com/repos/$LuxRepo/releases/latest"
try {
$Release = Invoke-RestMethod -Uri $ApiUrl -Headers @{ Accept = "application/vnd.github+json" } -UseBasicParsing
$Tag = $Release.tag_name
} catch {
Write-Host " Could not query GitHub releases. Falling back to 'latest'." -ForegroundColor Yellow
$Tag = "latest"
}
# --- Build download URL -----------------------------------------------------------
$Arch = if ([System.Environment]::Is64BitOperatingSystem) { "x86_64" } else { "i686" }
$AssetName = "lux-$Arch-pc-windows-msvc.zip"
if ($Tag -eq "latest") {
$DownloadUrl = "https://github.com/$LuxRepo/releases/latest/download/$AssetName"
} else {
$DownloadUrl = "https://github.com/$LuxRepo/releases/download/$Tag/$AssetName"
}
# --- Download to temp dir ---------------------------------------------------------
$TempDir = Join-Path ([System.IO.Path]::GetTempPath()) "lux-install"
$ZipPath = Join-Path $TempDir $AssetName
if (Test-Path $TempDir) { Remove-Item $TempDir -Recurse -Force }
New-Item -ItemType Directory -Path $TempDir -Force | Out-Null
Write-Host " Downloading $AssetName ($Tag) ..." -ForegroundColor White
try {
Invoke-WebRequest -Uri $DownloadUrl -OutFile $ZipPath -UseBasicParsing
} catch {
Write-Host ""
Write-Host " Download failed." -ForegroundColor Red
Write-Host " URL: $DownloadUrl" -ForegroundColor DarkGray
Write-Host " Make sure a release with asset '$AssetName' exists." -ForegroundColor DarkGray
Write-Host ""
exit 1
}
# --- Extract ----------------------------------------------------------------------
Write-Host " Extracting ..." -ForegroundColor White
Expand-Archive -Path $ZipPath -DestinationPath $TempDir -Force
# --- Install to ~/.lux/bin --------------------------------------------------------
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
}
$ExeSrc = Get-ChildItem -Path $TempDir -Filter $LuxBin -Recurse | Select-Object -First 1
if (-not $ExeSrc) {
Write-Host " Could not find $LuxBin in the downloaded archive." -ForegroundColor Red
exit 1
}
Copy-Item -Path $ExeSrc.FullName -Destination (Join-Path $InstallDir $LuxBin) -Force
# --- Add to PATH ------------------------------------------------------------------
$UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($UserPath -notlike "*$InstallDir*") {
[Environment]::SetEnvironmentVariable("Path", "$InstallDir;$UserPath", "User")
Write-Host " Added $InstallDir to user PATH." -ForegroundColor Green
}
# Also update the current session so the user can use lux right away
if ($env:Path -notlike "*$InstallDir*") {
$env:Path = "$InstallDir;$env:Path"
}
# --- Cleanup ----------------------------------------------------------------------
Remove-Item $TempDir -Recurse -Force -ErrorAction SilentlyContinue
# --- Done -------------------------------------------------------------------------
Write-Host ""
Write-Host " Lux installed successfully." -ForegroundColor Green
Write-Host ""
Write-Host " Location: $InstallDir\$LuxBin" -ForegroundColor White
Write-Host " Version: $Tag" -ForegroundColor White
Write-Host ""
Write-Host " Run 'lux --help' to get started." -ForegroundColor Cyan
Write-Host ""