vmail-stack/bin/vmail-dkim-add.sh

62 lines
1.8 KiB
Bash
Raw Normal View History

2021-02-10 16:16:23 -08:00
#!/bin/bash
#
# vmail-stack
# https://git.stack-source.com/msb/vmail-stack
# MIT License Copyright (c) 2021 Matthew Saunders Brown
2021-04-02 12:02:50 -07:00
# load include file
source $(dirname $0)/vmail.sh
2021-02-10 16:16:23 -08:00
2021-10-15 15:17:29 -07:00
help()
{
thisfilename=$(basename -- "$0")
echo "$thisfilename"
2022-07-22 12:46:50 -07:00
echo "Add DKIM key for specified domain.."
2021-10-15 15:17:29 -07:00
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
2021-02-10 16:16:23 -08:00
fi
# check for existing dkim
2021-10-15 15:17:29 -07:00
if [ -f /etc/ssl/dkim/$domain.dkim ]; then
echo "dkim for $domain already exists"
2021-02-10 16:16:23 -08:00
exit 1
fi
cd /etc/ssl/dkim
2021-10-15 15:17:29 -07:00
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.*
2021-02-10 16:16:23 -08:00
echo
echo Create this dns record:
2021-02-10 16:16:23 -08:00
echo
2021-10-15 15:17:29 -07:00
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