|
| 1 | +#!/bin/sh |
| 2 | +# Install tabb from GitHub releases. |
| 3 | +# Usage: curl -fsSL https://raw.githubusercontent.com/joelhelbling/tabb/main/install.sh | sh |
| 4 | +# Env: |
| 5 | +# TABB_VERSION pin a version (e.g. v0.1.0); default: latest |
| 6 | +# INSTALL_DIR install location; default: ~/.local/bin |
| 7 | +set -eu |
| 8 | + |
| 9 | +REPO="joelhelbling/tabb" |
| 10 | +INSTALL_DIR="${INSTALL_DIR:-$HOME/.local/bin}" |
| 11 | + |
| 12 | +# --- detect OS --- |
| 13 | +os="$(uname -s)" |
| 14 | +case "$os" in |
| 15 | + Linux) os="linux" ;; |
| 16 | + Darwin) os="darwin" ;; |
| 17 | + *) echo "tabb: unsupported OS: $os" >&2; exit 1 ;; |
| 18 | +esac |
| 19 | + |
| 20 | +# --- detect arch --- |
| 21 | +arch="$(uname -m)" |
| 22 | +case "$arch" in |
| 23 | + x86_64|amd64) arch="amd64" ;; |
| 24 | + arm64|aarch64) arch="arm64" ;; |
| 25 | + *) echo "tabb: unsupported architecture: $arch" >&2; exit 1 ;; |
| 26 | +esac |
| 27 | + |
| 28 | +# --- resolve version --- |
| 29 | +version="${TABB_VERSION:-}" |
| 30 | +if [ -z "$version" ]; then |
| 31 | + version="$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" \ |
| 32 | + | grep '"tag_name":' | head -n1 | sed -E 's/.*"tag_name": *"([^"]+)".*/\1/')" |
| 33 | +fi |
| 34 | +if [ -z "$version" ]; then |
| 35 | + echo "tabb: could not resolve release version" >&2 |
| 36 | + exit 1 |
| 37 | +fi |
| 38 | + |
| 39 | +# goreleaser strips the leading 'v' from the version in archive names. |
| 40 | +ver_no_v="${version#v}" |
| 41 | +archive="tabb_${ver_no_v}_${os}_${arch}.tar.gz" |
| 42 | +base="https://github.com/$REPO/releases/download/$version" |
| 43 | + |
| 44 | +tmp="$(mktemp -d)" |
| 45 | +trap 'rm -rf "$tmp"' EXIT |
| 46 | + |
| 47 | +echo "tabb: downloading $archive ($version)" |
| 48 | +curl -fsSL "$base/$archive" -o "$tmp/$archive" |
| 49 | +curl -fsSL "$base/checksums.txt" -o "$tmp/checksums.txt" |
| 50 | + |
| 51 | +# --- verify checksum --- |
| 52 | +echo "tabb: verifying checksum" |
| 53 | +expected="$(grep " $archive\$" "$tmp/checksums.txt" | awk '{print $1}')" |
| 54 | +if [ -z "$expected" ]; then |
| 55 | + echo "tabb: no checksum found for $archive" >&2 |
| 56 | + exit 1 |
| 57 | +fi |
| 58 | +if command -v sha256sum >/dev/null 2>&1; then |
| 59 | + actual="$(sha256sum "$tmp/$archive" | awk '{print $1}')" |
| 60 | +else |
| 61 | + actual="$(shasum -a 256 "$tmp/$archive" | awk '{print $1}')" |
| 62 | +fi |
| 63 | +if [ "$expected" != "$actual" ]; then |
| 64 | + echo "tabb: checksum mismatch (expected $expected, got $actual)" >&2 |
| 65 | + exit 1 |
| 66 | +fi |
| 67 | + |
| 68 | +# --- extract and install --- |
| 69 | +tar -xzf "$tmp/$archive" -C "$tmp" |
| 70 | +mkdir -p "$INSTALL_DIR" |
| 71 | +install -m 0755 "$tmp/tabb" "$INSTALL_DIR/tabb" |
| 72 | + |
| 73 | +echo "tabb: installed $version to $INSTALL_DIR/tabb" |
| 74 | +case ":$PATH:" in |
| 75 | + *":$INSTALL_DIR:"*) ;; |
| 76 | + *) echo "tabb: note — $INSTALL_DIR is not on your PATH" >&2 ;; |
| 77 | +esac |
0 commit comments