# fedtrustctl installer for Windows. # # irm https://federatedtrust.com/install.ps1 | iex # # Downloads the published fedtrustctl for this computer, checks its SHA-256 # against the published release index, and installs it for the current user at # %LOCALAPPDATA%\Programs\fedtrustctl\fedtrustctl.exe. It needs no administrator # rights, and it installs nothing unless the checksum matches. # # Environment: # FEDTRUSTCTL_INSTALL_DIR Directory to install into. # FEDTRUSTCTL_INSTALL_ORIGIN Origin to download from (default: # https://federatedtrust.com). For testing a mirror. # # Written for Windows PowerShell 5.1 and PowerShell 7. Failures are thrown, never # `exit`, so a failed install does not close the window it was pasted into. & { $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' $program = 'fedtrustctl' $defaultOrigin = 'https://federatedtrust.com' $indexPath = '/downloads/fedtrustctl/latest.json' $downloadPrefix = '/downloads/fedtrustctl' $indexSchema = 'federatedtrust.fedtrustctl-release/v1' $origin = $defaultOrigin if ($env:FEDTRUSTCTL_INSTALL_ORIGIN) { $origin = $env:FEDTRUSTCTL_INSTALL_ORIGIN.TrimEnd('/') } if ($env:OS -ne 'Windows_NT') { throw "$program install: this script is for Windows. On macOS or Linux run: curl -fsSL $defaultOrigin/install.sh | sh" } # A 32-bit PowerShell on 64-bit Windows reports the real processor in PROCESSOR_ARCHITEW6432. $arch = $env:PROCESSOR_ARCHITECTURE if ($env:PROCESSOR_ARCHITEW6432) { $arch = $env:PROCESSOR_ARCHITEW6432 } if ($arch -ne 'AMD64') { throw "$program install: there is no build for Windows on $arch. Nothing was installed." } $platform = 'windows-x64' if ($env:FEDTRUSTCTL_INSTALL_DIR) { $installDir = $env:FEDTRUSTCTL_INSTALL_DIR } elseif ($env:LOCALAPPDATA) { $installDir = Join-Path $env:LOCALAPPDATA 'Programs\fedtrustctl' } else { throw "$program install: LOCALAPPDATA is not set; set FEDTRUSTCTL_INSTALL_DIR to choose where to install." } # Windows PowerShell 5.1 does not always offer TLS 1.2 by default. try { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 } catch { Write-Verbose 'TLS 1.2 is already the default here.' } $indexUrl = "$origin$indexPath" try { $index = Invoke-RestMethod -Uri $indexUrl -UseBasicParsing } catch { throw "$program install: could not read the release index at $indexUrl. No release may be published yet. Nothing was installed." } if ($index.schema -ne $indexSchema) { throw "$program install: the release index at $indexUrl is not one this installer understands. Nothing was installed." } $artifact = $null foreach ($candidate in @($index.artifacts)) { if ($candidate.platform -eq $platform) { $artifact = $candidate } } if ($null -eq $artifact -or "$($artifact.sha256)" -cnotmatch '^[0-9a-f]{64}$') { throw "$program install: the published release has no build for $platform. Nothing was installed." } $expected = "$($artifact.sha256)" New-Item -ItemType Directory -Force -Path $installDir | Out-Null $destination = Join-Path $installDir "$program.exe" # The temporary file lives beside the destination, so the final step is a rename on one volume. $temporary = Join-Path $installDir ".$program.$PID.download" $downloadUrl = "$origin$downloadPrefix/$platform" try { Write-Host "Downloading $program $($index.version) for $platform..." try { Invoke-WebRequest -Uri $downloadUrl -OutFile $temporary -UseBasicParsing } catch { throw "$program install: the download from $downloadUrl failed. Nothing was installed." } $actual = (Get-FileHash -LiteralPath $temporary -Algorithm SHA256).Hash.ToLowerInvariant() if ($actual -cne $expected) { throw "$program install: checksum mismatch for ${platform}: the release index says $expected but the download is $actual. Nothing was installed." } try { Move-Item -LiteralPath $temporary -Destination $destination -Force } catch { throw "$program install: could not write $destination. If $program is running (an agent may have started it), close it and run this again. Nothing was installed." } } finally { if (Test-Path -LiteralPath $temporary) { Remove-Item -LiteralPath $temporary -Force } } Write-Host "Installed $program $($index.version) to $destination (SHA-256 $expected)." $onPath = $false foreach ($entry in "$env:Path".Split(';')) { if ($entry.TrimEnd('\') -ieq $installDir.TrimEnd('\')) { $onPath = $true } } if ($onPath) { Write-Host "Next: $program resources" } else { Write-Host "$installDir is not on your PATH. Add it for new windows with:" Write-Host " [Environment]::SetEnvironmentVariable('Path', '$installDir;' + [Environment]::GetEnvironmentVariable('Path', 'User'), 'User')" Write-Host "Next: & '$destination' resources" } }