# Genaia Bridge PowerShell Installer param([string]$InstallDir = "$env:USERPROFILE\bin") $ErrorActionPreference = "Stop" $BridgeName = "bridge.ps1" $FitaName = "fita-client.ps1" $InstallPath = Join-Path $InstallDir $BridgeName $FitaPath = Join-Path $InstallDir $FitaName $BridgeUrl = "https://get.genaia.app/bridge-powershell" $FitaUrl = "https://get.genaia.app/fita-client-powershell" $VersionUrl = "https://get.genaia.app/bridge-powershell-version" Write-Host "Genaia Bridge PowerShell Installer" -ForegroundColor Cyan Write-Host " Install dir: $InstallDir" # Debug: list $HOME\bin contents Write-Host "" Write-Host "[DEBUG] Contents of ${InstallDir}:" -ForegroundColor DarkGray if (Test-Path $InstallDir) { Get-ChildItem -Path $InstallDir | ForEach-Object { Write-Host " $($_.Name) ($([Math]::Round($_.Length / 1KB, 1)) KB) LastWrite: $($_.LastWriteTime)" -ForegroundColor DarkGray } } else { Write-Host " (directory does not exist)" -ForegroundColor DarkGray } # Debug: show raw version line from installed bridge.ps1 $_debugBridgePath = Join-Path $InstallDir "bridge.ps1" if (Test-Path $_debugBridgePath) { $_versionLine = Select-String -Path $_debugBridgePath -Pattern '^\$Version' | Select-Object -First 1 Write-Host "[DEBUG] Version line in bridge.ps1: $($_versionLine.Line)" -ForegroundColor DarkGray } else { Write-Host "[DEBUG] bridge.ps1 not found at $_debugBridgePath" -ForegroundColor DarkGray } Write-Host "" # Create directory if needed if (-not (Test-Path $InstallDir)) { New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null Write-Host " Created: $InstallDir" -ForegroundColor Green } # Check versions $LatestVersion = "" $CurrentVersion = "" try { $LatestVersion = (Invoke-WebRequest -Uri $VersionUrl -UseBasicParsing -TimeoutSec 10).Content.Trim() Write-Host " Latest version: $LatestVersion" -ForegroundColor Yellow } catch { Write-Host " Could not fetch latest version" -ForegroundColor Yellow } if (Test-Path $InstallPath) { try { $match = Select-String -Path $InstallPath -Pattern '^\$Version = "(.+?)"' | Select-Object -First 1 if ($match) { $CurrentVersion = $match.Matches.Groups[1].Value.Trim() } Write-Host " Installed version: $CurrentVersion" -ForegroundColor Yellow } catch { Write-Host " Could not detect installed version" -ForegroundColor Yellow } } if ($LatestVersion -and $CurrentVersion -and ($CurrentVersion -eq $LatestVersion)) { Write-Host "Already up to date ($CurrentVersion)" -ForegroundColor Green } else { if ($CurrentVersion -and $LatestVersion) { Write-Host " Updating $CurrentVersion -> $LatestVersion" -ForegroundColor Cyan } Write-Host " Downloading bridge.ps1..." -ForegroundColor Cyan try { Invoke-WebRequest -Uri $BridgeUrl -OutFile $InstallPath -UseBasicParsing Write-Host " bridge.ps1 OK ($([Math]::Round((Get-Item $InstallPath).Length / 1KB, 1)) KB)" -ForegroundColor Green } catch { Write-Host " Download failed: $_" -ForegroundColor Red exit 1 } } # Always update fita-client.ps1 (lightweight, always want latest) Write-Host " Downloading fita-client.ps1..." -ForegroundColor Cyan try { Invoke-WebRequest -Uri $FitaUrl -OutFile $FitaPath -UseBasicParsing Write-Host " fita-client.ps1 OK ($([Math]::Round((Get-Item $FitaPath).Length / 1KB, 1)) KB)" -ForegroundColor Green } catch { Write-Host " fita-client.ps1 download failed: $_ (bridge will attempt to download it at runtime)" -ForegroundColor Yellow } Write-Host "" Write-Host "Installation complete!" -ForegroundColor Green Write-Host "" Write-Host "Files installed:" -ForegroundColor Cyan Write-Host " $InstallPath" Write-Host " $FitaPath" Write-Host "" Write-Host "To run the bridge, create a config.json with your API key and bridgeId:" -ForegroundColor Yellow Write-Host " { `"bridgeId`": `"my-bridge`", `"apiKey`": `"your-api-key`" }" -ForegroundColor Gray Write-Host "" Write-Host "Then run:" -ForegroundColor Yellow Write-Host " powershell -ExecutionPolicy Bypass -File `"$InstallPath`"" -ForegroundColor Gray