Ansible roles by Evolix
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
ansible-roles/opendkim/files/opendkim-add.sh

39 lines
1.3 KiB

#!/bin/sh
if [ "$#" -ne 1 ]; then
echo "Usage : $0 example.com" >&2
exit 1
fi
servername="$(cat /etc/hostname)"
domain="$(echo "$1"|xargs)"
if [ ! -f "/etc/ssl/private/dkim-${servername}.private" ]; then
echo "Generate DKIM keys ..."
opendkim-genkey -h sha256 -b 4096 -D /etc/ssl/private/ -r -d "${domain}" -s "dkim-${servername}"
chown opendkim:opendkim "/etc/ssl/private/dkim-${servername}.private"
chmod 640 "/etc/ssl/private/dkim-${servername}.private"
mv "/etc/ssl/private/dkim-${servername}.txt" "/etc/ssl/certs/"
fi
grep -q "${domain}" /etc/opendkim/KeyTable
if [ "$?" -ne 0 ]; then
echo "Add ${domain} to KeyTable ..."
echo "dkim-${servername}._domainkey.${domain} ${domain}:dkim-${servername}:/etc/ssl/private/dkim-${servername}.private" >> /etc/opendkim/KeyTable
fi
grep -q "${domain}" /etc/opendkim/SigningTable
if [ "$?" -ne 0 ]; then
echo "Add ${domain} to SigningTable ..."
echo "*@${domain} dkim-${servername}._domainkey.${domain}" >> /etc/opendkim/SigningTable
fi
systemctl reload opendkim
if [ "$?" -eq 0 ]; then
echo "OpenDKIM successfully reloaded"
echo "Public key is in : /etc/ssl/certs/dkim-${servername}.txt"
exit 0
else
echo "An error has occurred while opendkim reload, please FIX configuration !" >&2
exit 1
fi