5 if [ ! -n "${selector}" ]; then
6 echo "Give DKIM selector argument."
10 # Set up DKIM key if necessary.
11 mkdir -p /etc/dkimkeys/
13 if [ ! -f "/etc/dkimkeys/${dkim_selector}.private" ]; then
15 dpkg -s opendkim-tools &> /dev/null
17 if [ ! "${preinstalled}" -eq "0" ]; then
18 apt install -y opendkim-tools
20 opendkim-genkey -s "${dkim_selector}"
21 if [ ! "${preinstalled}" -eq "0" ]; then
22 apt --purge autoremove opendkim-tools
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
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
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
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"