|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# install.sh — One-line installer for codebase-memory-mcp. |
| 5 | +# |
| 6 | +# Usage: |
| 7 | +# curl -fsSL https://raw.githubusercontent.com/DeusData/codebase-memory-mcp/main/install.sh | bash |
| 8 | +# curl -fsSL ... | bash -s -- --ui # Install the UI variant (graph visualization) |
| 9 | +# curl -fsSL ... | bash -s -- --dir /usr/local/bin # Custom install directory |
| 10 | +# |
| 11 | +# What it does: |
| 12 | +# 1. Detects OS (macOS/Linux/Windows) and architecture (arm64/amd64) |
| 13 | +# 2. Downloads the latest release binary from GitHub |
| 14 | +# 3. On macOS: removes quarantine/provenance xattrs, re-signs locally |
| 15 | +# 4. Installs to ~/.local/bin (or custom --dir) |
| 16 | +# 5. Runs `codebase-memory-mcp install` to configure all detected coding agents |
| 17 | + |
| 18 | +REPO="DeusData/codebase-memory-mcp" |
| 19 | +INSTALL_DIR="$HOME/.local/bin" |
| 20 | +VARIANT="standard" |
| 21 | + |
| 22 | +# ── Parse arguments ────────────────────────────────────────── |
| 23 | +for arg in "$@"; do |
| 24 | + case "$arg" in |
| 25 | + --ui) VARIANT="ui" ;; |
| 26 | + --standard) VARIANT="standard" ;; |
| 27 | + --dir=*) INSTALL_DIR="${arg#--dir=}" ;; |
| 28 | + --dir) shift; INSTALL_DIR="$1" ;; |
| 29 | + --help|-h) |
| 30 | + echo "Usage: install.sh [--ui] [--dir <path>]" |
| 31 | + echo " --ui Install the UI variant (with graph visualization)" |
| 32 | + echo " --standard Install the standard variant (default)" |
| 33 | + echo " --dir PATH Install directory (default: ~/.local/bin)" |
| 34 | + exit 0 |
| 35 | + ;; |
| 36 | + esac |
| 37 | +done |
| 38 | + |
| 39 | +# ── Detect OS ──────────────────────────────────────────────── |
| 40 | +detect_os() { |
| 41 | + case "$(uname -s)" in |
| 42 | + Darwin) echo "darwin" ;; |
| 43 | + Linux) echo "linux" ;; |
| 44 | + MINGW*|MSYS*|CYGWIN*) echo "windows" ;; |
| 45 | + *) |
| 46 | + echo "error: unsupported OS: $(uname -s)" >&2 |
| 47 | + exit 1 |
| 48 | + ;; |
| 49 | + esac |
| 50 | +} |
| 51 | + |
| 52 | +# ── Detect architecture ────────────────────────────────────── |
| 53 | +detect_arch() { |
| 54 | + case "$(uname -m)" in |
| 55 | + arm64|aarch64) echo "arm64" ;; |
| 56 | + x86_64|amd64) |
| 57 | + # On macOS, check if this is Apple Silicon running under Rosetta |
| 58 | + if [ "$(uname -s)" = "Darwin" ] && sysctl -n machdep.cpu.brand_string 2>/dev/null | grep -qi apple; then |
| 59 | + echo "arm64" |
| 60 | + else |
| 61 | + echo "amd64" |
| 62 | + fi |
| 63 | + ;; |
| 64 | + *) |
| 65 | + echo "error: unsupported architecture: $(uname -m)" >&2 |
| 66 | + exit 1 |
| 67 | + ;; |
| 68 | + esac |
| 69 | +} |
| 70 | + |
| 71 | +OS=$(detect_os) |
| 72 | +ARCH=$(detect_arch) |
| 73 | + |
| 74 | +echo "codebase-memory-mcp installer" |
| 75 | +echo " os: $OS" |
| 76 | +echo " arch: $ARCH" |
| 77 | +echo " variant: $VARIANT" |
| 78 | +echo " target: $INSTALL_DIR/codebase-memory-mcp" |
| 79 | +echo "" |
| 80 | + |
| 81 | +# ── Build download URL ─────────────────────────────────────── |
| 82 | +if [ "$OS" = "windows" ]; then |
| 83 | + EXT="zip" |
| 84 | +else |
| 85 | + EXT="tar.gz" |
| 86 | +fi |
| 87 | + |
| 88 | +if [ "$VARIANT" = "ui" ]; then |
| 89 | + ARCHIVE="codebase-memory-mcp-ui-${OS}-${ARCH}.${EXT}" |
| 90 | +else |
| 91 | + ARCHIVE="codebase-memory-mcp-${OS}-${ARCH}.${EXT}" |
| 92 | +fi |
| 93 | + |
| 94 | +URL="https://github.com/${REPO}/releases/latest/download/${ARCHIVE}" |
| 95 | + |
| 96 | +# ── Download ───────────────────────────────────────────────── |
| 97 | +TMPDIR=$(mktemp -d) |
| 98 | +trap 'rm -rf "$TMPDIR"' EXIT |
| 99 | + |
| 100 | +echo "Downloading ${ARCHIVE}..." |
| 101 | +if command -v curl &>/dev/null; then |
| 102 | + curl -fSL --progress-bar -o "$TMPDIR/$ARCHIVE" "$URL" |
| 103 | +elif command -v wget &>/dev/null; then |
| 104 | + wget -q --show-progress -O "$TMPDIR/$ARCHIVE" "$URL" |
| 105 | +else |
| 106 | + echo "error: curl or wget required" >&2 |
| 107 | + exit 1 |
| 108 | +fi |
| 109 | + |
| 110 | +# ── Extract ────────────────────────────────────────────────── |
| 111 | +echo "Extracting..." |
| 112 | +cd "$TMPDIR" |
| 113 | +if [ "$EXT" = "zip" ]; then |
| 114 | + unzip -q "$ARCHIVE" |
| 115 | +else |
| 116 | + tar -xzf "$ARCHIVE" |
| 117 | +fi |
| 118 | + |
| 119 | +BINARY="$TMPDIR/codebase-memory-mcp" |
| 120 | +if [ "$OS" = "windows" ] && [ -f "$TMPDIR/codebase-memory-mcp.exe" ]; then |
| 121 | + BINARY="$TMPDIR/codebase-memory-mcp.exe" |
| 122 | +fi |
| 123 | + |
| 124 | +if [ ! -f "$BINARY" ]; then |
| 125 | + echo "error: binary not found after extraction" >&2 |
| 126 | + exit 1 |
| 127 | +fi |
| 128 | + |
| 129 | +# ── macOS: fix signing ─────────────────────────────────────── |
| 130 | +if [ "$OS" = "darwin" ]; then |
| 131 | + echo "Fixing macOS code signing..." |
| 132 | + |
| 133 | + # Remove quarantine and provenance xattrs (set by browsers/curl on macOS) |
| 134 | + xattr -d com.apple.quarantine "$BINARY" 2>/dev/null || true |
| 135 | + xattr -d com.apple.provenance "$BINARY" 2>/dev/null || true |
| 136 | + |
| 137 | + # Re-sign locally with ad-hoc signature (required for Apple Silicon) |
| 138 | + codesign --force --sign - "$BINARY" 2>/dev/null || true |
| 139 | +fi |
| 140 | + |
| 141 | +# ── Install ────────────────────────────────────────────────── |
| 142 | +mkdir -p "$INSTALL_DIR" |
| 143 | +DEST="$INSTALL_DIR/codebase-memory-mcp" |
| 144 | +if [ "$OS" = "windows" ]; then |
| 145 | + DEST="${DEST}.exe" |
| 146 | +fi |
| 147 | + |
| 148 | +# Remove old binary if present (handles read-only files) |
| 149 | +if [ -f "$DEST" ]; then |
| 150 | + rm -f "$DEST" |
| 151 | +fi |
| 152 | + |
| 153 | +cp "$BINARY" "$DEST" |
| 154 | +chmod 755 "$DEST" |
| 155 | + |
| 156 | +# Verify binary runs |
| 157 | +echo "" |
| 158 | +VERSION=$("$DEST" --version 2>&1) || { |
| 159 | + echo "error: installed binary failed to run" >&2 |
| 160 | + echo " try: xattr -cr $DEST && codesign --force --sign - $DEST" >&2 |
| 161 | + exit 1 |
| 162 | +} |
| 163 | +echo "Installed: $VERSION" |
| 164 | + |
| 165 | +# ── Run install subcommand ─────────────────────────────────── |
| 166 | +echo "" |
| 167 | +echo "Configuring coding agents..." |
| 168 | +"$DEST" install -y 2>&1 || { |
| 169 | + echo "" |
| 170 | + echo "Agent configuration failed (non-fatal)." |
| 171 | + echo "You can run it manually: codebase-memory-mcp install" |
| 172 | +} |
| 173 | + |
| 174 | +# ── PATH check ─────────────────────────────────────────────── |
| 175 | +if ! echo "$PATH" | tr ':' '\n' | grep -qx "$INSTALL_DIR"; then |
| 176 | + echo "" |
| 177 | + echo "NOTE: $INSTALL_DIR is not in your PATH." |
| 178 | + echo "Add it to your shell config:" |
| 179 | + echo "" |
| 180 | + echo " echo 'export PATH=\"$INSTALL_DIR:\$PATH\"' >> ~/.zshrc" |
| 181 | + echo "" |
| 182 | +fi |
| 183 | + |
| 184 | +echo "" |
| 185 | +echo "Done! Restart your coding agent to start using codebase-memory-mcp." |
0 commit comments