#!/bin/sh set -eu cd "$(dirname "$0")/.." if [ -f .env ]; then added=$(python3 - <<'PYEOF' def pairs(path): result = [] for line in open(path, encoding="utf-8"): stripped = line.strip() if stripped and not stripped.startswith("#") and "=" in stripped: result.append((stripped.split("=", 1)[0], line.rstrip("\n"))) return result present = {name for name, _ in pairs(".env")} missing = [line for name, line in pairs(".env.example") if name not in present] if missing: with open(".env", "a", encoding="utf-8") as handle: handle.write("\n# Добавлено bootstrap из .env.example\n") for line in missing: handle.write(line + "\n") print(" ".join(line.split("=", 1)[0] for line in missing)) PYEOF ) if [ -n "$added" ]; then echo "в .env добавлены отсутствующие переменные: $added" fi else cp .env.example .env fi mkdir -p secrets if [ ! -f secrets/postgres_password ]; then python3 -c "import secrets; print(secrets.token_urlsafe(24))" > secrets/postgres_password fi password=$(cat secrets/postgres_password) printf 'postgresql://messenger:%s@postgres:5432/messenger\n' "$password" > secrets/database_url printf 'valkey://valkey:6379/0\n' > secrets/cache_url chmod 700 secrets chmod 600 secrets/postgres_password secrets/database_url secrets/cache_url echo "ready: .env and secrets/ created locally; they stay out of Git"