#!/bin/bash -e
echo "all arguments: "$@
echo "0: "$0
echo "1: "$1

if [[ -z "${MAIL_DOMAIN}" ]]; then
    echo "ERROR: MAIL_DOMAIN parameter not set ... exit ..."
    exit 1
fi

# $1 as hostname for this dovecot instance 
/etc/initial-config.sh "${MAIL_DOMAIN}"

if [[ "$1" == "bash" ]]; then
    echo "Starting interactive shell ..."
    bash
    echo "Interactive shell stopped."
    exit 0;
fi


/usr/bin/supervisord -c /etc/supervisor/supervisord.conf

# Tailing dovecot Logs as container output (auth)
tail -F /var/log/dovecot/*.log
