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
79 linesCodeBlameRaw
1#!/bin/sh
2# Installs the g1t CLI on Linux or macOS:
3#
4# curl -fsSL https://g1t.sh/install | sh
5#
6# It downloads the build for this system from g1t.sh/downloads/cli, checks it
7# against the release's SHA256SUMS, and puts it in ~/.local/bin.
8#
9# G1T_INSTALL_DIR where to put g1t (default: ~/.local/bin)
10# G1T_VERSION a version to install, such as 0.2.0 (default: the latest)
11#
12# Docs: https://docs.g1t.sh/guides/cli/
13set -eu
14
15base="${G1T_DOWNLOAD_URL:-https://g1t.sh/downloads/cli}"
16version="${G1T_VERSION:-latest}"
17version="${version#v}"
18dir="${G1T_INSTALL_DIR:-$HOME/.local/bin}"
19
20say() { printf '%s\n' "$*" >&2; }
21fail() {
22 say "g1t install: $*"
23 exit 1
24}
25
26case "$(uname -s)" in
27Linux) os=linux ;;
28Darwin) os=macos ;;
29MINGW* | MSYS* | CYGWIN*) fail "on Windows, run this in PowerShell instead: irm https://g1t.sh/install.ps1 | iex" ;;
30*) fail "there is no build for $(uname -s)." ;;
31esac
32case "$(uname -m)" in
33x86_64 | amd64) arch=x64 ;;
34arm64 | aarch64) arch=arm64 ;;
35*) fail "there is no build for $(uname -m)." ;;
36esac
37# An Intel shell on Apple silicon (Rosetta) gets the native build.
38if [ "$os" = macos ] && [ "$arch" = x64 ] && [ "$(sysctl -n sysctl.proc_translated 2>/dev/null || echo 0)" = 1 ]; then
39 arch=arm64
40fi
41file="g1t-$os-$arch"
42
43if command -v curl >/dev/null 2>&1; then
44 get() { curl -fsSL --retry 3 -o "$2" "$1"; }
45elif command -v wget >/dev/null 2>&1; then
46 get() { wget -q -O "$2" "$1"; }
47else
48 fail "this needs curl or wget."
49fi
50
51tmp="$(mktemp -d)"
52trap 'rm -rf "$tmp"' EXIT INT TERM
53
54say "Downloading g1t ($version, $os $arch)..."
55get "$base/$version/$file" "$tmp/g1t" || fail "could not download $base/$version/$file."
56get "$base/$version/SHA256SUMS" "$tmp/SHA256SUMS" || fail "could not download $base/$version/SHA256SUMS."
57
58# A name may carry sha256sum's binary-mode `*`.
59want="$(awk -v f="$file" '{ sub(/^[*]/, "", $2) } $2 == f { print $1 }' "$tmp/SHA256SUMS")"
60[ -n "$want" ] || fail "SHA256SUMS names no $file."
61if command -v sha256sum >/dev/null 2>&1; then
62 have="$(sha256sum "$tmp/g1t" | awk '{ print $1 }')"
63elif command -v shasum >/dev/null 2>&1; then
64 have="$(shasum -a 256 "$tmp/g1t" | awk '{ print $1 }')"
65else
66 fail "this needs sha256sum or shasum to check the download."
67fi
68[ "$want" = "$have" ] || fail "the download's SHA-256 is $have, not $want. Nothing was installed."
69
70chmod +x "$tmp/g1t"
71mkdir -p "$dir" || fail "could not make $dir. Set G1T_INSTALL_DIR to a directory you can write to."
72mv "$tmp/g1t" "$dir/g1t" || fail "could not write $dir/g1t. Set G1T_INSTALL_DIR to a directory you can write to."
73
74say "Installed $("$dir/g1t" --version) to $dir/g1t"
75case ":$PATH:" in
76*":$dir:"*) ;;
77*) say "$dir is not on your PATH. Add it to your shell's profile: export PATH=\"$dir:\$PATH\"" ;;
78esac
79say "Next: g1t auth login"