#!/bin/sh # ttl64 CLI installer. # # curl -fsSL https://ttl64.com/install | sh # # Environment: # TTL64_INSTALL_DIR install directory (default: ~/.local/bin) # TTL64_VERSION pin a version, e.g. 0.1.0 (default: latest) set -eu BASE_URL="https://get.ttl64.com/cli" INSTALL_DIR="${TTL64_INSTALL_DIR:-$HOME/.local/bin}" info() { printf '%s\n' "$*"; } error() { printf 'error: %s\n' "$*" >&2; exit 1; } command -v curl >/dev/null 2>&1 || error "curl is required" case "$(uname -s)" in Linux) os=linux ;; Darwin) os=darwin ;; *) error "unsupported operating system: $(uname -s)" ;; esac case "$(uname -m)" in x86_64 | amd64) arch=amd64 ;; aarch64 | arm64) arch=arm64 ;; *) error "unsupported architecture: $(uname -m)" ;; esac version="${TTL64_VERSION:-$(curl -fsSL "$BASE_URL/latest")}" version="${version#v}" [ -n "$version" ] || error "could not determine the latest version" asset="ttl64-$os-$arch" tmpdir=$(mktemp -d) trap 'rm -rf "$tmpdir"' EXIT INT TERM info "Downloading ttl64 $version ($os-$arch)..." curl -fsSL "$BASE_URL/v$version/$asset" -o "$tmpdir/$asset" curl -fsSL "$BASE_URL/v$version/SHA256SUMS" -o "$tmpdir/SHA256SUMS" expected=$(grep " $asset\$" "$tmpdir/SHA256SUMS" | awk '{print $1}') if command -v sha256sum >/dev/null 2>&1; then actual=$(sha256sum "$tmpdir/$asset" | awk '{print $1}') else actual=$(shasum -a 256 "$tmpdir/$asset" | awk '{print $1}') fi [ -n "$expected" ] && [ "$expected" = "$actual" ] || error "checksum verification failed" mkdir -p "$INSTALL_DIR" install -m 0755 "$tmpdir/$asset" "$INSTALL_DIR/ttl64" info "Installed ttl64 $version to $INSTALL_DIR/ttl64" case ":$PATH:" in *":$INSTALL_DIR:"*) ;; *) info "Add $INSTALL_DIR to your PATH: export PATH=\"$INSTALL_DIR:\$PATH\"" ;; esac info "Next: ttl64 login"