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
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
# 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
#######
# # 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 ######
# # 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
# * 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;
if [[ ! -r $f ]] || (( $(( $(date +%s) - $(stat -c %Y $f ) )) > 60*60*12 )); then
m apt-get update
fi
- m DEBIAN_FRONTEND=noninteractive apt-get -y install --purge --auto-remove "$@"
+ f=/usr/sbin/policy-rc.d
+ dd of=$f 2>/dev/null <<EOF
+#!/bin/sh
+exit 101
+EOF
+ chmod +x $f
+ ret=
+ DEBIAN_FRONTEND=noninteractive m apt-get -y install --purge --auto-remove "$@" || ret=$?
+ rm $f
+ if [[ $ret ]]; then
+ err-exit $ret "failed apt-get install above"
+ fi
}
postmaster=alerts
## * Install packages
# light version of exim does not have sasl auth support.
-pi exim4-daemon-heavy spamassassin spf-tools-perl openvpn dnsmasq
+pi exim4-daemon-heavy spamassassin spf-tools-perl dnsmasq openvpn
+# our nostart pi fails to avoid enabling
+sudo systemctl disable openvpn
# trisquel 8 = openvpn, debian stretch = openvpn-client
vpn_ser=openvpn-client
uhome=$(eval echo ~$u)
### * user forward file
-if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
- # afaik, these will get ignored because they are routing to my own
- # machine, but rm them is safer
- rm -fv $uhome/.forward /root/.forward
-else
- # this can\'t be a symlink and has permission restrictions
- # it might work in /etc/aliases, but this seems more proper.
- e setting $uhome/.forward to $forward
- install -m 644 {-o,-g}$u <(e $forward) $uhome/.forward
-fi
+
+case $HOSTNAME in
+ $MAIL_HOST|l2)
+ # afaik, these will get ignored on MAIL_HOST because they are routing to my own
+ # machine, but rm them is safer
+ rm -fv $uhome/.forward /root/.forward
+ ;;
+ *)
+ # this can\'t be a symlink and has permission restrictions
+ # it might work in /etc/aliases, but this seems more proper.
+ e setting $uhome/.forward to $forward
+ install -m 644 {-o,-g}$u <(e $forward) $uhome/.forward
+ ;;
+esac
# * Mail clean cronjob
if [[ -e $f ]]; then
source $f
fi
-if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
- local_mx=mail.iankelling.org
- rsync_common="rsync -ogtL --chown=root:Debian-exim --chmod=640 root@li.iankelling.org:/etc/letsencrypt/live/$local_mx/"
- ${rsync_common}fullchain.pem /etc/exim4/exim.crt
- ret=$?
- ${rsync_common}privkey.pem /etc/exim4/exim.key
- new_ret=$?
- if [[ $ret != $new_ret ]]; then
- echo "$0: error: differing rsync returns, $ret, $new_ret"
- exit 1
- fi
+if [[ $HOSTNAME != "$MAIL_HOST" ]]; then
+ exit 0
fi
-if [[ $new_ret != 0 ]]; then
- if ! openssl x509 -checkend $(( 60 * 60 * 24 * 3 )) -noout -in /etc/exim4/exim.crt; then
- echo "$0: error!: cert rsync failed and it will expire in less than 3 days"
- exit 1
- fi
+local_mx=mail.iankelling.org
+mkdir -p /etc/letsencrypt/live/$local_mx
+chmod 700 /etc/letsencrypt/live
+rsync_common="rsync -ogtL --chown=root:Debian-exim --chmod=640 root@li.iankelling.org:/etc/letsencrypt/live/$local_mx/"
+# allow for temporary connection issues
+${rsync_common}fullchain.pem /etc/exim4/exim.crt ||:
+${rsync_common}privkey.pem /etc/exim4/exim.key ||:
+if ! openssl x509 -checkend $(( 60 * 60 * 24 * 3 )) -noout -in /etc/exim4/exim.crt; then
+ echo "$0: error!: cert rsync failed and it will expire in less than 3 days"
+ exit 1
fi
exit 0
EOF
# * common exim4 config
source /a/bin/bash_unpublished/source-state
+if [[ ! $MAIL_HOST ]]; then
+ err "\$MAIL_HOST not set"
+fi
+
+m sudo gpasswd -a iank adm #needed for reading logs
+
### make local bounces go to normal maildir
# local mail that bounces goes to /Maildir or /root/Maildir
dirs=(/m/md/bounces/{cur,tmp,new})
m mkdir -p ${dirs[@]}
+m chown iank:iank /m /m/md
+m ln -sfT /m/md /m/iank
+m chmod 700 /m /m/md
m chown -R $u:Debian-exim /m/md/bounces
m chmod 775 ${dirs[@]}
m usermod -a -G Debian-exim $u
m ln -sf -T /m/md/bounces $d
done
-
-### begin setup passwd.client
-f=/etc/exim4/passwd.client
-rm -fv /etc/exim4/passwd.client
-m install -m 640 -g Debian-exim /dev/null $f
-while read -r domain _ pass; do
- # reference: exim4_passwd_client(5)
- printf "%s:%s\n" "$domain" "$pass" >>$f
-done </etc/mailpass
-### end setup passwd.client
+# Note, even the server needs permissions of this file right
+# if it exists, so do this up here.
+f=/p/c/filesystem/etc/exim4/passwd.client
+if [[ ! -e $f ]]; then
+ f=/p/c/machine_specific/$HOSTNAME/filesystem/etc/exim4/passwd.client
+fi
+m sudo rsync -ahhi --chown=root:Debian-exim --chmod=0640 $f /etc/exim4/
# by default, only 10 days of logs are kept. increase that.
m sed -ri 's/^(\s*rotate\s).*/\11000/' /etc/logrotate.d/exim4-base
sed -r s/^\\S+:/$b:/ 600_exim4-config_userforward >175_$b
-m rm -f /etc/exim4/conf.d/main/000_localmacros # old filename
+rm -vf /etc/exim4/conf.d/main/000_localmacros # old filename
cat >/etc/exim4/conf.d/main/000_local <<EOF
MAIN_TLS_ENABLE = true
-
# debian exim config added this in 2016 or so?
# it's part of the smtp spec, to limit lines to 998 chars
# but a fair amount of legit mail does not adhere to it. I don't think
# more verbose logs
MAIN_LOG_SELECTOR = +all
+
+# normally empty, I set this so I can set the envelope address
+# when doing mail redelivery to invoke filters. Also allows
+# me exiqgrep and stuff.
+MAIN_TRUSTED_GROUPS = $u
+
+# default is 10. when exim has been down for a bit, fsf mailserver
+# will do a big send in one connection, then exim decides to put
+# the messages in the queue instead of delivering them, to avoid
+# spawning too many delivery processes. Pretty sure my system
+# can handle a lot more, but lets go with this.
+smtp_accept_queue_per_connection = 100
+
+
+DKIM_CANON = relaxed
+DKIM_SELECTOR = li
+
+# from comments in
+# https://debian-administration.org/article/718/DKIM-signing_outgoing_mail_with_exim4
+
+# The file is based on the outgoing domain-name in the from-header.
+DKIM_DOMAIN = \${lc:\${domain:\$h_from:}}
+# sign if key exists
+DKIM_PRIVATE_KEY = \${if exists{/etc/exim4/\${dkim_domain}-private.pem} {/etc/exim4/\${dkim_domain}-private.pem}}
+
+# most of the ones that gmail seems to use.
+# Exim has horrible default of signing unincluded
+# list- headers since they got mentioned in an
+# rfc, but this messes up mailing lists, like gnu/debian which want to
+# keep your dkim signature intact but add list- headers.
+DKIM_SIGN_HEADERS = mime-version:in-reply-to:references:from:date:subject:to
EOF
rm -fv /etc/exim4/rcpt_local_acl # old path
dc_mailname_in_oh='true'
EOF
-# * if MAIL_HOST
-if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
- # ** dovecot
- ####### begin dovecot setup ########
+
+# ** dovecot
+dovecot-setup() {
# based on a little google and package search, just the dovecot
# packages we need instead of dovecot-common.
#
# internet. I was torn about whether to do this or not, meh.
pi dovecot-core dovecot-imapd dovecot-sieve dovecot-lmtpd
+ for f in /p/c{/machine_specific/$HOSTNAME,}/filesystem/etc/dovecot/users; do
+ e $f
+ if [[ -e $f ]]; then
+ m sudo rsync -ahhi --chown=root:dovecot --chmod=0640 $f /etc/dovecot/
+ break
+ fi
+ done
for f in /p/c/subdir_files/sieve/*sieve /a/c/subdir_files/sieve/*sieve; do
m sudo -u $u /a/exe/lnf -T $f $uhome/sieve/${f##*/}
done
- # if we changed 90-sieve.conf and removed the active part of the
+ # If we changed 90-sieve.conf and removed the active part of the
# sieve option, we wouldn\'t need this, but I\'d rather not modify a
# default config if not needed. This won\'t work as a symlink in /a/c
# unfortunately.
- m sudo -u $u /a/exe/lnf -T sieve/main.sieve $uhome/.dovecot.sieve
+ if [[ -e $uhome/sieve/personal.sieve ]]; then
+ m sudo -u $u /a/exe/lnf -T sieve/main.sieve $uhome/.dovecot.sieve
+ fi
# we set this later in local.conf
sed -ri -f - /etc/dovecot/conf.d/10-mail.conf <<'EOF'
# ian: added this, more secure, per google etc
ssl_prefer_server_ciphers = yes
-
+# ian: %u is used for alerts user vs iank
mail_location = maildir:/m/%u:LAYOUT=fs:INBOX=/m/%u/INBOX
mail_uid = $u
mail_gid = $u
# auth_verbose=yes
#mail_debug=yes
EOF
- ####### end dovecot setup ########
+ ####### end dovecot-setup ########
+}
- # ** exim
- # mail.iankelling.org so local imap clients can connect with tls and
- # when they happen to not be local.
- sed -ri -f - /etc/hosts <<'EOF'
+
+# * if MAIL_HOST
+case $HOSTNAME in
+ $MAIL_HOST)
+ dovecot-setup
+
+ # ** exim
+
+ sudo rsync -ahhi --chown=root:Debian-exim --chmod=0640 \
+ /p/c/filesystem/etc/exim4/passwd /p/c/filesystem/etc/exim4/*.pem /etc/exim4/
+
+
+ # mail.iankelling.org so local imap clients can connect with tls and
+ # when they happen to not be local.
+ sed -ri -f - /etc/hosts <<'EOF'
/^127\.0\.1\.1.* mail\.iankelling\.org\b/{p;d}
/^127\.0\.1\.1 /s/ *$/ mail.iankelling.org/
EOF
- /a/exe/cedit mail /etc/dnsmasq-servers.conf <<'EOF' || [[ $? == 1 ]]
+
+ # note: systemd-resolved will consult /etc/hosts, dnsmasq wont. this assumes
+ # weve configured this file in dnsmasq if we are using it.
+ /a/exe/cedit mail /etc/dnsmasq-servers.conf <<'EOF' || [[ $? == 1 ]]
server=/mail.iankelling.org/127.0.1.1
EOF
- if systemctl is-active dnsmasq >/dev/null; then
- m systemctl reload dnsmasq
- fi
+ if systemctl is-active dnsmasq >/dev/null; then
+ m systemctl restart dnsmasq
+ fi
+ m nscd -i hosts
- # 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 <<EOF
+ cat >>/etc/exim4/update-exim4.conf.conf <<EOF
# note: some things we don't set that are here by default because they are unused.
dc_eximconfig_configtype='internet'
-# man page: is used to build the local_domains list, together with “localhost”
+# man page: is used to build the local_domains list, together with "localhost"
# iank.bid is for testing
# mail.iankelling.org is for machines i own
dc_other_hostnames='*.iankelling.org;iankelling.org;*iank.bid;iank.bid;*zroe.org;zroe.org;*.b8.nz;b8.nz'
# because this machine serves as secondary MX for these domains. Sets MAIN_RELAY_TO_DOMAINS.
# todo: we should not accept from anywhere, only the mx for fsf.
dc_relay_domains='*.fsf.org;fsf.org'
+dc_localdelivery='dovecot_lmtp'
EOF
- # the debconf output about mailname is as follows:
- # The 'mail name' is the domain name used to 'qualify' mail addresses without a domain
- # name.
- # This name will also be used by other programs. It should be the single, fully
- # qualified domain name (FQDN).
- # Thus, if a mail address on the local host is foo@example.org, the correct value for
- # this option would be example.org.
- # This name won\'t appear on From: lines of outgoing messages if rewriting is enabled.
+ # the debconf output about mailname is as follows:
+ # The 'mail name' is the domain name used to 'qualify' mail addresses without a domain
+ # name.
+ # This name will also be used by other programs. It should be the single, fully
+ # qualified domain name (FQDN).
+ # Thus, if a mail address on the local host is foo@example.org, the correct value for
+ # this option would be example.org.
+ # This name won\'t appear on From: lines of outgoing messages if rewriting is enabled.
- echo mail.iankelling.org > /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 <<EOF
+ # 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 <<EOF
# enable 587 in addition to the default 25, so that
# i can send mail where port 25 is firewalled by isp
daemon_smtp_ports = 25 : 587
-# i don't have ipv6 setup properly yet
-disable_ipv6 = true
-DKIM_CANON = relaxed
-DKIM_SELECTOR = li
-
-# from comments in
-# https://debian-administration.org/article/718/DKIM-signing_outgoing_mail_with_exim4
-
-# The file is based on the outgoing domain-name in the from-header.
-DKIM_DOMAIN = \${lc:\${domain:\$h_from:}}
-# sign if key exists
-DKIM_PRIVATE_KEY= \${if exists{/etc/exim4/\${dkim_domain}-private.pem} {/etc/exim4/\${dkim_domain}-private.pem}}
# failing message on mail-tester.com:
# Seems logical for this to be the same as mailname.
MAIN_HARDCODE_PRIMARY_HOSTNAME = mail.iankelling.org
-# normally empty, I set this so I can set the envelope address
-# when doing mail redelivery to invoke filters
-MAIN_TRUSTED_GROUPS = $u
-
-LOCAL_DELIVERY = dovecot_lmtp
-
# options exim has to avoid having to alter the default config files
CHECK_RCPT_LOCAL_ACL_FILE = /etc/exim4/conf.d/rcpt_local_acl
CHECK_DATA_LOCAL_ACL_FILE = /etc/exim4/conf.d/data_local_acl
-# most of the ones that gmail seems to use.
-# Exim has horrible default of signing unincluded
-# list- headers since they got mentioned in an
-# rfc, but this messes up mailing lists, like gnu/debian which want to
-# keep your dkim signature intact but add list- headers.
-DKIM_SIGN_HEADERS = mime-version:in-reply-to:references:from:date:subject:to
# recommended if dns is expected to work
CHECK_RCPT_VERIFY_SENDER = true
#dmarc_tld_file = /etc/public_suffix_list.dat
EOF
- f=/etc/cron.daily/refresh-dmarc-tld-file
- cat >$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 <<EOF
+ sed -i --follow-symlinks -f - /etc/aliases <<EOF
\$a root: $postmaster
/^root:/d
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'
+ # 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
# 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. uses 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
-
- 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 <<EOF
+ echo | /a/exe/cedit mail /etc/dnsmasq-servers.conf || [[ $? == 1 ]]
+ if systemctl is-active dnsmasq >/dev/null; then
+ m systemctl restart dnsmasq # reload does not ensure new config is used
+ fi
+ m nscd -i hosts
+
+ 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
+ #
+ #
+ # 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 <<EOF
dc_eximconfig_configtype='smarthost'
dc_smarthost='$smarthost'
# The manpage incorrectly states this will do header rewriting, but
# that only happens if we have dc_hide_mailname is set.
dc_readhost='iankelling.org'
-# Only used in case of bounces.
-dc_localdelivery='maildir_home'
EOF
- hostname -f >/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 <<EOF
-\$a root: root@mail.iankelling.org
+
+ ;;&
+ ## we use this host to monitor MAIL_HOST
+ l2)
+ dovecot-setup
+ m systemctl enable dovecot
+ m systemctl restart dovecot
+ cat >>/etc/exim4/update-exim4.conf.conf <<EOF
+# man page: is used to build the local_domains list, together with "localhost"
+# mail.iankelling.org is for machines i own
+dc_other_hostnames='l2.b8.nz'
+dc_localdelivery='dovecot_lmtp'
+EOF
+ # 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 <<EOF
+\$a root: iank
/^root:/d
EOF
+ ;;
+ # not l2 and not MAIL_HOST
+ *)
+
-fi # end $HOSTNAME != $MAIL_HOST
+ # 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 <<EOF
+\$a root: root@mail.iankelling.org
+/^root:/d
+EOF
+ cat >>/etc/exim4/update-exim4.conf.conf <<EOF
+# Only used in case of bounces.
+dc_localdelivery='maildir_home'
+EOF
+ m systemctl disable dovecot ||:
+ m systemctl stop dovecot ||:
+ ;;
+esac # end $HOSTNAME != $MAIL_HOST
# * spool dir setup
# i have the spool directory be common to distro multi-boot, so
# we need the uid to be the same. 608 cuz it's kind of in the middle
# of the free system uids.
-IFS=:; read _ _ uid _ < <(getent passwd Debian-exim ||:) ||:; unset IFS
-IFS=:; read _ _ gid _ < <(getent group Debian-exim ||:) ||:; unset IFS
+IFS=:; read -r _ _ uid _ < <(getent passwd Debian-exim ||:) ||:; unset IFS
+IFS=:; read -r _ _ gid _ < <(getent group Debian-exim ||:) ||:; unset IFS
if [[ ! $uid ]]; then
# from /var/lib/dpkg/info/exim4-base.postinst, plus uid and gid options
m adduser --uid 608 --system --group --quiet --home /var/spool/exim4 \
- --no-create-home --disabled-login --force-badname Debian-exim
+ --no-create-home --disabled-login --force-badname Debian-exim
elif [[ $uid != 608 ]]; then
m systemctl stop exim4 ||:
m usermod -u 608 Debian-exim
m groupmod -g 608 Debian-exim
m usermod -g 608 Debian-exim
- m find / /nocow -xdev -uid $uid -exec chown -h 608 {} +
- m find / /nocow -xdev -gid $gid -exec chgrp -h 608 {} +
+ m find / /nocow -path ./var/tmp -prune -o -xdev -uid $uid -execdir chown -h 608 {} +
+ m find / /nocow -path ./var/tmp -prune -o -xdev -gid $gid -execdir chgrp -h 608 {} +
fi
# * mail monitoring / testing
-if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
- f=/usr/local/bin/send-test-forward
- cat >$f <<'EOFOUTER'
+
+case $HOSTNAME in
+ $MAIL_HOST|l2)
+ # note: cronjob "ian" also does some important monitoring
+ cat >/etc/cron.d/mailtest <<EOF
+SHELL=/bin/bash
+PATH=/usr/bin:/bin:/usr/local/bin
+*/5 * * * * $u send-test-forward |& log-once send-test-forward
+*/10 * * * * root chmod -R g+rw /m/md/bounces |& log-once -1 bounces-chmod
+EOF
+ ;;&
+ $MAIL_HOST)
+ test_from=ian@iankelling.org
+ test_to=iank@posteo.de
+
+ cat >>/etc/cron.d/mailtest <<EOF
+*/5 * * * * $u mailtest-check |& log-once -1 mailtest-check
+2 * * * * $u check-remote-mailqs |& log-once check-remote-mailqs
+EOF
+ m sudo rsync -ahhi --chown=root:root --chmod=0755 \
+ /b/ds/mailtest-check /b/ds/check-remote-mailqs /usr/local/bin/
+ ;;&
+ l2)
+ test_from=iank@l2.b8.nz
+ test_to=testignore@iankelling.org
+ ;;&
+ $MAIL_HOST|l2)
+ cat >/usr/local/bin/send-test-forward <<EOFOUTER
#!/bin/bash
/usr/sbin/exim -t <<EOF
-From: ian@iankelling.org
-To: iank@posteo.de
-Subject: primary_test $(date +%s) $(date +%Y-%m-%dT%H:%M:%S%z)
+From: $test_from
+To: $test_to
+Subject: primary_test \$(date +%s) \$(date +%Y-%m-%dT%H:%M:%S%z)
eom
EOF
EOFOUTER
- m chmod +x $f
-
- cat >/etc/cron.d/mailtest <<EOF
-SHELL=/bin/bash
-# running as user just because no need to run as root
-*/10 * * * * $u $f 2>&1 | /usr/local/bin/log-once send-test-forward
-*/10 * * * * $u /usr/local/bin/mailtest-check 2>&1 | /usr/local/bin/log-once -1 mailtest-check
-*/10 * * * * root chmod -R g+rw /m/md/bounces 2>&1 | /usr/local/bin/log-once -1 bounces-chmod
-EOF
- m cp /a/bin/distro-setup/filesystem/usr/local/bin/mailtest-check /usr/local/bin
-else
- rm -fv /etc/cron.d/mailtest
-fi
-
+ m chmod +x /usr/local/bin/send-test-forward
+ ;;
+ *)
+ rm -fv /etc/cron.d/mailtest
+ ;;
+esac
-# * Radicale
-# MAIL_HOST also does radicale, and easier to start and stop it here
-# for when MAIL_HOST changes, so radicale gets the synced files and
-# does not stop us from remounting /o.
-if dpkg -s radicale &>/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