$ErrorActionPreference = 'Stop' $AppName = 'kaino' $DefaultDownloadBaseUrl = 'https://github.com/Kainotomic/kaino-code-releases/releases/latest/download' $DownloadBaseUrl = if ($env:KAINO_DOWNLOAD_BASE_URL) { $env:KAINO_DOWNLOAD_BASE_URL } else { $DefaultDownloadBaseUrl } $Architecture = [System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString() switch ($Architecture) { 'X64' { $AssetName = 'kaino-windows-x64.exe' } default { Write-Error "Unsupported Windows architecture: $Architecture" exit 1 } } if ($env:KAINO_INSTALL_DIR) { $InstallDir = $env:KAINO_INSTALL_DIR } elseif ($env:LOCALAPPDATA) { $InstallDir = Join-Path $env:LOCALAPPDATA 'Kaino\bin' } else { $InstallDir = Join-Path $HOME '.kaino\bin' } New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null $TargetPath = Join-Path $InstallDir 'kaino.exe' $TempFile = Join-Path ([System.IO.Path]::GetTempPath()) ("kaino-" + [System.Guid]::NewGuid().ToString() + ".exe") $DownloadUrl = "$DownloadBaseUrl/$AssetName" try { Write-Host "Downloading $AppName for Windows $Architecture..." Invoke-WebRequest -Uri $DownloadUrl -OutFile $TempFile -UseBasicParsing Move-Item -Path $TempFile -Destination $TargetPath -Force } catch { if (Test-Path $TempFile) { Remove-Item $TempFile -Force } Write-Error "Failed to download $DownloadUrl. A Windows release binary may not be published yet." exit 1 } $CurrentUserPath = [Environment]::GetEnvironmentVariable('Path', 'User') $PathEntries = @() if ($CurrentUserPath) { $PathEntries = $CurrentUserPath -split ';' | Where-Object { $_ } } $AlreadyOnPath = $PathEntries | Where-Object { $_.TrimEnd('\') -ieq $InstallDir.TrimEnd('\') } | Select-Object -First 1 if (-not $AlreadyOnPath) { $NewUserPath = if ($CurrentUserPath) { "$CurrentUserPath;$InstallDir" } else { $InstallDir } [Environment]::SetEnvironmentVariable('Path', $NewUserPath, 'User') $env:Path = "$env:Path;$InstallDir" Write-Host "Added $InstallDir to your user PATH. Open a new PowerShell window if 'kaino' is not found." } Write-Host "Installed $AppName to $TargetPath" Write-Host "Run 'kaino' to launch Kaino Code."