X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=all_new_2018%2Fsetup_scripts%2Fsetup_mail.sh;h=208070524e40916861f13610284c320678216f52;hb=c652b4a2a6e909e721e0b7d50a653dd839292074;hp=c8d4254dc20f9c924fb437334bb8f3d989ac1e24;hpb=eafecb0ed8c373dc4f33b6190375fdc3d5c4d841;p=config diff --git a/all_new_2018/setup_scripts/setup_mail.sh b/all_new_2018/setup_scripts/setup_mail.sh index c8d4254..2080705 100755 --- a/all_new_2018/setup_scripts/setup_mail.sh +++ b/all_new_2018/setup_scripts/setup_mail.sh @@ -1,6 +1,7 @@ #/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'." @@ -14,23 +15,19 @@ config_tree_prefix="${HOME}/config/all_new_2018" 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. @@ -64,10 +61,34 @@ echo "${mail_domain}" > /etc/mailname # allow for sophisticated stuff like dovecot-side sieve filtering (installed # with dovecot-sieve). 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 +# ~/.dovecot.sieve to move mails targeted to the fetched mail account to their +# own mbox. +apt -y install fetchmail +cp "${config_tree_prefix}/user_files/fetchmailrc" /home/plom/.fetchmailrc +chown plom:plom /home/plom/.fetchmailrc +chmod 0700 /home/plom/.fetchmailrc + +# Pingmail and fetchmail have some systemd timers waiting. To let systemd +# know about them, do this. +systemctl daemon-reload + +# 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: passwd plom for IMAPS login" +echo "TODO: adapt /home/plom/.fetchmailrc and then do: systemctl start fetchmail.timer" +echo "TODO: adapt /home/plom/.dovecot.sieve and /home/plom/.pingmailrc (sieve mail by pingmail target person into mbox defined in .pingmailrc), then run: systemctl start pingmail.timer" +echo "TODO: Add the follow DMARK entry as TXT to your DNS configugration: 'v=DMARC1; p=none; rua=mailto:plom+dmarc@plomlompom.com;' mapped to _dmarc" +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"