# Installs the Buraq command line tool on Windows. # # irm https://staging.buraq.fly/install.ps1 | iex # # It downloads the build for this computer, checks it against SHA256SUMS, checks that list's # signature with the key below, and only then puts buraq.exe in your user folder and on your PATH. # It needs no administrator rights. Read it first if you like; it is short. # # $env:BURAQ_INSTALL_DIR where to put it (default %LOCALAPPDATA%\Programs\Buraq) & { $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' # Windows PowerShell 5 may otherwise offer TLS 1.0, which Buraq refuses. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $api = 'https://staging-api.buraq.fly' $key = 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB7Whyoic/hv40YxvsiTFth27XsVkVy5E8FVBCmHCL5G' $dir = if ($env:BURAQ_INSTALL_DIR) { $env:BURAQ_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA 'Programs\Buraq' } function Say($text) { Write-Host " $text" } function Fail($text) { throw "Buraq was not installed: $text" } # Windows on Arm runs the x64 build through its emulator. if (-not [Environment]::Is64BitOperatingSystem) { Fail 'there is no 32-bit Windows build.' } $platform = 'windows-x86_64' $work = Join-Path ([IO.Path]::GetTempPath()) ('buraq-' + [Guid]::NewGuid()) New-Item -ItemType Directory -Path $work | Out-Null try { Say "Downloading Buraq for $platform" $sums = Join-Path $work 'SHA256SUMS' $sig = Join-Path $work 'SHA256SUMS.sig' Invoke-WebRequest -UseBasicParsing "$api/v1/downloads/cli/SHA256SUMS" -OutFile $sums Invoke-WebRequest -UseBasicParsing "$api/v1/downloads/cli/SHA256SUMS.sig" -OutFile $sig # The signature proves the list came from Buraq, even if the server that sent it did not. # ssh-keygen comes with Windows 10 and 11. The list goes in as a file, byte for byte. $sshKeygen = Get-Command ssh-keygen -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1 if (-not $sshKeygen) { Fail 'Install OpenSSH 8.1 or later to verify the release signature.' } $signers = Join-Path $work 'allowed_signers' $err = Join-Path $work 'err' [IO.File]::WriteAllText($signers, "buraq namespaces=`"buraq-release`" $key`n") $run = Start-Process -FilePath $sshKeygen.Source -NoNewWindow -Wait -PassThru ` -ArgumentList @('-Y', 'verify', '-f', "`"$signers`"", '-I', 'buraq', '-n', 'buraq-release', '-s', "`"$sig`"") ` -RedirectStandardInput $sums -RedirectStandardOutput (Join-Path $work 'out') -RedirectStandardError $err if ($run.ExitCode -ne 0) { Fail 'The release signature could not be verified. This requires OpenSSH 8.1 or later.' } Say 'Signature checked' # Files are named buraq--, which the signature covers. $line = Get-Content $sums | Where-Object { $_ -match "^([0-9a-f]{64}) (buraq-(\S+-)?$platform\.zip)$" } | Select-Object -First 1 if (-not $line) { Fail "this release has no build for $platform." } $null = $line -match '^([0-9a-f]{64}) (\S+)$' $want = $Matches[1] $zip = Join-Path $work $Matches[2] Invoke-WebRequest -UseBasicParsing "$api/v1/downloads/cli/$platform" -OutFile $zip if ((Get-FileHash -Algorithm SHA256 $zip).Hash.ToLower() -ne $want) { Fail 'the download does not match its checksum. Nothing was changed.' } Say 'Checksum matches' Expand-Archive -Path $zip -DestinationPath (Join-Path $work 'x') -Force New-Item -ItemType Directory -Path $dir -Force | Out-Null $exe = Join-Path $dir 'buraq.exe' Copy-Item (Join-Path $work 'x\buraq.exe') $exe -Force Unblock-File $exe $path = [Environment]::GetEnvironmentVariable('Path', 'User') if (-not (($path -split ';') -contains $dir)) { [Environment]::SetEnvironmentVariable('Path', ((@($path, $dir) | Where-Object { $_ }) -join ';'), 'User') $env:Path = "$env:Path;$dir" Say "Added $dir to your PATH. New terminals will find buraq." } Say "Installed $(& $exe --version) in $dir" Say 'Run: buraq' } finally { Remove-Item -Recurse -Force $work -ErrorAction SilentlyContinue } }