#!/bin/ash
if ! [ -e /etc/dovecot/dh-params/2048.pem ]; then
openssl dhparam -out /etc/dovecot/dh-params/2048.pem -2 2048
fi
cat >> /etc/dovecot/dovecot-ldap.conf.ext << EOF
auth_bind = yes
hosts = $LDAP_SERVER
base = $LDAP_BASE
dn = $LDAP_USER
dnpass = $LDAP_PASSWORD
tls = yes
pass_filter = (mail=%u)
EOF
[ -e /var/lib/dovecot/instances ] && rm -rf /var/lib/dovecot/instances
exec dovecot -F