Files
mtusi2026lab6/scripts/bootstrap.sh
T
2026-11-17 13:08:13 +03:00

31 lines
1022 B
Bash
Executable File

#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
umask 077
mkdir -p secrets/lab6
if [ ! -f .env.lab6 ]; then
{ printf 'POSTGRES_PASSWORD='; openssl rand -hex 24
printf 'REDIS_PASSWORD='; openssl rand -hex 24
printf 'HOST_PORT=18086\nAPI_REPLICAS=2\nSESSION_TTL_SECONDS=14400\n'
} > .env.lab6
fi
if [ ! -f secrets/lab6/private_key.pem ]; then
openssl genrsa -out secrets/lab6/private_key.pem 2048 2>/dev/null
fi
if [ ! -f secrets/lab6/public_key.pem ]; then
openssl rsa -in secrets/lab6/private_key.pem -pubout -out secrets/lab6/public_key.pem 2>/dev/null
fi
# Only synthetic stand keys, readable by the non-root application inside containers.
chmod 755 secrets secrets/lab6
chmod 444 secrets/lab6/*.pem
printf '%s\n' 'Local lab6 settings and synthetic keys ready; existing files preserved.'
python3 scripts/bootstrap-storage.py
python3 scripts/bootstrap-broker.py
if [ ! -f secrets/lab6/grafana_password ]; then
openssl rand -hex 24 > secrets/lab6/grafana_password
fi
chmod 444 secrets/lab6/grafana_password