# Brocoded installer for Windows: irm https://brocoded.cloud/install | iex # # What it does (read it, it is short): downloads the Windows installer from the same place the website's download button # uses, checks its size and checksum, closes a running Brocoded, installs it for you only (no administrator needed) and # opens it. A file fetched by PowerShell is not tagged "downloaded from the internet", so SmartScreen does not show the # "Windows protected your PC" warning. Your pairing and account (in %USERPROFILE%\.foreman) are kept. Nothing else is touched. # # Test without installing: $env:BROCODED_DRY = "1"; irm https://brocoded.cloud/install.ps1 | iex & { $ErrorActionPreference = "Stop" $ProgressPreference = "SilentlyContinue" # the progress bar makes Invoke-WebRequest many times slower in Windows PowerShell [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 $site = if ($env:BROCODED_SITE) { $env:BROCODED_SITE } else { "https://brocoded.cloud" } if ($env:OS -ne "Windows_NT") { Write-Host "This installer is for Windows. Mac: curl -fsSL $site/install | sh"; return } if (-not [Environment]::Is64BitOperatingSystem) { Write-Host "Brocoded needs 64-bit Windows 10 or 11."; return } $tmp = Join-Path ([IO.Path]::GetTempPath()) ("brocoded-" + [Guid]::NewGuid().ToString("N")) New-Item -ItemType Directory -Path $tmp | Out-Null try { Write-Host "Finding the latest Brocoded for Windows..." $release = (Invoke-RestMethod -UseBasicParsing "$site/releases.json").windows if (-not $release.url) { Write-Host "No Windows build is published yet. See $site/downloads/"; return } Write-Host "Downloading Brocoded $($release.version) ($([math]::Round($release.size / 1MB)) MB, this can take a few minutes)..." $exe = Join-Path $tmp "Brocoded-Setup-x64.exe" # stream it ourselves so there is a live progress line (Invoke-WebRequest's own bar is far too slow to leave on, and # without it a 130 MB download looks frozen for minutes); a stalled connection fails after 60 s instead of hanging $req = [Net.HttpWebRequest]::Create($release.url) $req.Timeout = 60000 $req.ReadWriteTimeout = 60000 $res = $req.GetResponse() $total = if ($res.ContentLength -gt 0) { $res.ContentLength } else { [int64]$release.size } $in = $res.GetResponseStream() $out = [IO.File]::Create($exe) try { $buf = New-Object byte[] 262144 $done = [int64]0 $last = -1 $clock = [Diagnostics.Stopwatch]::StartNew() while (($n = $in.Read($buf, 0, $buf.Length)) -gt 0) { $out.Write($buf, 0, $n) $done += $n $pct = [int][math]::Floor($done * 100 / $total) if ($pct -ne $last) { $last = $pct $mbps = ($done / 1MB) / [math]::Max($clock.Elapsed.TotalSeconds, 0.1) Write-Host -NoNewline ("`r {0,3}% {1:N0} of {2:N0} MB ({3:N1} MB/s) " -f $pct, ($done / 1MB), ($total / 1MB), $mbps) } } Write-Host "" } finally { $out.Dispose(); $in.Dispose(); $res.Dispose() } $got = (Get-Item $exe).Length if ($got -ne [int64]$release.size) { Write-Host "The download is incomplete ($got of $($release.size) bytes). Please try again."; return } if ($release.sha256) { $have = (Get-FileHash -Algorithm SHA256 $exe).Hash.ToLower() if ($have -ne $release.sha256.ToLower()) { Write-Host "The download doesn't match its checksum. Nothing was installed. Please try again."; return } } if ($env:BROCODED_DRY -eq "1") { Write-Host "Dry run: downloaded and checked Brocoded $($release.version). Nothing was installed."; return } # close the running app and its daemon (sessions running under it stop and come back when it reopens) $dir = Join-Path $env:LOCALAPPDATA "Programs\Brocoded" $running = Get-Process -ErrorAction SilentlyContinue | Where-Object { $_.Path -and $_.Path.StartsWith($dir, [StringComparison]::OrdinalIgnoreCase) } if ($running) { Write-Host "Closing the running Brocoded..." $running | Stop-Process -Force -ErrorAction SilentlyContinue Start-Sleep -Seconds 2 } Write-Host "Installing..." $p = Start-Process -FilePath $exe -ArgumentList "/S" -Wait -PassThru if ($p.ExitCode -ne 0) { Write-Host "The installer stopped with code $($p.ExitCode). Try the download on $site/downloads/ instead."; return } $app = Join-Path $dir "Brocoded.exe" if (-not (Test-Path $app)) { Write-Host "Installed, but Brocoded.exe was not found in $dir. Open Brocoded from the Start menu."; return } Write-Host "Installed Brocoded $($release.version). Opening it..." Start-Process -FilePath $app Write-Host "If Windows Defender Firewall asks, allow Brocoded on private networks." } finally { Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue } }