# SBX Connect bootstrap for Windows (download only). Read it before you run it. # 1. Detects your CPU and downloads the matching SBX Connect file from connect.sbx360.com. # 2. Verifies its SHA-256 against the release manifest (and against -Sha256 if you pass one). # 3. Saves it to %LOCALAPPDATA%\SBX360\Connect and removes the "downloaded from internet" mark. # It never installs a service, never needs administrator rights, never runs the downloaded file. # Uninstall: delete the folder %LOCALAPPDATA%\SBX360\Connect. # Flags: -Version X.Y.Z -Sha256 HEX -Tool sbx-connect|sbx-sap-test -BaseUrl URL -DryRun [CmdletBinding()] param( [string]$Version = '', [string]$Sha256 = '', [ValidateSet('sbx-connect', 'sbx-sap-test')][string]$Tool = 'sbx-connect', [string]$BaseUrl = 'https://connect.sbx360.com', [switch]$DryRun ) Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' function Fail([string]$m) { throw "error: $m" } try { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 } catch { } $BaseUrl = $BaseUrl.TrimEnd('/') if ($BaseUrl -notmatch '^https://' -and $BaseUrl -notmatch '^http://(localhost|127\.0\.0\.1)(:\d+)?(/|$)') { Fail '-BaseUrl must be https (or http://localhost for testing)' } $verRe = '^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$' if ($Version -ne '' -and $Version -notmatch $verRe) { Fail 'invalid -Version' } if ($Sha256 -ne '') { $Sha256 = $Sha256.ToLowerInvariant() if ($Sha256 -notmatch '^[0-9a-f]{64}$') { Fail '-Sha256 must be 64 hex characters' } } $archRaw = if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE } switch ($archRaw) { 'AMD64' { $arch = 'amd64' } 'ARM64' { $arch = 'arm64' } default { Fail "unsupported CPU $archRaw" } } $name = "$Tool-windows-$arch.exe" $manifestUrl = if ($Version -ne '') { "$BaseUrl/releases/$Version/manifest.json" } else { "$BaseUrl/releases/latest/manifest.json" } Write-Host "Fetching manifest: $manifestUrl" try { $manifest = (Invoke-WebRequest -UseBasicParsing -Uri $manifestUrl -TimeoutSec 60).Content | ConvertFrom-Json } catch { Fail "could not download the manifest: $($_.Exception.Message)" } if ($manifest -is [byte[]]) { $manifest = [Text.Encoding]::UTF8.GetString($manifest) | ConvertFrom-Json } $relVersion = [string]$manifest.version if ($relVersion -notmatch $verRe) { Fail 'manifest has no valid version' } if ($Version -ne '' -and $Version -ne $relVersion) { Fail "manifest version $relVersion does not match requested $Version" } $entry = @($manifest.files | Where-Object { $_.name -ceq $name }) | Select-Object -First 1 if (-not $entry) { Fail "release $relVersion has no file $name for this computer" } $manifestSha = ([string]$entry.sha256).ToLowerInvariant() if ($manifestSha -notmatch '^[0-9a-f]{64}$') { Fail "manifest entry for $name has no valid sha256" } # The URL is built from the version and the file name computed here, never taken from the manifest. $fileUrl = "$BaseUrl/releases/$relVersion/$name" $destDir = Join-Path $env:LOCALAPPDATA 'SBX360\Connect' $target = Join-Path $destDir $name Write-Host "Release: $relVersion" Write-Host "File: $name" Write-Host "Manifest sha256: $manifestSha" Write-Host "Source: $fileUrl" Write-Host "Target: $target" if ($DryRun) { Write-Host 'Dry run: nothing downloaded or written.'; exit 0 } New-Item -ItemType Directory -Force -Path $destDir | Out-Null $part = Join-Path $destDir "$name.part" try { Write-Host 'Downloading...' Invoke-WebRequest -UseBasicParsing -Uri $fileUrl -OutFile $part -TimeoutSec 300 $got = (Get-FileHash -Algorithm SHA256 -LiteralPath $part).Hash.ToLowerInvariant() Write-Host "Computed sha256: $got" if ($got -ne $manifestSha) { Fail 'sha256 does not match the manifest. File discarded.' } if ($Sha256 -ne '') { if ($got -ne $Sha256) { Fail 'sha256 does not match the value you passed (-Sha256). File discarded.' } Write-Host 'Matches the value you passed.' } else { Write-Host 'Tip: compare this hash with the one your SBX360 contact gives you by phone or chat (-Sha256).' } Unblock-File -LiteralPath $part Move-Item -Force -LiteralPath $part -Destination $target } finally { if (Test-Path -LiteralPath $part) { Remove-Item -Force -LiteralPath $part } } Write-Host '' Write-Host "Saved: $target" Write-Host "Run it: & `"$target`"" Write-Host "Uninstall: Remove-Item -Recurse -Force `"$destDir`""