#!/bin/sh # Mercury installer — https://mercury-cli.ai/install # # curl -fsSL https://mercury-cli.ai/install | sh # # Downloads the release archive for this machine from GitHub Releases, checks # its SHA-256 against the release's checksum file, unpacks it, and runs the # archive's own `mercury install` — the user-local installer that puts the # release under ~/.mercury/versions/ and a `mercury` command in ~/.local/bin, # then puts that folder on your PATH (one line in your shell's rc file) when it # is not already. No administrator access; nothing outside your home. # Rerunning is safe. # # Knobs (all optional): # MERCURY_VERSION a release tag (default: the newest release) # MERCURY_INSTALL_BASE_URL where the assets live (default: the GitHub release) # MERCURY_INSTALL_ARGS extra args for `mercury install` (e.g. --force) set -eu REPO="Whq02/MercuryCLI" say() { printf '%s\n' "$*"; } die() { printf 'mercury install: %s\n' "$*" >&2; exit 1; } need() { command -v "$1" >/dev/null 2>&1 || die "this installer needs '$1' — install it and rerun"; } need curl; need tar # ── which archive ──────────────────────────────────────────────────────────── os=$(uname -s); arch=$(uname -m) case "$os/$arch" in Darwin/arm64) target=macos-arm64 ;; Darwin/x86_64) target=macos-x64 ;; Linux/x86_64|Linux/amd64) target=linux-x64 ;; Linux/aarch64|Linux/arm64) die "no Linux arm64 build yet — build from source: https://github.com/$REPO" ;; MINGW*|MSYS*|CYGWIN*|Windows*) die "on Windows use PowerShell: irm https://mercury-cli.ai/install.ps1 | iex" ;; *) die "unsupported platform: $os $arch" ;; esac # ── which version ──────────────────────────────────────────────────────────── version=${MERCURY_VERSION:-} if [ -z "$version" ]; then # The newest release, pre-releases included (the /latest endpoint hides them). version=$(curl -fsSL "https://api.github.com/repos/$REPO/releases?per_page=1" 2>/dev/null \ | grep -m1 '"tag_name"' | sed 's/.*"tag_name": *"\([^"]*\)".*/\1/' || true) [ -n "$version" ] || die "could not find the newest release at github.com/$REPO — set MERCURY_VERSION=vX.Y.Z" fi case "$version" in v*) ;; *) version="v$version" ;; esac asset="mercury-$version-$target.tar.gz" base=${MERCURY_INSTALL_BASE_URL:-"https://github.com/$REPO/releases/download/$version"} # ── download + verify ──────────────────────────────────────────────────────── tmp=$(mktemp -d "${TMPDIR:-/tmp}/mercury-install.XXXXXX") trap 'rm -rf "$tmp"' EXIT say "Mercury $version for $target" say " downloading $asset" curl -fsSL --retry 3 -o "$tmp/$asset" "$base/$asset" || die "download failed: $base/$asset" curl -fsSL --retry 3 -o "$tmp/SHA256SUMS.txt" "$base/SHA256SUMS.txt" || die "download failed: $base/SHA256SUMS.txt" want=$(grep " $asset\$" "$tmp/SHA256SUMS.txt" | awk '{print $1}' | head -1) [ -n "$want" ] || die "$asset is not listed in SHA256SUMS.txt" if command -v sha256sum >/dev/null 2>&1; then got=$(sha256sum "$tmp/$asset" | awk '{print $1}') else got=$(shasum -a 256 "$tmp/$asset" | awk '{print $1}'); fi [ "$got" = "$want" ] || die "checksum mismatch for $asset (got $got, want $want) — nothing installed" say " checksum ok" # ── unpack + the archive's own installer ───────────────────────────────────── tar -xzf "$tmp/$asset" -C "$tmp" [ -x "$tmp/mercury/mercury" ] || die "the archive has no launcher at mercury/mercury" say " installing (user-local; no administrator access)" # shellcheck disable=SC2086 "$tmp/mercury/mercury" install ${MERCURY_INSTALL_ARGS:-} # ── the command on PATH ────────────────────────────────────────────────────── # ~/.local/bin is not on a fresh macOS PATH (and reaches a Linux PATH only at # the next login). One guarded line in the login shell's rc file makes # `mercury` work in every new terminal. bin="$HOME/.local/bin" case ":${PATH}:" in *":$bin:"*) say "" say "Done. Run: mercury" ;; *) line="export PATH=\"\$HOME/.local/bin:\$PATH\"" case "$(basename "${SHELL:-sh}")" in zsh) rc="$HOME/.zshrc" ;; bash) if [ "$os" = Darwin ]; then rc="$HOME/.bash_profile"; else rc="$HOME/.bashrc"; fi ;; fish) rc="$HOME/.config/fish/config.fish"; line="fish_add_path \"\$HOME/.local/bin\"" ;; *) rc="$HOME/.profile" ;; esac if [ -f "$rc" ] && grep -Fq '.local/bin' "$rc" 2>/dev/null; then say "" say "Done. $rc already names ~/.local/bin — open a new terminal and run: mercury" else mkdir -p "$(dirname "$rc")" printf '\n# mercury: the user-local command\n%s\n' "$line" >> "$rc" say "" say "Done. Added ~/.local/bin to PATH in $rc — open a new terminal and run: mercury" say " (this terminal: $line)" fi ;; esac