Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t.sh
57 linesCodeBlameRaw
1# Installs the g1t CLI on Windows:
2#
3# irm https://g1t.sh/install.ps1 | iex
4#
5# It downloads the build from g1t.sh/downloads/cli, checks it against the
6# release's SHA256SUMS, puts it in %LOCALAPPDATA%\g1t\bin, and adds that to
7# your PATH.
8#
9# G1T_INSTALL_DIR where to put g1t.exe
10# G1T_VERSION a version to install, such as 0.2.0 (default: the latest)
11#
12# Docs: https://docs.g1t.sh/guides/cli/
13$ErrorActionPreference = 'Stop'
14$ProgressPreference = 'SilentlyContinue'
15
16$base = if ($env:G1T_DOWNLOAD_URL) { $env:G1T_DOWNLOAD_URL } else { 'https://g1t.sh/downloads/cli' }
17$version = if ($env:G1T_VERSION) { $env:G1T_VERSION.TrimStart('v') } else { 'latest' }
18$dir = if ($env:G1T_INSTALL_DIR) { $env:G1T_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA 'g1t\bin' }
19
20$arch = $env:PROCESSOR_ARCHITECTURE
21if ($arch -ne 'AMD64' -and $arch -ne 'ARM64') { throw "g1t install: there is no build for $arch." }
22# Windows on ARM runs the x64 build.
23$file = 'g1t-windows-x64.exe'
24
25[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
26$tmp = Join-Path ([IO.Path]::GetTempPath()) ('g1t-' + [Guid]::NewGuid())
27New-Item -ItemType Directory -Path $tmp | Out-Null
28try {
29 Write-Host "Downloading g1t ($version, windows x64)..."
30 $exe = Join-Path $tmp 'g1t.exe'
31 Invoke-WebRequest -UseBasicParsing -Uri "$base/$version/$file" -OutFile $exe
32 $sumsFile = Join-Path $tmp 'SHA256SUMS'
33 Invoke-WebRequest -UseBasicParsing -Uri "$base/$version/SHA256SUMS" -OutFile $sumsFile
34 $want = Get-Content $sumsFile |
35 Where-Object { ($_ -split '\s+')[1] -eq $file } |
36 ForEach-Object { ($_ -split '\s+')[0] } |
37 Select-Object -First 1
38 if (-not $want) { throw "g1t install: SHA256SUMS names no $file." }
39 $have = (Get-FileHash -Algorithm SHA256 -Path $exe).Hash.ToLower()
40 if ($have -ne $want.ToLower()) { throw "g1t install: the download's SHA-256 is $have, not $want. Nothing was installed." }
41 New-Item -ItemType Directory -Force -Path $dir | Out-Null
42 Move-Item -Force -Path $exe -Destination (Join-Path $dir 'g1t.exe')
43}
44finally {
45 Remove-Item -Recurse -Force -Path $tmp -ErrorAction SilentlyContinue
46}
47
48$userPath = [Environment]::GetEnvironmentVariable('Path', 'User')
49if (-not (($userPath -split ';') -contains $dir)) {
50 $joined = if ($userPath) { "$userPath;$dir" } else { $dir }
51 [Environment]::SetEnvironmentVariable('Path', $joined, 'User')
52 $env:Path = "$env:Path;$dir"
53 Write-Host "Added $dir to your PATH; terminals opened from now on have it."
54}
55$installed = & (Join-Path $dir 'g1t.exe') --version
56Write-Host "Installed $installed to $dir\g1t.exe"
57Write-Host 'Next: g1t auth login'