#!/usr/bin/env bash

if [ ! -f /data/users.db ]; then
    echo -e "\t\t\033[1;33m* initalizing Users database\033[0m"

    touch /data/users.db
    chown mail:mail /data
    chown mail:mail /data/users.db
    sudo -u mail php /opt/admin/bin/console --env=prod doctrine:schema:update --force --complete > /dev/null
fi

chown mail:mail /data
chown mail:mail /data/users.db

php /opt/admin/upgrades/01-forward-domain-bin.php
php /opt/admin/upgrades/02-limits.php
php /opt/admin/upgrades/03-limits.php
php /opt/admin/upgrades/04-outbound.php
php /opt/admin/upgrades/05-strict.php
php /opt/admin/upgrades/06-limits.php
php /opt/admin/upgrades/07-guard.php
php /opt/admin/upgrades/08-limits.php
php /opt/admin/upgrades/09-refid.php
php /opt/admin/upgrades/10-force-route.php
php /opt/admin/upgrades/11-discard.php
php /opt/admin/upgrades/12-outbound-ip.php
php /opt/admin/upgrades/13-internal-only.php
