Files
mtusi2026lab6/scripts/init-local.sh
T

29 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
mkdir -p secrets
if [ ! -f secrets/postgres_password ]; then
umask 077
openssl rand -hex 24 > secrets/postgres_password
fi
if [ ! -f secrets/redis_password ]; then
umask 077
openssl rand -hex 24 > secrets/redis_password
fi
postgres_password=$(cat secrets/postgres_password)
redis_password=$(cat secrets/redis_password)
umask 077
printf 'postgres://messenger:%s@postgres:5432/messenger?sslmode=disable\n' "$postgres_password" > secrets/database_url
printf 'redis://:%s@redis:6379/0\n' "$redis_password" > secrets/cache_url
if [ ! -f .env ]; then cp .env.example .env; fi
for secret_name in s3_admin_access s3_admin_secret s3_access_key_id s3_secret_access_key; do
if [ ! -f "secrets/$secret_name" ]; then openssl rand -hex 24 > "secrets/$secret_name"; fi
done
printf '%s\n' 'S3 credentials ready; bucket and policy are bootstrapped by s3-init.'
if [ ! -f secrets/broker_password ]; then openssl rand -hex 24 > secrets/broker_password; fi
broker_password=$(cat secrets/broker_password)
printf 'redis://:%s@broker:6379/0\n' "$broker_password" > secrets/broker_url
if [ ! -f secrets/grafana_admin_password ]; then openssl rand -hex 24 > secrets/grafana_admin_password; fi