From e73673605e04ace48827db6827c815e2033668bb Mon Sep 17 00:00:00 2001 From: "bjorn.englesson" Date: Thu, 1 Oct 2026 13:10:35 +0200 Subject: [PATCH] Add install.ps1 --- install.ps1 | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 install.ps1 diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 0000000..f38b329 --- /dev/null +++ b/install.ps1 @@ -0,0 +1,42 @@ +# 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 page''s curl line.' -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 } +}