# Cortex66 installer for Windows (D465, FL108 L3b): irm https://cortex66.com/install.ps1 | iex # It ends in exactly the install `npm install -g cortex66` makes: the same npm package and version, the same `cortex66` command. # It only adds Node when Node 20+ is missing: the official nodejs.org zip into %LOCALAPPDATA%\cortex66\node, checked against # nodejs.org's SHASUMS256.txt. No admin, no telemetry, no account; only your user PATH changes. # Options (a pipe cannot pass arguments, so they are environment variables): # $env:CORTEX66_VERSION = "0.5.70" (default latest) # $env:CORTEX66_DRY_RUN = "1" (print the plan, change nothing) # $env:CORTEX66_NO_MODIFY_PATH = "1" (leave PATH as it is) $ErrorActionPreference = 'Stop' function Install-Cortex66 { param([string]$Version = 'latest', [switch]$DryRun, [switch]$NoModifyPath) $NodeMin = 20 $NodeLine = 24 # the Node LTS line we download when Node is missing (nodejs.org/dist/latest-v24.x) $Root = Join-Path $env:LOCALAPPDATA 'cortex66' $env:NPM_CONFIG_FUND = 'false'; $env:NPM_CONFIG_UPDATE_NOTIFIER = 'false' # calm output only; the install is the same function Say($m) { Write-Host "cortex66: $m" } function Run([string]$exe, [string[]]$argv) { if ($DryRun) { Write-Host " would run: $exe $($argv -join ' ')" } else { & $exe @argv; if ($LASTEXITCODE) { throw "$exe failed ($LASTEXITCODE)" } } } $arch = switch ($env:PROCESSOR_ARCHITECTURE) { 'AMD64' { 'x64' } 'ARM64' { 'arm64' } default { $null } } if (-not $arch) { throw "no Node build for $($env:PROCESSOR_ARCHITECTURE); install Node $NodeMin+ yourself, then run: npm install -g cortex66" } Say "system: win-$arch, cortex66 version: $Version" # 1. Node: use yours when it is 20 or newer; otherwise download the official LTS zip into %LOCALAPPDATA%\cortex66\node. $major = $null if ((Get-Command node -ErrorAction SilentlyContinue) -and (Get-Command npm -ErrorAction SilentlyContinue)) { if ((node --version) -match '^v(\d+)') { $major = [int]$Matches[1] } } $ownNode = -not ($major -and $major -ge $NodeMin) if (-not $ownNode) { Say "Node $(node --version) found: installing with your npm" $npm = 'npm' } else { if ($major) { Say "Node v$major is older than ${NodeMin}: getting Node $NodeLine LTS into $Root\node (yours stays as it is)" } else { Say "Node not found: getting Node $NodeLine LTS into $Root\node" } $base = "https://nodejs.org/dist/latest-v$NodeLine.x" if ($DryRun) { Write-Host " would download: $base/node-v$NodeLine.*-win-$arch.zip" Write-Host " would verify: its SHA-256 against $base/SHASUMS256.txt" Write-Host " would unpack: $Root\node" } else { $tmp = Join-Path ([IO.Path]::GetTempPath()) ("cortex66-" + [guid]::NewGuid()) New-Item -ItemType Directory -Path $tmp | Out-Null try { $sums = (Invoke-WebRequest -UseBasicParsing "$base/SHASUMS256.txt").Content -split "`n" $line = $sums | Where-Object { $_ -match " (node-v[\d.]+-win-$arch\.zip)$" } | Select-Object -First 1 if (-not $line) { throw "nodejs.org lists no Node $NodeLine build for win-$arch" } $want, $file = $line.Trim() -split '\s+' Say "downloading $file" Invoke-WebRequest -UseBasicParsing "$base/$file" -OutFile (Join-Path $tmp $file) $got = (Get-FileHash -Algorithm SHA256 (Join-Path $tmp $file)).Hash.ToLower() if ($got -ne $want.ToLower()) { throw "checksum mismatch for $file (expected $want, got $got); nothing was installed" } Say 'checksum ok (SHA-256 matches nodejs.org SHASUMS256.txt)' Expand-Archive -Path (Join-Path $tmp $file) -DestinationPath (Join-Path $tmp 'unpack') New-Item -ItemType Directory -Force -Path $Root | Out-Null if (Test-Path "$Root\node") { Remove-Item -Recurse -Force "$Root\node" } Move-Item (Join-Path $tmp "unpack\$($file -replace '\.zip$', '')") "$Root\node" } finally { Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue } } $env:Path = "$Root\node;$env:Path" $npm = "$Root\node\npm.cmd" } # 2. cortex66: the same npm package and version as `npm install -g cortex66`. With our Node, npm's global prefix is the Node # folder itself (the zip's own default), so one PATH entry holds node and cortex66. Never as administrator. $prefix = $null if ($ownNode) { $prefix = "$Root\node" } else { $global = (npm prefix -g) 2>$null $probe = if ($global) { Join-Path $global ".cortex66-write-test" } else { $null } try { if (-not $probe) { throw 'no prefix' }; [IO.File]::WriteAllText($probe, ''); Remove-Item $probe; Say "npm global prefix $global is writable: global install" } catch { Say "npm global prefix $global is not writable (no admin): installing into $Root\bin"; $prefix = "$Root\bin" } } if ($prefix) { if (-not $DryRun) { New-Item -ItemType Directory -Force -Path $prefix | Out-Null } Run $npm @('install', '-g', '--prefix', $prefix, "cortex66@$Version") $bin = $prefix } else { Run $npm @('install', '-g', "cortex66@$Version") $bin = $global } # 3. PATH: the folder is added to your user PATH once, only when it is not there yet. $userPath = [Environment]::GetEnvironmentVariable('Path', 'User') $parts = @($userPath -split ';' | Where-Object { $_ }) if ($prefix -and ($parts -notcontains $bin)) { if ($NoModifyPath) { Say "PATH left as it is (CORTEX66_NO_MODIFY_PATH); add this folder to your user PATH yourself: $bin" } elseif ($DryRun) { Write-Host " would add to your user PATH: $bin" } else { [Environment]::SetEnvironmentVariable('Path', (@($bin) + $parts) -join ';', 'User') $env:Path = "$bin;$env:Path" Say "added $bin to your user PATH (open a new terminal to use it everywhere)" } } # 4. Done: the version, and the one next step. if ($DryRun) { Say 'dry run: nothing was changed'; return } Say "installed: $(& (Join-Path $bin 'cortex66.cmd') --version)" Say 'next: cortex66 connect' } $v = if ($env:CORTEX66_VERSION) { $env:CORTEX66_VERSION } else { 'latest' } Install-Cortex66 -Version $v -DryRun:($env:CORTEX66_DRY_RUN -eq '1') -NoModifyPath:($env:CORTEX66_NO_MODIFY_PATH -eq '1')