From 842502ca5a61d8c9d3ed4b9ef88be77bc60f2352 Mon Sep 17 00:00:00 2001 From: Chaim Date: Sat, 4 Apr 2026 18:06:54 +0000 Subject: [PATCH] feat: auto-install missing prerequisites (go, git, jq) Install script now detects missing dependencies and installs them automatically via apt/dnf/yum/pacman/apk/brew. Go is installed directly from go.dev if missing or too old. Also added note about global config path in README. Co-Authored-By: Claude Opus 4.6 (1M context) --- README.md | 5 ++- install.sh | 119 ++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 112 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 1ee644c..25611ac 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,10 @@ curl -fsSL https://gitea.dev.marcus-law.co.il/Chaim/gitea-mcp/raw/branch/main/in curl -fsSL https://gitea.dev.marcus-law.co.il/Chaim/gitea-mcp/raw/branch/main/install.sh | bash ``` -## הגדרה ידנית +## הגדר�� ידנית + +> **חשוב:** כדי שההגדרה תהיה **גלובלית** (זמינה בכל פרויקט), יש לכתוב אותה ב-`~/.claude/settings.json` תחת `mcpServers`. +> אל תשתמשו ב-`.mcp.json` ברמת פרויקט — זה יגרום לכפילויות ויעבוד רק בתיקייה הספציפית. ### שרת יחיד diff --git a/install.sh b/install.sh index 67c6e67..441dfb3 100755 --- a/install.sh +++ b/install.sh @@ -66,6 +66,81 @@ ask_input() { fi } +# ── Auto-install helpers ─────────────────────────────────────────────────── + +detect_pkg_manager() { + if command -v apt-get &>/dev/null; then echo "apt" + elif command -v dnf &>/dev/null; then echo "dnf" + elif command -v yum &>/dev/null; then echo "yum" + elif command -v pacman &>/dev/null; then echo "pacman" + elif command -v apk &>/dev/null; then echo "apk" + elif command -v brew &>/dev/null; then echo "brew" + else echo ""; fi +} + +install_pkg() { + local pkg="$1" + local pm + pm=$(detect_pkg_manager) + + case "$pm" in + apt) sudo apt-get update -qq && sudo apt-get install -y -qq "$pkg" ;; + dnf) sudo dnf install -y -q "$pkg" ;; + yum) sudo yum install -y -q "$pkg" ;; + pacman) sudo pacman -S --noconfirm "$pkg" ;; + apk) sudo apk add --quiet "$pkg" ;; + brew) brew install "$pkg" ;; + *) return 1 ;; + esac +} + +install_go() { + local GO_VERSION_TARGET="1.24.2" + local ARCH + ARCH=$(uname -m) + case "$ARCH" in + x86_64) ARCH="amd64" ;; + aarch64|arm64) ARCH="arm64" ;; + *) error "Unsupported architecture: $ARCH"; return 1 ;; + esac + local OS + OS=$(uname -s | tr '[:upper:]' '[:lower:]') + + local TARBALL="go${GO_VERSION_TARGET}.${OS}-${ARCH}.tar.gz" + local URL="https://go.dev/dl/$TARBALL" + + info "Downloading Go $GO_VERSION_TARGET for $OS/$ARCH ..." + local tmpfile + tmpfile=$(mktemp) + if command -v curl &>/dev/null; then + curl -fsSL "$URL" -o "$tmpfile" + elif command -v wget &>/dev/null; then + wget -q "$URL" -O "$tmpfile" + else + error "Neither curl nor wget found — cannot download Go" + return 1 + fi + + info "Installing Go to /usr/local/go ..." + sudo rm -rf /usr/local/go + sudo tar -C /usr/local -xzf "$tmpfile" + rm -f "$tmpfile" + + # Add to PATH for this session + export PATH="/usr/local/go/bin:$PATH" + + # Persist in shell profile if not already there + local profile="$HOME/.profile" + [ -f "$HOME/.bashrc" ] && profile="$HOME/.bashrc" + [ -f "$HOME/.zshrc" ] && profile="$HOME/.zshrc" + if ! grep -q '/usr/local/go/bin' "$profile" 2>/dev/null; then + echo 'export PATH="/usr/local/go/bin:$PATH"' >> "$profile" + info "Added Go to PATH in $profile" + fi + + ok "Go $GO_VERSION_TARGET installed" +} + # ── Step 0: Prerequisites ────────────────────────────────────────────────── echo "" @@ -74,25 +149,47 @@ echo "" info "Checking prerequisites..." -if ! command -v go &>/dev/null; then - error "Go is required but not found. Install from https://go.dev/dl/" - exit 1 -fi -GO_VERSION=$(go version | grep -oP 'go\d+\.\d+') -ok "go ($GO_VERSION)" - +# --- git --- if ! command -v git &>/dev/null; then - error "git is required but not found" - exit 1 + warn "git not found, installing..." + if ! install_pkg git; then + error "Failed to install git. Install manually and re-run." + exit 1 + fi fi ok "git ($(git --version | cut -d' ' -f3))" +# --- jq --- if ! command -v jq &>/dev/null; then - error "jq is required but not found. Install: sudo apt install jq" - exit 1 + warn "jq not found, installing..." + if ! install_pkg jq; then + error "Failed to install jq. Install manually and re-run." + exit 1 + fi fi ok "jq ($(jq --version 2>/dev/null))" +# --- Go --- +if ! command -v go &>/dev/null; then + warn "Go not found, installing..." + if ! install_go; then + error "Failed to install Go. Install manually from https://go.dev/dl/ and re-run." + exit 1 + fi +fi +GO_VERSION=$(go version | grep -oP 'go\d+\.\d+') +GO_MAJOR=$(echo "$GO_VERSION" | grep -oP '\d+' | head -1) +GO_MINOR=$(echo "$GO_VERSION" | grep -oP '\d+' | tail -1) +if [ "$GO_MAJOR" -lt 1 ] || { [ "$GO_MAJOR" -eq 1 ] && [ "$GO_MINOR" -lt 24 ]; }; then + warn "Go $GO_VERSION is too old (need 1.24+), upgrading..." + if ! install_go; then + error "Failed to upgrade Go. Install manually from https://go.dev/dl/ and re-run." + exit 1 + fi + GO_VERSION=$(go version | grep -oP 'go\d+\.\d+') +fi +ok "go ($GO_VERSION)" + # ── Step 1: Clone or update ──────────────────────────────────────────────── echo ""