-
Notifications
You must be signed in to change notification settings - Fork 0
/
opendkim_add_key
executable file
·61 lines (50 loc) · 1.64 KB
/
opendkim_add_key
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh
# Add DKIM key
# 08/16/17 - Created by Andrew Puckett
if [ $# -lt 1 ]; then
echo "NAME"
echo " $(basename $0) options"
echo
echo "DESCRIPTION"
echo " $(basename $0) is used to add a dkim key to postfix."
echo
echo "OPTIONS"
echo " -d"
echo " Domain. Required."
echo " -n"
echo " Name of host (abbreviation). Optional."
echo
echo "AUTHOR"
echo " Andrew Puckett"
echo
exit 1
fi
[ $(id -u) != "0" ] && echo "ERROR: You must be the superuser to run this script" >&2 && exit 1
SHORT_NAME=
DOMAIN=
while getopts d:n: opt
do
case "$opt" in
d) DOMAIN=$OPTARG;;
n) SHORT_NAME=$OPTARG;;
esac
done
[ -z "$SHORT_NAME" ] && SHORT_NAME=$DOMAIN
DKIMNAME=$(echo $SHORT_NAME | tr _. -)
DKIMNAME=${DKIMNAME}$(date +"%Y%m")
if ! grep -q "*@$DOMAIN $SHORT_NAME\$" /etc/opendkim/signing.table; then
[ -f /etc/opendkim/signing.table ] && cat /etc/opendkim/signing.table > /etc/opendkim/signing.table_new
echo "*@$DOMAIN $SHORT_NAME" >> /etc/opendkim/signing.table_new
mv --backup=numbered /etc/opendkim/signing.table_new /etc/opendkim/signing.table
fi
opendkim-genkey -s $DKIMNAME -d $DOMAIN
mv --backup=numbered ./$DKIMNAME.private /etc/dkimkeys/$DKIMNAME.key
chmod 0600 /etc/dkimkeys/$DKIMNAME.key
chown -R opendkim:opendkim /etc/dkimkeys
[ -f /etc/opendkim/key.table ] && cat /etc/opendkim/key.table > /etc/opendkim/key.table_new
echo "$SHORT_NAME ${DOMAIN}:${DKIMNAME}:/etc/dkimkeys/$DKIMNAME.key" >> /etc/opendkim/key.table_new
mv --backup=numbered /etc/opendkim/key.table_new /etc/opendkim/key.table
cat ./$DKIMNAME.txt
read -p "Has the public key been added to the DNS [y]?: " CONFIRM
[ "$CONFIRM" = "y" ] || exit 2
service opendkim reload