check-prereqs.sh
1 #!/usr/bin/env bash 2 # Check that required tools for pre-commit are available. 3 # Recommended: use devbox so pre-commit, task, jq, yamlfmt, shellcheck, markdownlint are provided. 4 5 set -e 6 7 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 8 ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" 9 10 required=(pre-commit task) 11 # Used by task markdownlint, yamlfmt, jsonfmt; shellcheck hook 12 optional=(jq yamlfmt markdownlint shellcheck) 13 14 missing=() 15 for util in "${required[@]}"; do 16 if command -v "$util" >/dev/null 2>&1; then 17 : "found $util" 18 else 19 missing+=("$util") 20 fi 21 done 22 23 for util in "${optional[@]}"; do 24 if command -v "$util" >/dev/null 2>&1; then 25 : "found $util" 26 else 27 missing+=("$util") 28 fi 29 done 30 31 if [ ${#missing[@]} -gt 0 ]; then 32 echo "check-prereqs: missing: ${missing[*]}" >&2 33 if command -v devbox >/dev/null 2>&1 && [ -f "${ROOT}/devbox.json" ]; then 34 echo " Recommended: devbox shell, then retry. Devbox provides pre-commit, task, jq, yamlfmt, shellcheck, markdownlint." >&2 35 else 36 echo " pre-commit: brew install pre-commit (or pip install pre-commit)" >&2 37 echo " task: brew install go-task (or use devbox)" >&2 38 echo " jq: brew install jq | yamlfmt: go install github.com/google/yamlfmt/cmd/yamlfmt@latest | shellcheck: brew install shellcheck | markdownlint: use devbox" >&2 39 fi 40 exit 1 41 fi 42 43 exit 0