| 1 | # brtwin installer — run: irm https://brt.sushii.dev/win/install.ps1 | iex |
| 2 | #Requires -Version 5.1 |
| 3 | $ErrorActionPreference = "Stop" |
| 4 | |
| 5 | if ($env:OS -ne "Windows_NT") { |
| 6 | Write-Host "! This installer is for Windows." -ForegroundColor Yellow |
| 7 | Write-Host "macOS / Linux: curl -fsSL https://brt.sushii.dev/install.sh | sh" |
| 8 | exit 1 |
| 9 | } |
| 10 | |
| 11 | $BrtWinBaseUrl = if ($env:BRTWIN_BASE_URL) { $env:BRTWIN_BASE_URL } else { "https://brt.sushii.dev/win" } |
| 12 | $BrtWinInstallDir = if ($env:BRTWIN_INSTALL_DIR) { $env:BRTWIN_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA "brtwin" } |
| 13 | $BrtWinBinDir = if ($env:BRTWIN_BIN_DIR) { $env:BRTWIN_BIN_DIR } else { Join-Path $env:LOCALAPPDATA "Microsoft\WindowsApps" } |
| 14 | |
| 15 | function Write-BrtInfo($msg) { Write-Host "● $msg" -ForegroundColor Cyan } |
| 16 | function Write-BrtOk($msg) { Write-Host "✓ $msg" -ForegroundColor Green } |
| 17 | function Write-BrtWarn($msg) { Write-Host "! $msg" -ForegroundColor Yellow } |
| 18 | function Write-BrtErr($msg) { Write-Host "✗ $msg" -ForegroundColor Red; exit 1 } |
| 19 | |
| 20 | function Get-RemoteVersion { |
| 21 | try { |
| 22 | return (Invoke-WebRequest -Uri "$BrtWinBaseUrl/version" -UseBasicParsing).Content.Trim() |
| 23 | } catch { |
| 24 | Write-BrtWarn "Could not fetch remote version" |
| 25 | return $null |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | function Get-InstalledVersion { |
| 30 | $vf = Join-Path $BrtWinInstallDir "version" |
| 31 | if (Test-Path $vf) { return (Get-Content $vf -Raw).Trim() } |
| 32 | return $null |
| 33 | } |
| 34 | |
| 35 | function Invoke-Download([string]$RelPath) { |
| 36 | $dest = Join-Path $BrtWinInstallDir $RelPath |
| 37 | $dir = Split-Path $dest -Parent |
| 38 | if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Force -Path $dir | Out-Null } |
| 39 | $url = "$BrtWinBaseUrl/$($RelPath -replace '\\','/')" |
| 40 | Invoke-WebRequest -Uri $url -OutFile $dest -UseBasicParsing |
| 41 | } |
| 42 | |
| 43 | $InstallFiles = @( |
| 44 | "brtwin.cmd", |
| 45 | "brtwin.ps1", |
| 46 | "version", |
| 47 | "lib\brtwin.py", |
| 48 | "lib\access.ps1", |
| 49 | "lib\shared\access.py", |
| 50 | "lib\shared\browse.py", |
| 51 | "lib\shared\media.py" |
| 52 | ) |
| 53 | |
| 54 | Write-BrtInfo "Installing brtwin to $BrtWinInstallDir" |
| 55 | |
| 56 | if (-not (Get-Command python -ErrorAction SilentlyContinue) -and -not (Get-Command py -ErrorAction SilentlyContinue)) { |
| 57 | Write-BrtWarn "Python 3 not found — install from https://python.org (required for brtwin)" |
| 58 | } |
| 59 | |
| 60 | $remoteVer = Get-RemoteVersion |
| 61 | $localVer = Get-InstalledVersion |
| 62 | if ($localVer -and $remoteVer -and $localVer -eq $remoteVer) { |
| 63 | Write-BrtOk "Already up to date (v$localVer)" |
| 64 | } else { |
| 65 | if ($localVer) { Write-BrtInfo "Updating $localVer → $remoteVer" } |
| 66 | foreach ($f in $InstallFiles) { |
| 67 | Write-BrtInfo " $f" |
| 68 | Invoke-Download $f |
| 69 | } |
| 70 | Write-BrtOk "Downloaded brtwin v$(Get-InstalledVersion)" |
| 71 | } |
| 72 | |
| 73 | # PATH shim: brtwin.cmd in WindowsApps (usually on PATH) |
| 74 | $shim = Join-Path $BrtWinBinDir "brtwin.cmd" |
| 75 | $shimContent = @" |
| 76 | @echo off |
| 77 | setlocal |
| 78 | set "BRTWIN_HOME=$BrtWinInstallDir" |
| 79 | powershell -NoProfile -ExecutionPolicy Bypass -File "%BRTWIN_HOME%\brtwin.ps1" %* |
| 80 | exit /b %ERRORLEVEL% |
| 81 | "@ |
| 82 | if (-not (Test-Path $BrtWinBinDir)) { |
| 83 | New-Item -ItemType Directory -Force -Path $BrtWinBinDir | Out-Null |
| 84 | } |
| 85 | Set-Content -Path $shim -Value $shimContent -Encoding ASCII |
| 86 | Write-BrtOk "Command shim: $shim" |
| 87 | |
| 88 | Write-Host "" |
| 89 | Write-BrtOk "brtwin installed" |
| 90 | Write-Host " Run: brtwin -help" |
| 91 | Write-Host " Remote access (cross-platform with brt on macOS/Linux):" |
| 92 | Write-Host " brtwin -access serve" |
| 93 | Write-Host "" |
| 94 | Write-Host "Install command:" |
| 95 | Write-Host " irm $BrtWinBaseUrl/install.ps1 | iex" |
| 96 | |