#!/usr/bin/env bash # Install chiron-estimate (released binary) as an MCP server for Claude Code or Cursor, plus the skill. # # curl -fsSL https://raw.githubusercontent.com/chironvisioninc/chiron-estimator/main/install.sh -o install.sh # less install.sh && bash install.sh # # Also works from an unpacked release archive: the binary next to this script is used (no download). if [ -z "${BASH_VERSION:-}" ]; then exec bash "$0" "$@"; fi set -euo pipefail REPO="chironvisioninc/chiron-estimator" SERVER_NAME="chiron-estimate" HERE="$(cd "$(dirname "$0")" && pwd)" TARGET=""; INSTALL_DIR="$HOME/bin"; TAG="v0.1.0"; ASSUME_YES=0; BASE_URL="https://dda5275nshs90.cloudfront.net/estimator/ea324478d02311d6b42f939c08b08394/0.1.0"; AGENT=0 SAMPLES_DIR="$HOME/chiron-estimate/samples" TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT die() { echo "error: $*" >&2; exit 1; } say() { printf '%s\n' "$*"; } have() { command -v "$1" >/dev/null 2>&1; } # Ask on the terminal even when the script is piped in (curl ... | bash): stdin is then the script # itself, so read the answer from /dev/tty. With no terminal at all (CI, containers) keep the defaults. have_tty() { [ -t 0 ] || { : /dev/null; } interactive() { [ "$ASSUME_YES" -eq 0 ] && have_tty; } ask() { if [ -t 0 ]; then read -r -p "$1" "$2"; else read -r -p "$1" "$2" /dev/null; then if out="$(cosign verify-blob --bundle "$TMP/${file}.bundle" \ --certificate-identity-regexp "$identity" --certificate-oidc-issuer "$issuer" "$TMP/$file" 2>&1)"; then say "Sigstore OK: $file" return 0 fi bundle_failed=1 fi if ! curl -fsSL "$base/${file}.sig" -o "$TMP/${file}.sig"; then [ "$bundle_failed" = 0 ] || die "cosign verify failed for $file: $out" say "note: no Sigstore signature for $file; checksums only" return 0 fi curl -fsSL "$base/${file}.pem" -o "$TMP/${file}.pem" \ || die "signature present but certificate missing for $file" # cosign writes its progress and deprecation warnings to stderr; show them only on failure. out="$(cosign verify-blob \ --certificate "$TMP/${file}.pem" \ --signature "$TMP/${file}.sig" \ --certificate-identity-regexp "$identity" \ --certificate-oidc-issuer "$issuer" \ "$TMP/$file" 2>&1)" \ || die "cosign verify failed for $file: $out" say "Sigstore OK: $file" } verify_blob checksums.txt verify_blob "$ARCHIVE" tar -xzf "$TMP/$ARCHIVE" -C "$TMP" EX="$TMP/chiron-estimate-${VERSION}-${PLATFORM}" SRC_BIN="$EX/chiron-estimate"; SKILL_SRC="$EX/SKILL.md"; LICENSE_SRC="$EX/LICENSE"; SAMPLES_SRC="$EX/samples" # Archives from before samples were bundled: fall back to a source checkout's samples/ next to this script. [ -d "$SAMPLES_SRC" ] || SAMPLES_SRC="$HERE/samples" fi # Check a temp copy: a browser-downloaded archive marks the binary quarantined, and Gatekeeper kills # (SIGKILL) the ad-hoc-signed binary on first run unless the quarantine flag is cleared first. cp "$SRC_BIN" "$TMP/chiron-estimate.bin" [ "$(uname -s)" = Darwin ] && xattr -d com.apple.quarantine "$TMP/chiron-estimate.bin" 2>/dev/null || true if ! RUN_OUT="$("$TMP/chiron-estimate.bin" version 2>&1)"; then MSG="$SRC_BIN does not run on this machine" if [ "$(uname -s)" = Linux ]; then # The loader names the glibc version a too-old system lacks: "version `GLIBC_2.39' not found". NEED="$(printf '%s\n' "$RUN_OUT" | grep -o "GLIBC_[0-9][0-9.]*'" | sed "s/GLIBC_//; s/'//" | sort -V | tail -1 || true)" LDD_OUT="$(ldd --version 2>&1 | head -1 || true)" HAVE="$(printf '%s' "$LDD_OUT" | grep -o '[0-9][0-9]*\.[0-9][0-9]*$' || true)" if [ -n "$NEED" ]; then MSG="chiron-estimate needs glibc $NEED or newer, but this machine has ${HAVE:-an older glibc}. Use a newer Linux distribution, or run it in a container with a newer glibc." elif printf '%s' "$LDD_OUT" | grep -qi musl; then MSG="chiron-estimate is built for glibc, and this machine uses musl (for example Alpine). Use a glibc-based Linux distribution, or run it in a container based on one." fi fi die "$MSG" fi mkdir -p "$INSTALL_DIR" install -m 0755 "$TMP/chiron-estimate.bin" "$INSTALL_DIR/chiron-estimate" [ "$(uname -s)" = Darwin ] && xattr -d com.apple.quarantine "$INSTALL_DIR/chiron-estimate" 2>/dev/null || true BIN="$INSTALL_DIR/chiron-estimate" say "installed binary: $BIN (version $("$BIN" version | head -1 | awk '{print $2}'))" case ":$PATH:" in *":$INSTALL_DIR:"*) ;; *) say "note: $INSTALL_DIR is not on PATH; add: export PATH=\"$INSTALL_DIR:\$PATH\"" ;; esac # Copy the bundled sample to a stable folder (the tool writes its work directory next to the sample), # so the first prompt below can name a real path. Existing files there other than the sample are kept. SAMPLE="" if [ -d "$SAMPLES_SRC/zookeeper" ]; then mkdir -p "$SAMPLES_DIR" (cd "$SAMPLES_SRC" && tar --exclude=.chiron-estimate -cf - .) | tar -C "$SAMPLES_DIR" -xf - SAMPLES_DIR="$(cd "$SAMPLES_DIR" && pwd)" SAMPLE="$SAMPLES_DIR/zookeeper" say "sample logs: $SAMPLE" fi # The agent file needs absolute paths. It starts the MCP server itself, so nothing is registered globally. install_agent() { mkdir -p "$HOME/.claude/agents" cat > "$TMP/agent.md" <<'AGENT' --- name: chiron-estimator description: Estimates how much Splunk license a prospect would save with Chiron log consolidation, offline, from a log sample. Use for a Chiron savings estimate, a consolidation policy, a consolidation report or a pilot configuration. mcpServers: - chiron-estimate: type: stdio command: __BIN__ args: ["mcp"] tools: Read, Write, Edit, Glob, Bash, mcp__chiron-estimate__* --- Before doing anything else, Read `__SKILL__` in full and follow it. Its MCP tools (inspect, estimate, compare, confirm, report) are already connected for you. The binary is not on PATH. For CLI-only commands, call it by full path, for example `__BIN__ policy init `. Use Read only on that SKILL.md, policy.json and the result files a tool's response names, and only after that tool call has returned its final result. Never read, open or copy the log sample or the work directory's decoded copy of it, and read nothing while a call is still running. You can't talk to the user directly. Whenever the skill says to ask the user something, or to show them a `confirm` block verbatim, stop and return: put the question or the block verbatim in your final message, with its `section` and `section_hash`, and say what you're waiting for. You'll be resumed with the user's reply; record it word for word. Never record a decision the user didn't give. AGENT sed -e "s|__BIN__|$BIN|g" -e "s|__SKILL__|$HOME/.claude/skills/chiron-estimate/SKILL.md|g" "$TMP/agent.md" > "$HOME/.claude/agents/chiron-estimator.md" } # Add the server to a JSON config file (keeps a .bak of an existing file). add_mcp_json() { python3 - "$1" "$SERVER_NAME" "$BIN" "$2" <<'PY' import json, os, shutil, sys path, name, cmd, typed = sys.argv[1:5] data = {} if os.path.exists(path) and os.path.getsize(path) > 0: shutil.copy(path, path + ".bak") data = json.load(open(path)) entry = {"command": cmd, "args": ["mcp"]} if typed == "stdio": entry = {"type": "stdio", **entry} data.setdefault("mcpServers", {})[name] = entry os.makedirs(os.path.dirname(path), exist_ok=True) json.dump(data, open(path, "w"), indent=2) PY } register_claude() { mkdir -p "$HOME/.claude/skills/chiron-estimate" cp "$SKILL_SRC" "$HOME/.claude/skills/chiron-estimate/SKILL.md" [ -f "$LICENSE_SRC" ] && cp "$LICENSE_SRC" "$HOME/.claude/skills/chiron-estimate/" if [ "$AGENT" -eq 0 ]; then if [ $CLAUDE_CLI -eq 1 ]; then claude mcp remove "$SERVER_NAME" --scope user >/dev/null 2>&1 || true claude mcp add --scope user "$SERVER_NAME" -- "$BIN" mcp else add_mcp_json "$HOME/.claude.json" stdio fi # The Claude desktop app (chat) reads its own config; its Code tab uses ~/.claude like Claude Code. if [ $CLAUDE_DESKTOP -eq 1 ]; then add_mcp_json "$CLAUDE_DESKTOP_CFG" plain say "Claude desktop app: registered in $CLAUDE_DESKTOP_CFG; quit and reopen the app" fi fi if [ "$AGENT" -eq 1 ]; then install_agent say "Claude Code: agent chiron-estimator at ~/.claude/agents/chiron-estimator.md; skill at ~/.claude/skills/chiron-estimate/" else say "Claude: registered$([ $CLAUDE_CLI -eq 1 ] || echo ' (no claude command needed)'); skill at ~/.claude/skills/chiron-estimate/" fi } register_cursor() { local cfg="$HOME/.cursor/mcp.json" mkdir -p "$HOME/.cursor/rules" python3 - "$cfg" "$SERVER_NAME" "$BIN" <<'PY' import json, os, shutil, sys path, name, cmd = sys.argv[1:4] data = {} if os.path.exists(path) and os.path.getsize(path) > 0: shutil.copy(path, path + ".bak") data = json.load(open(path)) data.setdefault("mcpServers", {})[name] = {"command": cmd, "args": ["mcp"]} json.dump(data, open(path, "w"), indent=2) PY { printf -- '---\ndescription: Estimate Chiron log consolidation savings with the chiron-estimate MCP tools\nalwaysApply: false\n---\n\n'; cat "$SKILL_SRC"; } > "$HOME/.cursor/rules/chiron-estimate.mdc" say "Cursor: registered in $cfg (backup kept as mcp.json.bak); rule at ~/.cursor/rules/chiron-estimate.mdc" } case "$TARGET" in claude) register_claude ;; cursor) register_cursor ;; both) register_claude; register_cursor ;; esac say "" if [ -n "$SAMPLE" ]; then say "Done. Open a new session and paste this to try the bundled sample (swap in your own log folder later):" P="$SAMPLE"; F="$SAMPLE" else say "Done. Open a new session and paste:" P=""; F="" fi if [ "$AGENT" -eq 1 ]; then say " Use the chiron-estimator agent: I'd like a Chiron savings estimate for my logs, start to finish. The sample is at $P. Keep everything in $F." else say " Use the chiron-estimate skill to estimate Chiron savings for the sample in $P." fi