+if [ $# -lt 2 ]; then
+ echo "Give arguments of mail domain and DKIM selector."
+ echo "Also, if hosting mail for entire domain, give third argument 'domainwide'."
+ false
+fi
+mail_domain="$1"
+dkim_selector="$2"
+domainwide="$3"
+
+# Set up DKIM key if necessary.
+mkdir -p /etc/dkimkeys/
+add_dkim_record=0
+if [ ! -f "/etc/dkimkeys/${dkim_selector}.private" ]; then
+ add_dkim_record=1
+ set +e
+ dpkg -s opendkim-tools &> /dev/null
+ preinstalled="$?"
+ set -e
+ if [ ! "${preinstalled}" -eq "0" ]; then
+ apt install -y opendkim-tools
+ fi
+ opendkim-genkey -s "${dkim_selector}"
+ mv "${dkim_selector}.private" /etc/dkimkeys/
+ if [ ! "${preinstalled}" -eq "0" ]; then
+ apt -y --purge autoremove opendkim-tools
+ fi
+fi
+
+# Link and adapt mail-server-specific /etc/ files.
+./hardlink_etc.sh mail
+sed -i "s/REPLACE_maildomain_ECALPER/${mail_domain}/g" /etc/mailutils.conf
+sed -i "s/REPLACE_Domain_ECALPER/${mail_domain}/g" /etc/opendkim.conf
+sed -i "s/REPLACE_Selector_ECALPER/${dkim_selector}/g" /etc/opendkim.conf
+sed -i "s/REPLACE_myhostname_ECALPER/$(hostname -f)/g" /etc/postfix/main.cf
+if [ "${domainwide}" = "domainwide" ]; then
+ sed -i 's/REPLACE_mydomain_if_domainwide_ECALPER/$mydomain/g' /etc/postfix/main.cf
+else
+ sed -i 's/REPLACE_mydomain_if_domainwide_ECALPER//g' /etc/postfix/main.cf
+fi
+# Since we re-set the iptables rules, we need to reload them.
+iptables-restore /etc/iptables/rules.v4
+
+# Some useful debconf selections.