#!/bin/sh # Hearth installer: downloads `hearth` and `hearth-agent` from a GitHub release, checks them # against the release's SHA256SUMS, and puts them in ~/.local/bin. # # curl -fsSL https://raw.githubusercontent.com/test-zeus-ai/testzeus-hearth/main/install.sh | sh # curl -fsSL https://raw.githubusercontent.com/test-zeus-ai/testzeus-hearth/main/install.sh | sh -s -- --version 0.2.0 --dry-run # # Options (or environment variables): # --version HEARTH_VERSION release to install, e.g. 0.2.0 (default: latest) # --install-dir HEARTH_INSTALL_DIR where to put the binaries (default: ~/.local/bin) # --sudo HEARTH_USE_SUDO=1 use sudo if the directory is not writable # --dry-run print what would happen, change nothing # -h, --help # # For testing and mirrors: HEARTH_DOWNLOAD_BASE replaces the release URL; assets are fetched from # "$HEARTH_DOWNLOAD_BASE/" (file:// works with curl). HEARTH_REPO defaults to test-zeus-ai/testzeus-hearth. # # Licensed under Apache-2.0. Source: https://github.com/test-zeus-ai/testzeus-hearth/blob/main/install.sh set -eu REPO="${HEARTH_REPO:-test-zeus-ai/testzeus-hearth}" VERSION="${HEARTH_VERSION:-latest}" INSTALL_DIR="${HEARTH_INSTALL_DIR:-}" USE_SUDO="${HEARTH_USE_SUDO:-0}" DOWNLOAD_BASE="${HEARTH_DOWNLOAD_BASE:-}" DRY_RUN=0 BINARIES="hearth hearth-agent" TMP_DIR="" say() { printf '%s\n' "$*"; } warn() { printf 'hearth-install: warning: %s\n' "$*" >&2; } die() { printf 'hearth-install: error: %s\n' "$*" >&2 exit 1 } has() { command -v "$1" >/dev/null 2>&1; } usage() { cat <<'EOF' Install the hearth CLI and hearth-agent from a GitHub release. Usage: install.sh [--version ] [--install-dir ] [--sudo] [--dry-run] --version release to install, e.g. 0.2.0 (default: latest; env HEARTH_VERSION) --install-dir where to put the binaries (default: ~/.local/bin; env HEARTH_INSTALL_DIR) --sudo use sudo if the directory is not writable (env HEARTH_USE_SUDO=1) --dry-run print what would happen, change nothing -h, --help show this help curl -fsSL https://raw.githubusercontent.com/test-zeus-ai/testzeus-hearth/main/install.sh | sh -s -- --version 0.2.0 EOF } cleanup() { if [ -n "$TMP_DIR" ] && [ -d "$TMP_DIR" ]; then rm -rf "$TMP_DIR" fi } parse_args() { while [ $# -gt 0 ]; do case "$1" in --version) [ $# -ge 2 ] || die "--version needs a value" VERSION="$2" shift 2 ;; --version=*) VERSION="${1#*=}" shift ;; --install-dir) [ $# -ge 2 ] || die "--install-dir needs a value" INSTALL_DIR="$2" shift 2 ;; --install-dir=*) INSTALL_DIR="${1#*=}" shift ;; --sudo) USE_SUDO=1 shift ;; --dry-run) DRY_RUN=1 shift ;; -h | --help) usage exit 0 ;; *) die "unknown option: $1 (try --help)" ;; esac done if [ -z "$INSTALL_DIR" ]; then [ -n "${HOME:-}" ] || die "HOME is not set; pass --install-dir" INSTALL_DIR="$HOME/.local/bin" fi # Accept both 0.2.0 and v0.2.0. case "$VERSION" in latest) ;; v*) VERSION="${VERSION#v}" ;; esac } # Prints the Rust target triple of this machine, e.g. aarch64-apple-darwin. detect_target() { os="$(uname -s)" arch="$(uname -m)" case "$os" in Darwin) os_part="apple-darwin" ;; Linux) if [ -f /etc/alpine-release ] || { has ldd && ldd --version 2>&1 | grep -qi musl; }; then die "musl-based Linux (e.g. Alpine) is not supported by the release builds; build from source: https://test-zeus-ai.github.io/testzeus-hearth/guide/install/#build-from-source" fi os_part="unknown-linux-gnu" ;; *) die "unsupported OS: $os (Hearth releases cover macOS and Linux)" ;; esac case "$arch" in x86_64 | amd64) arch_part="x86_64" ;; arm64 | aarch64) arch_part="aarch64" ;; *) die "unsupported CPU architecture: $arch (releases cover x86_64 and arm64)" ;; esac # A shell running under Rosetta reports x86_64 on Apple silicon; prefer the native build. if [ "$os" = Darwin ] && [ "$arch_part" = x86_64 ]; then if [ "$(sysctl -n sysctl.proc_translated 2>/dev/null || echo 0)" = 1 ]; then arch_part="aarch64" fi fi printf '%s-%s\n' "$arch_part" "$os_part" } base_url() { if [ -n "$DOWNLOAD_BASE" ]; then printf '%s\n' "${DOWNLOAD_BASE%/}" elif [ "$VERSION" = latest ]; then printf 'https://github.com/%s/releases/latest/download\n' "$REPO" else printf 'https://github.com/%s/releases/download/v%s\n' "$REPO" "$VERSION" fi } download() { # url dest if has curl; then curl --proto '=https,file' --tlsv1.2 -fsSL --retry 3 -o "$2" "$1" elif has wget; then wget -q -O "$2" "$1" else die "need curl or wget to download" fi } sha256_of() { # file if has sha256sum; then sha256sum "$1" | cut -d ' ' -f 1 elif has shasum; then shasum -a 256 "$1" | cut -d ' ' -f 1 elif has openssl; then openssl dgst -sha256 "$1" | sed 's/^.*= //' else die "need sha256sum, shasum or openssl to verify the download" fi } verify() { # archive sums asset expected="$(awk -v a="$3" '{ f = $2; sub(/^\*/, "", f); if (f == a) { print $1; exit } }' "$2")" [ -n "$expected" ] || die "SHA256SUMS has no entry for $3" actual="$(sha256_of "$1")" if [ "$expected" != "$actual" ]; then die "checksum mismatch for $3: expected $expected, got $actual. Nothing was installed." fi say "Checksum OK ($actual)" } # Runs a command, with sudo when the install directory needs it. as_installer() { if [ "$NEED_SUDO" = 1 ]; then sudo "$@" else "$@" fi } check_install_dir() { NEED_SUDO=0 dir="$INSTALL_DIR" # Find the nearest existing parent to see whether we can create or write into it. while [ ! -d "$dir" ]; do dir="$(dirname "$dir")" done if [ ! -w "$dir" ]; then if [ "$USE_SUDO" = 1 ]; then has sudo || die "$INSTALL_DIR is not writable and sudo is not available" NEED_SUDO=1 else die "$INSTALL_DIR is not writable. Pick another directory with --install-dir (or HEARTH_INSTALL_DIR), or allow sudo with --sudo." fi fi } path_hint() { case ":${PATH:-}:" in *":$INSTALL_DIR:"*) ;; *) say "" say "$INSTALL_DIR is not on your PATH. Add it, for example:" say " echo 'export PATH=\"$INSTALL_DIR:\$PATH\"' >> ~/.profile && . ~/.profile" ;; esac } next_steps() { say "" say "Next steps:" say " hearth up local # a farm on this machine (needs Docker, kind, Helm, kubectl)" say " hearth status # pools, capacity and queues" say " hearth skills install # teach your coding agent to use Hearth" say "" say "Docs: https://test-zeus-ai.github.io/testzeus-hearth/guide/getting-started/" } main() { parse_args "$@" target="$(detect_target)" asset="hearth-$target.tar.gz" base="$(base_url)" say "Hearth installer" say " version: $VERSION" say " platform: $target" say " archive: $base/$asset" say " checksums: $base/SHA256SUMS" say " install to: $INSTALL_DIR" if [ "$DRY_RUN" = 1 ]; then say "" say "Dry run: would download the archive and SHA256SUMS, verify the archive's SHA-256," say "and install $BINARIES into $INSTALL_DIR. Nothing was changed." next_steps return 0 fi check_install_dir TMP_DIR="$(mktemp -d 2>/dev/null || mktemp -d -t hearth-install)" trap cleanup EXIT trap 'cleanup; exit 130' INT TERM say "" say "Downloading $asset ..." download "$base/$asset" "$TMP_DIR/$asset" || die "download failed: $base/$asset (does release '$VERSION' exist for $target?)" download "$base/SHA256SUMS" "$TMP_DIR/SHA256SUMS" || die "download failed: $base/SHA256SUMS" verify "$TMP_DIR/$asset" "$TMP_DIR/SHA256SUMS" "$asset" mkdir "$TMP_DIR/x" tar -xzf "$TMP_DIR/$asset" -C "$TMP_DIR/x" for bin in $BINARIES; do [ -f "$TMP_DIR/x/$bin" ] || die "$asset does not contain $bin" done as_installer mkdir -p "$INSTALL_DIR" for bin in $BINARIES; do # Copy then rename, so a running binary is replaced atomically. as_installer cp "$TMP_DIR/x/$bin" "$INSTALL_DIR/.$bin.new" as_installer chmod 755 "$INSTALL_DIR/.$bin.new" as_installer mv -f "$INSTALL_DIR/.$bin.new" "$INSTALL_DIR/$bin" say "Installed $INSTALL_DIR/$bin" done if installed="$("$INSTALL_DIR/hearth" --version 2>/dev/null)"; then say "$installed" else warn "$INSTALL_DIR/hearth did not run; check that the build matches this machine" fi path_hint next_steps } main "$@"