-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
57 lines (45 loc) · 1.63 KB
/
Copy pathinstall.ps1
File metadata and controls
57 lines (45 loc) · 1.63 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
$ErrorActionPreference = "Stop"
$Repo = $env:SPM_REPO
if (-not $Repo) {
$Repo = "exa-studio/spm"
}
$Version = $env:SPM_VERSION
if (-not $Version) {
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest"
$Version = $release.tag_name
}
if ($Version -notmatch '^v') {
$Version = "v$Version"
}
$arch = $env:PROCESSOR_ARCHITECTURE
switch ($arch) {
"AMD64" { $arch = "amd64" }
"ARM64" { $arch = "arm64" }
default { throw "Unsupported architecture: $arch" }
}
$asset = "spm_windows_$arch.zip"
$url = "https://github.com/$Repo/releases/download/$Version/$asset"
$tempDir = Join-Path $env:TEMP "spm-install-$PID"
New-Item -ItemType Directory -Path $tempDir | Out-Null
$zipPath = Join-Path $tempDir $asset
Write-Host "Downloading $url"
Invoke-WebRequest -Uri $url -OutFile $zipPath
Expand-Archive -Path $zipPath -DestinationPath $tempDir -Force
$installDir = $env:SPM_INSTALL_DIR
if (-not $installDir) {
$installDir = Join-Path $env:USERPROFILE "bin"
}
New-Item -ItemType Directory -Path $installDir -Force | Out-Null
$sourceExe = Join-Path $tempDir "spm.exe"
if (-not (Test-Path $sourceExe)) {
throw "Expected spm.exe not found in archive."
}
Copy-Item $sourceExe (Join-Path $installDir "spm.exe") -Force
Write-Host "Installed spm to $installDir\spm.exe"
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if (-not $userPath) { $userPath = "" }
if ($userPath -notlike "*$installDir*") {
$newPath = if ($userPath) { "$installDir;$userPath" } else { $installDir }
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
Write-Host "Added $installDir to PATH (User). Restart your terminal."
}