exherbo-dockermail/email_core/boot.d/opendkim
Val 7a05a328b4 Improve modular setup for DKIM
Start Amavis integration
2015-07-12 23:54:35 +01:00

50 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
echo 'Running opendkim boot script'
export DOCKERMAIL_OPENDKIM_ENV_OPEN_DKIM=true
export DOCKERMAIL_OPENDKIM_PORT_8891_TCP_ADDR=172.17.0.10
POSTFIX_MAIN_CF=/etc/postfix/main.cf
env_dump=$(printenv)
OPENDKIM_CONFIG_HEADER="# OpenDKIM - dockermail - start"
OPENDKIM_CONFIG_FOOTER="# OpenDKIM - dockermail - end"
function remove_opendkim () {
if grep -q "$OPENDKIM_CONFIG_HEADER" "$POSTFIX_MAIN_CF"; then
sed "/$OPENDKIM_CONFIG_HEADER/,/$OPENDKIM_CONFIG_FOOTER/d" "$POSTFIX_MAIN_CF"
fi
}
function add_opendkim () {
if ! grep -q "$OPENDKIM_CONFIG_HEADER" "$POSTFIX_MAIN_CF"; then
echo "$OPENDKIM_CONFIG_HEADER" >> "$POSTFIX_MAIN_CF"
echo "milter_default_action = accept" >> "$POSTFIX_MAIN_CF"
echo "milter_protocol = 2" >> "$POSTFIX_MAIN_CF"
if [[ $env_dump =~ ^.*PORT_8891_TCP_ADDR=([0-9\.]*) ]] ; then
echo "smtpd_milters = inet:${BASH_REMATCH[1]}:8891" >> "$POSTFIX_MAIN_CF"
echo "non_smtpd_milters = inet:${BASH_REMATCH[1]}:8891" >> "$POSTFIX_MAIN_CF"
fi
echo "$OPENDKIM_CONFIG_FOOTER" >> "$POSTFIX_MAIN_CF"
else
echo "Warning: $POSTFIX_MAIN_CF already contains OpenDKIM configuration, skipping"
fi
}
if [[ $env_dump =~ ^(.+OPEN_DKIM)= ]] ; then
if [ ! -z "${BASH_REMATCH[1]}" ]; then
echo "OPEN_DKIM env set, enabling email signing"
remove_opendkim # Remove first, to refresh IP info
add_opendkim
fi
else
echo "Cant find OPEN_DKIM env, signing will be disabled"
remove_opendkim
fi
echo 'Finished opendkim boot script'