From: Christian Heller Date: Mon, 18 May 2020 20:59:20 +0000 (+0200) Subject: Add mail data migration to mail setup script. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7Bprefix%7D%7D/process_efforts?a=commitdiff_plain;h=3ddd30bea0bf9f7f966b3fed8d2cb455a148092f;p=config Add mail data migration to mail setup script. --- diff --git a/buster/setup_scripts/setup_mail.sh b/buster/setup_scripts/setup_mail.sh index 925d433..a72dc2a 100755 --- a/buster/setup_scripts/setup_mail.sh +++ b/buster/setup_scripts/setup_mail.sh @@ -1,11 +1,12 @@ #!/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 @@ -13,9 +14,10 @@ echo "postfix postfix/mailname string $(hostname -f)" | 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 @@ -44,6 +46,21 @@ password=$(pwgen -s 100 1) #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 @@ -52,7 +69,7 @@ echo "To put into DNS:" 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}"