#Requires -Version 5.1 <# .SYNOPSIS RasterizedDB: download the latest server release for this Windows machine, check it against the release's SHA256SUMS, and install rasterizeddb.exe. .EXAMPLE .\setup.ps1 .\setup.ps1 -InstallDir 'C:\Program Files\RasterizedDB' -AddToPath #> [CmdletBinding()] param( # Where rasterizeddb.exe goes. [string]$InstallDir = $(if ($env:RDB_INSTALL_DIR) { $env:RDB_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA 'Programs\RasterizedDB' }), # A version such as 1.1.0, or latest. [string]$Version = $(if ($env:RDB_VERSION) { $env:RDB_VERSION } else { 'latest' }), # A release archive already on disk: skips the download. [string]$Archive = $env:RDB_ARCHIVE, [string]$Repo = $(if ($env:RDB_REPO) { $env:RDB_REPO } else { 'milen-denev/rasterizeddb' }), # Also put InstallDir on this user's PATH. [switch]$AddToPath ) $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' # Invoke-WebRequest is far faster without the progress bar [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 $osArch = $env:PROCESSOR_ARCHITECTURE try { $osArch = [string][System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture } catch { } switch -Regex ($osArch) { '^(X64|AMD64)$' { $platform = 'windows-x86_64' } '^(Arm64|ARM64)$' { $platform = 'windows-arm64' } default { throw "No release binary for architecture '$osArch': there are x86_64 and arm64 builds." } } $work = Join-Path ([System.IO.Path]::GetTempPath()) ("rdb-install-" + [guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Force -Path $work | Out-Null try { if ($Archive) { if (-not (Test-Path -LiteralPath $Archive -PathType Leaf)) { throw "Archive '$Archive' is not a file." } $zip = (Resolve-Path -LiteralPath $Archive).Path Write-Host "Using $zip (no download, no checksum check)" } else { $headers = @{ 'User-Agent' = 'rasterizeddb-install-script' } if ($Version -eq 'latest') { # The newest release tagged v..; client-v…, # server-v… and pre-release tags are skipped. $releases = Invoke-RestMethod -Headers $headers -Uri "https://api.github.com/repos/$Repo/releases?per_page=30" $tag = $releases | Where-Object { $_.tag_name -match '^v\d+\.\d+\.\d+$' } | Select-Object -First 1 -ExpandProperty tag_name if (-not $tag) { throw 'Could not find a release; pass -Version, or -Archive with a downloaded archive.' } $Version = $tag } $Version = $Version.TrimStart('v') $name = "rasterizeddb-server-$Version-$platform.zip" $base = "https://github.com/$Repo/releases/download/v$Version" $zip = Join-Path $work $name Write-Host "Downloading $name" Invoke-WebRequest -UseBasicParsing -Headers $headers -Uri "$base/$name" -OutFile $zip $sums = Join-Path $work 'SHA256SUMS' Invoke-WebRequest -UseBasicParsing -Headers $headers -Uri "$base/SHA256SUMS" -OutFile $sums $line = Get-Content $sums | Where-Object { $_ -match ('\s' + [regex]::Escape($name) + '$') } | Select-Object -First 1 if (-not $line) { throw "$name is not listed in SHA256SUMS." } $expected = ($line -split '\s+')[0].ToLowerInvariant() $actual = (Get-FileHash -Algorithm SHA256 -LiteralPath $zip).Hash.ToLowerInvariant() if ($expected -ne $actual) { throw "Checksum mismatch for ${name}: expected $expected, got $actual." } } $unpacked = Join-Path $work 'unpacked' Expand-Archive -LiteralPath $zip -DestinationPath $unpacked -Force $exe = Get-ChildItem -Path $unpacked -Recurse -Filter 'rasterizeddb.exe' | Select-Object -First 1 if (-not $exe) { throw "No rasterizeddb.exe in $zip." } New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null $target = Join-Path $InstallDir 'rasterizeddb.exe' Copy-Item -LiteralPath $exe.FullName -Destination $target -Force } finally { Remove-Item -LiteralPath $work -Recurse -Force -ErrorAction SilentlyContinue } & $target --version if ($LASTEXITCODE -ne 0) { throw "$target did not run (exit $LASTEXITCODE)." } Write-Host "Installed $target" if ($AddToPath) { $userPath = [Environment]::GetEnvironmentVariable('Path', 'User') if (-not (($userPath -split ';') -contains $InstallDir)) { [Environment]::SetEnvironmentVariable('Path', ($(if ($userPath) { "$userPath;" } else { '' }) + $InstallDir), 'User') Write-Host "Added $InstallDir to your PATH (open a new terminal to use it)." } } Write-Host 'Next: rasterizeddb.exe --help lists every option; the local-dev script starts a server to try.'