home · contact · privacy
Update Firefox version.
[config] / bin / setup_opendkim.sh
1 #!/bin/sh
2 set -e
3 selector=$1
4 file=$2
5
6 if [ ! -n "$selector" ]; then
7     cat << EOF
8 Usage: $0 SELECTOR [KEYFILE] - set up DKIM system and configuration
9
10 If existing KEYFILE is given, set up DKIM to use SELECTOR and apply key from
11 KEYFILE.
12
13 If existing KEYFILE is not given, generate KEYFILE and DNS TXT file for
14 SELECTOR.
15 EOF
16     exit
17 fi
18
19 if [ ! "$(id -u)" -eq "0" ]; then
20     echo "Must be run as root."
21     exit 1
22 fi
23
24 set -x
25 apt-get -y install opendkim
26
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
31     set +x
32     echo
33     echo 'Generated key file at '$selector'.private.'
34     echo 'Also generated '$selector'.txt, APPLY its content below to your DNS' \
35          'record.'
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).'
38     echo
39     cat $selector.txt
40 else
41     if [ ! -f "$file" ]; then
42         set +x
43         echo
44         echo "Keyfile $file does not exist."
45         exit 1
46     fi
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~
52     fi
53     cp $file /etc/opendkim/dkim.key
54     cp ~/config/systemfiles/main.cf /etc/postfix/main.cf
55     cat >> /etc/postfix/main.cf << EOF
56
57 # Use opendkim at given port as mail filter.
58 non_smtpd_milters = inet:localhost:12301
59 EOF
60     service opendkim restart
61     service postfix restart
62     set +x
63     echo
64     echo 'Ensure the DKIM TXT entry in your DNS record matches!'
65 fi