#!/bin/bash # init.sh — environment health check for homelab-mcp-gitea. # # Adapted from python-project-template-internal's init.sh but trimmed to # what makes sense for an MCP server: no Docker, no CI-to-NAS, no deploy. # Just the quality gate: uv sync + ruff lint + ruff format + mypy + pytest. # # Usage: # ./init.sh # run the health check # ./init.sh help # show this help # # Exit 0 = everything OK. Exit 1 = stop and fix before touching code. set -e RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' ok() { echo -e "${GREEN}[OK]${NC} $1"; } fail() { echo -e "${RED}[FAIL]${NC} $1"; exit 1; } warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } SUBCMD="${1:-check}" shift || true case "$SUBCMD" in check|"") echo "=== init.sh — environment check ===" # 1. uv if ! command -v uv &>/dev/null; then fail "uv not found. Install: curl -LsSf https://astral.sh/uv/install.sh | sh" fi ok "uv found: $(uv --version)" # 2. Python version PYTHON_VERSION=$(uv python find 2>/dev/null || echo "none") if [[ "$PYTHON_VERSION" == "none" ]]; then fail "No compatible Python found. Install: uv python install 3.12" fi ok "Python found: $PYTHON_VERSION" # 3. Sync dependencies echo "Syncing dependencies..." uv sync --all-groups --quiet || fail "uv sync failed" ok "dependencies synced" # 4. Ruff lint uv run ruff check src tests --quiet || fail "ruff check failed — run: uv run ruff check src tests" ok "ruff check passed" # 5. Ruff format uv run ruff format --check src tests --quiet || fail "ruff format check failed — run: uv run ruff format src tests" ok "ruff format passed" # 6. Mypy uv run mypy src --no-error-summary > /dev/null || fail "mypy failed — run: uv run mypy src" ok "mypy passed" # 7. Tests uv run pytest --tb=short -q || fail "tests failed — run: uv run pytest" ok "tests passed" echo "" echo -e "${GREEN}=== Environment ready ===${NC}" ;; help|--help|-h) cat <