forked from mtusi2026/mtusi2026lab5
lab5 na4
This commit is contained in:
Executable
+27
@@ -0,0 +1,27 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
[ -f .env ] || { cp .env.example .env; echo ".env создан из .env.example"; }
|
||||
mkdir -p secrets
|
||||
python3 - <<'PY'
|
||||
from pathlib import Path
|
||||
import secrets
|
||||
env = Path('.env')
|
||||
lines = env.read_text().splitlines()
|
||||
values = dict(line.split('=', 1) for line in lines if '=' in line and not line.startswith('#'))
|
||||
password_file = Path('secrets/postgres_password.txt')
|
||||
values['POSTGRES_PASSWORD'] = values.get('POSTGRES_PASSWORD') or (password_file.read_text().strip() if password_file.exists() else secrets.token_hex(24))
|
||||
values['DATABASE_URL'] = values.get('DATABASE_URL') or f"postgres://{values.get('POSTGRES_USER', 'messenger')}:{values['POSTGRES_PASSWORD']}@postgres:5432/{values.get('POSTGRES_DB', 'messenger')}?sslmode=disable"
|
||||
for key in ('POSTGRES_PASSWORD', 'DATABASE_URL'):
|
||||
lines = [line for line in lines if not line.startswith(key + '=')]
|
||||
lines.append(key + '=' + values[key])
|
||||
for filename, key in [('postgres_password.txt', 'POSTGRES_PASSWORD'), ('database_url.txt', 'DATABASE_URL')]:
|
||||
p = Path('secrets') / filename
|
||||
if not p.exists():
|
||||
p.write_text(values[key])
|
||||
env.write_text('\n'.join(lines) + '\n')
|
||||
env.chmod(0o600)
|
||||
PY
|
||||
./scripts/gen-s3-secrets.sh
|
||||
chmod 644 secrets/*
|
||||
echo "секреты готовы"
|
||||
Reference in New Issue
Block a user