Files
mtusi2026lab3-implementaion/scripts/init-secrets.sh
T

19 lines
591 B
Bash
Executable File

#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
mkdir -p secrets
chmod 700 secrets
if [ ! -f secrets/postgres_password ]; then
head -c 24 /dev/urandom | od -An -tx1 | tr -d ' \n' > secrets/postgres_password
fi
password=$(cat secrets/postgres_password)
[ -f secrets/database_url ] ||
printf 'postgres://messenger:%s@postgres:5432/messenger?sslmode=disable\n' "$password" > secrets/database_url
[ -f secrets/cache_url ] ||
printf 'redis://redis:6379/0\n' > secrets/cache_url
chmod 644 secrets/postgres_password secrets/database_url secrets/cache_url
echo "secrets ready in ./secrets"