#!/usr/bin/env bash # Install the bino CLI on macOS or Linux. # # Release assets of a private repository are not reachable over the git protocol: they are # served by the REST API behind an Authorization header. gh already holds a token from # `gh auth login`, so this script uses it rather than asking anyone to create another # credential. See docs/cli-distribution-plan.md, section 3.8. # # Exit codes: 0 installed, 1 failed, 3 not authorized. set -euo pipefail REPO="${BINO_REPO:-Colombino-Universe/binoflow}" ROOT="${BINO_ROOT:-$HOME/.bino}" BIN_DIR="$ROOT/bin" LINK_DIR="$HOME/.local/bin" # Global rather than local to main: the EXIT trap runs after main has returned, when a local # is gone and `set -u` would turn the cleanup itself into a failure of a finished install. STAGING="" cleanup() { if [ -n "$STAGING" ]; then rm -rf "$STAGING" fi } die() { printf '%s\n' "$*" >&2; exit 1; } note() { printf '%s\n' "$*"; } require_gh() { if ! command -v gh >/dev/null 2>&1; then printf '%s\n' \ "The GitHub CLI (gh) was not found on PATH." \ "bino downloads its releases from a private repository, which needs a token." \ "Install gh, run 'gh auth login', then run this script again." >&2 exit 3 fi if ! gh auth status >/dev/null 2>&1; then printf '%s\n' \ "gh is installed but not authenticated." \ "Run 'gh auth login' and try again." >&2 exit 3 fi } detect_platform() { local os arch case "$(uname -s)" in Darwin) os=darwin ;; Linux) os=linux ;; *) die "Unsupported operating system: $(uname -s). Use bootstrap.ps1 on Windows." ;; esac case "$(uname -m)" in x86_64 | amd64) arch=amd64 ;; arm64 | aarch64) arch=arm64 ;; *) die "Unsupported architecture: $(uname -m)" ;; esac printf 'bino_%s_%s' "$os" "$arch" } latest_tag() { gh release list --repo "$REPO" --limit 100 \ --json tagName,isDraft \ --jq '[.[] | select(.isDraft == false) | select(.tagName | startswith("cli-"))][0].tagName' } verify_checksum() { local dir="$1" asset="$2" expected actual expected="$(awk -v name="$asset" '$2 == name || $2 == "*" name { print $1 }' "$dir/SHA256SUMS")" [ -n "$expected" ] || die "SHA256SUMS does not list $asset" if command -v sha256sum >/dev/null 2>&1; then actual="$(sha256sum "$dir/$asset" | awk '{print $1}')" elif command -v shasum >/dev/null 2>&1; then actual="$(shasum -a 256 "$dir/$asset" | awk '{print $1}')" else die "Neither sha256sum nor shasum is available; cannot verify the download." fi [ "$expected" = "$actual" ] || die "Checksum mismatch for $asset: expected $expected, got $actual" } main() { require_gh local asset tag asset="$(detect_platform)" tag="$(latest_tag)" [ -n "$tag" ] && [ "$tag" != "null" ] || die "No cli-* release found in $REPO." note "Installing $tag ($asset)" STAGING="$(mktemp -d)" trap cleanup EXIT gh release download "$tag" --repo "$REPO" --dir "$STAGING" \ --pattern "$asset" --pattern SHA256SUMS --clobber verify_checksum "$STAGING" "$asset" mkdir -p "$BIN_DIR" install -m 0755 "$STAGING/$asset" "$BIN_DIR/bino" # A symlink only where the directory is already on PATH; editing a shell profile behind # someone's back is not this script's business. if [ -d "$LINK_DIR" ] && printf '%s' ":$PATH:" | grep -q ":$LINK_DIR:"; then ln -sf "$BIN_DIR/bino" "$LINK_DIR/bino" note "Linked $LINK_DIR/bino" else note "" note "$BIN_DIR is not on your PATH. Add this line to your shell profile:" note " export PATH=\"$BIN_DIR:\$PATH\"" fi note "" "$BIN_DIR/bino" --version note "Run 'bino' to choose which AI agents receive the shared skills." } main "$@"