#!/bin/sh # Create a local .env with fresh synthetic passwords. The file is ignored by # Git, is readable only by the current user, and its values are never printed. set -eu cd "$(dirname "$0")/.." if [ -f .env ]; then echo ".env already exists; refusing to overwrite it" >&2 exit 0 fi # Alphanumeric only, so the values are safe inside a URL with no percent # encoding. 32 bytes of /dev/urandom gives 256 bits of entropy. random_secret() { LC_ALL=C tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 32 } postgres_password=$(random_secret) valkey_password=$(random_secret) if [ "${#postgres_password}" -ne 32 ] || [ "${#valkey_password}" -ne 32 ]; then echo "could not generate local secrets" >&2 exit 1 fi umask 077 sed \ -e "s|^POSTGRES_PASSWORD=.*|POSTGRES_PASSWORD=${postgres_password}|" \ -e "s|^VALKEY_PASSWORD=.*|VALKEY_PASSWORD=${valkey_password}|" \ .env.example > .env chmod 600 .env echo "wrote .env with generated local synthetic credentials (mode 600); values not printed"