|
| 1 | +#!/usr/bin/env bash |
| 2 | +# scripts/bootstrap — first-time setup for this repository. |
| 3 | +# |
| 4 | +# Usage: scripts/bootstrap |
| 5 | +# or: make bootstrap |
| 6 | +# |
| 7 | +# What it does: |
| 8 | +# 1. Verifies required tools are present (git). |
| 9 | +# 2. Ensures all scripts in scripts/ and bin/ are executable. |
| 10 | +# 3. Creates .env from .env.example if .env does not already exist. |
| 11 | +# 4. Optionally installs / checks pre-commit if Python is available. |
| 12 | + |
| 13 | +set -euo pipefail |
| 14 | + |
| 15 | +REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 16 | +cd "$REPO_ROOT" |
| 17 | + |
| 18 | +# ── helpers ────────────────────────────────────────────────────────────────── |
| 19 | +info() { printf '\033[1;34m==> %s\033[0m\n' "$*"; } |
| 20 | +ok() { printf '\033[1;32m ✓ %s\033[0m\n' "$*"; } |
| 21 | +warn() { printf '\033[1;33mwarn: %s\033[0m\n' "$*"; } |
| 22 | +die() { printf '\033[1;31merror: %s\033[0m\n' "$*" >&2; exit 1; } |
| 23 | + |
| 24 | +# ── 1. required tools ───────────────────────────────────────────────────────── |
| 25 | +info "Checking required tools…" |
| 26 | +command -v git >/dev/null 2>&1 || die "git is required but not found. Install git and re-run." |
| 27 | +ok "git found: $(git --version)" |
| 28 | + |
| 29 | +# ── 2. make scripts executable ─────────────────────────────────────────────── |
| 30 | +info "Ensuring scripts are executable…" |
| 31 | +for dir in scripts bin; do |
| 32 | + if [ -d "$dir" ]; then |
| 33 | + find "$dir" -type f ! -name "*.*" -exec chmod +x {} \; |
| 34 | + ok "$dir/ scripts marked executable" |
| 35 | + fi |
| 36 | +done |
| 37 | + |
| 38 | +# ── 3. create .env if missing ───────────────────────────────────────────────── |
| 39 | +if [ -f ".env.example" ] && [ ! -f ".env" ]; then |
| 40 | + info "Creating .env from .env.example…" |
| 41 | + cp ".env.example" ".env" |
| 42 | + ok ".env created (review and customise as needed)" |
| 43 | +elif [ -f ".env" ]; then |
| 44 | + ok ".env already exists" |
| 45 | +fi |
| 46 | + |
| 47 | +# ── 4. pre-commit (optional) ────────────────────────────────────────────────── |
| 48 | +if command -v python3 >/dev/null 2>&1; then |
| 49 | + info "Python found — checking pre-commit…" |
| 50 | + if ! command -v pre-commit >/dev/null 2>&1; then |
| 51 | + warn "pre-commit not found. Install it with: pip install pre-commit" |
| 52 | + warn "Then run: pre-commit install" |
| 53 | + else |
| 54 | + ok "pre-commit found: $(pre-commit --version)" |
| 55 | + if [ -f ".pre-commit-config.yaml" ]; then |
| 56 | + info "Installing pre-commit hooks…" |
| 57 | + pre-commit install |
| 58 | + ok "pre-commit hooks installed" |
| 59 | + else |
| 60 | + warn "No .pre-commit-config.yaml found — skipping hook install." |
| 61 | + fi |
| 62 | + fi |
| 63 | +else |
| 64 | + warn "python3 not found — skipping pre-commit setup." |
| 65 | + warn "Install Python 3 and run: pip install pre-commit && pre-commit install" |
| 66 | +fi |
| 67 | + |
| 68 | +info "Bootstrap complete." |
0 commit comments