#!/bin/sh
set -e
-if [ "$#" -ne 1 ]; then
- echo 'Need mail for letsencrypt.'
+if [ "$#" -lt 1 ]; then
+ echo 'Need mail for letsencrypt (and optionally old server IP).'
false
fi
mail="$1"
+old_server="$2"
config_tree_prefix="${HOME}/config/buster"
echo "postfix postfix/main_mailer_type string 'Internet Site'" | debconf-set-selections
./install_for_target.sh mail
./copy_dirtree.sh "${config_tree_prefix}/etc_files" "" mail
nft -f /etc/nftables.conf
+newaliases
cat "${config_tree_prefix}/other_files/append_postfix_main.cf" >> /etc/postfix/main.cf
-cat "${config_tree_prefix}/other_files/append_postfix_master.cf" >> /etc/postfix/main.cf
+cat "${config_tree_prefix}/other_files/append_postfix_master.cf" >> /etc/postfix/master.cf
cat "${config_tree_prefix}/other_files/append_opendkim.conf" >> /etc/opendkim.conf
# Set up letsencrypt certificate. We need this for STARTTLS on port
#echo 'mail_privileged_group = mail' >> /etc/dovecot/conf.d/99-mail.conf
echo "plom:${password}" | chpasswd
+# Get old mail data.
+if [ "${old_server}" != "" ]; then
+ cp "${config_tree_prefix}/setup_scripts/prepare_to_meet_server.sh" /home/plom/
+ chown plom:plom /home/plom/prepare_to_meet_server.sh
+ su -lc "./prepare_to_meet_server.sh ${old_server}" plom
+ read -p'Hit Enter when you are done.' ignore
+ rm /home/plom/prepare_to_meet_server.sh
+ cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
+ su -lc "./mirror_dir.sh ${old_server} /home/plom/mail" plom
+ rm /home/plom/mirror_dir.sh
+ su -lc "scp plom@${old_server}:.dovecot.sieve ~" plom
+ su -lc "scp plom@${old_server}:/var/mail/plom /var/mail/plom" plom
+ su -lc "ssh plom@${old_server} \"su -lc 'service postfix stop'\"" plom
+fi
+
service opendkim restart
service postfix restart
service dovecot restart
cat "/etc/dkimkeys/${selector}.txt"
echo "If subdomain, append .subdomain to _domainkeys!"
echo "Also ensure DMARC record of 'v=DMARC1; p=none; rua=mailto:plom+dmarc@plomlompom.com;' as TXT entry at _dmarc or, if subdomain, _dmarc.subdomain"
-echo "Also ensure SPF record of 'v=spf1 mx -all' at @ or subdomain"
+echo "Also ensure SPF record of 'v=spf1 mx -all' as TXT entry at @ or subdomain"
echo "Also ensure reverse DNS lookup for our IP points to $(hostname -f)"
echo "Also ensure MX record of priority 10 for @ or subdomain pointing to $(hostname -f)"
echo "IMAPS password for user plom is: ${password}"