#!/bin/bash -e
# reconfigure: no
# reconfigure-title: Symfony Secrets
# reconfigure-description: Regenerate the application secret and database password.
# Regenerate the Symfony secret key and MariaDB password.

. /etc/default/inithooks

CONF=/var/www/symfony/.env.local

sed -i "\|^APP_SECRET|s|=.*|=$(mcookie)|" "$CONF"

# set Symfony user DB password
PASSWORD=$(mcookie)
sed -i "\|^DATABASE_URL|s|mysql://symfony:.*@|mysql://symfony:${PASSWORD}@|" "$CONF"
$INITHOOKS_PATH/bin/mysqlconf.py --user=symfony --pass="$PASSWORD"
