exherbo-dockermail/core/boot.d/opendkim
2015-07-27 12:23:08 +01:00

41 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
echo 'Running opendkim boot script'
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" -i
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"
echo "smtpd_milters = inet:opendkim:8891" >> "$POSTFIX_MAIN_CF"
echo "non_smtpd_milters = inet:opendkim:8891" >> "$POSTFIX_MAIN_CF"
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"
add_opendkim
fi
else
echo "Cant find OPEN_DKIM env, signing will be disabled"
remove_opendkim
fi
echo 'Finished opendkim boot script'