-
Notifications
You must be signed in to change notification settings - Fork 216
Expand file tree
/
Copy pathinstall.ps1
More file actions
267 lines (223 loc) · 8.08 KB
/
Copy pathinstall.ps1
File metadata and controls
267 lines (223 loc) · 8.08 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# FastClaw Windows Installer
# Usage: powershell -ExecutionPolicy Bypass -Command "Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/fastclaw-ai/fastclaw/main/install.ps1' -OutFile 'install.ps1'; .\install.ps1"
# Or: powershell -ExecutionPolicy Bypass -Command "iex(New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/fastclaw-ai/fastclaw/main/install.ps1')"
param(
[switch]$Help,
[string]$Path = "$env:USERPROFILE\.fastclaw\bin"
)
$ErrorActionPreference = "Stop"
function Write-Header {
Write-Host ""
Write-Host "⚡ FastClaw - Lightweight AI Agent Framework" -ForegroundColor Cyan
Write-Host ""
}
function Write-Info {
param([string]$Message)
Write-Host "[*] $Message" -ForegroundColor Green
}
function Write-Error-Msg {
param([string]$Message)
Write-Host "[!] $Message" -ForegroundColor Red
}
function Write-Success {
param([string]$Message)
Write-Host "[+] $Message" -ForegroundColor Green
}
function Show-Help {
Write-Header
Write-Host "Usage: powershell -ExecutionPolicy Bypass -Command `"iex(New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/fastclaw-ai/fastclaw/main/install.ps1')`"" -ForegroundColor Yellow
Write-Host ""
Write-Host "Or download and run locally:"
Write-Host " powershell -ExecutionPolicy Bypass -File .\install.ps1" -ForegroundColor Yellow
Write-Host ""
Write-Host "Options:"
Write-Host " -Help Show this help message"
Write-Host " -Path <path> Custom install path (default: $env:USERPROFILE\.fastclaw\bin)"
Write-Host ""
}
function Get-LatestRelease {
Write-Info "Fetching latest release info..."
try {
$apiUrl = "https://api.github.com/repos/fastclaw-ai/fastclaw/releases/latest"
$response = Invoke-WebRequest -Uri $apiUrl -UseBasicParsing -Headers @{"Accept"="application/vnd.github.v3+json"}
$release = $response.Content | ConvertFrom-Json
return $release
}
catch {
Write-Error-Msg "Failed to fetch release info: $_"
Write-Host ""
Write-Host "Manual installation:" -ForegroundColor Yellow
Write-Host "1. Visit: https://github.com/fastclaw-ai/fastclaw/releases"
Write-Host "2. Download fastclaw_windows_amd64.zip or fastclaw_windows_arm64.zip"
Write-Host "3. Extract and run fastclaw.exe"
Write-Host ""
exit 1
}
}
function Detect-Architecture {
try {
# Check actual processor architecture using Win32_Processor
$processor = Get-WmiObject Win32_Processor -ErrorAction Stop | Select-Object -First 1
# Architecture property: 9 = x64 (amd64), 12 = ARM64
switch ($processor.Architecture) {
12 { return "arm64" }
9 { return "amd64" }
default {
Write-Error-Msg "Unsupported processor architecture: $($processor.Architecture)"
Write-Host "Supported: x64 (amd64) and ARM64"
exit 1
}
}
}
catch {
Write-Error-Msg "Failed to detect architecture: $_"
exit 1
}
}
function Download-Release {
param(
[object]$Release,
[string]$Arch
)
$filename = "fastclaw_windows_$Arch.zip"
$asset = $Release.assets | Where-Object { $_.name -eq $filename }
if (-not $asset) {
Write-Error-Msg "Release not found for architecture: $Arch"
Write-Host "Available assets:" -ForegroundColor Yellow
$Release.assets | ForEach-Object { Write-Host " - $($_.name)" }
exit 1
}
$downloadUrl = $asset.browser_download_url
$tempDir = [System.IO.Path]::GetTempPath()
$zipPath = Join-Path $tempDir $filename
Write-Info "Downloading FastClaw ($Arch) from $downloadUrl..."
try {
Invoke-WebRequest -Uri $downloadUrl -OutFile $zipPath -UseBasicParsing -ErrorAction Stop
Write-Success "Downloaded to $zipPath"
return $zipPath
}
catch {
Write-Error-Msg "Failed to download: $_"
exit 1
}
}
function Extract-Archive {
param(
[string]$ZipPath,
[string]$TargetPath
)
Write-Info "Extracting to $TargetPath..."
# If target exists, back it up instead of deleting
if (Test-Path $TargetPath) {
$backupPath = "$TargetPath.backup.$(Get-Date -Format 'yyyyMMdd_HHmmss')"
Write-Info "Backing up existing installation to $backupPath..."
try {
Rename-Item -Path $TargetPath -NewName $backupPath -ErrorAction Stop | Out-Null
}
catch {
Write-Error-Msg "Failed to backup existing installation: $_"
exit 1
}
}
try {
New-Item -ItemType Directory -Path $TargetPath -Force | Out-Null
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($ZipPath, $TargetPath)
Write-Success "Extracted successfully"
return $true
}
catch {
Write-Error-Msg "Failed to extract: $_"
exit 1
}
}
function Add-ToPath {
param([string]$BinPath)
$userPath = [Environment]::GetEnvironmentVariable("PATH", "User")
$pathEntries = $userPath -split ';' | Where-Object { $_ }
# Check if path is already present (exact match)
if ($pathEntries -contains $BinPath) {
Write-Info "Path already in PATH"
return $true
}
Write-Info "Adding to PATH..."
$newPath = if ($userPath) { "$userPath;$BinPath" } else { $BinPath }
try {
[Environment]::SetEnvironmentVariable("PATH", $newPath, "User")
$env:PATH = $env:PATH + ";$BinPath"
Write-Success "Added to PATH"
return $true
}
catch {
Write-Error-Msg "Failed to add to PATH (may require admin): $_"
return $false
}
}
function Create-StartMenuShortcut {
param([string]$ExePath)
try {
$startMenuPath = "$env:APPDATA\Microsoft\Windows\Start Menu\Programs"
$shortcutPath = Join-Path $startMenuPath "FastClaw.lnk"
$shell = New-Object -ComObject WScript.Shell
$shortcut = $shell.CreateShortcut($shortcutPath)
$shortcut.TargetPath = $ExePath
$shortcut.WorkingDirectory = $env:USERPROFILE
$shortcut.Description = "FastClaw - AI Agent Framework"
$shortcut.Save()
Write-Success "Created Start Menu shortcut"
}
catch {
Write-Info "Could not create Start Menu shortcut (optional): $_"
}
}
function Test-Installation {
param([string]$ExePath)
Write-Info "Testing installation..."
try {
$result = & $ExePath version 2>&1 | Select-Object -First 1
if ($result) {
Write-Success "Installation verified: $result"
return $true
}
}
catch {
Write-Info "Could not verify version (may still work)"
}
return $true
}
# Main script
Write-Header
if ($Help) {
Show-Help
exit 0
}
$arch = Detect-Architecture
Write-Info "Detected architecture: $arch"
$release = Get-LatestRelease
$version = $release.tag_name
Write-Info "Latest version: $version"
$zipPath = Download-Release -Release $release -Arch $arch
$installPath = $Path
Extract-Archive -ZipPath $zipPath -TargetPath $installPath
$exePath = Join-Path $installPath "fastclaw.exe"
$pathAdded = Add-ToPath -BinPath $installPath
Create-StartMenuShortcut -ExePath $exePath
Test-Installation -ExePath $exePath
Write-Host ""
Write-Success "FastClaw $version installed successfully!"
Write-Host ""
Write-Host "Next steps:" -ForegroundColor Cyan
Write-Host "1. Open a new PowerShell or Command Prompt window"
Write-Host "2. Run: fastclaw"
Write-Host "3. Setup wizard will open in your browser at http://localhost:18953"
Write-Host ""
if (-not $pathAdded) {
Write-Host "⚠️ WARNING: FastClaw was not added to PATH (admin privileges may be required)" -ForegroundColor Yellow
Write-Host "You can run fastclaw from: $exePath" -ForegroundColor Yellow
Write-Host ""
}
Write-Host "Or run from Start Menu: FastClaw" -ForegroundColor Cyan
Write-Host ""
# Cleanup
Remove-Item -Path $zipPath -Force -ErrorAction SilentlyContinue | Out-Null
Write-Host "Installation complete! 🚀" -ForegroundColor Green