Files
framework-ignition-docker/scripts/install-hooks.sh
2026-03-17 13:29:29 -05:00

35 lines
1.3 KiB
Bash

#!/usr/bin/env bash
# install-hooks.sh — install git hooks for this repo.
# Called automatically by setup.sh; safe to re-run.
# Usage: bash scripts/install-hooks.sh
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
HOOKS_DIR="$REPO_ROOT/.git/hooks"
if [[ ! -d "$HOOKS_DIR" ]]; then
echo "ERROR: .git/hooks directory not found. Are you in a git repo?"
exit 1
fi
# ── post-push: sync markdown docs to WikiJS ───────────────────────────────────
POST_PUSH="$HOOKS_DIR/post-push"
cat > "$POST_PUSH" << 'EOF'
#!/usr/bin/env bash
# post-push hook — sync markdown files to WikiJS after every push.
cd "$(git rev-parse --show-toplevel)"
PYTHON=$(command -v python3 2>/dev/null || command -v python 2>/dev/null || true)
if [[ -z "$PYTHON" ]]; then
echo "[wikijs] python not found — skipping doc sync"
elif ! "$PYTHON" -c "import requests" &>/dev/null; then
echo "[wikijs] requests not installed — skipping doc sync (run: $PYTHON -m pip install requests python-dotenv)"
else
"$PYTHON" tools/publish_docs.py || echo "[wikijs] publish failed — run manually: $PYTHON tools/publish_docs.py"
fi
EOF
chmod +x "$POST_PUSH"
echo " Installed post-push hook → $POST_PUSH"