vmail-stack/bin/vmail-dkim-add.sh
Matthew Saunders Brown 4bf85f8839 reworked getopts
2021-10-15 15:17:29 -07:00

56 lines
1.5 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 "Get email alias data from vmail database."
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
echo