Files
releases/install.ps1
2026-10-03 10:01:04 +02:00

43 lines
2.4 KiB
PowerShell

# Agent Hub's install: installs the newest Agent Hub for this user and opens it; running it again updates (HUB-10).
# Its line: irm https://git.bengles.se/agent-hub/releases/raw/branch/main/install.ps1 | iex
# AGENT_HUB_SETUP_ARGS, when set, is added to the setup's arguments, e.g. --no-start.
& {
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
$v = $PSVersionTable.PSVersion
if ($v.Major -lt 5 -or ($v.Major -eq 5 -and $v.Minor -lt 1) -or ($PSVersionTable.PSEdition -eq 'Core' -and -not $IsWindows)) {
Write-Host 'This line installs Agent Hub on Windows, from PowerShell 5.1 or later. On Linux, run the curl line instead.' -ForegroundColor Red
return
}
if ($PSVersionTable.PSEdition -ne 'Core') {
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
}
$exe = Join-Path $env:TEMP 'agent-hub-setup.exe'
Write-Host 'Downloading Agent Hub...'
try {
Invoke-WebRequest -Uri 'https://git.bengles.se/agent-hub/releases/releases/download/latest/agent-hub-setup.exe' -OutFile $exe -UseBasicParsing
} catch {
$failure = $_
$status = 0
try { $status = [int]$failure.Exception.Response.StatusCode } catch {}
if ($status -eq 0) {
try { Invoke-WebRequest -Uri 'https://git.bengles.se/agent-hub/releases/releases/download/latest/agent-hub-setup.exe' -Method Head -UseBasicParsing | Out-Null }
catch { try { $status = [int]$_.Exception.Response.StatusCode } catch {} }
}
if ($status -eq 404) { Write-Host 'Can''t download Agent Hub from git.bengles.se/agent-hub/releases: it has no release yet. Try again in a minute.' -ForegroundColor Red }
else { Write-Host ('Can''t download Agent Hub from git.bengles.se/agent-hub/releases: ' + $failure.Exception.Message + ' ' + 'Try again in a minute.') -ForegroundColor Red }
return
}
$saved = @{}
$extra = @("$env:AGENT_HUB_SETUP_ARGS" -split '\s+' | Where-Object { $_ })
Write-Host 'Installing Agent Hub...'
try {
& $exe @extra
$code = $LASTEXITCODE
} finally {
foreach ($name in $saved.Keys) { [Environment]::SetEnvironmentVariable($name, $saved[$name]) }
}
Remove-Item $exe -ErrorAction SilentlyContinue
if ($code -ne 0) { Write-Host 'Agent Hub''s setup stopped: see above.' -ForegroundColor Red }
}