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

37 lines
898 B
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
# load config
source /usr/local/etc/vmail.conf
# check for and set virtualhost
if [ -n "$1" ]; then
virtualhost=$1
else
echo "virtualhost not set"
exit 1
fi
# check for existing dkim
if [ -f /etc/ssl/dkim/$virtualhost.dkim ]; then
echo "dkim for $virtualhost already exists"
exit 1
fi
cd /etc/ssl/dkim
date +%Y%m%d > $virtualhost.selector
openssl genrsa -out $virtualhost.pem 2048
openssl rsa -in $virtualhost.pem -out $virtualhost.pub -pubout
tail -n +2 $virtualhost.pub |head -n -1|tr -d '\n' > $virtualhost.dkim
echo `cat $virtualhost.selector`._domainkey.$virtualhost. 3600 IN TXT \""k=rsa; p=`cat $virtualhost.dkim`"\" > $virtualhost.dns
chown Debian-exim:ssl-cert $virtualhost.*
echo
echo create this dns record:
echo
cat $virtualhost.dns
echo