forked from mtusi2026/mtusi2026lab3
14 lines
631 B
Bash
Executable File
14 lines
631 B
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
ROOT="$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)"
|
|
mkdir -p "$ROOT/secrets"
|
|
if [ ! -f "$ROOT/secrets/postgres_password" ]; then
|
|
openssl rand -base64 24 | tr -d '\n' > "$ROOT/secrets/postgres_password"
|
|
fi
|
|
PASS=$(cat "$ROOT/secrets/postgres_password")
|
|
ENC=$(printf '%s' "$PASS" | python3 -c 'import sys,urllib.parse; print(urllib.parse.quote(sys.stdin.read(), safe=""))')
|
|
printf 'postgres://messenger:%s@postgres:5432/messenger?sslmode=disable\n' "$ENC" > "$ROOT/secrets/database_url"
|
|
printf 'redis://valkey:6379/0\n' > "$ROOT/secrets/cache_url"
|
|
chmod 644 "$ROOT/secrets/"*
|
|
echo "secrets ready in $ROOT/secrets"
|