# Gerdoo CLI installer for Windows. Downloads the binary, verifies it against # checksums.txt, installs it for the current user and adds it to the user PATH. # Intended to be served and piped from PowerShell: # # irm https://get.gerdoo.cloud/install.ps1 | iex # # Overridable via env: # GERDOO_CLI_BASE_URL where the binaries live (default below) # GERDOO_BIN_DIR install location (default %LOCALAPPDATA%\Programs\gerdoo) # GERDOO_VERSION version subpath to fetch (default "latest") $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 function Get-Setting($name, $default) { $v = [Environment]::GetEnvironmentVariable($name) if ([string]::IsNullOrWhiteSpace($v)) { return $default } return $v } $baseUrl = (Get-Setting 'GERDOO_CLI_BASE_URL' 'https://get.gerdoo.cloud/cli').TrimEnd('/') $version = Get-Setting 'GERDOO_VERSION' 'latest' $binDir = Get-Setting 'GERDOO_BIN_DIR' (Join-Path $env:LOCALAPPDATA 'Programs\gerdoo') $arch = $env:PROCESSOR_ARCHITEW6432 if (-not $arch) { $arch = $env:PROCESSOR_ARCHITECTURE } if ($arch -ne 'AMD64') { Write-Error "gerdoo: unsupported architecture: $arch (only amd64 builds are published for Windows)" } $file = 'gerdoo_windows_amd64.exe' $url = "$baseUrl/$version/$file" $tmp = Join-Path ([IO.Path]::GetTempPath()) ("gerdoo-" + [Guid]::NewGuid().ToString('N') + '.exe') try { Write-Host "Downloading $url" try { Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $tmp } catch { Write-Error "gerdoo: download failed from ${url}: $($_.Exception.Message)" } # Verify against checksums.txt when the host publishes one. try { $sums = (Invoke-WebRequest -UseBasicParsing -Uri "$baseUrl/$version/checksums.txt").Content if ($sums -is [byte[]]) { $sums = [Text.Encoding]::UTF8.GetString($sums) } $line = $sums -split "`n" | Where-Object { $_ -match ("\s" + [regex]::Escape($file) + "\s*$") } | Select-Object -First 1 if ($line) { $want = ($line.Trim() -split '\s+')[0].ToLower() $got = (Get-FileHash -Algorithm SHA256 -Path $tmp).Hash.ToLower() if ($want -ne $got) { throw "checksum mismatch (expected $want, got $got)" } } } catch [System.Net.WebException] { # checksums.txt unreachable: continue, the download itself succeeded. } New-Item -ItemType Directory -Force -Path $binDir | Out-Null $target = Join-Path $binDir 'gerdoo.exe' # A running gerdoo.exe can be renamed but not overwritten; move it aside first. if (Test-Path $target) { Remove-Item -Force -ErrorAction SilentlyContinue "$target.old" Move-Item -Force $target "$target.old" } Move-Item -Force $tmp $target Remove-Item -Force -ErrorAction SilentlyContinue "$target.old" } finally { if (Test-Path $tmp) { Remove-Item -Force $tmp } } # Add to the user PATH (persistent) and to this session so `gerdoo` works now. $userPath = [Environment]::GetEnvironmentVariable('Path', 'User') $entries = @() if ($userPath) { $entries = $userPath -split ';' | Where-Object { $_ } } if ($entries -notcontains $binDir) { [Environment]::SetEnvironmentVariable('Path', (($entries + $binDir) -join ';'), 'User') Write-Host "Added $binDir to your PATH (open a new terminal for other windows to pick it up)" } if (($env:Path -split ';') -notcontains $binDir) { $env:Path = "$env:Path;$binDir" } Write-Host "Installed: $(& $target version)" Write-Host "Run 'gerdoo login' to get started."