#!/bin/bash DOCUMENT_ROOT=$(dirname ${APACHE_DOCUMENT_ROOT}) # set default database port if undefined case "${POSTFIXADMIN_DATABASE_TYPE}" in sqlite) ;; mysqli) : "${POSTFIXADMIN_DATABASE_PORT:=3306}" ;; pgsql) : "${POSTFIXADMIN_DATABASE_PORT:=5432}" : "${POSTFIXADMIN_DATABASE_NAME:=postgres}" ;; *) echo >&2 "${POSTFIXADMIN_DATABASE_TYPE} is not a supported value." exit 1 ;; esac # check if database user and password is defined and if database answer of an icmp ping if [ "${POSTFIXADMIN_DATABASE_TYPE}" != "sqlite" ]; then if [ -z "${POSTFIXADMIN_DATABASE_USER}" -o -z "${POSTFIXADMIN_DATABASE_PASSWORD}" ]; then echo >&2 'Error: POSTFIXADMIN_DATABASE_USER and POSTFIXADMIN_DATABASE_PASSWORD must be specified. ' exit 1 fi timeout 15 bash -c "until echo > /dev/tcp/${POSTFIXADMIN_DATABASE_HOST}/${POSTFIXADMIN_DATABASE_PORT}; do sleep 0.5; done" fi # create sqlite.db if sqlite is specified as backend if [ "${POSTFIXADMIN_DATABASE_TYPE}" = 'sqlite' ]; then export POSTFIXADMIN_DATABASE_NAME=${POSTFIXADMIN_DATABASE_NAME:=/var/tmp/postfixadmin.db} if [ ! -f "${POSTFIXADMIN_DATABASE_NAME}" ]; then echo "Create sqlite database: ${POSTFIXADMIN_DATABASE_NAME}" touch ${POSTFIXADMIN_DATABASE_NAME} chown www-data:www-data ${POSTFIXADMIN_DATABASE_NAME} chmod 0700 ${POSTFIXADMIN_DATABASE_NAME} fi fi # create config.local.pgp with vaules from env with POSTFIXADMIN_ prefix POSTFIXADMIN_ENV_VARS=($(env | sort | grep --perl-regexp '^POSTFIXADMIN_.*')) cat > ${DOCUMENT_ROOT}/config.local.php <> ${DOCUMENT_ROOT}/config.local.php done cat >> ${DOCUMENT_ROOT}/config.local.php < EOF chown www-data: ${DOCUMENT_ROOT}/config.local.php # start database migration if [ -f public/upgrade.php ]; then echo "Running database / environment upgrade.php " gosu www-data php public/upgrade.php fi exec "$@"