-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
123 lines (103 loc) · 3.94 KB
/
install.ps1
File metadata and controls
123 lines (103 loc) · 3.94 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#Requires -Version 5.1
param(
[string]$Version = "",
[string]$InstallDir = "",
[switch]$Help
)
$ErrorActionPreference = "Stop"
$Repo = "dvaji/infera"
$BinaryName = "infs.exe"
if ($Help) {
Write-Host "Usage: irm https://raw.githubusercontent.com/dvaji/infera/main/install.ps1 | iex"
Write-Host " or: irm https://raw.githubusercontent.com/dvaji/infera/main/install.ps1 | iex -Version v1.0.0"
Write-Host ""
Write-Host "Parameters:"
Write-Host " -Version - Version to install (default: latest)"
Write-Host " -InstallDir - Directory to install infs (default: `$env:USERPROFILE\.local\bin)"
Write-Host ""
Write-Host "Examples:"
Write-Host " irm https://raw.githubusercontent.com/dvaji/infera/main/install.ps1 | iex"
Write-Host " irm https://raw.githubusercontent.com/dvaji/infera/main/install.ps1 | iex -InstallDir 'C:\Tools'"
exit 0
}
function Write-Info {
param([string]$Message)
Write-Host "[INFO] " -ForegroundColor Green -NoNewline
Write-Host $Message
}
function Write-Warn {
param([string]$Message)
Write-Host "[WARN] " -ForegroundColor Yellow -NoNewline
Write-Host $Message
}
function Write-Err {
param([string]$Message)
Write-Host "[ERROR] " -ForegroundColor Red -NoNewline
Write-Host $Message
exit 1
}
function Get-LatestVersion {
$releaseUrl = "https://api.github.com/repos/$Repo/releases/latest"
try {
$response = Invoke-RestMethod -Uri $releaseUrl -UseBasicParsing
return $response.tag_name
} catch {
Write-Err "Failed to fetch latest version: $_"
}
}
function Get-Platform {
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
$archString = switch ($arch) {
"X64" { "x86_64" }
"Arm64" { Write-Err "Windows ARM64 is not supported. Only x86_64 builds are available." }
default { Write-Err "Unsupported architecture: $arch" }
}
return "windows-$archString"
}
if (-not $InstallDir) {
$InstallDir = Join-Path $env:USERPROFILE ".local\bin"
}
if (-not $Version) {
$Version = Get-LatestVersion
}
$Platform = Get-Platform
$AssetName = "infs-$Platform.exe"
$DownloadUrl = "https://github.com/$Repo/releases/download/$Version/$AssetName"
Write-Info "Installing infs $Version for $Platform..."
$installPath = Join-Path $InstallDir $BinaryName
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
Write-Info "Created directory: $InstallDir"
}
Write-Info "Downloading from $DownloadUrl..."
try {
$tempFile = Join-Path $env:TEMP "infs-download.exe"
Invoke-WebRequest -Uri $DownloadUrl -OutFile $tempFile -UseBasicParsing
if (Test-Path $installPath) {
$oldPath = "$installPath.old"
if (Test-Path $oldPath) {
Remove-Item $oldPath -Force
}
Move-Item $installPath $oldPath -Force
}
Move-Item $tempFile $installPath -Force
} catch {
Write-Err "Failed to download or install infs: $_"
}
Write-Info "Installed infs to $installPath"
$userPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($userPath -notlike "*$InstallDir*") {
Write-Info "Adding $InstallDir to your PATH..."
$currentPath = if ($null -eq $userPath) { "" } else { $userPath }
$newPath = if ($currentPath.EndsWith(";")) { $currentPath + $InstallDir } else {
if ([string]::IsNullOrEmpty($currentPath)) { $InstallDir } else { $currentPath + ";" + $InstallDir }
}
[Environment]::SetEnvironmentVariable("PATH", $newPath, "User")
$processPath = if ([string]::IsNullOrEmpty($env:PATH)) { "" } else { $env:PATH }
$env:PATH = if ($processPath.EndsWith(";")) { $processPath + $InstallDir } else {
if ([string]::IsNullOrEmpty($processPath)) { $InstallDir } else { $processPath + ";" + $InstallDir }
}
Write-Info "Added to PATH. You may need to restart your terminal for the change to take effect."
}
& $installPath --version
Write-Info "Installation complete!"