6 if [ ! -n "$selector" ]; then
8 Usage: $0 SELECTOR [KEYFILE] - set up DKIM system and configuration
10 If existing KEYFILE is given, set up DKIM to use SELECTOR and apply key from
13 If existing KEYFILE is not given, generate KEYFILE and DNS TXT file for
19 if [ ! "$(id -u)" -eq "0" ]; then
20 echo "Must be run as root."
25 apt-get -y install opendkim
27 if [ ! -n "$file" ]; then
28 apt-get -y install opendkim-tools
29 opendkim-genkey -d plomlompom.com -s $selector
30 apt-get -y --purge autoremove opendkim-tools
33 echo 'Generated key file at '$selector'.private.'
34 echo 'Also generated '$selector'.txt, APPLY its content below to your DNS' \
36 echo 'AFTER the waiting time for DNS propagation RERUN this script with' \
37 'the key file as SECOND parameter (still use selector as first one).'
41 if [ ! -f "$file" ]; then
44 echo "Keyfile $file does not exist."
47 cp ~/config/systemfiles/opendkim.conf /etc/opendkim.conf
48 sed -r -i 's/^#Selector .*$/Selector '$selector'/' /etc/opendkim.conf
49 mkdir -p /etc/opendkim
50 if [ -f /etc/opendkim/dkim.key ]; then
51 cp /etc/opendkim/dkim.key /etc/opendkim/dkim.key~
53 cp $file /etc/opendkim/dkim.key
54 cp ~/config/systemfiles/main.cf /etc/postfix/main.cf
55 cat >> /etc/postfix/main.cf << EOF
57 # Use opendkim at given port as mail filter.
58 non_smtpd_milters = inet:localhost:12301
60 service opendkim restart
61 service postfix restart
64 echo 'Ensure the DKIM TXT entry in your DNS record matches!'