home · contact · privacy
285ecb689b63481b052295cb348c68bdbbd59704
[config] / all_new_2018 / setup_mail.sh
1 #/bin/sh
2 set -e
3
4 selector=$1
5 if [ ! -n "${selector}" ]; then
6     echo "Give DKIM selector argument."
7     false
8 fi
9
10 # Set up DKIM key if necessary.
11 mkdir -p /etc/dkimkeys/
12 add_dkim_record=0
13 if [ ! -f "/etc/dkimkeys/${dkim_selector}.private" ]; then
14     add_dkim_record=1
15     dpkg -s opendkim-tools &> /dev/null
16     preinstalled="$?"
17     if [ ! "${preinstalled}" -eq "0" ]; then
18         apt install -y opendkim-tools
19     fi
20     opendkim-genkey -s "${dkim_selector}"
21     if [ ! "${preinstalled}" -eq "0" ]; then
22         apt --purge autoremove opendkim-tools
23     fi
24 fi
25
26 # Link and adapt mail-server-specific /etc/ files.
27 ./hardlink_etc.sh mail
28 sed -i "s/REPLACE_Domain_ECALPER/$(hostname -f)/g" /etc/opendkim.conf
29 sed -i "s/REPLACE_Selector_ECALPER/${dkim_selector}/g" /etc/opendkim.conf
30
31 # Some useful debconf selections.
32 echo "postfix postfix/main_mailer_type string 'Internet Site'" | debconf-set-selections
33 echo "ssl_cert = </etc/letsencrypt/live/$(hostname -f)/fullchain.pem" > /etc/dovecot/conf.d/99-ssl-certs.conf
34 echo "ssl_key = </etc/letsencrypt/live/$(hostname -f)/privkey.pem" >> /etc/dovecot/conf.d/99-ssl-certs.conf
35
36 # The second line should not be necessary due to the first line, but for
37 # some reason the installation forgets to set up /etc/mailname early
38 # enough to not (when running newaliases) stumble over its absence.
39 echo "postfix postfix/mailname string $(hostname -f)" | debconf-set-selections
40 echo "$(hostname -f)" > /etc/mailname
41
42 # Everything should now be ready for installations.
43 apt install -y postfix dovecot-imapd opendkim
44 echo "TODO: Ensure a proper SPF entry for this system in your DNS configuration."
45 if [ "${add_dkim_record}" -eq "1" ]; then
46     echo "TODO: Add the following DKIM entry to your DNS configuration (possibly with slightly changed host entry – if your mail domain includes a subdomain, append that with a dot):"
47     cat "${dkim_selector}.txt"
48 fi