vmail-stack/bin/vmail-dkim-add.sh
2022-08-19 09:45:39 -07:00

62 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
#
# vmail-stack
# https://git.stack-source.com/msb/vmail-stack
# MIT License Copyright (c) 2021 Matthew Saunders Brown
# load include file
source $(dirname $0)/vmail.sh
help()
{
thisfilename=$(basename -- "$0")
echo "$thisfilename"
echo "Add DKIM key for specified domain.."
echo ""
echo "usage: $thisfilename -d <domain> [-h]"
echo ""
echo " -h Print this help."
echo " -d Domain name to add DKIM to."
echo ""
echo " This will create a DKIM key that exim will start using immediately for"
echo " all outgoing messages for the specified domain. A DNS entry needs to"
echo " be created for the domain so that DKIM validation works. The DNS entry"
echo " to add is output on the command line and is stored in the file:"
echo " /etc/ssl/dkim/<domain>.dns"
exit
}
vmail:getoptions "$@"
# check for domain
if [[ -z $domain ]]; then
echo "domain name is required"
exit
fi
# check for existing dkim
if [ -f /etc/ssl/dkim/$domain.dkim ]; then
echo "dkim for $domain already exists"
exit 1
fi
cd /etc/ssl/dkim
date +%Y%m%d > $domain.selector
openssl genrsa -out $domain.pem 2048
openssl rsa -in $domain.pem -out $domain.pub -pubout
tail -n +2 $domain.pub |head -n -1|tr -d '\n' > $domain.dkim
echo `cat $domain.selector`._domainkey.$domain 3600 IN TXT \""k=rsa; p=`cat $domain.dkim`"\" > $domain.dns
chown Debian-exim:ssl-cert $domain.*
echo
echo Create this dns record:
echo
cat $domain.dns
if [[ -f /usr/local/etc/pdns.conf ]]; then
echo
echo Looks like you have powerdns-tools enabled, you can simply run this:
echo
echo pdns-rr-rep.sh -z $domain -n `cat $domain.selector`._domainkey.$domain -t TXT -r \'k=rsa\; p=`cat $domain.dkim`\'
echo
fi