win/install.ps1

3.3 KB · 96 lines · text

1# brtwin installer — run: irm https://brt.sushii.dev/win/install.ps1 | iex
2#Requires -Version 5.1
3$ErrorActionPreference = "Stop"
4
5if ($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
15function Write-BrtInfo($msg) { Write-Host "● $msg" -ForegroundColor Cyan }
16function Write-BrtOk($msg) { Write-Host "✓ $msg" -ForegroundColor Green }
17function Write-BrtWarn($msg) { Write-Host "! $msg" -ForegroundColor Yellow }
18function Write-BrtErr($msg) { Write-Host "✗ $msg" -ForegroundColor Red; exit 1 }
19
20function 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
29function Get-InstalledVersion {
30 $vf = Join-Path $BrtWinInstallDir "version"
31 if (Test-Path $vf) { return (Get-Content $vf -Raw).Trim() }
32 return $null
33}
34
35function 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
54Write-BrtInfo "Installing brtwin to $BrtWinInstallDir"
55
56if (-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
62if ($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
77setlocal
78set "BRTWIN_HOME=$BrtWinInstallDir"
79powershell -NoProfile -ExecutionPolicy Bypass -File "%BRTWIN_HOME%\brtwin.ps1" %*
80exit /b %ERRORLEVEL%
81"@
82if (-not (Test-Path $BrtWinBinDir)) {
83 New-Item -ItemType Directory -Force -Path $BrtWinBinDir | Out-Null
84}
85Set-Content -Path $shim -Value $shimContent -Encoding ASCII
86Write-BrtOk "Command shim: $shim"
87
88Write-Host ""
89Write-BrtOk "brtwin installed"
90Write-Host " Run: brtwin -help"
91Write-Host " Remote access (cross-platform with brt on macOS/Linux):"
92Write-Host " brtwin -access serve"
93Write-Host ""
94Write-Host "Install command:"
95Write-Host " irm $BrtWinBaseUrl/install.ps1 | iex"
96