#!/bin/sh # Install the Indent CLI. # # Usage: # curl -sf https://install.indent.com | sh # curl -sf https://install.indent.com | INDENT_VERSION=1.2.3 sh # # Environment: # INDENT_VERSION Pin a specific version (defaults to the latest published). # INDENT_INSTALL Install prefix (defaults to /usr/local/bin, falls back to $HOME/.local/bin). # INDENT_HOST Override the install host (defaults to https://install.indent.com). set -eu HOST="${INDENT_HOST:-https://install.indent.com}" BIN_NAME="indent" say() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } die() { printf '\033[1;31merror:\033[0m %s\n' "$*" >&2; exit 1; } detect_target() { os=$(uname -s | tr '[:upper:]' '[:lower:]') arch=$(uname -m) case "$arch" in x86_64|amd64) arch=x64 ;; aarch64|arm64) arch=arm64 ;; *) die "Unsupported architecture: $arch" ;; esac case "$os" in linux) echo "indent-linux-${arch}" ;; darwin) if [ "$arch" != "arm64" ]; then die "Unsupported macOS architecture: $arch. Only arm64 (Apple Silicon) is supported." fi echo "indent-darwin-arm64" ;; *) die "Unsupported OS: $os (use the Windows installer instead)" ;; esac } choose_prefix() { if [ -n "${INDENT_INSTALL:-}" ]; then echo "$INDENT_INSTALL" return fi if [ -w /usr/local/bin ] 2>/dev/null; then echo /usr/local/bin else mkdir -p "$HOME/.local/bin" echo "$HOME/.local/bin" fi } main() { target=$(detect_target) if [ -n "${INDENT_VERSION:-}" ]; then version="$INDENT_VERSION" else say "Resolving latest version from ${HOST}..." version=$(curl -sf "${HOST}/latest" | tr -d '[:space:]') [ -n "$version" ] || die "Unable to determine latest version from ${HOST}/latest" fi url="${HOST}/bin/${target}" say "Downloading ${url}" tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT curl -sfL "$url" -o "$tmp/$BIN_NAME" curl -sfL "${url}.sha256" -o "$tmp/${BIN_NAME}.sha256" \ || die "Failed to download checksum (${url}.sha256); refusing to install without integrity verification." say "Verifying checksum" expected=$(awk '{print $1}' "$tmp/${BIN_NAME}.sha256") [ -n "$expected" ] || die "Checksum file is empty" if command -v sha256sum >/dev/null 2>&1; then actual=$(sha256sum "$tmp/$BIN_NAME" | awk '{print $1}') elif command -v shasum >/dev/null 2>&1; then actual=$(shasum -a 256 "$tmp/$BIN_NAME" | awk '{print $1}') else die "Neither sha256sum nor shasum is available; cannot verify checksum" fi [ "$expected" = "$actual" ] || die "Checksum mismatch: expected $expected, got $actual" chmod +x "$tmp/$BIN_NAME" prefix=$(choose_prefix) dest="$prefix/$BIN_NAME" mv "$tmp/$BIN_NAME" "$dest" say "Installed ${BIN_NAME} ${version} to ${dest}" case ":$PATH:" in *":$prefix:"*) ;; *) say "Note: ${prefix} is not on your PATH; add it to your shell profile." ;; esac } main "$@"