Files
mtusi2026lab3/scripts/init-secrets.sh
T

20 lines
671 B
Bash
Executable File

#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
umask 077
mkdir -p secrets
if [ -e secrets/postgres_password ] || [ -e secrets/database_url ]; then
if [ ! -s secrets/postgres_password ] || [ ! -s secrets/database_url ]; then
printf '%s\n' 'Incomplete secrets directory; repair it manually without replacing an existing database password.' >&2
exit 1
fi
exit 0
fi
password="$(openssl rand -hex 24)"
printf '%s' "$password" > secrets/postgres_password
printf 'Host=postgres;Port=5432;Database=messenger;Username=messenger;Password=%s' "$password" > secrets/database_url
printf '%s\n' 'Created local database secrets in ignored secrets/ directory.'