#!/bin/sh # Ferrite CLI installer. # # Downloads the CLI for this platform from downloads.ferrite.cloud, verifies it # against the published SHA256SUMS, and installs it into a user-owned bin # directory. No sudo, no package manager, no Node.js. # # curl -fsSL https://downloads.ferrite.cloud/install.sh | sh # # Flags: # --no-agents install the binary only; skip agent MCP wiring # --dry-run report what would happen and exit # # The whole script is a set of functions called from the last line, so a # download that is cut short runs nothing instead of running half an install. set -eu BASE="${FERRITE_DOWNLOADS_BASE:-https://downloads.ferrite.cloud/releases/0.1.53}" MCP_ENDPOINT="https://mcp.ferrite.cloud/mcp" DASHBOARD_URL="https://dashboard.ferrite.cloud" PLUGIN_VERSION="0.1.53" BIN_DIR="${FERRITE_BIN_DIR:-$HOME/.local/bin}" # Release signing (readiness audit 2026-09-17, INST-3). The archive and # SHA256SUMS come from the same host, so the checksum catches a corrupt # download, not a compromised host: the trust boundary is write access to # that host plus TLS. When this constant holds the PEM public half of the # release key, SHA256SUMS must come with a valid detached signature # SHA256SUMS.sig (made by ops/ferrite/launch/build-cli-artifacts.sh) and the # installer refuses without openssl, without the signature, or with a bad one. # Empty means: verify the checksum only, exactly as before, and say nothing # about signatures. RELEASE_PUBKEY_PEM="-----BEGIN PUBLIC KEY----- MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEYpcwn2PKI1/SOP5z2fX9MRF3MlEp kUPHOOyCkYKZXDnvX8nK0A0EPu29xS8hJiIAzsuE27GluxlPF+8a+5gQmA== -----END PUBLIC KEY-----" # No account exists yet on this path (--no-agents, no Node.js or tar, or agent setup failed). manual_next_steps() { echo "" echo 'Start a Ferrite Cloud trial with $5 of credit for 48 hours:' echo " $BIN_DIR/ferrite login --ephemeral --endpoint $MCP_ENDPOINT" echo "Then: ferrite new hello my-app && cd my-app && ferrite check && ferrite dev" rust_next_steps deploy_next_steps } # Agent setup has already signed the CLI and the agents in (it prints "Shared account: "), so # these steps never ask for another login. A fresh trial on 19 November 2026 was told to run # 'ferrite login --ephemeral' right under the line naming the trial account setup had just made. signed_in_next_steps() { account=$("$BIN_DIR/ferrite" account 2>/dev/null | sed -n 's/^account: //p' | head -n 1) || account="" echo "" echo "Start a new session in your coding agent, then ask it to build and test an app." echo "Or by hand: ferrite new hello my-app && cd my-app && ferrite check && ferrite dev" rust_next_steps echo "To deploy, run: ferrite deploy" case "$account" in eph-*) echo " You are already signed in: setup created the trial account $account for this CLI and your" echo " coding agents, so there is no need to run 'ferrite login'." trial_next_steps ;; "") echo " This CLI and your coding agents share the account setup signed in above; there is no need" echo " to run 'ferrite login'." ;; *) echo " You are already signed in to the account $account, shared by this CLI and your coding agents." ;; esac echo " ferrite usage shows each app's requests and latency, and ferrite withdraw takes one down;" echo " use ferrite statement to see the account's available credit and ferrite cost to estimate your app." } # ferrite check, test and dev compile the app on this machine; ferrite deploy does not, because the # platform runs the same checks and builds the app itself. The same trial reached 'cargo did not # start' by following the steps above on a machine without Rust, and nothing had said it was needed. rust_next_steps() { if ! command -v cc >/dev/null 2>&1; then echo "Local builds need a C linker. On Debian or Ubuntu install build-essential. On macOS run xcode-select --install." fi if command -v cargo >/dev/null 2>&1; then return 0 fi echo "" if [ -x "$HOME/.cargo/bin/cargo" ]; then echo "Rust is installed in ~/.cargo but is not on PATH in this shell. Run:" echo " . \"\$HOME/.cargo/env\"" echo "ferrite check, ferrite test and ferrite dev need it; ferrite deploy does not." return 0 fi echo "Rust was not found. ferrite check, ferrite test and ferrite dev compile your app on this machine" echo "and need it. Install it with:" echo " curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh" echo "ferrite deploy works without Rust: the platform runs the same checks and builds the app remotely." } # Upstream Core deploys from a temporary account at once, and its applications go offline at the # server-provided expiry unless its human signs in; work that should last goes in an account the # human keeps. `ferrite new` prints the same rule; keep the two in step # (ops/ferrite/launch/test/onboarding-copy.test.mjs). trial_next_steps() { echo ' A Ferrite Cloud trial starts with $5 of credit. Trial apps go offline after 48 hours unless you claim them.' echo " Run 'ferrite claim --link' and open the link before expiry to keep the trial as your account" echo " or move its apps into an existing account. In MCP, use claim_url to get the link." } deploy_next_steps() { echo "To deploy, run: ferrite deploy" trial_next_steps echo " To start with an existing account, run 'ferrite login --sign-in'." echo " ferrite usage shows each app's requests and latency, and ferrite withdraw takes one down;" echo " use ferrite statement to see the account's available credit and ferrite cost to estimate your app." } # Name every missing tool at once, before anything is downloaded. Minimal # container images lack gzip or tar, and the failure used to arrive as a bare # "command not found" after the download. # Before launch the downloads host sits behind the platform's sign-in gate; a terminal gets through with the # preview token the sign-in page gives out, passed as FERRITE_PREVIEW_TOKEN. fetch() { if [ -n "${FERRITE_PREVIEW_TOKEN:-}" ]; then # Keep the bearer credential out of curl's process arguments. A config # file is private, short-lived, and removed even when the transfer fails. case "$FERRITE_PREVIEW_TOKEN" in *[!A-Za-z0-9._~/+=-]*) echo "Invalid preview credential." >&2; return 1 ;; esac preview_config=$(mktemp "${TMPDIR:-/tmp}/ferrite-install.XXXXXX") chmod 0600 "$preview_config" printf 'header = "X-Ferrite-Preview: %s"\n' "$FERRITE_PREVIEW_TOKEN" > "$preview_config" preview_status=0 curl -fsSL --config "$preview_config" "$@" || preview_status=$? rm -f "$preview_config" return "$preview_status" else curl -fsSL "$@" fi } require_tools() { missing="" for tool in "$@"; do command -v "$tool" >/dev/null 2>&1 || missing="$missing $tool" done if [ -n "$missing" ]; then echo "The installer needs these commands, which were not found:$missing" >&2 echo "Install them with your package manager and run the installer again." >&2 exit 1 fi } sha256_of() { if command -v shasum >/dev/null 2>&1; then shasum -a 256 "$1" | awk '{print $1}' else sha256sum "$1" | awk '{print $1}' fi } main() { AGENTS=1 DRY=0 for arg in "$@"; do case "$arg" in --no-agents) AGENTS=0 ;; --dry-run) DRY=1 ;; *) echo "unknown option: $arg" >&2; exit 2 ;; esac done os=$(uname -s) arch=$(uname -m) case "$os/$arch" in Darwin/arm64) asset="ferrite-aarch64-apple-darwin.gz" ;; Linux/x86_64) asset="ferrite-x86_64-unknown-linux-gnu.gz" ;; Linux/aarch64|Linux/arm64) asset="ferrite-aarch64-unknown-linux-gnu.gz" ;; *) echo "No published Ferrite CLI for $os/$arch." >&2 echo "Available: Darwin/arm64, Linux/x86_64, Linux/aarch64 — see $BASE/" >&2 exit 1 ;; esac echo "Ferrite CLI: $asset" if [ "$DRY" -eq 1 ]; then echo "would download $BASE/$asset" echo "would verify against $BASE/SHA256SUMS" [ -z "$RELEASE_PUBKEY_PEM" ] || echo "would verify $BASE/SHA256SUMS.sig against the release key" echo "would install to $BIN_DIR/ferrite" exit 0 fi require_tools curl awk grep gzip mktemp if ! command -v shasum >/dev/null 2>&1 && ! command -v sha256sum >/dev/null 2>&1; then echo "Neither shasum nor sha256sum is available — refusing to install unverified." >&2 exit 1 fi if [ -n "$RELEASE_PUBKEY_PEM" ] && ! command -v openssl >/dev/null 2>&1; then echo "This release is signed and checking the signature needs openssl, which was not found — refusing to install unverified." >&2 echo "Install openssl with your package manager and run the installer again." >&2 exit 1 fi # A template under TMPDIR: on macOS a bare mktemp ignores TMPDIR for the per-user # temporary directory, which an agent's sandbox often keeps read-only. tmp=$(mktemp -d "${TMPDIR:-/tmp}/ferrite-install.XXXXXX") candidate="" trap 'rm -rf "$tmp"; [ -z "$candidate" ] || rm -f "$candidate"' EXIT echo "Downloading…" fetch "$BASE/$asset" -o "$tmp/$asset" fetch "$BASE/SHA256SUMS" -o "$tmp/SHA256SUMS" # With a release key published above, SHA256SUMS itself must be signed; # nothing is unpacked or replaced before that holds. if [ -n "$RELEASE_PUBKEY_PEM" ]; then echo "Verifying signature…" if ! fetch "$BASE/SHA256SUMS.sig" -o "$tmp/SHA256SUMS.sig"; then echo "SHA256SUMS.sig is missing from $BASE — refusing to install an unsigned release." >&2 exit 1 fi printf '%s\n' "$RELEASE_PUBKEY_PEM" > "$tmp/release.pub" if ! openssl dgst -sha256 -verify "$tmp/release.pub" -signature "$tmp/SHA256SUMS.sig" "$tmp/SHA256SUMS" >/dev/null 2>&1; then echo "SHA256SUMS.sig does not verify against the release key — refusing to install." >&2 exit 1 fi fi echo "Verifying checksum…" expected=$(grep " $asset\$" "$tmp/SHA256SUMS" | awk '{print $1}') if [ -z "$expected" ]; then echo "No checksum published for $asset — refusing to install." >&2 exit 1 fi actual=$(sha256_of "$tmp/$asset") if [ "$expected" != "$actual" ]; then echo "Checksum mismatch for $asset." >&2 echo " expected $expected" >&2 echo " actual $actual" >&2 exit 1 fi # Unpack beside the destination (a temporary directory may be mounted # noexec), prove the binary runs on this machine, and only then replace an # existing install with one atomic rename. mkdir -p "$BIN_DIR" candidate="$BIN_DIR/.ferrite-install.$$" gzip -dc "$tmp/$asset" > "$candidate" chmod 755 "$candidate" if ! "$candidate" --version; then echo "" >&2 echo "The downloaded CLI does not run on this machine, so nothing was installed." >&2 if [ "$os" = "Linux" ]; then echo "The Linux build needs glibc 2.34 or newer (Ubuntu 22.04, Debian 12, Fedora 35," >&2 echo "Amazon Linux 2023 or later). musl systems such as Alpine are not supported." >&2 fi exit 1 fi mv -f "$candidate" "$BIN_DIR/ferrite" candidate="" echo "Installed $BIN_DIR/ferrite" case ":$PATH:" in *":$BIN_DIR:"*) ;; *) echo ""; echo "Add it to your PATH:"; echo " export PATH=\"$BIN_DIR:\$PATH\"" ;; esac if [ "$AGENTS" -ne 1 ]; then manual_next_steps exit 0 fi # Agent setup: the hosted plugin carries the MCP bridge and the setup script # that registers Ferrite with Codex, Claude Code, OpenCode and Pi, then signs # the CLI and every agent into one ephemeral account. It needs Node.js 18+. if ! command -v node >/dev/null 2>&1; then echo "" echo "Node.js 18+ was not found, so coding agents were not connected." manual_next_steps exit 0 fi if ! command -v tar >/dev/null 2>&1; then echo "" echo "tar was not found, so coding agents were not connected." manual_next_steps exit 0 fi plugin="ferrite-plugin-$PLUGIN_VERSION.tar.gz" fetch "$BASE/$plugin" -o "$tmp/$plugin" expected=$(grep " $plugin\$" "$tmp/SHA256SUMS" | awk '{print $1}') actual=$(sha256_of "$tmp/$plugin") if [ -z "$expected" ] || [ "$expected" != "$actual" ]; then echo "Checksum mismatch for $plugin; coding agents were not connected." >&2 manual_next_steps exit 0 fi setup_root="${FERRITE_SETUP_ROOT:-$HOME/.local/share/ferrite/setup-$PLUGIN_VERSION}" rm -rf "$setup_root" mkdir -p "$setup_root" tar -xzf "$tmp/$plugin" -C "$setup_root" --strip-components=1 echo "" # The setup reuses the CLI verified above rather than downloading another: # nothing it could fetch now is covered by the signature checked here. if FERRITE_DOWNLOADS_BASE="$BASE" FERRITE_MCP_ENDPOINT="$MCP_ENDPOINT" FERRITE_SETUP_BIN_DIR="$BIN_DIR" \ FERRITE_SETUP_INSTALLED_CLI="$BIN_DIR/ferrite" \ node "$setup_root/plugins/ferrite/artifacts/ferrite-setup.mjs"; then signed_in_next_steps else echo "Agent setup did not complete; the CLI is installed." >&2 manual_next_steps fi } main "$@"