X-Git-Url: https://iankelling.org/git/?p=distro-setup;a=blobdiff_plain;f=mail-setup;h=68478bec55a07860a6c86d82ec3cefaae97704c9;hp=ee8482d6495f7b53b00ef9a44c6509166d14e292;hb=32a1673064cfd9eaa165b4ea62fa416f02f3dfd2;hpb=4d0dc703ef2e62cd16ea84f27456f6f50f74baa3 diff --git a/mail-setup b/mail-setup index ee8482d..68478be 100755 --- a/mail-setup +++ b/mail-setup @@ -11,9 +11,7 @@ m() { printf "$pre %s\n" "$*"; "$@"; } e() { printf "$pre %s\n" "$*"; } err() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $0: $*" >&2; } - -# TODO: copy dkim keys from within this file. its now done in conflink. -# TODO: fix dkim key to b chmod 640, group Debian-exim +shopt -s nullglob if [[ -s /usr/local/lib/err ]]; then source /usr/local/lib/err @@ -37,9 +35,6 @@ usage() { Usage: ${0##*/} Setup exim4 & dovecot & related things -The minimal assumption we have is that /etc/mailpass exists - - -h|--help Print help and exit. EOF exit $1 @@ -55,7 +50,9 @@ EOF # background: ovecot does not yet have ocsp stapling support # reference: https://community.letsencrypt.org/t/simple-guide-using-lets-encrypt-ssl-certs-with-dovecot/2921 # -# for phone, same thing but username alerts, pass in ivy-pass. +# for phone, k9mail, same thing but username alerts, pass in ivy-pass. +# also, l2.b8.nz for secondary alerts +# fetching mail settings: folder poll frequency 10 minutes ####### @@ -64,30 +61,19 @@ EOF # # for hosts which have all private files I just use the same user # # for other hosts, each one get\'s their own password. # # for generating secure pass, and storing for server too: -# # user=USUALLY_SAME_AS_HOSTNAME -# user=li # f=$(mktemp) +# I use $HOSTNAME as username # apg -m 50 -x 70 -n 1 -a 1 -M CLN >$f -# s sed -i "/^$user:/d" /p/c/filesystem/etc/exim4/passwd -# echo "$user:$(mkpasswd -m sha-512 -s <$f)" >>/p/c/filesystem/etc/exim4/passwd -# # todo: port is no longer used in mailpass, remove it. -# echo "mail.iankelling.org 587 $user:$(<$f)" >> /p/c/machine_specific/$user/filesystem/etc/mailpass -# # then run this script, or part of it which uses /etc/mailpass +# s sed -i "/^$HOSTNAME:/d" /p/c/filesystem/etc/exim4/passwd +# echo "$HOSTNAME:$(mkpasswd -m sha-512 -s <$f)" >>/p/c/filesystem/etc/exim4/passwd +# reference: exim4_passwd_client(5) +# echo "mail.iankelling.org:$HOSTNAME:$(<$f)" > /p/c/machine_specific/$HOSTNAME/filesystem/etc/exim4/passwd.client +# # then run this script # # dovecot password, i just need 1 as I\'m the only user # mkdir /p/c/filesystem/etc/dovecot # echo "iank:$(doveadm pw -s ssha256)::::::" >>/p/c/filesystem/etc/dovecot/users -# conflink - - -# # for ad-hoc testing of some random new host sending mail: -# user=li # client host username & hostname -# f=$(mktemp) -# apg -m 50 -x 70 -n 1 -a 1 -M CLN >$f -# s sed -i "/^$user:/d" /etc/exim4/passwd -# echo "$user:$(mkpasswd -m sha-512 -s <$f)" | s tee -a /etc/exim4/passwd -# echo "mail.iankelling.org:$user:$(<$f)" | ssh root@$user dd of=/etc/exim4/passwd.client ####### end perstent password instructions ###### @@ -113,12 +99,7 @@ EOF # # lines 2+: append to hold space # echo "txt record contents:" # echo "v=DKIM1; k=rsa; p=$(sed -n '${x;s/\n//gp};2,$H' $domain.pem)" -# chmod 644 $domain.pem -# chmod 640 $domain-private.pem -# # in conflink, we chown these to group debian -# conflink # # selector was also put into /etc/exim4/conf.d/main/000_local, -# # via the mail-setup scripts # # 2017-02 dmarc policies: # # host -t txt _dmarc.gmail.com @@ -152,7 +133,7 @@ EOF # * functions constants e() { printf "%s\n" "$*"; } -pi() { # package install +pi() { # package install without starting daemons local f if dpkg -s -- "$@" &> /dev/null; then return 0; @@ -162,7 +143,18 @@ pi() { # package install if [[ ! -r $f ]] || (( $(( $(date +%s) - $(stat -c %Y $f ) )) > 60*60*12 )); then m apt-get update fi - DEBIAN_FRONTEND=noninteractive m apt-get -y install --purge --auto-remove "$@" + f=/usr/sbin/policy-rc.d + dd of=$f 2>/dev/null <>$f -done /dev/null; then - m systemctl reload dnsmasq - fi + if systemctl is-active dnsmasq >/dev/null; then + m systemctl reload dnsmasq + m nscd -i hosts + fi - # I used to use debconf-set-selections + dpkg-reconfigure, - # which then updates this file - # but the process is slower than updating it directly and then I want to set other things in - # update-exim4.conf.conf, so there's no point. - # The file is documented in man update-exim4.conf, - # except the man page is not perfect, read the bash script to be sure about things. + # I used to use debconf-set-selections + dpkg-reconfigure, + # which then updates this file + # but the process is slower than updating it directly and then I want to set other things in + # update-exim4.conf.conf, so there's no point. + # The file is documented in man update-exim4.conf, + # except the man page is not perfect, read the bash script to be sure about things. - # The debconf questions output is additional documentation that is not - # easily accessible, but super long, along with the initial default comment in this - # file, so I've saved that into ./mail-notes.conf. + # The debconf questions output is additional documentation that is not + # easily accessible, but super long, along with the initial default comment in this + # file, so I've saved that into ./mail-notes.conf. - cat >>/etc/exim4/update-exim4.conf.conf <>/etc/exim4/update-exim4.conf.conf < /etc/mailname + echo mail.iankelling.org > /etc/mailname - # MAIN_HARDCODE_PRIMARY_HOSTNAME might mess up the - # smarthost config type, not sure. all other settings - # would be unused in that config type. - cat >>/etc/exim4/conf.d/main/000_local <>/etc/exim4/conf.d/main/000_local <$f <<'EOF' + f=/etc/cron.daily/refresh-dmarc-tld-file + cat >$f <<'EOF' #!/bin/bash cd /etc wget -q -N https://publicsuffix.org/list/public_suffix_list.dat EOF - m chmod 755 $f + m chmod 755 $f - sed -i --follow-symlinks -f - /etc/aliases <$d/override.conf <<'EOF' + # https://selivan.github.io/2017/12/30/systemd-serice-always-restart.html + d=/etc/systemd/system/openvpn@mail.service.d + m mkdir -p $d + cat >$d/override.conf <<'EOF' [Service] Restart=always # time to sleep before restarting a service @@ -767,63 +786,93 @@ RestartSec=1 # StartLimitIntervalSec in recent systemd versions StartLimitInterval=0 EOF - if ! systemctl cat openvpn@mail.service|grep -xF StartLimitInterval=0 &>/dev/null; then - # needed for the above config to go into effect - m systemctl daemon-reexec - fi - + if ! systemctl cat openvpn@mail.service|grep -xF StartLimitInterval=0 &>/dev/null; then + # needed for the above config to go into effect + m systemctl daemon-reexec + fi - m systemctl enable mailclean.timer - m systemctl start mailclean.timer - m systemctl restart $vpn_ser@mail - m systemctl enable $vpn_ser@mail - m systemctl enable dovecot - m systemctl restart dovecot + m systemctl enable mailclean.timer + m systemctl start mailclean.timer + m systemctl restart $vpn_ser@mail + m systemctl enable $vpn_ser@mail + m systemctl enable dovecot + m systemctl restart dovecot + ;; # * not MAIL_HOST -else # $HOSTNAME != $MAIL_HOST - # remove mail. 2 lines to properly remove whitespace - sed -ri -f - /etc/hosts <<'EOF' + *) # $HOSTNAME != $MAIL_HOST + # remove mail. 2 lines to properly remove whitespace + sed -ri -f - /etc/hosts <<'EOF' s#^(127\.0\.1\.1 .*) +mail\.iankelling\.org$#\1# s#^(127\.0\.1\.1 .*)mail\.iankelling\.org +(.*)#\1\2# EOF - echo | /a/exe/cedit mail /etc/dnsmasq-servers.conf || [[ $? == 1 ]] - if systemctl is-active dnsmasq >/dev/null; then - m systemctl reload dnsmasq - fi + echo | /a/exe/cedit mail /etc/dnsmasq-servers.conf || [[ $? == 1 ]] + if systemctl is-active dnsmasq >/dev/null; then + m nscd -i hosts + m systemctl reload dnsmasq + fi - m systemctl disable mailclean.timer &>/dev/null ||: - m systemctl stop mailclean.timer &>/dev/null ||: - m systemctl disable $vpn_ser@mail - m systemctl stop $vpn_ser@mail - m systemctl disable dovecot ||: - m systemctl stop dovecot ||: - # - # - # would only exist because I wrote it i the previous condition, - # it\'s not part of exim - rm -fv /etc/exim4/conf.d/main/000_localmacros - cat >>/etc/exim4/update-exim4.conf.conf </dev/null ||: + m systemctl stop mailclean.timer &>/dev/null ||: + m systemctl disable $vpn_ser@mail + m systemctl stop $vpn_ser@mail + # + # + # would only exist because I wrote it i the previous condition, + # it\'s not part of exim + rm -fv /etc/exim4/conf.d/main/000_localmacros + cat >>/etc/exim4/update-exim4.conf.conf </etc/mailname + hostname -f >/etc/mailname - # This ends up at alerts mailbox on MAIL_HOST, but using a user that doesn't exist elsewhere - # is no good. - sed -i --follow-symlinks -f - /etc/aliases <>/etc/exim4/update-exim4.conf.conf <>/etc/exim4/update-exim4.conf.conf <$f <<'EOFOUTER' -#!/bin/bash -/usr/sbin/exim -t </etc/cron.d/mailtest </etc/cron.d/mailtest <>/etc/cron.d/mailtest </usr/local/bin/send-test-forward </dev/null; then - if [[ $HOSTNAME == "$MAIL_HOST" ]]; then - m systemctl restart radicale - m systemctl enable radicale - if [[ -e /etc/logrotate.d/radicale.disabled ]]; then - m mv /etc/logrotate.d/radicale{.disabled,} - fi - else - m systemctl stop radicale - m systemctl disable radicale - # weekly logrotate tries to restart radicale even if it's a disabled service in flidas. - if [[ -e /etc/logrotate.d/radicale ]]; then - m mv /etc/logrotate.d/radicale{,.disabled} - fi - fi -fi # * misc m sudo -u $u ln -sf -T /m/.mu /home/$u/.mu