#!/usr/bin/env bash # server/bootstrap_local_env.sh # # Crée (si absent) et charge un fichier .env.local pour les lancements DEV. # Objectif: éviter l'oubli des tokens (Fiche #23) + garder une expérience "plug&play". # # Usage: # ./server/bootstrap_local_env.sh (depuis la racine projet) set -euo pipefail PROJECT_DIR="${PROJECT_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}" ENV_FILE="${ENV_FILE:-$PROJECT_DIR/.env.local}" _has_cmd() { command -v "$1" >/dev/null 2>&1; } _gen_hex_32() { if _has_cmd openssl; then openssl rand -hex 32 else python3 - <<'PY' import secrets print(secrets.token_hex(32)) PY fi } if [[ ! -f "$ENV_FILE" ]]; then umask 077 cat >"$ENV_FILE" < (read-only ou admin)"