#!/bin/sh

BASEDIR=/srv/www/pa4home

# Creating directory and set permissions
mkdir -p ${BASEDIR}/onyx/log
chown -R www-data:www-data ${BASEDIR}/onyx/log

# Update database profile
cat <<EOF > ${BASEDIR}/onyx/db/docker.profile.php &&
<?php

if(!defined('ONYX')) exit;

\$___profile['db'] = '$DB_ENV_MYSQL_DATABASE';
\$___profile['host'] = '$DB_PORT_3306_TCP_ADDR';
\$___profile['user'] = '$DB_ENV_MYSQL_USER';
\$___profile['pass'] = '$DB_ENV_MYSQL_PASSWORD';
EOF
sed -i 's/"profile">sample</"profile">docker</' ${BASEDIR}/onyx/config/root.xml

# Continue execution
exec "$@"
