X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;f=setup_opendkim.sh;h=ce1e3d5a4790871297064ddcb1a470c4bc4f6d5f;hb=8d3cd074591a3ebc0f9782a1d4bc785352fc74fc;hp=6d9749beea2f469363d8a8f250e3f0803e392aa2;hpb=2df2a310bead167e85198376ef9fa501f5bd5406;p=config
diff --git a/setup_opendkim.sh b/setup_opendkim.sh
index 6d9749b..ce1e3d5 100755
--- a/setup_opendkim.sh
+++ b/setup_opendkim.sh
@@ -1,44 +1,65 @@
#!/bin/sh
-set -x
set -e
selector=$1
file=$2
-if [ "$(id -u)" -eq "0" ]; then
- echo "Must be run as root."
+if [ ! -n "$selector" ]; then
+ cat << EOF
+Usage: $0 SELECTOR [KEYFILE] - set up DKIM system and configuration
+
+If existing KEYFILE is given, set up DKIM to use SELECTOR and apply key from
+KEYFILE.
+
+If existing KEYFILE is not given, generate KEYFILE and DNS TXT file for
+SELECTOR.
+EOF
exit
fi
-apt-get -y install opendkim opendkim-tools
-cp ~/config/systemfiles/opendkim.conf /etc/opendkim.conf
-
-if [ -f /etc/opendkim/dkim.key ]; then
- cp /etc/opendkim/dkim.key /etc/opendkim/dkim.key~
+if [ ! "$(id -u)" -eq "0" ]; then
+ echo "Must be run as root."
+ exit 1
fi
-sed -r -i 's/^#Selector .*$/Selector '$selector'/' /etc/opendkim.conf
+set -x
+apt-get -y install opendkim
-if [ ! -f $file ]; then
+if [ ! -n "$file" ]; then
+ apt-get -y install opendkim-tools
opendkim-genkey -d plomlompom.com -s $selector
- mv "$selector".private /etc/opendkim/dkim.key
+ apt-get -y --purge autoremove opendkim-tools
+ set +x
+ echo
+ echo 'Generated key file at '$selector'.private.'
+ echo 'Also generated '$selector'.txt, APPLY its content below to your DNS' \
+ 'record.'
+ echo 'AFTER the waiting time for DNS propagation RERUN this script with' \
+ 'the key file as SECOND parameter (still use selector as first one).'
+ echo
+ cat $selector.txt
else
+ if [ ! -f "$file" ]; then
+ set +x
+ echo
+ echo "Keyfile $file does not exist."
+ exit 1
+ fi
+ cp ~/config/systemfiles/opendkim.conf /etc/opendkim.conf
+ sed -r -i 's/^#Selector .*$/Selector '$selector'/' /etc/opendkim.conf
+ mkdir -p /etc/opendkim
+ if [ -f /etc/opendkim/dkim.key ]; then
+ cp /etc/opendkim/dkim.key /etc/opendkim/dkim.key~
+ fi
cp $file /etc/opendkim/dkim.key
-fi
-
-cp ~/config/systemfiles/main.cf /etc/postfix/main.cf
-echo >> /etc/postfix/main.cf << EOF
+ cp ~/config/systemfiles/main.cf /etc/postfix/main.cf
+ cat >> /etc/postfix/main.cf << EOF
# Use opendkim at given port as mail filter.
non_smtpd_milters = inet:localhost:12301
-smtpd_milters = inet:localhost:12301
EOF
-service postfix restart
-service opendkim restart
-
-echo 'TAKE NOTE:'
-if [ -f $selector.txt ]; then
- echo 'Apply the content of '$selector'.txt to your DNS record!'
- cat $selector.txt
-else
- echo 'Make sure the DKIM TXT entry in your DNS record matches!'
+ service opendkim restart
+ service postfix restart
+ set +x
+ echo
+ echo 'Ensure the DKIM TXT entry in your DNS record matches!'
fi