# RDX installer for Windows: installs the `rdx` CLI. # irm https://getrdx.io/install.ps1 | iex # # `iex` cannot take parameters, so options come from environment variables: # RDX_VERSION install this release instead of the latest # RDX_CHANNEL channel (default: release) # RDX_INSTALL_DIR install directory (default: $env:LOCALAPPDATA\Programs\RDX\bin) # RDX_DL_BASE download base URL (default: https://dl.getrdx.io) # RDX_UNINSTALL set to 1 to remove rdx.exe and its PATH entry # RDX_DRY_RUN set to 1 to show what would happen and change nothing # # Everything lives in a function invoked on the last line, so a truncated # download installs nothing. The script never calls `exit`, so it cannot # close the shell it is piped into. function Install-Rdx { Set-StrictMode -Version 2.0 $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 $dlBase = $env:RDX_DL_BASE if (-not $dlBase) { $dlBase = 'https://dl.getrdx.io' } $dlBase = $dlBase.TrimEnd('/') $version = $env:RDX_VERSION $channel = $env:RDX_CHANNEL if (-not $channel) { $channel = 'release' } $installDir = $env:RDX_INSTALL_DIR if (-not $installDir) { $installDir = Join-Path $env:LOCALAPPDATA 'Programs\RDX\bin' } $uninstall = ($env:RDX_UNINSTALL -eq '1') $dryRun = ($env:RDX_DRY_RUN -eq '1') if ($channel -notmatch '^[A-Za-z0-9._-]+$') { throw "Invalid channel: $channel" } if ($version -and $version -notmatch '^[A-Za-z0-9._+-]+$') { throw "Invalid version: $version" } if ($uninstall) { Uninstall-Rdx -InstallDir $installDir -DryRun $dryRun return } Assert-SupportedPlatform if ($version) { $manifestUrl = "$dlBase/v$($version.TrimStart('v'))/manifest.json" } elseif ($channel -eq 'release') { $manifestUrl = "$dlBase/latest.json" } else { $manifestUrl = "$dlBase/$channel/latest.json" } $manifest = Get-RdxManifest -Url $manifestUrl -HasVersion ([bool]$version) if (-not $manifest) { return } $artifact = $null $prop = $manifest.artifacts.PSObject.Properties['windows-x64'] if ($prop) { $artifact = $prop.Value } if (-not $artifact) { throw 'This release has no build for windows-x64.' } $sha = ([string]$artifact.sha256).ToLowerInvariant() if ($sha -notmatch '^[0-9a-f]{64}$') { throw 'The release manifest has an invalid checksum.' } $artifactUrl = [string]$artifact.url if ($artifactUrl -notmatch '^https?://') { $artifactUrl = "$dlBase/$artifactUrl" } Write-Host "RDX $($manifest.version) for windows-x64" if ($dryRun) { Write-Host "[dry-run] would download $artifactUrl ($($artifact.size) bytes)" Write-Host "[dry-run] would verify SHA-256 $sha" Write-Host "[dry-run] would install to $installDir\rdx.exe and add it to your user PATH" return } $work = Join-Path ([IO.Path]::GetTempPath()) ("rdx-install-" + [Guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Path $work | Out-Null try { $zip = Join-Path $work 'rdx.zip' Invoke-WebRequest -UseBasicParsing -Uri $artifactUrl -OutFile $zip if ((Get-Item $zip).Length -ne [int64]$artifact.size) { throw "Download size mismatch (expected $($artifact.size) bytes). Nothing was installed." } $actual = (Get-FileHash -Algorithm SHA256 -Path $zip).Hash.ToLowerInvariant() if ($actual -ne $sha) { throw "SHA-256 mismatch (expected $sha, got $actual). Nothing was installed." } $extract = Join-Path $work 'extract' Expand-Archive -Path $zip -DestinationPath $extract -Force Assert-NoZipSlip -Root $extract $newExe = Join-Path $extract 'rdx.exe' if (-not (Test-Path -LiteralPath $newExe -PathType Leaf)) { throw 'The archive does not contain rdx.exe.' } New-Item -ItemType Directory -Force -Path $installDir | Out-Null $staged = Join-Path $installDir ".rdx.install.$PID.exe" $target = Join-Path $installDir 'rdx.exe' Copy-Item -LiteralPath $newExe -Destination $staged -Force Move-Item -LiteralPath $staged -Destination $target -Force } finally { Remove-Item -LiteralPath $work -Recurse -Force -ErrorAction SilentlyContinue } Add-UserPath -Dir $installDir Write-Host "Installed $target" & $target --version Write-Host 'Open a new terminal for the PATH change to take effect, then run: rdx host or rdx join ' } function Assert-SupportedPlatform { if (-not [Environment]::Is64BitOperatingSystem) { throw 'RDX needs 64-bit Windows.' } $arch = $env:PROCESSOR_ARCHITEW6432 if (-not $arch) { $arch = $env:PROCESSOR_ARCHITECTURE } if ($arch -ne 'AMD64') { throw "Windows on $arch is not supported. RDX supports Windows x64 only." } } # Returns the parsed manifest, or $null after printing the no-release message. function Get-RdxManifest { param([string]$Url, [bool]$HasVersion) try { $response = Invoke-WebRequest -UseBasicParsing -Uri $Url } catch { $status = $null $resp = $_.Exception.PSObject.Properties['Response'] if ($resp -and $resp.Value) { $status = [int]$resp.Value.StatusCode } if ($status -eq 404) { if ($HasVersion) { throw "That RDX version was not found." } Write-Host 'No RDX release is published yet.' return $null } throw "Could not download ${Url}: $($_.Exception.Message)" } $content = $response.Content if ($content -is [byte[]]) { $content = [Text.Encoding]::UTF8.GetString($content) } return ($content | ConvertFrom-Json) } function Assert-NoZipSlip { param([string]$Root) $rootFull = [IO.Path]::GetFullPath($Root).TrimEnd('\') + '\' Get-ChildItem -LiteralPath $Root -Recurse -Force | ForEach-Object { $full = [IO.Path]::GetFullPath($_.FullName) if (-not $full.StartsWith($rootFull, [StringComparison]::OrdinalIgnoreCase)) { throw "Unsafe path in archive: $($_.FullName)" } } } function Add-UserPath { param([string]$Dir) $current = [Environment]::GetEnvironmentVariable('Path', 'User') if (-not $current) { $current = '' } $entries = $current -split ';' | Where-Object { $_ } if ($entries -contains $Dir) { return } $new = (@($entries) + $Dir) -join ';' [Environment]::SetEnvironmentVariable('Path', $new, 'User') } function Remove-UserPath { param([string]$Dir) $current = [Environment]::GetEnvironmentVariable('Path', 'User') if (-not $current) { return } $entries = @($current -split ';' | Where-Object { $_ -and ($_ -ne $Dir) }) [Environment]::SetEnvironmentVariable('Path', ($entries -join ';'), 'User') } function Uninstall-Rdx { param([string]$InstallDir, [bool]$DryRun) $target = Join-Path $InstallDir 'rdx.exe' if ($DryRun) { Write-Host "[dry-run] would remove $target and its user PATH entry" return } if (Test-Path -LiteralPath $target) { Remove-Item -LiteralPath $target -Force Write-Host "Removed $target" } else { Write-Host "Nothing to remove: $target does not exist." } Remove-UserPath -Dir $InstallDir } Install-Rdx