#!/bin/sh set -e RELEASES_URL="https://clireleases.blacksmith.sh/cli" CHANNEL="${BLACKSMITH_CHANNEL:-latest}" # Detect OS OS="$(uname -s | tr '[:upper:]' '[:lower:]')" case "$OS" in linux|darwin) ;; *) echo "Error: unsupported OS: $OS" >&2 echo "Blacksmith CLI supports linux and darwin (macOS)." >&2 exit 1 ;; esac # Detect architecture ARCH="$(uname -m)" case "$ARCH" in x86_64|amd64) ARCH="amd64" ;; arm64|aarch64) ARCH="arm64" ;; *) echo "Error: unsupported architecture: $ARCH" >&2 echo "Blacksmith CLI supports amd64 and arm64." >&2 exit 1 ;; esac BINARY_URL="${RELEASES_URL}/${CHANNEL}/${OS}/${ARCH}/blacksmith" CHECKSUM_URL="${BINARY_URL}.sha256" TMPDIR="$(mktemp -d)" trap 'rm -rf "$TMPDIR"' EXIT echo "Installing Blacksmith CLI (${OS}/${ARCH}) from ${CHANNEL} channel..." # Download binary curl -fsSL "$BINARY_URL" -o "$TMPDIR/blacksmith" # Download and verify checksum curl -fsSL "$CHECKSUM_URL" -o "$TMPDIR/blacksmith.sha256" EXPECTED="$(awk '{print $1}' "$TMPDIR/blacksmith.sha256")" if command -v sha256sum >/dev/null 2>&1; then ACTUAL="$(sha256sum "$TMPDIR/blacksmith" | awk '{print $1}')" elif command -v shasum >/dev/null 2>&1; then ACTUAL="$(shasum -a 256 "$TMPDIR/blacksmith" | awk '{print $1}')" else echo "Error: no SHA-256 tool found (need sha256sum or shasum)" >&2 exit 1 fi if [ "$EXPECTED" != "$ACTUAL" ]; then echo "Error: checksum verification failed" >&2 echo " expected: $EXPECTED" >&2 echo " got: $ACTUAL" >&2 exit 1 fi chmod +x "$TMPDIR/blacksmith" # Install to /usr/local/bin (or BLACKSMITH_INSTALL_DIR if set) INSTALL_DIR="${BLACKSMITH_INSTALL_DIR:-/usr/local/bin}" if [ -w "$INSTALL_DIR" ]; then mv "$TMPDIR/blacksmith" "$INSTALL_DIR/blacksmith" else echo "Installing to $INSTALL_DIR (requires sudo)..." sudo mv "$TMPDIR/blacksmith" "$INSTALL_DIR/blacksmith" fi echo "" echo "Blacksmith CLI installed successfully to ${INSTALL_DIR}/blacksmith" "$INSTALL_DIR/blacksmith" --version 2>/dev/null || true echo "" echo "Get started:" echo " blacksmith auth login" echo " blacksmith testbox --help"