#!/bin/sh # Hydra CLI installer for Linux (x64) and macOS (Apple silicon). # # curl -fsSL https://dl.hydrasim.ai/Hydra/free/hydra_cli/install.sh | sh # curl -fsSL https://dl.hydrasim.ai/Hydra/free/hydra_cli/install.sh | sh -s -- --uninstall # # Per-user, no sudo: # $HYDRA_CLI_HOME//{bin,lib} (default ~/.local/share/hydra-cli) # $HYDRA_CLI_BIN_DIR/hydra_cli (default ~/.local/bin; a symlink to the real binary) # # Contract: hydra_cli is found on PATH, and its libraries are in ../lib beside the symlink's # target, the same layout as the release tarball's -/ folder. # # Generated by hcli/packaging/package.sh from install.sh.in: the version and the sha256 of each # archive are filled in at packaging time, so this script installs exactly one release. set -eu VERSION='0.1.1' BASE_URL="${HYDRA_CLI_BASE_URL:-https://dl.hydrasim.ai/Hydra/free/hydra_cli}" # override only for testing; the sha256s stay pinned SHA256_LINUX_X64='251d959841710c8729939ccba69be313a4d2f377a0a9401149dfc04268ac813f' SHA256_DARWIN_ARM64='2c7474923511e62e03d6761e15012b29baaac25c4a60664de3f95058201d7fbe' say() { printf '%s\n' "$*"; } die() { printf 'hydra_cli install: %s\n' "$*" >&2; exit 1; } main() { home_dir="${HOME:?HOME is not set}" install_root="${HYDRA_CLI_HOME:-$home_dir/.local/share/hydra-cli}" bin_dir="${HYDRA_CLI_BIN_DIR:-$home_dir/.local/bin}" link="$bin_dir/hydra_cli" case "${1:-}" in --uninstall) uninstall; return ;; '') ;; *) die "unknown option: $1 (only --uninstall is accepted)" ;; esac plat="$(detect_platform)" case "$plat" in linux-x64) sha="$SHA256_LINUX_X64" ;; darwin-arm64) sha="$SHA256_DARWIN_ARM64" ;; esac archive="hydra_cli-$VERSION-$plat.tar.gz" url="$BASE_URL/$VERSION/$archive" tmp="$(mktemp -d 2>/dev/null || mktemp -d -t hydra_cli)" trap 'rm -rf "$tmp"' EXIT INT TERM say "Downloading Hydra CLI $VERSION for $plat..." fetch "$url" "$tmp/$archive" got="$(sha256_of "$tmp/$archive")" [ "$got" = "$sha" ] || die "checksum mismatch for $archive (expected $sha, got $got); not installing" check_archive "$tmp/$archive" "$plat" mkdir -p "$install_root" "$bin_dir" staging="$install_root/.staging-$$" rm -rf "$staging" mkdir -p "$staging" tar -xzf "$tmp/$archive" -C "$staging" [ -x "$staging/$plat/bin/hydra_cli" ] || die "the archive has no $plat/bin/hydra_cli" target="$install_root/$VERSION" rm -rf "$target" mv "$staging/$plat" "$target" rm -rf "$staging" if ! out="$("$target/bin/hydra_cli" --version 2>&1)"; then rm -rf "$target" say "$out" >&2 if [ "$plat" = linux-x64 ]; then die "hydra_cli does not run on this system. It needs glibc 2.38 and libstdc++ from GCC 13 or newer (Ubuntu 24.04, Debian 13, Fedora 39 or later)." fi die "hydra_cli does not run on this system (see the error above)" fi # Replace the link last, so an existing install keeps working until the new one is verified. ln -sfn "$target/bin/hydra_cli" "$link" # Older versions: nothing links to them any more. for old in "$install_root"/*; do [ -d "$old" ] || continue [ "$old" = "$target" ] && continue rm -rf "$old" done say "Installed: $out" say " files: $target" say " link: $link" path_hint "$bin_dir" } detect_platform() { os="$(uname -s)" arch="$(uname -m)" case "$os" in Linux) case "$arch" in x86_64|amd64) echo linux-x64 ;; *) die "no build for Linux on $arch (only x86_64)" ;; esac ;; Darwin) # A shell running under Rosetta reports x86_64; the hardware decides. if [ "$arch" = arm64 ] || [ "$(sysctl -n hw.optional.arm64 2>/dev/null || echo 0)" = 1 ]; then echo darwin-arm64 else die "no build for Intel Macs (only Apple silicon)" fi ;; MINGW*|MSYS*|CYGWIN*) die "on Windows, use the installer: $BASE_URL/$VERSION/hydra_cli-$VERSION-win32-x64-setup.exe" ;; *) die "unsupported system: $os $arch" ;; esac } fetch() { if command -v curl >/dev/null 2>&1; then curl -fsSL --retry 3 -o "$2" "$1" || die "download failed: $1" elif command -v wget >/dev/null 2>&1; then wget -q -O "$2" "$1" || die "download failed: $1" else die "neither curl nor wget is installed" fi } sha256_of() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d' ' -f1 elif command -v shasum >/dev/null 2>&1; then shasum -a 256 "$1" | cut -d' ' -f1 else die "neither sha256sum nor shasum is installed" fi } # Only plain files and directories, all under /, nothing absolute and no "..". check_archive() { tar -tzvf "$1" | while IFS= read -r line; do case "$line" in -*|d*) ;; *) die "the archive contains a link or special file: $line" ;; esac done tar -tzf "$1" | while IFS= read -r name; do case "$name" in "$2"/*|"$2") ;; *) die "unexpected path in the archive: $name" ;; esac case "/$name/" in */../*) die "unsafe path in the archive: $name" ;; esac done } path_hint() { case ":${PATH:-}:" in *":$1:"*) say "Run: hydra_cli --help" ;; *) say "" say "$1 is not on your PATH. Add it, then open a new terminal:" case "${SHELL:-}" in */zsh) say " echo 'export PATH=\"$1:\$PATH\"' >> ~/.zprofile" ;; */fish) say " fish_add_path $1" ;; *) say " echo 'export PATH=\"$1:\$PATH\"' >> ~/.profile" ;; esac ;; esac } uninstall() { if [ -L "$link" ]; then case "$(readlink "$link")" in "$install_root"/*) rm -f "$link" ;; *) say "Leaving $link alone: it does not point into $install_root" ;; esac fi rm -rf "$install_root" say "Hydra CLI removed from $install_root" } main "$@"