114 lines
4.3 KiB
Bash
Executable File
114 lines
4.3 KiB
Bash
Executable File
#!/bin/sh
|
|
set -e
|
|
|
|
# @NOTE: Directories in /var/mail/vhosts/* need to be owned by the UID/GID defined in custom/41-virtual.cf
|
|
|
|
DEFAULTS=/defaults
|
|
POSTFIX=/etc/postfix
|
|
CUSTOM=${POSTFIX}/custom
|
|
INCLUDE_DIR=${POSTFIX}/include
|
|
NAME="SMTP"
|
|
|
|
function stop {
|
|
echo "Stopping ${NAME}"
|
|
postfix stop
|
|
kill $(cat /run/saslauthd/saslauthd.pid)
|
|
kill $(cat /run/opendkim/opendkim.pid)
|
|
}
|
|
|
|
trap 'stop' SIGTERM
|
|
|
|
if [ -z "$@" ]; then
|
|
if [ -z `hostname -d` ]; then
|
|
echo "You must start this container with --hostname= specifying a domain name"
|
|
exit 1
|
|
fi
|
|
|
|
# Start some supporting daemons
|
|
/usr/sbin/saslauthd -m /run/saslauthd -ca shadow
|
|
/usr/sbin/opendkim -u opendkim -P /run/opendkim/opendkim.pid
|
|
|
|
if [ -n "${SPAMHAUS_DQS_KEY}" ]; then
|
|
sed -i -e "s/@SPAMHAUS_DQS_KEY@/${SPAMHAUS_DQS_KEY}/g" ${DEFAULTS}/dnsbl-reply-map ${INCLUDE_DIR}/01-custom.cf
|
|
sed -i -e "s/^#reject/ reject/" ${INCLUDE_DIR}/01-custom.cf
|
|
|
|
if [ ! -f ${CUSTOM}/dnsbl-reply-map ]; then
|
|
cp ${DEFAULTS}/dnsbl-reply-map ${CUSTOM}/
|
|
postmap -o lmdb:${CUSTOM}/dnsbl-reply-map
|
|
fi
|
|
|
|
cp ${DEFAULTS}/60-spamhaus.cf ${INCLUDE_DIR}/
|
|
fi
|
|
|
|
# Setup our postfix environment
|
|
if [ -d ${INCLUDE_DIR} ]; then
|
|
if ls -1 ${INCLUDE_DIR}/*.cf >/dev/null 2>&1; then
|
|
echo "* Adding to main.cf"
|
|
echo '##### CUSTOM CONFIGURATION ####' >> ${POSTFIX}/main.cf
|
|
|
|
for i in ${INCLUDE_DIR}/*.cf; do
|
|
echo "* Adding [${i}] to main.cf"
|
|
echo "# - ${i}" >> ${POSTFIX}/main.cf
|
|
cat $i >> ${POSTFIX}/main.cf
|
|
done
|
|
|
|
echo '##### END CUSTOM CONFIGURATION ####' >> ${POSTFIX}/main.cf
|
|
fi
|
|
fi
|
|
|
|
[ ! -f ${CUSTOM}/relay_domains ] && cp ${DEFAULTS}/relay_domains ${CUSTOM}/
|
|
postmap -o lmdb:${CUSTOM}/relay_domains
|
|
|
|
[ ! -f ${CUSTOM}/relay_recipient_maps ] && cp ${DEFAULTS}/relay_recipient_maps ${CUSTOM}/
|
|
postmap -o lmdb:${CUSTOM}/relay_recipient_maps
|
|
|
|
touch ${CUSTOM}/sasl_passwd
|
|
postmap -o lmdb:${CUSTOM}/sasl_passwd
|
|
|
|
[ -n "${VIRTUAL_ALIAS_DOMAINS}" ] && sed -i -e "s%#virtual_alias_domains = @VIRTUAL_ALIAS_DOMAINS@%virtual_alias_domains = ${VIRTUAL_ALIAS_DOMAINS}%" ${POSTFIX}/main.cf
|
|
[ ! -f ${CUSTOM}/virtual_alias_maps ] && cp ${DEFAULTS}/virtual_alias_maps ${CUSTOM}/
|
|
postmap -o lmdb:${CUSTOM}/virtual_alias_maps
|
|
|
|
[ -n "${VIRTUAL_DOMAINS}" ] && sed -i -e "s%#virtual_mailbox_domains = @VIRTUAL_DOMAINS@%virtual_mailbox_domains = ${VIRTUAL_DOMAINS}%" ${POSTFIX}/main.cf
|
|
[ ! -f ${CUSTOM}/virtual_mailbox_maps ] && cp ${DEFAULTS}/virtual_mailbox_maps ${CUSTOM}/
|
|
postmap -o lmdb:${CUSTOM}/virtual_mailbox_maps
|
|
|
|
# Create some default LDAP templates
|
|
if [ -n "${LDAP_SEARCH_BASE}" ]; then
|
|
sed -i -e "s%^# ldap:% ldap:%" ${POSTFIX}/main.cf
|
|
|
|
if [ ! -f ${CUSTOM}/ldap_virtual_alias_maps ]; then
|
|
cp ${DEFAULTS}/ldap_virtual_alias_maps ${CUSTOM}/
|
|
sed -i -e "s%@THIS_HOST@%${HOSTNAME}%" -e "s%@LDAP_SEARCH_BASE@%${LDAP_SEARCH_BASE}%" ${CUSTOM}/ldap_virtual_alias_maps
|
|
fi
|
|
if [ ! -f ${CUSTOM}/ldap_virtual_mailbox_maps ]; then
|
|
cp ${DEFAULTS}/ldap_virtual_mailbox_maps ${CUSTOM}/
|
|
sed -i -e "s%@THIS_HOST@%${HOSTNAME}%" -e "s%@LDAP_SEARCH_BASE@%${LDAP_SEARCH_BASE}%" ${CUSTOM}/ldap_virtual_mailbox_maps
|
|
fi
|
|
if [ ! -f ${CUSTOM}/ldap_relay_domains ]; then
|
|
cp ${DEFAULTS}/ldap_relay_domains ${CUSTOM}/
|
|
sed -i -e "s%@THIS_HOST@%${HOSTNAME}%" -e "s%@LDAP_SEARCH_BASE@%${LDAP_SEARCH_BASE}%" ${CUSTOM}/ldap_relay_domains
|
|
fi
|
|
if [ ! -f ${CUSTOM}/ldap_relay_recipient_maps ]; then
|
|
cp ${DEFAULTS}/ldap_relay_recipient_maps ${CUSTOM}/
|
|
sed -i -e "s%@THIS_HOST@%${HOSTNAME}%" -e "s%@LDAP_SEARCH_BASE@%${LDAP_SEARCH_BASE}%" ${CUSTOM}/ldap_relay_recipient_maps
|
|
fi
|
|
fi
|
|
|
|
[ ! -f ${CUSTOM}/header_checks ] && cp ${DEFAULTS}/header_checks ${CUSTOM}/ && postmap -o lmdb:${CUSTOM}/header_checks
|
|
[ ! -f ${CUSTOM}/helo_access ] && cp ${DEFAULTS}/helo_access ${CUSTOM}/ && postmap -o lmdb:${CUSTOM}/helo_access
|
|
[ ! -f ${CUSTOM}/recipient_access ] && cp ${DEFAULTS}/recipient_access ${CUSTOM}/ && postmap -o lmdb:${CUSTOM}/recipient_access
|
|
[ ! -f ${CUSTOM}/recipient_canonical ] && cp ${DEFAULTS}/recipient_canonical ${CUSTOM}/ && postmap -o lmdb:${CUSTOM}/recipient_canonical
|
|
[ ! -f ${CUSTOM}/sender_access ] && cp ${DEFAULTS}/sender_access ${CUSTOM}/ && postmap -o lmdb:${CUSTOM}/sender_access
|
|
[ ! -f ${CUSTOM}/sender_canonical ] && cp ${DEFAULTS}/sender_canonical ${CUSTOM}/ && postmap -o lmdb:${CUSTOM}/sender_canonical
|
|
|
|
newaliases
|
|
postfix start
|
|
|
|
# Sleep,enabling our SIGTERM to shut us down gracefully
|
|
(while true; do sleep 3600; done) &
|
|
wait
|
|
else
|
|
exec $@
|
|
fi
|