#/bin/sh
set -e
+# Check we have the necessary arguments.
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'."
setup_scripts_dir="${config_tree_prefix}/setup_scripts"
cd "${setup_scripts_dir}"
-# Set up DKIM key if necessary.
+# Set up DKIM key. Only keep opendkim-tools on system if pre-installed.
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
+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
# Link and adapt mail-server-specific /etc/ files.
apt install -y -o Dpkg::Options::=--force-confold postfix dovecot-imapd dovecot-lmtpd dovecot-sieve opendkim
cp "${config_tree_prefix}/user_files/dovecot.sieve" /home/plom/.dovecot.sieve
chown plom:plom /home/plom/.dovecot.sieve
+
+# Pingmail setup.
+apt install -y mailutils
cp "${config_tree_prefix}/user_files/pingmailrc" /home/plom/.pingmailrc
chown plom:plom /home/plom/.pingmailrc
+su plom -c "cd && git clone https://plomlompom.com/repos/clone/pingmail.git"
# In addition to our postfix server receiving mails, we funnel mails from a
# POP3 account into dovecot via fetchmail. It might make sense to adapt the
cp "${config_tree_prefix}/user_files/fetchmailrc" /home/plom/.fetchmailrc
chown plom:plom /home/plom/.fetchmailrc
chmod 0700 /home/plom/.fetchmailrc
-set +e
-apt install -y fetchmail
+
+# Pingmail and fetchmail have some systemd timers waiting. To let systemd
+# know about them, do this.
systemctl daemon-reload
-systemctl start fetchmail.timer
-set -e
# Final advice to user.
echo "TODO: Ensure MX entry for your system in your DNS configuration."
echo "TODO: Ensure a proper SPF entry for this system in your DNS configuration; something like 'v=spf1 mx -all' mapped to your host."
-if [ "${add_dkim_record}" -eq "1" ]; then
- 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):"
- cat "${dkim_selector}.txt"
-fi
-echo "TODO: passwd plom"
-echo "TODO: adapt /home/plom/.dovecot.sieve /home/plom/.fetchmailrc /home/plom/.pingmailrc"
+echo "TODO: passwd plom for IMAPS login"
+echo "TODO: adapt /home/plom/.dovecot.sieve /home/plom/.fetchmailrc /home/plom/.pingmailrc, then run: systemctl start pingmail.timer && systemctl start fetchmail.timer"
+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):"
+cat "${dkim_selector}.txt"