mirror of
https://github.com/hanzoskill/meshguard.git
synced 2026-10-30 21:13:02 +00:00
103 lines
3.2 KiB
Bash
103 lines
3.2 KiB
Bash
#!/usr/bin/env bash
|
||
# meshguard-setup.sh — First-time MeshGuard configuration wizard
|
||
set -euo pipefail
|
||
|
||
CONFIG_DIR="${HOME}/.meshguard"
|
||
CONFIG_FILE="${CONFIG_DIR}/config"
|
||
|
||
echo "╔══════════════════════════════════════════╗"
|
||
echo "║ MeshGuard Setup Wizard ║"
|
||
echo "╚══════════════════════════════════════════╝"
|
||
echo ""
|
||
|
||
# Check dependencies
|
||
for bin in curl jq; do
|
||
if ! command -v "$bin" &>/dev/null; then
|
||
echo "⚠️ Missing dependency: $bin"
|
||
echo " Install it before continuing."
|
||
exit 1
|
||
fi
|
||
done
|
||
|
||
# Load existing config if present
|
||
if [[ -f "$CONFIG_FILE" ]]; then
|
||
echo "ℹ️ Existing config found at $CONFIG_FILE"
|
||
# shellcheck source=/dev/null
|
||
source "$CONFIG_FILE"
|
||
echo " Current URL: ${MESHGUARD_URL:-<not set>}"
|
||
echo ""
|
||
read -rp "Overwrite existing config? [y/N] " overwrite
|
||
[[ "$overwrite" =~ ^[Yy] ]] || { echo "Keeping existing config."; exit 0; }
|
||
echo ""
|
||
fi
|
||
|
||
# Gateway URL
|
||
read -rp "MeshGuard Gateway URL [https://dashboard.meshguard.app]: " url
|
||
url="${url:-https://dashboard.meshguard.app}"
|
||
# Strip trailing slash
|
||
url="${url%/}"
|
||
|
||
# API Key
|
||
echo ""
|
||
echo "API Key — found in MeshGuard Dashboard → Settings → API Keys"
|
||
read -rp "API Key: " api_key
|
||
if [[ -z "$api_key" ]]; then
|
||
echo "⚠️ No API key provided. You can add it later to $CONFIG_FILE"
|
||
fi
|
||
|
||
# Admin Token (optional)
|
||
echo ""
|
||
echo "Admin Token (optional) — needed for org signup and admin operations."
|
||
echo "Leave blank if you don't have one."
|
||
read -rp "Admin Token: " admin_token
|
||
|
||
# Save config
|
||
mkdir -p "$CONFIG_DIR"
|
||
cat > "$CONFIG_FILE" <<EOF
|
||
# MeshGuard configuration — generated by meshguard-setup.sh
|
||
# $(date -Iseconds)
|
||
export MESHGUARD_URL="${url}"
|
||
export MESHGUARD_API_KEY="${api_key}"
|
||
export MESHGUARD_ADMIN_TOKEN="${admin_token}"
|
||
EOF
|
||
|
||
chmod 600 "$CONFIG_FILE"
|
||
echo ""
|
||
echo "✅ Config saved to $CONFIG_FILE (permissions: 600)"
|
||
|
||
# Test connection
|
||
echo ""
|
||
echo "Testing connection to ${url}..."
|
||
api_base="${url}/api/v1"
|
||
|
||
if response=$(curl -sf --max-time 10 -H "Content-Type: application/json" "${api_base}/health" 2>&1); then
|
||
echo "✅ Gateway is reachable!"
|
||
echo "$response" | jq '.' 2>/dev/null || echo "$response"
|
||
else
|
||
echo "⚠️ Could not reach ${api_base}/health"
|
||
echo " This may be expected if the gateway is on a private network."
|
||
echo " Config was still saved — you can test later with:"
|
||
echo " bash skills/meshguard/scripts/meshguard-cli.sh status"
|
||
fi
|
||
|
||
# Test API key if provided
|
||
if [[ -n "$api_key" ]]; then
|
||
echo ""
|
||
echo "Testing API key..."
|
||
if response=$(curl -sf --max-time 10 \
|
||
-H "Authorization: Bearer ${api_key}" \
|
||
-H "Content-Type: application/json" \
|
||
"${api_base}/agents" 2>&1); then
|
||
echo "✅ API key is valid!"
|
||
else
|
||
echo "⚠️ API key test failed. Key may be invalid or gateway unreachable."
|
||
echo " You can update it later in $CONFIG_FILE"
|
||
fi
|
||
fi
|
||
|
||
echo ""
|
||
echo "Setup complete! You can now use MeshGuard commands:"
|
||
echo " bash skills/meshguard/scripts/meshguard-cli.sh status"
|
||
echo " bash skills/meshguard/scripts/meshguard-cli.sh agents list"
|
||
echo " bash skills/meshguard/scripts/meshguard-cli.sh help"
|