-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
254 lines (222 loc) · 10.5 KB
/
Copy pathinstall.ps1
File metadata and controls
254 lines (222 loc) · 10.5 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
# Hexos Installer for Windows
# Usage: irm https://hexos.kadangkesel.net/install.ps1 | iex
#
# Environment variables:
# $env:HEXOS_VERSION - Specific version to install (default: latest)
# $env:HEXOS_DIR - Installation directory (default: ~/.hexos)
# $env:GITHUB_REPO - GitHub repository (default: kadangkesel/hexos)
$ErrorActionPreference = "Stop"
# Configuration
$GithubRepo = if ($env:GITHUB_REPO) { $env:GITHUB_REPO } else { "kadangkesel/hexos" }
$BaseUrl = "https://hexos.kadangkesel.net"
$HexosDir = if ($env:HEXOS_DIR) { $env:HEXOS_DIR } else { Join-Path $HOME ".hexos" }
$BinDir = Join-Path $HexosDir "bin"
function Write-Info($msg) { Write-Host "==> " -ForegroundColor Cyan -NoNewline; Write-Host $msg }
function Write-Ok($msg) { Write-Host "==> " -ForegroundColor Green -NoNewline; Write-Host $msg }
function Write-Warn($msg) { Write-Host "==> " -ForegroundColor Yellow -NoNewline; Write-Host $msg }
function Write-Err($msg) { Write-Host "==> " -ForegroundColor Red -NoNewline; Write-Host $msg }
function Get-LatestVersion {
# Try custom domain first (lightweight, no GitHub API rate limit)
try {
$version = (Invoke-WebRequest -Uri "$BaseUrl/version" -UseBasicParsing).Content.Trim()
if ($version) { return $version }
}
catch {}
# Fallback to GitHub API
$url = "https://api.github.com/repos/$GithubRepo/releases/latest"
try {
$response = Invoke-RestMethod -Uri $url -UseBasicParsing
$version = $response.tag_name -replace '^v', ''
return $version
}
catch {
Write-Err "Failed to fetch latest version"
exit 1
}
}
function Get-Checksum($filePath) {
$hash = Get-FileHash -Path $filePath -Algorithm SHA256
return $hash.Hash.ToLower()
}
function Add-ToPath($dir) {
$currentPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($currentPath -split ";" | Where-Object { $_ -eq $dir }) {
return $false
}
[Environment]::SetEnvironmentVariable("Path", "$dir;$currentPath", "User")
$env:Path = "$dir;$env:Path"
return $true
}
function Main {
$startTime = Get-Date
Write-Host ""
Write-Host " Hexos Installer" -ForegroundColor White
Write-Host ""
# Detect platform
$arch = if ([Environment]::Is64BitOperatingSystem) { "amd64" } else { "386" }
$platform = "windows/$arch"
Write-Info "Platform: $platform"
# Get version
$version = $env:HEXOS_VERSION
if (-not $version) {
Write-Info "Fetching release information..."
$version = Get-LatestVersion
}
Write-Info "Version: $version"
# Construct download URL (via custom domain, proxied to GitHub Releases)
$archiveName = "hexos-$version-windows-$arch.zip"
$downloadUrl = "$BaseUrl/download/v$version/$archiveName"
$checksumUrl = "$BaseUrl/download/v$version/hexos-$version-checksums.txt"
# Create temp directory
$tmpDir = Join-Path ([System.IO.Path]::GetTempPath()) "hexos-install-$(Get-Random)"
New-Item -ItemType Directory -Path $tmpDir -Force | Out-Null
try {
# Download archive
Write-Info "Downloading hexos $version..."
$archivePath = Join-Path $tmpDir $archiveName
Invoke-WebRequest -Uri $downloadUrl -OutFile $archivePath -UseBasicParsing
# Download and verify checksum
Write-Info "Verifying checksum..."
try {
$checksumPath = Join-Path $tmpDir "checksums.txt"
Invoke-WebRequest -Uri $checksumUrl -OutFile $checksumPath -UseBasicParsing
$checksumContent = Get-Content $checksumPath
$expectedLine = $checksumContent | Where-Object { $_ -match $archiveName }
if ($expectedLine) {
$expectedHash = ($expectedLine -split "\s+")[0]
$actualHash = Get-Checksum $archivePath
if ($actualHash -ne $expectedHash) {
Write-Err "Checksum mismatch!"
Write-Err " Expected: $expectedHash"
Write-Err " Got: $actualHash"
exit 1
}
Write-Ok "Checksum verified"
}
else {
Write-Warn "Checksum not found for $archiveName"
}
}
catch {
Write-Warn "Could not download checksums - skipping verification"
}
# Extract
Write-Info "Extracting..."
$extractDir = Join-Path $tmpDir "extracted"
Expand-Archive -Path $archivePath -DestinationPath $extractDir -Force
# Create directories
New-Item -ItemType Directory -Path $HexosDir -Force | Out-Null
New-Item -ItemType Directory -Path $BinDir -Force | Out-Null
# Install binary
$binarySrc = Join-Path $extractDir "hexos.exe"
if (-not (Test-Path $binarySrc)) {
# Try finding it recursively
$binarySrc = Get-ChildItem -Path $extractDir -Filter "hexos.exe" -Recurse | Select-Object -First 1 -ExpandProperty FullName
}
if (-not $binarySrc -or -not (Test-Path $binarySrc)) {
Write-Err "Binary not found in archive"
exit 1
}
Copy-Item $binarySrc (Join-Path $BinDir "hexos.exe") -Force
# Install dashboard
$dashboardSrc = Join-Path $extractDir "dashboard"
if (Test-Path $dashboardSrc) {
$dashboardDest = Join-Path $HexosDir "dashboard"
if (Test-Path $dashboardDest) { Remove-Item $dashboardDest -Recurse -Force }
Copy-Item $dashboardSrc $dashboardDest -Recurse
Write-Info "Dashboard installed"
}
# Install automation scripts
$automationSrc = Join-Path $extractDir "automation"
if (Test-Path $automationSrc) {
$automationDest = Join-Path $HexosDir "automation"
New-Item -ItemType Directory -Path $automationDest -Force | Out-Null
Copy-Item "$automationSrc\*" $automationDest -Recurse -Force
Write-Info "Automation scripts installed"
}
# Install data files (WASM modules, etc.)
$dataSrc = Join-Path $extractDir "data"
if (Test-Path $dataSrc) {
$dataDest = Join-Path $HexosDir "data"
New-Item -ItemType Directory -Path $dataDest -Force | Out-Null
Copy-Item "$dataSrc\*" $dataDest -Recurse -Force
Write-Info "Data files installed"
}
# Add to PATH
Write-Info "Setting up PATH..."
$pathAdded = Add-ToPath $BinDir
Write-Ok "Installed to: $BinDir\hexos.exe"
# Setup Windows startup task (hidden — no visible terminal window)
Write-Info "Setting up startup task..."
$hexosExe = Join-Path $BinDir "hexos.exe"
# Create a VBScript launcher that starts hexos completely hidden (window style 0)
# Belt-and-suspenders: binary is compiled with --windows-hide-console,
# but the VBS wrapper guarantees no flash even on edge-case Windows configs
$vbsLauncher = Join-Path $HexosDir "hexos-launcher.vbs"
$vbsContent = @"
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run """$hexosExe"" start", 0, False
"@
Set-Content -Path $vbsLauncher -Value $vbsContent -Encoding ASCII
$taskCreated = $false
try {
# Remove old task if exists
Unregister-ScheduledTask -TaskName "Hexos" -Confirm:$false -ErrorAction SilentlyContinue
# Launch via wscript.exe running the VBS launcher — zero visible UI
$action = New-ScheduledTaskAction -Execute "wscript.exe" -Argument """$vbsLauncher"""
# Use DOMAIN\Username format — bare username fails on many Windows configs
$currentUser = "$env:USERDOMAIN\$env:USERNAME"
$trigger = New-ScheduledTaskTrigger -AtLogOn -User $currentUser
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -RestartCount 3 -RestartInterval (New-TimeSpan -Minutes 1)
Register-ScheduledTask -TaskName "Hexos" -Action $action -Trigger $trigger -Settings $settings -Description "Hexos AI API Proxy" -RunLevel Limited | Out-Null
# Start it now
Start-ScheduledTask -TaskName "Hexos" -ErrorAction SilentlyContinue
$taskCreated = $true
Write-Ok "Startup task created (runs at login, hidden, auto-restarts on failure)"
}
catch {
Write-Warn "Could not create startup task: $_"
Write-Warn "Starting hexos in background instead..."
}
# If scheduled task failed or wasn't created, start as background process
if (-not $taskCreated) {
try {
Start-Process -FilePath "wscript.exe" -ArgumentList """$vbsLauncher""" -WindowStyle Hidden
Write-Ok "Hexos started as hidden background process"
Write-Warn "Note: hexos won't auto-start at login. Run manually: hexos start"
}
catch {
Write-Warn "Could not start hexos: $_"
Write-Warn "Start manually: hexos start"
}
}
# Calculate elapsed time
$elapsed = [math]::Round(((Get-Date) - $startTime).TotalSeconds, 1)
Write-Host ""
Write-Ok "Successfully installed hexos $version! (${elapsed}s)"
Write-Host ""
Write-Host " Service:" -ForegroundColor White
Write-Host " Hexos is running and will auto-start at login"
Write-Host " Get-ScheduledTask Hexos " -ForegroundColor Cyan -NoNewline; Write-Host "Check status"
Write-Host " Stop-ScheduledTask Hexos " -ForegroundColor Cyan -NoNewline; Write-Host "Stop service"
Write-Host ""
Write-Host " Dashboard:" -ForegroundColor White
Write-Host " Open " -NoNewline; Write-Host "http://localhost:7470" -ForegroundColor Cyan -NoNewline; Write-Host ""
Write-Host ""
Write-Host " Quick start:" -ForegroundColor White
Write-Host " hexos key create " -ForegroundColor Cyan -NoNewline; Write-Host "Generate an API key"
Write-Host " hexos auth connect " -ForegroundColor Cyan -NoNewline; Write-Host "Add a provider account"
Write-Host ""
Write-Host " Browser automation (optional):" -ForegroundColor White
Write-Host " hexos auth setup-automation" -ForegroundColor Cyan -NoNewline; Write-Host " Install Python + Camoufox"
Write-Host ""
if ($pathAdded) {
Write-Warn "Restart your terminal for PATH changes to take effect"
}
}
finally {
# Cleanup
Remove-Item $tmpDir -Recurse -Force -ErrorAction SilentlyContinue
}
}
Main