#!/bin/bash

##
## /var/log might be plugged into an empty volume for saving logs, so we
## must make sure that /var/log/exim4 exists and has correct permissions.

mkdir -p /var/log/exim4
chmod -R u+rw /var/log/exim4
chown -R Debian-exim /var/log/exim4


echo "Propagating docker shell environment variables to CRON scripts."

rm -f /etc/cron.d/*
cp -a /etc/cron/* /etc/cron.d/

for f in /etc/crontab /etc/cron.d/*; do
    [ -e "$f" ] || continue
    mv "$f" /tmp/tempfile
    {
        declare -xp | egrep '_PORT_[0-9]+_'  | sed -r 's/^declare -x //g'
        echo "TZ=$TZ"
        echo
        cat /tmp/tempfile
    } > "$f"
    rm /tmp/tempfile
done


echo "Launching cron."
## Give back PID 1, so that cron process receives signals.
exec /usr/sbin/cron -f