Files
mtusi2026lab3/scripts/init-secrets.sh
T

17 lines
645 B
Bash
Executable File

#!/bin/sh
# Creates local synthetic credentials and .env once. Never overwrites: the pgdata volume keeps the old password.
set -eu
cd "$(dirname "$0")/.."
[ -f .env ] || cp .env.example .env
if [ -f secrets/postgres_password ]; then
echo "secrets/ already exists, keeping it"
exit 0
fi
mkdir -p secrets
chmod 700 secrets
password=$(openssl rand -hex 24)
printf '%s' "$password" > secrets/postgres_password
printf 'postgres://messenger:%s@postgres:5432/messenger' "$password" > secrets/database_url
chmod 644 secrets/postgres_password secrets/database_url # read by container users; the directory stays 700
echo "created secrets/ and .env"