-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
194 lines (157 loc) · 5.31 KB
/
Copy pathinstall.ps1
File metadata and controls
194 lines (157 loc) · 5.31 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# Arc CLI Installation Script for Windows
# Usage: irm https://raw.githubusercontent.com/arc-framework/arc-cli/main/install.ps1 | iex
param(
[string]$Version = "latest",
[string]$InstallDir = "$env:LOCALAPPDATA\arc"
)
$ErrorActionPreference = "Stop"
$ProgressPreference = 'SilentlyContinue'
$GitHubRepo = "arc-framework/arc-cli"
# Colors
function Write-ColorOutput($ForegroundColor, $Message) {
$fc = $host.UI.RawUI.ForegroundColor
$host.UI.RawUI.ForegroundColor = $ForegroundColor
Write-Output $Message
$host.UI.RawUI.ForegroundColor = $fc
}
function Write-Info($Message) {
Write-ColorOutput Blue "ℹ️ $Message"
}
function Write-Success($Message) {
Write-ColorOutput Green "✅ $Message"
}
function Write-Error($Message) {
Write-ColorOutput Red "❌ $Message"
}
function Write-Warning($Message) {
Write-ColorOutput Yellow "⚠️ $Message"
}
function Get-LatestRelease {
if ($Version -eq "latest") {
try {
$latestRelease = Invoke-RestMethod -Uri "https://api.github.com/repos/$GitHubRepo/releases/latest"
return $latestRelease.tag_name
}
catch {
# Try to get the most recent release (including pre-releases)
$releases = Invoke-RestMethod -Uri "https://api.github.com/repos/$GitHubRepo/releases"
if ($releases.Count -gt 0) {
return $releases[0].tag_name
}
throw "Could not determine latest version"
}
}
return $Version
}
function Get-AssetFilename {
param(
[string]$Arch,
[string]$Version
)
try {
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$GitHubRepo/releases/tags/$Version"
$assets = $release.assets | Where-Object { $_.name -like "arc-cli_windows_${Arch}_*.zip" }
if ($assets.Count -eq 0) {
Write-Error "Could not find asset matching pattern: arc-cli_windows_${Arch}_*.zip"
Write-Info "Available assets:"
$release.assets | ForEach-Object { Write-Output " $($_.name)" }
throw "No matching asset found"
}
return $assets[0].name
}
catch {
throw "Failed to get asset filename: $_"
}
}
function Install-ArcCLI {
Write-Output ""
Write-ColorOutput Blue "📦 Arc CLI Installer"
Write-Output ""
# Detect architecture
$arch = if ([Environment]::Is64BitOperatingSystem) { "amd64" } else { "386" }
Write-Info "Detecting system..."
Write-Info "OS: Windows"
Write-Info "Architecture: $arch"
# Get version
try {
$releaseVersion = Get-LatestRelease
}
catch {
Write-Error "Failed to determine version: $_"
exit 1
}
Write-Info "Version: $releaseVersion"
# Get the correct filename from release assets
try {
$filename = Get-AssetFilename -Arch $arch -Version $releaseVersion
Write-Info "Found asset: $filename"
}
catch {
Write-Error $_
exit 1
}
# Construct download URL
$downloadUrl = "https://github.com/$GitHubRepo/releases/download/$releaseVersion/$filename"
Write-Info "Downloading from: $downloadUrl"
# Create temp directory
$tmpDir = Join-Path $env:TEMP "arc-install-$(Get-Random)"
New-Item -ItemType Directory -Path $tmpDir | Out-Null
$zipPath = Join-Path $tmpDir $filename
# Download
try {
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath -UseBasicParsing
Write-Success "Downloaded successfully"
}
catch {
Write-Error "Failed to download Arc CLI: $_"
Remove-Item -Recurse -Force $tmpDir
exit 1
}
# Extract
Write-Info "Extracting..."
try {
Expand-Archive -Path $zipPath -DestinationPath $tmpDir -Force
}
catch {
Write-Error "Failed to extract archive: $_"
Remove-Item -Recurse -Force $tmpDir
exit 1
}
# Find binary
$binaryPath = Get-ChildItem -Path $tmpDir -Recurse -Filter "arc.exe" | Select-Object -First 1
if (-not $binaryPath) {
Write-Error "Binary not found in archive"
Remove-Item -Recurse -Force $tmpDir
exit 1
}
# Install
Write-Info "Installing to $InstallDir..."
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
}
Copy-Item -Path $binaryPath.FullName -Destination (Join-Path $InstallDir "arc.exe") -Force
# Cleanup
Remove-Item -Recurse -Force $tmpDir
Write-Success "Arc CLI installed successfully!"
# Add to PATH if not already there
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($userPath -notlike "*$InstallDir*") {
Write-Info "Adding $InstallDir to PATH..."
[Environment]::SetEnvironmentVariable("Path", "$userPath;$InstallDir", "User")
$env:Path = "$env:Path;$InstallDir"
Write-Success "Added to PATH (restart your terminal for changes to take effect)"
}
Write-Output ""
Write-ColorOutput Green "🚀 Get started by running:"
Write-ColorOutput Blue " arc --help"
Write-Output ""
# Try to run version (might need new shell)
try {
$arcExe = Join-Path $InstallDir "arc.exe"
& $arcExe --version
}
catch {
Write-Warning "Restart your terminal and run 'arc --version' to verify installation"
}
}
Install-ArcCLI