-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathinstall.ps1
More file actions
557 lines (497 loc) · 19.7 KB
/
install.ps1
File metadata and controls
557 lines (497 loc) · 19.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
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
# OpenAEON Installer for Windows
# Usage: iwr -useb https://raw.githubusercontent.com/openaeon/OpenAEON/main/install.ps1 | iex
# & ([scriptblock]::Create((iwr -useb https://raw.githubusercontent.com/openaeon/OpenAEON/main/install.ps1))) -Tag beta -NoOnboard -DryRun
param(
[string]$Tag = "latest",
[ValidateSet("npm", "git")]
[string]$InstallMethod = "git",
[string]$GitDir,
[switch]$NoOnboard,
[switch]$NoGitUpdate,
[switch]$DryRun
)
$ErrorActionPreference = "Stop"
Write-Host ""
Write-Host " OpenAEON Installer" -ForegroundColor Cyan
Write-Host ""
# Check if running in PowerShell
if ($PSVersionTable.PSVersion.Major -lt 5) {
Write-Host "Error: PowerShell 5+ required" -ForegroundColor Red
exit 1
}
Write-Host "[OK] Windows detected" -ForegroundColor Green
if (-not $PSBoundParameters.ContainsKey("InstallMethod")) {
if (-not [string]::IsNullOrWhiteSpace($env:OPENAEON_INSTALL_METHOD)) {
$InstallMethod = $env:OPENAEON_INSTALL_METHOD
}
}
if (-not $PSBoundParameters.ContainsKey("GitDir")) {
if (-not [string]::IsNullOrWhiteSpace($env:OPENAEON_GIT_DIR)) {
$GitDir = $env:OPENAEON_GIT_DIR
}
}
if (-not $PSBoundParameters.ContainsKey("NoOnboard")) {
if ($env:OPENAEON_NO_ONBOARD -eq "1") {
$NoOnboard = $true
}
}
if (-not $PSBoundParameters.ContainsKey("NoGitUpdate")) {
if ($env:OPENAEON_GIT_UPDATE -eq "0") {
$NoGitUpdate = $true
}
}
if (-not $PSBoundParameters.ContainsKey("DryRun")) {
if ($env:OPENAEON_DRY_RUN -eq "1") {
$DryRun = $true
}
}
if ([string]::IsNullOrWhiteSpace($GitDir)) {
$userHome = [Environment]::GetFolderPath("UserProfile")
$GitDir = (Join-Path $userHome "openaeon")
}
# Check for Node.js
function Check-Node {
try {
$nodeVersion = (node -v 2>$null)
if ($nodeVersion) {
$version = [int]($nodeVersion -replace 'v(\d+)\..*', '$1')
if ($version -ge 22) {
Write-Host "[OK] Node.js $nodeVersion found" -ForegroundColor Green
return $true
} else {
Write-Host "[!] Node.js $nodeVersion found, but v22+ required" -ForegroundColor Yellow
return $false
}
}
} catch {
Write-Host "[!] Node.js not found" -ForegroundColor Yellow
return $false
}
return $false
}
# Install Node.js
function Install-Node {
Write-Host "[*] Installing Node.js..." -ForegroundColor Yellow
# Try winget first (Windows 11 / Windows 10 with App Installer)
if (Get-Command winget -ErrorAction SilentlyContinue) {
Write-Host " Using winget..." -ForegroundColor Gray
winget install OpenJS.NodeJS.LTS --accept-package-agreements --accept-source-agreements
# Refresh PATH
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
Write-Host "[OK] Node.js installed via winget" -ForegroundColor Green
return
}
# Try Chocolatey
if (Get-Command choco -ErrorAction SilentlyContinue) {
Write-Host " Using Chocolatey..." -ForegroundColor Gray
choco install nodejs-lts -y
# Refresh PATH
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
Write-Host "[OK] Node.js installed via Chocolatey" -ForegroundColor Green
return
}
# Try Scoop
if (Get-Command scoop -ErrorAction SilentlyContinue) {
Write-Host " Using Scoop..." -ForegroundColor Gray
scoop install nodejs-lts
Write-Host "[OK] Node.js installed via Scoop" -ForegroundColor Green
return
}
# Manual download fallback
Write-Host ""
Write-Host "Error: Could not find a package manager (winget, choco, or scoop)" -ForegroundColor Red
Write-Host ""
Write-Host "Please install Node.js 22+ manually:" -ForegroundColor Yellow
Write-Host " https://nodejs.org/en/download/" -ForegroundColor Cyan
Write-Host ""
Write-Host "Or install winget (App Installer) from the Microsoft Store." -ForegroundColor Gray
exit 1
}
# Check for existing OpenAEON installation
function Check-ExistingOpenAEON {
try {
$null = Get-Command openaeon -ErrorAction Stop
Write-Host "[*] Existing OpenAEON installation detected" -ForegroundColor Yellow
return $true
} catch {
return $false
}
}
# Uninstall existing OpenAEON background service and binary
function Uninstall-ExistingOpenAEON {
Write-Host "[*] Attempting to uninstall existing OpenAEON before installing custom version..." -ForegroundColor Yellow
# Try removing the gateway service if accessible
try {
openaeon gateway uninstall --force 2>$null | Out-Null
} catch {}
# Attempt to uninstall generic NPM package
try {
Write-Host " Uninstalling NPM openaeon globally..." -ForegroundColor Gray
npm uninstall -g openaeon 2>$null | Out-Null
} catch {}
Write-Host "[OK] Legacy OpenAEON cleaned up (if any)" -ForegroundColor Green
}
function Check-Git {
try {
$null = Get-Command git -ErrorAction Stop
return $true
} catch {
return $false
}
}
function Require-Git {
if (Check-Git) { return }
Write-Host ""
Write-Host "Error: Git is required for --InstallMethod git." -ForegroundColor Red
Write-Host "Install Git for Windows:" -ForegroundColor Yellow
Write-Host " https://git-scm.com/download/win" -ForegroundColor Cyan
Write-Host "Then re-run this installer." -ForegroundColor Yellow
exit 1
}
function Ensure-OpenAEONOnPath {
if (Get-Command openaeon -ErrorAction SilentlyContinue) {
return $true
}
$npmPrefix = $null
try {
$npmPrefix = (npm config get prefix 2>$null).Trim()
} catch {
$npmPrefix = $null
}
if (-not [string]::IsNullOrWhiteSpace($npmPrefix)) {
$npmBin = Join-Path $npmPrefix "bin"
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if (-not ($userPath -split ";" | Where-Object { $_ -ieq $npmBin })) {
[Environment]::SetEnvironmentVariable("Path", "$userPath;$npmBin", "User")
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
Write-Host "[!] Added $npmBin to user PATH (restart terminal if command not found)" -ForegroundColor Yellow
}
if (Test-Path (Join-Path $npmBin "openaeon.cmd")) {
return $true
}
}
Write-Host "[!] openaeon is not on PATH yet." -ForegroundColor Yellow
Write-Host "Restart PowerShell or add the npm global bin folder to PATH." -ForegroundColor Yellow
if ($npmPrefix) {
Write-Host "Expected path: $npmPrefix\\bin" -ForegroundColor Cyan
} else {
Write-Host "Hint: run \"npm config get prefix\" to find your npm global path." -ForegroundColor Gray
}
return $false
}
function Ensure-Pnpm {
if (Get-Command pnpm -ErrorAction SilentlyContinue) {
return
}
if (Get-Command corepack -ErrorAction SilentlyContinue) {
try {
corepack enable | Out-Null
corepack prepare pnpm@latest --activate | Out-Null
if (Get-Command pnpm -ErrorAction SilentlyContinue) {
Write-Host "[OK] pnpm installed via corepack" -ForegroundColor Green
return
}
} catch {
# fallthrough to npm install
}
}
Write-Host "[*] Installing pnpm..." -ForegroundColor Yellow
npm install -g pnpm
Write-Host "[OK] pnpm installed" -ForegroundColor Green
}
# Install OpenAEON
function Install-OpenAEON {
if ([string]::IsNullOrWhiteSpace($Tag)) {
$Tag = "latest"
}
# Use openaeon package for beta, openaeon for stable
$packageName = "openaeon"
if ($Tag -eq "beta" -or $Tag -match "^beta\.") {
$packageName = "openaeon"
}
Write-Host "[*] Installing OpenAEON ($packageName@$Tag)..." -ForegroundColor Yellow
$prevLogLevel = $env:NPM_CONFIG_LOGLEVEL
$prevUpdateNotifier = $env:NPM_CONFIG_UPDATE_NOTIFIER
$prevFund = $env:NPM_CONFIG_FUND
$prevAudit = $env:NPM_CONFIG_AUDIT
$env:NPM_CONFIG_LOGLEVEL = "error"
$env:NPM_CONFIG_UPDATE_NOTIFIER = "false"
$env:NPM_CONFIG_FUND = "false"
$env:NPM_CONFIG_AUDIT = "false"
try {
$npmOutput = npm install -g "$packageName@$Tag" 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host "[!] npm install failed" -ForegroundColor Red
if ($npmOutput -match "spawn git" -or $npmOutput -match "ENOENT.*git") {
Write-Host "Error: git is missing from PATH." -ForegroundColor Red
Write-Host "Install Git for Windows, then reopen PowerShell and retry:" -ForegroundColor Yellow
Write-Host " https://git-scm.com/download/win" -ForegroundColor Cyan
} else {
Write-Host "Re-run with verbose output to see the full error:" -ForegroundColor Yellow
Write-Host " iwr -useb https://raw.githubusercontent.com/openaeon/OpenAEON/main/install.ps1 | iex" -ForegroundColor Cyan
}
$npmOutput | ForEach-Object { Write-Host $_ }
exit 1
}
} finally {
$env:NPM_CONFIG_LOGLEVEL = $prevLogLevel
$env:NPM_CONFIG_UPDATE_NOTIFIER = $prevUpdateNotifier
$env:NPM_CONFIG_FUND = $prevFund
$env:NPM_CONFIG_AUDIT = $prevAudit
}
Write-Host "[OK] OpenAEON installed" -ForegroundColor Green
}
# Install OpenAEON from GitHub
function Install-OpenAEONFromGit {
param(
[string]$RepoDir,
[switch]$SkipUpdate
)
Require-Git
Ensure-Pnpm
$repoUrl = "https://github.com/openaeon/OpenAEON.git"
Write-Host "[*] Installing OpenAEON from GitHub ($repoUrl)..." -ForegroundColor Yellow
if (-not (Test-Path $RepoDir)) {
git clone $repoUrl $RepoDir
}
if (-not $SkipUpdate) {
if (-not (git -C $RepoDir status --porcelain 2>$null)) {
git -C $RepoDir pull --rebase 2>$null
} else {
Write-Host "[!] Repo is dirty; skipping git pull" -ForegroundColor Yellow
}
} else {
Write-Host "[!] Git update disabled; skipping git pull" -ForegroundColor Yellow
}
Remove-LegacySubmodule -RepoDir $RepoDir
pnpm -C $RepoDir install
if (-not (pnpm -C $RepoDir ui:build)) {
Write-Host "[!] UI build failed; continuing (CLI may still work)" -ForegroundColor Yellow
}
pnpm -C $RepoDir build
$binDir = Join-Path $env:USERPROFILE ".local\\bin"
if (-not (Test-Path $binDir)) {
New-Item -ItemType Directory -Force -Path $binDir | Out-Null
}
$cmdPath = Join-Path $binDir "openaeon.cmd"
$cmdContents = "@echo off`r`nnode ""$RepoDir\\dist\\entry.js"" %*`r`n"
Set-Content -Path $cmdPath -Value $cmdContents -NoNewline
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if (-not ($userPath -split ";" | Where-Object { $_ -ieq $binDir })) {
[Environment]::SetEnvironmentVariable("Path", "$userPath;$binDir", "User")
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
Write-Host "[!] Added $binDir to user PATH (restart terminal if command not found)" -ForegroundColor Yellow
}
Write-Host "[OK] OpenAEON wrapper installed to $cmdPath" -ForegroundColor Green
Write-Host "[i] This checkout uses pnpm. For deps, run: pnpm install (avoid npm install in the repo)." -ForegroundColor Gray
}
# Run doctor for migrations (safe, non-interactive)
function Run-Doctor {
Write-Host "[*] Running doctor to migrate settings..." -ForegroundColor Yellow
try {
openaeon doctor --non-interactive
} catch {
# Ignore errors from doctor
}
Write-Host "[OK] Migration complete" -ForegroundColor Green
}
function Test-GatewayServiceLoaded {
try {
$statusJson = (openaeon daemon status --json 2>$null)
if ([string]::IsNullOrWhiteSpace($statusJson)) {
return $false
}
$parsed = $statusJson | ConvertFrom-Json
if ($parsed -and $parsed.service -and $parsed.service.loaded) {
return $true
}
} catch {
return $false
}
return $false
}
function Refresh-GatewayServiceIfLoaded {
if (-not (Get-Command openaeon -ErrorAction SilentlyContinue)) {
return
}
if (-not (Test-GatewayServiceLoaded)) {
return
}
Write-Host "[*] Refreshing loaded gateway service..." -ForegroundColor Yellow
try {
openaeon gateway install --force | Out-Null
} catch {
Write-Host "[!] Gateway service refresh failed; continuing." -ForegroundColor Yellow
return
}
try {
openaeon gateway restart | Out-Null
openaeon gateway status --probe --json | Out-Null
Write-Host "[OK] Gateway service refreshed" -ForegroundColor Green
} catch {
Write-Host "[!] Gateway service restart failed; continuing." -ForegroundColor Yellow
}
}
function Get-LegacyRepoDir {
if (-not [string]::IsNullOrWhiteSpace($env:OPENAEON_GIT_DIR)) {
return $env:OPENAEON_GIT_DIR
}
$userHome = [Environment]::GetFolderPath("UserProfile")
return (Join-Path $userHome "openaeon")
}
function Remove-LegacySubmodule {
param(
[string]$RepoDir
)
if ([string]::IsNullOrWhiteSpace($RepoDir)) {
$RepoDir = Get-LegacyRepoDir
}
$legacyDir = Join-Path $RepoDir "Peekaboo"
if (Test-Path $legacyDir) {
Write-Host "[!] Removing legacy submodule checkout: $legacyDir" -ForegroundColor Yellow
Remove-Item -Recurse -Force $legacyDir
}
}
# Main installation flow
function Main {
if ($InstallMethod -ne "npm" -and $InstallMethod -ne "git") {
Write-Host "Error: invalid -InstallMethod (use npm or git)." -ForegroundColor Red
exit 2
}
if ($DryRun) {
Write-Host "[OK] Dry run" -ForegroundColor Green
Write-Host "[OK] Install method: $InstallMethod" -ForegroundColor Green
if ($InstallMethod -eq "git") {
Write-Host "[OK] Git dir: $GitDir" -ForegroundColor Green
if ($NoGitUpdate) {
Write-Host "[OK] Git update: disabled" -ForegroundColor Green
} else {
Write-Host "[OK] Git update: enabled" -ForegroundColor Green
}
}
if ($NoOnboard) {
Write-Host "[OK] Onboard: skipped" -ForegroundColor Green
}
return
}
Remove-LegacySubmodule -RepoDir $RepoDir
# Check for existing installation
$isUpgrade = Check-ExistingOpenAEON
if ($isUpgrade) {
Uninstall-ExistingOpenAEON
}
# Step 1: Node.js
if (-not (Check-Node)) {
Install-Node
# Verify installation
if (-not (Check-Node)) {
Write-Host ""
Write-Host "Error: Node.js installation may require a terminal restart" -ForegroundColor Red
Write-Host "Please close this terminal, open a new one, and run this installer again." -ForegroundColor Yellow
exit 1
}
}
$finalGitDir = $null
# Step 2: OpenAEON
if ($InstallMethod -eq "git") {
$finalGitDir = $GitDir
Install-OpenAEONFromGit -RepoDir $GitDir -SkipUpdate:$NoGitUpdate
} else {
Install-OpenAEON
}
if (-not (Ensure-OpenAEONOnPath)) {
Write-Host "Install completed, but OpenAEON is not on PATH yet." -ForegroundColor Yellow
Write-Host "Open a new terminal, then run: openaeon doctor" -ForegroundColor Cyan
return
}
Refresh-GatewayServiceIfLoaded
# Step 3: Run doctor for migrations if upgrading or git install
if ($isUpgrade -or $InstallMethod -eq "git") {
Run-Doctor
}
$installedVersion = $null
try {
$installedVersion = (openaeon --version 2>$null).Trim()
} catch {
$installedVersion = $null
}
if (-not $installedVersion) {
try {
$npmList = npm list -g --depth 0 --json 2>$null | ConvertFrom-Json
if ($npmList -and $npmList.dependencies -and $npmList.dependencies.openaeon -and $npmList.dependencies.openaeon.version) {
$installedVersion = $npmList.dependencies.openaeon.version
}
} catch {
$installedVersion = $null
}
}
Write-Host ""
if ($installedVersion) {
Write-Host "OpenAEON installed successfully ($installedVersion)!" -ForegroundColor Green
} else {
Write-Host "OpenAEON installed successfully!" -ForegroundColor Green
}
Write-Host ""
if ($isUpgrade) {
$updateMessages = @(
"Leveled up! New skills unlocked. You're welcome.",
"Fresh code, same lobster. Miss me?",
"Back and better. Did you even notice I was gone?",
"Update complete. I learned some new tricks while I was out.",
"Upgraded! Now with 23% more sass.",
"I've evolved. Try to keep up.",
"New version, who dis? Oh right, still me but shinier.",
"Patched, polished, and ready to pinch. Let's go.",
"The lobster has molted. Harder shell, sharper claws.",
"Update done! Check the changelog or just trust me, it's good.",
"Reborn from the boiling waters of npm. Stronger now.",
"I went away and came back smarter. You should try it sometime.",
"Update complete. The bugs feared me, so they left.",
"New version installed. Old version sends its regards.",
"Firmware fresh. Brain wrinkles: increased.",
"I've seen things you wouldn't believe. Anyway, I'm updated.",
"Back online. The changelog is long but our friendship is longer.",
"Upgraded! Peter fixed stuff. Blame him if it breaks.",
"Molting complete. Please don't look at my soft shell phase.",
"Version bump! Same chaos energy, fewer crashes (probably)."
)
Write-Host (Get-Random -InputObject $updateMessages) -ForegroundColor Gray
Write-Host ""
} else {
$completionMessages = @(
"Ahh nice, I like it here. Got any snacks? ",
"Home sweet home. Don't worry, I won't rearrange the furniture.",
"I'm in. Let's cause some responsible chaos.",
"Installation complete. Your productivity is about to get weird.",
"Settled in. Time to automate your life whether you're ready or not.",
"Cozy. I've already read your calendar. We need to talk.",
"Finally unpacked. Now point me at your problems.",
"cracks claws Alright, what are we building?",
"The lobster has landed. Your terminal will never be the same.",
"All done! I promise to only judge your code a little bit."
)
Write-Host (Get-Random -InputObject $completionMessages) -ForegroundColor Gray
Write-Host ""
}
if ($InstallMethod -eq "git") {
Write-Host "Source checkout: $finalGitDir" -ForegroundColor Cyan
Write-Host "Wrapper: $env:USERPROFILE\\.local\\bin\\openaeon.cmd" -ForegroundColor Cyan
Write-Host ""
}
if ($isUpgrade) {
Write-Host "Upgrade complete. Run " -NoNewline
Write-Host "openaeon doctor" -ForegroundColor Cyan -NoNewline
Write-Host " to check for additional migrations."
} else {
if ($NoOnboard) {
Write-Host "Skipping onboard (requested). Run " -NoNewline
Write-Host "openaeon onboard" -ForegroundColor Cyan -NoNewline
Write-Host " later."
} else {
Write-Host "Starting setup..." -ForegroundColor Cyan
Write-Host ""
openaeon onboard
}
}
}
Main