# gitroots installer for Windows # # irm https://gitroots.com/cli/install.ps1 | iex # & ([scriptblock]::Create((irm https://gitroots.com/cli/install.ps1))) 0.5.0 # a specific version # # Installs gitroots.exe to %USERPROFILE%\.local\bin and adds it to your user PATH. param([string]$Version = $env:GITROOTS_VERSION) $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' $Base = if ($env:GITROOTS_DOWNLOAD_BASE) { $env:GITROOTS_DOWNLOAD_BASE.TrimEnd('/') } else { 'https://gitroots.com/cli' } function Ok($m) { Write-Host " " -NoNewline; Write-Host "✓" -ForegroundColor Green -NoNewline; Write-Host " $m" } function Die($m) { Write-Host " " -NoNewline; Write-Host "✕ $m" -ForegroundColor Red; exit 1 } $arch = switch ($env:PROCESSOR_ARCHITECTURE) { 'AMD64' { 'x64' } 'ARM64' { 'x64' } default { Die "unsupported CPU: $env:PROCESSOR_ARCHITECTURE" } } $platform = "win32-$arch" Write-Host "" Write-Host "gitroots" -ForegroundColor Green -NoNewline; Write-Host " installer · $platform" -ForegroundColor DarkGray if (-not $Version -or $Version -eq 'latest') { try { $Version = (Invoke-RestMethod "$Base/latest").Trim() } catch { Die "can't reach $Base/latest" } } try { $sums = Invoke-RestMethod "$Base/$Version/SHA256SUMS" } catch { Die "gitroots $Version not found at $Base/$Version" } $file = "gitroots-$Version-$platform.zip" $want = ($sums -split "`n" | Where-Object { $_ -match " $([regex]::Escape($file))$" } | ForEach-Object { ($_ -split '\s+')[0] }) if (-not $want) { Die "no Windows build in gitroots $Version" } $tmp = Join-Path ([IO.Path]::GetTempPath()) ("gitroots-" + [guid]::NewGuid()) New-Item -ItemType Directory -Path $tmp | Out-Null try { Write-Host " downloading gitroots $Version…" -ForegroundColor DarkGray Invoke-WebRequest "$Base/$Version/$file" -OutFile "$tmp\$file" -UseBasicParsing $got = (Get-FileHash "$tmp\$file" -Algorithm SHA256).Hash.ToLower() if ($got -ne $want) { Die "checksum mismatch for $file · nothing was installed" } Ok "checksum verified" $data = Join-Path $env:USERPROFILE ".local\share\gitroots\versions\$Version" $bin = Join-Path $env:USERPROFILE ".local\bin" New-Item -ItemType Directory -Force -Path $data, $bin | Out-Null Expand-Archive -Force -Path "$tmp\$file" -DestinationPath $data $exe = Join-Path $bin 'gitroots.exe' if (Test-Path $exe) { Remove-Item "$exe.old" -ErrorAction SilentlyContinue; Rename-Item $exe "gitroots.exe.old" } Copy-Item (Join-Path $data 'gitroots.exe') $exe Ok "installed gitroots $Version → $exe" $userPath = [Environment]::GetEnvironmentVariable('Path', 'User') if (($userPath -split ';') -notcontains $bin) { [Environment]::SetEnvironmentVariable('Path', "$bin;$userPath", 'User') $env:Path = "$bin;$env:Path" Ok "added $bin to your user PATH (open a new terminal)" } & $exe --version | Out-Null } finally { Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue } Write-Host "" Write-Host " → gitroots " -ForegroundColor Green -NoNewline; Write-Host "welcome and quick start" -ForegroundColor DarkGray Write-Host " → gitroots login " -ForegroundColor Green -NoNewline; Write-Host "connect your gitroots server" -ForegroundColor DarkGray Write-Host " → gitroots doctor " -ForegroundColor Green -NoNewline; Write-Host "check the install" -ForegroundColor DarkGray Write-Host ""