<# Route6 client installer for Windows. irm https://dl.route6.me/install.ps1 | iex With your API key: $env:ROUTE6_API_KEY="sk_a6_..."; irm https://dl.route6.me/install.ps1 | iex With options: & ([scriptblock]::Create((irm https://dl.route6.me/install.ps1))) -Version v1.3.0 -DryRun The Windows twin of install.sh (r6me-client.md WU-1.5a / Appendix A). It works out your architecture, resolves the version, downloads the matching build AND the checksum manifest, REFUSES TO CONTINUE unless they match, then installs r6me.exe for the current user. No administrator rights: the binary goes to %LOCALAPPDATA%\Programs\r6me and that folder is added to your user PATH. It runs on Windows PowerShell 5.1 (built into Windows 10/11) and PowerShell 7. Environment: ROUTE6_API_KEY, R6ME_VERSION, R6ME_BASE_URL, R6ME_INSTALL_DIR, R6ME_ARCH_OVERRIDE (tests). Errors are thrown, never `exit`: under `irm | iex` this script runs inside the user's own PowerShell session, and `exit` would close their window. #> param( [string]$Version = $env:R6ME_VERSION, [string]$Key = $env:ROUTE6_API_KEY, [string]$Dir = $env:R6ME_INSTALL_DIR, [switch]$DryRun, [switch]$Help ) $ErrorActionPreference = 'Stop' # Windows PowerShell 5.1 redraws a progress bar per chunk, which makes a # download many times slower. $ProgressPreference = 'SilentlyContinue' function Say([string]$m) { Write-Host $m } function Die([string]$m) { Write-Host "error: $m" -ForegroundColor Red throw "r6me install failed: $m" } if ($Help) { Say 'Route6 client installer (Windows)' Say '' Say ' irm https://dl.route6.me/install.ps1 | iex' Say '' Say 'Options (via & ([scriptblock]::Create((irm https://dl.route6.me/install.ps1))) ):' Say ' -Version vX.Y.Z install a specific version (default: current stable)' Say ' -Key sk_a6_... write %USERPROFILE%\.r6me\config.toml with this API key' Say ' -Dir install directory (default: %LOCALAPPDATA%\Programs\r6me)' Say ' -DryRun report what would happen and change nothing' return } $BaseUrl = 'https://dl.route6.me' if ($env:R6ME_BASE_URL) { $BaseUrl = $env:R6ME_BASE_URL.TrimEnd('/') } $MirrorUrl = 'https://github.com/route6me/r6me-releases/releases/download' # Windows PowerShell 5.1 still offers TLS 1.0 first; our hosts require 1.2+. [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 # ---------------------------------------------------------------- platform --- $onWindows = ($PSVersionTable.PSEdition -ne 'Core') -or $IsWindows if (-not $onWindows -and -not $env:R6ME_ALLOW_NON_WINDOWS) { Die 'this installer is for Windows. On Linux and macOS use: curl -fsSL https://dl.route6.me/install.sh | sh' } # A 32-bit PowerShell on 64-bit Windows reports x86 in PROCESSOR_ARCHITECTURE # and the real machine in PROCESSOR_ARCHITEW6432. $rawArch = $env:R6ME_ARCH_OVERRIDE if (-not $rawArch) { $rawArch = $env:PROCESSOR_ARCHITEW6432 } if (-not $rawArch) { $rawArch = $env:PROCESSOR_ARCHITECTURE } switch ($rawArch) { 'AMD64' { $Arch = 'amd64' } 'ARM64' { $Arch = 'arm64' } default { Die "unsupported architecture: $rawArch. Windows builds exist for amd64 and arm64; see $BaseUrl/" } } # ----------------------------------------------------------------- version --- if (-not $Version) { try { $Version = ([string](Invoke-RestMethod -UseBasicParsing -Uri "$BaseUrl/stable")).Trim() } catch { Die "could not resolve the current version from $BaseUrl/stable - pass -Version vX.Y.Z" } } if (-not $Version.StartsWith('v')) { $Version = "v$Version" } $Bare = $Version.Substring(1) $Asset = "r6me_${Bare}_windows_${Arch}.zip" # ------------------------------------------------------------- destination --- if (-not $Dir) { if ($env:LOCALAPPDATA) { $Dir = Join-Path $env:LOCALAPPDATA 'Programs\r6me' } else { $Dir = Join-Path $HOME 'Programs\r6me' } } Say "Route6 client $Version" Say " platform: windows/$Arch" Say " source: $BaseUrl/$Version/$Asset" Say " install: $(Join-Path $Dir 'r6me.exe')" if ($DryRun) { Say '' Say '-DryRun: nothing was changed.' return } # ------------------------------------------------------------- download ------ $tmp = Join-Path ([IO.Path]::GetTempPath()) ('r6me-' + [guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Path $tmp | Out-Null try { $zip = Join-Path $tmp $Asset $sums = Join-Path $tmp 'checksums.txt' Say '' Say 'downloading...' try { Invoke-WebRequest -UseBasicParsing -Uri "$BaseUrl/$Version/$Asset" -OutFile $zip try { Invoke-WebRequest -UseBasicParsing -Uri "$BaseUrl/$Version/checksums.txt" -OutFile $sums } catch { Die 'could not download checksums.txt - refusing to install an unverified binary' } } catch { if ($_.Exception.Message -like 'r6me install failed*') { throw } Say " $BaseUrl unreachable, trying the public mirror" try { Invoke-WebRequest -UseBasicParsing -Uri "$MirrorUrl/$Version/$Asset" -OutFile $zip Invoke-WebRequest -UseBasicParsing -Uri "$MirrorUrl/$Version/checksums.txt" -OutFile $sums } catch { Die "could not download $Asset and its checksums from either location" } } # ----------------------------------------------------------- verify ------ # Fail closed on every branch: a missing manifest line is as bad as a # mismatch, because both mean we cannot say what we just downloaded. $want = $null foreach ($line in [IO.File]::ReadAllLines($sums)) { $parts = $line.Trim() -split '\s+' if ($parts.Count -eq 2 -and $parts[1] -eq $Asset) { $want = $parts[0].ToLowerInvariant() } } if (-not $want) { Die "checksum for $Asset is not listed in checksums.txt - refusing to install" } $got = (Get-FileHash -Algorithm SHA256 -Path $zip).Hash.ToLowerInvariant() if ($want -ne $got) { Write-Host " expected: $want" Write-Host " actual: $got" Die "checksum mismatch for $Asset - refusing to install; the download does not match the published checksum" } Say ' checksum verified' if ($env:R6ME_TEST_STOP_AFTER_VERIFY) { Say ' (test mode: stopping after verification)' return } # ---------------------------------------------------------- install ------ $unpacked = Join-Path $tmp 'x' Expand-Archive -Path $zip -DestinationPath $unpacked -Force $exe = Join-Path $unpacked 'r6me.exe' if (-not (Test-Path $exe)) { Die 'archive did not contain r6me.exe' } New-Item -ItemType Directory -Force -Path $Dir | Out-Null $target = Join-Path $Dir 'r6me.exe' $staged = Join-Path $Dir 'r6me.exe.new' Copy-Item -Force -Path $exe -Destination $staged # A running r6me.exe cannot be overwritten on Windows, but it can be # renamed: move the old one aside, then put the new one in its place. if (Test-Path $target) { $old = Join-Path $Dir 'r6me.exe.old' Remove-Item -Force -ErrorAction SilentlyContinue $old Move-Item -Force -Path $target -Destination $old } Move-Item -Force -Path $staged -Destination $target Remove-Item -Force -ErrorAction SilentlyContinue (Join-Path $Dir 'r6me.exe.old') Say " installed $target" # PATH: the USER's, never the machine's (that would need administrator). $userPath = [Environment]::GetEnvironmentVariable('Path', 'User') if (-not $userPath) { $userPath = '' } $entries = $userPath.Split(';') | Where-Object { $_ -ne '' } if ($entries -notcontains $Dir) { $newPath = (@($entries) + $Dir) -join ';' [Environment]::SetEnvironmentVariable('Path', $newPath, 'User') $env:Path = "$env:Path;$Dir" Say " added $Dir to your user PATH (open a new terminal for other windows to see it)" } # ----------------------------------------------------------- config ------ # Written as UTF-8 WITHOUT a byte-order mark: Windows PowerShell 5.1's # Out-File / Set-Content add one, and the client reads plain UTF-8 TOML. $noBom = New-Object System.Text.UTF8Encoding($false) $home6 = $env:USERPROFILE if (-not $home6) { $home6 = $HOME } $stateDir = Join-Path $home6 '.r6me' New-Item -ItemType Directory -Force -Path $stateDir | Out-Null # Record how the binary got here (the install-channel metric). Never # overwrite an existing marker: another installer may have put it there. $marker = Join-Path $stateDir 'install_channel' if (-not (Test-Path $marker) -or ((Get-Item $marker).Length -eq 0)) { [IO.File]::WriteAllText($marker, "powershell`n", $noBom) } if ($Key) { $cfg = Join-Path $stateDir 'config.toml' if ((Test-Path $cfg) -and ([IO.File]::ReadAllText($cfg) -match '(?m)^\s*api_key')) { Say " $cfg already has a key - left alone" } else { [IO.File]::WriteAllText($cfg, "api_key = `"$Key`"`n", $noBom) Say " wrote $cfg" } } Say '' Say "$(& $target version)" Say '' Say 'Next: r6me up' Say 'There is no Windows service yet: start it with `r6me up` after each sign-in.' } finally { Remove-Item -Recurse -Force -ErrorAction SilentlyContinue $tmp }