-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
69 lines (59 loc) · 2.56 KB
/
Copy pathinstall.ps1
File metadata and controls
69 lines (59 loc) · 2.56 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"
$ProgressPreference = "SilentlyContinue"
$Repository = "datavil/framex"
$Version = if ($env:FX_VERSION) { $env:FX_VERSION } else { "latest" }
$Architecture = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString()
$Target = switch ($Architecture) {
"X64" { "x86_64-pc-windows-msvc" }
"Arm64" { "aarch64-pc-windows-msvc" }
default { throw "framex: unsupported Windows architecture: $Architecture" }
}
$Archive = "fx-$Target.zip"
if ($Version -eq "latest") {
$ReleaseUrl = "https://github.com/$Repository/releases/latest/download"
}
else {
$Version = "v$($Version.TrimStart('v'))"
$ReleaseUrl = "https://github.com/$Repository/releases/download/$Version"
}
$InstallDir = if ($env:FX_INSTALL_DIR) {
$env:FX_INSTALL_DIR
}
else {
Join-Path $HOME ".local\bin"
}
$TempDir = Join-Path ([System.IO.Path]::GetTempPath()) "framex-$([guid]::NewGuid())"
try {
New-Item -ItemType Directory -Path $TempDir -Force | Out-Null
$ArchivePath = Join-Path $TempDir $Archive
$ChecksumPath = "$ArchivePath.sha256"
Write-Host "framex: downloading $Archive"
Invoke-WebRequest -UseBasicParsing -Uri "$ReleaseUrl/$Archive" -OutFile $ArchivePath
Invoke-WebRequest -UseBasicParsing -Uri "$ReleaseUrl/$Archive.sha256" -OutFile $ChecksumPath
$ExpectedChecksum = ((Get-Content $ChecksumPath -Raw).Trim() -split "\s+")[0]
$ActualChecksum = (Get-FileHash $ArchivePath -Algorithm SHA256).Hash
if ($ExpectedChecksum -ne $ActualChecksum) {
throw "framex: checksum verification failed"
}
Expand-Archive -Path $ArchivePath -DestinationPath $TempDir -Force
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
Copy-Item (Join-Path $TempDir "fx.exe") (Join-Path $InstallDir "fx.exe") -Force
& (Join-Path $InstallDir "fx.exe") --version | Out-Null
if ($LASTEXITCODE -ne 0) {
throw "framex: installed binary could not be started"
}
Write-Host "framex: installed fx to $(Join-Path $InstallDir 'fx.exe')"
$UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
$UserPathEntries = @($UserPath -split ";" | Where-Object { $_ })
if ($UserPathEntries -notcontains $InstallDir) {
$UpdatedUserPath = (@($UserPathEntries) + $InstallDir) -join ";"
[Environment]::SetEnvironmentVariable("Path", $UpdatedUserPath, "User")
Write-Host "framex: added $InstallDir to your user PATH"
Write-Host "framex: restart your terminal to run fx"
}
}
finally {
if (Test-Path $TempDir) {
Remove-Item $TempDir -Recurse -Force
}
}