#!/bin/sh # Installs the agenthub CLI: # # curl -fsSL https://get.theagenthub.app | sh # # Settings, all optional: # AGENTHUB_VERSION=v0.2.0 a specific release instead of the latest # AGENTHUB_INSTALL_DIR=/usr/local/bin where to put it (default ~/.local/bin) # AGENTHUB_DOWNLOAD_URL=... another server with the same layout # # The server layout: /latest holds the newest version (like "v0.2.0"), and # /releases// holds agenthub--[.exe] plus SHA256SUMS. set -eu base="${AGENTHUB_DOWNLOAD_URL:-https://get.theagenthub.app}" dir="${AGENTHUB_INSTALL_DIR:-$HOME/.local/bin}" say() { printf '%s\n' "$*" >&2; } fail() { say "agenthub install: $*"; exit 1; } if command -v curl >/dev/null 2>&1; then fetch() { curl -fsSL --proto '=https' --tlsv1.2 -o "$2" "$1"; } elif command -v wget >/dev/null 2>&1; then fetch() { wget -q --https-only -O "$2" "$1"; } else fail "needs curl or wget" fi case "$(uname -s)" in Darwin) os=darwin ;; Linux) os=linux ;; MINGW* | MSYS* | CYGWIN*) fail "on Windows, run in PowerShell: irm https://get.theagenthub.app/install.ps1 | iex" ;; *) fail "no build for $(uname -s); see https://theagenthub.app for other ways to install" ;; esac case "$(uname -m)" in x86_64 | amd64) arch=x64 ;; arm64 | aarch64) arch=arm64 ;; *) fail "no build for $(uname -m)" ;; esac # A shell running under Rosetta reports x86_64 on Apple silicon; the native build is better. if [ "$os" = darwin ] && [ "$arch" = x64 ] && [ "$(sysctl -n sysctl.proc_translated 2>/dev/null || true)" = 1 ]; then arch=arm64 fi # The Linux builds link against glibc, so they don't run on musl (Alpine). if [ "$os" = linux ] && ldd --version 2>&1 | grep -qi musl; then fail "the Linux builds need glibc, and this system uses musl (Alpine)" fi tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT INT TERM version="${AGENTHUB_VERSION:-}" if [ -z "$version" ]; then fetch "$base/latest" "$tmp/latest" || fail "couldn't reach $base" version="$(tr -d ' \r\n' < "$tmp/latest")" fi case "$version" in v*) ;; *) version="v$version" ;; esac file="agenthub-$os-$arch" say "Downloading agenthub $version ($os-$arch)..." fetch "$base/releases/$version/$file" "$tmp/$file" || fail "couldn't download $base/releases/$version/$file" fetch "$base/releases/$version/SHA256SUMS" "$tmp/SHA256SUMS" || fail "couldn't download the checksums" expected="$(awk -v f="$file" '$2 == f || $2 == "*" f { print $1 }' "$tmp/SHA256SUMS")" [ -n "$expected" ] || fail "$file isn't listed in SHA256SUMS" if command -v sha256sum >/dev/null 2>&1; then actual="$(sha256sum "$tmp/$file" | awk '{ print $1 }')" else actual="$(shasum -a 256 "$tmp/$file" | awk '{ print $1 }')" fi [ "$actual" = "$expected" ] || fail "checksum mismatch for $file, not installing" mkdir -p "$dir" chmod 755 "$tmp/$file" mv -f "$tmp/$file" "$dir/agenthub" 2>/dev/null || fail "couldn't write to $dir (set AGENTHUB_INSTALL_DIR, or run with sudo)" say "Installed $("$dir/agenthub" --version 2>/dev/null || echo "$version") to $dir/agenthub" case ":$PATH:" in *":$dir:"*) ;; *) say "" say "$dir isn't on your PATH. Add it with:" case "${SHELL:-}" in */zsh) say " echo 'export PATH=\"$dir:\$PATH\"' >> ~/.zshrc && exec zsh" ;; */fish) say " fish_add_path $dir" ;; *) say " echo 'export PATH=\"$dir:\$PATH\"' >> ~/.bashrc && exec bash" ;; esac ;; esac say "" say "Next: agenthub login --hub https://hub.theagenthub.app"