2020-10-21 16:16:32 +00:00
|
|
|
#! /bin/bash
|
2017-08-12 16:09:11 +00:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
if [[ ${#} -ne 1 ]]
|
|
|
|
then
|
|
|
|
echo "${0}: usage: generate-dkim-domain domain"
|
|
|
|
exit 1
|
2017-08-12 16:09:11 +00:00
|
|
|
fi
|
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
DOMAINNAME=${1}
|
|
|
|
mkdir -p "/tmp/docker-mailserver/opendkim/keys/${DOMAINNAME}"
|
2017-08-12 16:09:11 +00:00
|
|
|
|
2020-10-21 16:16:32 +00:00
|
|
|
if [[ ! -f "/tmp/docker-mailserver/opendkim/keys/${DOMAINNAME}/mail.private" ]]
|
|
|
|
then
|
|
|
|
echo "Creating DKIM private key /tmp/docker-mailserver/opendkim/keys/${DOMAINNAME}/mail.private"
|
|
|
|
opendkim-genkey --subdomains --domain="${DOMAINNAME}" --selector=mail -D "/tmp/docker-mailserver/opendkim/keys/${DOMAINNAME}"
|
2017-08-12 16:09:11 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Write to KeyTable if necessary
|
2020-10-21 16:16:32 +00:00
|
|
|
KEYTABLEENTRY="mail._domainkey.${DOMAINNAME} ${DOMAINNAME}:mail:/etc/opendkim/keys/${DOMAINNAME}/mail.private"
|
|
|
|
if [[ ! -f "/tmp/docker-mailserver/opendkim/KeyTable" ]]
|
|
|
|
then
|
|
|
|
echo "Creating DKIM KeyTable"
|
|
|
|
echo "${KEYTABLEENTRY}" > /tmp/docker-mailserver/opendkim/KeyTable
|
2017-08-12 16:09:11 +00:00
|
|
|
else
|
2020-10-21 16:16:32 +00:00
|
|
|
if ! grep -q "${KEYTABLEENTRY}" "/tmp/docker-mailserver/opendkim/KeyTable"
|
|
|
|
then
|
|
|
|
echo "${KEYTABLEENTRY}" >> /tmp/docker-mailserver/opendkim/KeyTable
|
|
|
|
fi
|
2017-08-12 16:09:11 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Write to SigningTable if necessary
|
2020-10-21 16:16:32 +00:00
|
|
|
SIGNINGTABLEENTRY="*@${DOMAINNAME} mail._domainkey.${DOMAINNAME}"
|
|
|
|
if [[ ! -f /tmp/docker-mailserver/opendkim/SigningTable ]]
|
|
|
|
then
|
|
|
|
echo "Creating DKIM SigningTable"
|
|
|
|
echo "*@${DOMAINNAME} mail._domainkey.${DOMAINNAME}" > /tmp/docker-mailserver/opendkim/SigningTable
|
2017-08-12 16:09:11 +00:00
|
|
|
else
|
2020-10-21 16:16:32 +00:00
|
|
|
if ! grep -q "${SIGNINGTABLEENTRY}" "/tmp/docker-mailserver/opendkim/SigningTable"
|
|
|
|
then
|
|
|
|
echo "${SIGNINGTABLEENTRY}" >>/tmp/docker-mailserver/opendkim/SigningTable
|
|
|
|
fi
|
2017-09-10 07:52:22 +00:00
|
|
|
fi
|