82 lines
2.9 KiB
Bash
82 lines
2.9 KiB
Bash
#!/usr/bin/env sh
|
|
# One-time bootstrap for the covert-gpt MCP gateway on a user's laptop.
|
|
#
|
|
# curl -fsSL https://git.nic-oconnor.com/public/dotfiles/raw/branch/main/mcp-config/install.sh | sh
|
|
#
|
|
# It is interactive (prompts for the user's LiteLLM key) UNLESS LITELLM_KEY is
|
|
# already set in the environment, e.g.:
|
|
# curl -fsSL .../install.sh | LITELLM_KEY=sk-... sh
|
|
#
|
|
# What it installs (all under the user's home, no root):
|
|
# ~/.config/mcp-sync/sync.sh the per-shell refresh hook (from Gitea)
|
|
# ~/.config/mcp-sync/key the user's LiteLLM virtual key (chmod 600)
|
|
# a line in the user's shell rc that sources sync.sh on each shell start
|
|
# After this, every new shell refreshes the gateway config automatically.
|
|
set -eu
|
|
|
|
RAW_BASE="${MCP_SYNC_RAW_BASE:-https://git.nic-oconnor.com/public/dotfiles/raw/branch/main/mcp-config}"
|
|
SYNC_HOME="$HOME/.config/mcp-sync"
|
|
SYNC_SH="$SYNC_HOME/sync.sh"
|
|
KEYFILE="$SYNC_HOME/key"
|
|
HOOK_MARKER="# >>> covert-gpt mcp-sync >>>"
|
|
|
|
say() { printf '%s\n' "$*" >&2; }
|
|
|
|
command -v curl >/dev/null 2>&1 || { say "error: curl is required"; exit 1; }
|
|
|
|
mkdir -p "$SYNC_HOME"
|
|
|
|
# --- 1. fetch the sync hook ------------------------------------------------
|
|
say "Fetching mcp-sync hook..."
|
|
curl -fsSL -m 15 "$RAW_BASE/sync.sh" -o "$SYNC_SH"
|
|
chmod 0644 "$SYNC_SH"
|
|
|
|
# --- 2. capture the LiteLLM key -------------------------------------------
|
|
if [ "${LITELLM_KEY:-}" = "" ]; then
|
|
# Read from the controlling TTY since stdin is the piped script.
|
|
if [ -r /dev/tty ]; then
|
|
printf 'Paste your LiteLLM virtual key (sk-...): ' >&2
|
|
IFS= read -r LITELLM_KEY < /dev/tty
|
|
else
|
|
say "error: no LITELLM_KEY in env and no TTY to prompt."
|
|
say "re-run as: curl ... | LITELLM_KEY=sk-... sh"
|
|
exit 1
|
|
fi
|
|
fi
|
|
LITELLM_KEY="$(printf '%s' "$LITELLM_KEY" | tr -d ' \t\r\n')"
|
|
case "$LITELLM_KEY" in
|
|
sk-*) : ;;
|
|
*) say "warning: key does not start with 'sk-' — continuing anyway." ;;
|
|
esac
|
|
printf '%s' "$LITELLM_KEY" > "$KEYFILE"
|
|
chmod 0600 "$KEYFILE"
|
|
say "Key stored at $KEYFILE (0600)."
|
|
|
|
# --- 3. wire the shell rc --------------------------------------------------
|
|
# Detect the user's interactive rc; default to zsh on macOS, bash elsewhere.
|
|
case "${SHELL:-}" in
|
|
*zsh) RC="$HOME/.zshrc" ;;
|
|
*bash) RC="$HOME/.bashrc" ;;
|
|
*) [ -f "$HOME/.zshrc" ] && RC="$HOME/.zshrc" || RC="$HOME/.bashrc" ;;
|
|
esac
|
|
touch "$RC"
|
|
|
|
if grep -qF "$HOOK_MARKER" "$RC" 2>/dev/null; then
|
|
say "Shell hook already present in $RC."
|
|
else
|
|
{
|
|
printf '\n%s\n' "$HOOK_MARKER"
|
|
printf '%s\n' '[ -f "$HOME/.config/mcp-sync/sync.sh" ] && . "$HOME/.config/mcp-sync/sync.sh"'
|
|
printf '%s\n' "# <<< covert-gpt mcp-sync <<<"
|
|
} >> "$RC"
|
|
say "Added mcp-sync hook to $RC."
|
|
fi
|
|
|
|
# --- 4. run it once now so the config exists immediately -------------------
|
|
# shellcheck disable=SC1090
|
|
. "$SYNC_SH" || true
|
|
|
|
say ""
|
|
say "Done. Open a new terminal (or 'source $RC') and run opencode."
|
|
say "The gateway config refreshes automatically on each new shell."
|