-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
79 lines (64 loc) · 2.7 KB
/
Copy pathinstall.ps1
File metadata and controls
79 lines (64 loc) · 2.7 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
# Fused CLI Installation Script for Windows
# Run with: irm https://raw.githubusercontent.com/Usefused/cli/main/install.ps1 | iex
# Or to install a specific version:
# $env:VERSION="v1.0.0"; irm https://raw.githubusercontent.com/Usefused/cli/main/install.ps1 | iex
$ErrorActionPreference = "Stop"
$Repo = "Usefused/cli"
$Binary = "fused-cli"
$InstallDir = "$env:LOCALAPPDATA\Programs\fused-cli"
# Detect architecture
$Arch = if ([System.Environment]::Is64BitOperatingSystem) { "x86_64" } else {
Write-Error "Unsupported architecture. Only x86_64 is supported on Windows."
exit 1
}
Write-Host "=> Detected Windows $Arch"
# Determine version
$TargetVersion = $env:VERSION
if (-not $TargetVersion) {
Write-Host "=> Fetching latest release version..."
$Release = Invoke-RestMethod "https://api.github.com/repos/$Repo/releases/latest"
$TargetVersion = $Release.tag_name
}
if (-not $TargetVersion) {
Write-Error "Could not determine release version."
exit 1
}
Write-Host "=> Installing version $TargetVersion"
# Construct download URL (GoReleaser naming: fused-cli_Windows_x86_64.zip)
$ZipName = "${Binary}_Windows_${Arch}.zip"
$DownloadUrl = "https://github.com/$Repo/releases/download/$TargetVersion/$ZipName"
# Create a temporary directory
$TmpDir = New-TemporaryFile | ForEach-Object { Remove-Item $_; New-Item -ItemType Directory -Path $_ }
try {
$ZipPath = Join-Path $TmpDir $ZipName
Write-Host "=> Downloading $DownloadUrl..."
Invoke-WebRequest -Uri $DownloadUrl -OutFile $ZipPath -UseBasicParsing
Write-Host "=> Extracting archive..."
Expand-Archive -Path $ZipPath -DestinationPath $TmpDir -Force
# Create install directory and move binary
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir | Out-Null
}
$BinaryPath = Join-Path $TmpDir "${Binary}.exe"
Write-Host "=> Installing to $InstallDir..."
Move-Item -Path $BinaryPath -Destination (Join-Path $InstallDir "${Binary}.exe") -Force
} finally {
Remove-Item -Recurse -Force $TmpDir -ErrorAction SilentlyContinue
}
# Add to user PATH if not already present
$UserPath = [System.Environment]::GetEnvironmentVariable("PATH", "User")
if ($UserPath -notlike "*$InstallDir*") {
Write-Host "=> Adding $InstallDir to your user PATH..."
[System.Environment]::SetEnvironmentVariable(
"PATH",
"$UserPath;$InstallDir",
"User"
)
$env:PATH = "$env:PATH;$InstallDir"
Write-Host "=> PATH updated. You may need to restart your terminal for the change to take effect."
} else {
Write-Host "=> $InstallDir is already on your PATH."
}
Write-Host ""
Write-Host "=> Installation complete!"
Write-Host "=> Run 'fused-cli --help' to get started."