#!/bin/bash -e
# regenerate matomo secrets and mysql password

. /etc/default/inithooks

CRON_FILE='/etc/cron.d/matomo-archive'
USER="$(cut -d ' ' -f 6 "$CRON_FILE")"
CRON_CMD="$(cut -d ' ' -f 7- "$CRON_FILE")"
su -s /bin/bash -c "$CRON_CMD" "$USER"

SALT=$(mcookie)
$INITHOOKS_PATH/bin/matomo_config.py "[General]" "salt" "$SALT"

PASSWORD=$(mcookie)
$INITHOOKS_PATH/bin/matomo_config.py "[database]" "password" "$PASSWORD"
$INITHOOKS_PATH/bin/mysqlconf.py --user=matomo --pass="$PASSWORD"

