3 # Copyright (C) 2019 Ian Kelling
4 # SPDX-License-Identifier: AGPL-3.0-or-later
6 # todo: hosts should only allow external mail that is authed and
7 # destined for backup route. it is a minor issue since traffic is
8 # limited to the wghole network.
10 # todo: emailing info@amnimal.ninja produces a bounce, user doesn't exist
11 # instead of a simple rejection like it should.
13 # todo: auto restart of je on checkrestart
15 # todo: run mailping test after running, or otherwise
16 # clear out terminal alert
18 # todo: reinstall bk with bigger filesystem
20 # todo: on bk, dont send email if mailvpn is not up
22 # todo: mailtest-check should check on bk too
24 # todo: disable postgrey
26 # todo: in testforward-check, we should also look
28 # todo: test that bounces dont help create valid mailtest-check
30 # todo: move mail stuff in distro-end into this file
32 # todo: consider rotating dkim & publishing key so every past email I sent
33 # isnt necessarily signed
35 # todo: consider how to get clamav out of Debian-exim group
36 # so it cant read/write the whole mail spool, for better
39 # todo: create a cronjob to update or warn on expiring dnssec keys
41 # todo: we should test failed mail daily or so
42 # failed cronjob, failed sysd-log-once,
43 # a local bounce from a cronjob, a local bounce
44 # to a bad remote address, perhaps a local failure
45 # when the sending daemon is down.
46 # And send an alert email if no alerts have been sent
47 # in 2 or 3 days or something. todo, test cron mail on li.
49 # todo: look at mailinabox extra dns records, note these changelogs:
50 # - An MTA-STS policy for incoming mail is now published (in DNS and over HTTPS) when the primary hostname and email address domain both have a signed TLS certificate installed, allowing senders to know that an encrypted connection should be enforced.
51 # - The per-IP connection limit to the IMAP server has been doubled to allow more devices to connect at once, especially with multiple users behind a NAT.
54 # todo: mailtest-check failure on remote hosts is not going to alert me.
56 # todo: test mail failure as well as success.
58 # todo: validate that mailtest-check is doing dnsbl checks.
60 # background: I want to run exim in a network namespace so it can send
61 # and receive through a vpn. This is needed so it can do ipv6, because
62 # outside the namespace if we dont have ipv6, to send ipv6 through the
63 # vpn, we have to send all our ipv6 through the vpn. I did this for a
64 # long time, it was fine, but it causes various pains, like increased
65 # latency, increased recaptcha because my ip is from a data center, just
66 # various issues I dont want on all the time. The problem with the
67 # namespace is that all kinds of programs want to invoke exim, but they
68 # wont be in the namespace. I could replace exim with a wrapper that
69 # jumps into the namespace, i tried that, it works fine. One remaining
70 # problem was that I would have needed to hook into exim upgrades to
71 # move exim and replace it with my wrapper script. Also, my script to
72 # join the namespace is not super reliable because it uses a pgrep.
73 # Instead, I should have created a systemd service for a process that
74 # will never die and just writes its pid somewhere convenient.
79 # user ALL=(ALL) /usr/sbin/exim4
81 # move exim4 to eximian, use this script for exim4:
84 # if ip a show veth1-mail &>/dev/null; then
85 # /usr/sbin/eximian "$@"
89 # if [[ $USER && $USER != root ]]; then
92 # pid=$(pgrep -f "/usr/sbin/openvpn .* --config /etc/openvpn/.*mail.conf")
94 # sudo nsenter -t $pid -n -m sudo -u $USER /usr/sbin/eximian "$@"
96 # nsenter -t $pid -n -m /usr/sbin/eximian "$@"
100 # an alternate solution: there is a small setguid program for
101 # network namespaces in my bookmarks.
103 # However, the solution I went with is: have 2 exim
104 # configs. A nonstandard location for the daemon that runs
105 # in the namespace. For all other invocations, it uses
106 # the default config location, which is altered to be
107 # in a smarthost config which sends mail to the deaemon.
109 # I have a bash function, enn to invoke exim like the daemon is running.
110 # and mailbash to just enter its network namespace.
112 if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
116 if [[ -s /usr
/local
/lib
/err
]]; then
117 source /usr
/local
/lib
/err
118 elif [[ -s /a
/bin
/errhandle
/err
]]; then
119 source /a
/bin
/errhandle
/err
121 err
"no err tracing script found"
123 source /a
/bin
/distro-functions
/src
/identify-distros
124 source /a
/bin
/distro-functions
/src
/package-manager-abstractions
126 # has nextcloud_admin_pass in it
127 f
=/p
/c
/machine_specific
/$HOSTNAME/mail
129 # shellcheck source=/p/c/machine_specific/bk/mail
134 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
142 Usage: ${0##*/} anything_here_to_debug
143 Setup exim4 & dovecot & related things
145 -h|--help Print help and exit.
150 # debug output if we pass any arg
156 ####### instructions for icedove #####
157 # Incoming mail server: mail.iankelling.org, port 143, username iank, connection security starttls, authentication method normal password,
158 # then click advanced so it accepts it.
159 # we could also just use 127.0.0.1 with no ssl
161 # hamburger -> preferences -> preferences -> advanced tab -> config editor button -> security.ssl.enable_ocsp_must_staple = false
162 # background: dovecot does not yet have ocsp stapling support
163 # reference: https://community.letsencrypt.org/t/simple-guide-using-lets-encrypt-ssl-certs-with-dovecot/2921
165 # for phone, k9mail, same thing but username alerts, pass in ivy-pass.
166 # also, bk.b8.nz for secondary alerts, username is iank. same alerts pass.
167 # fetching mail settings: folder poll frequency 10 minutes
171 # * perstent password instructions
172 # Note: for cert cron, we need to manually run first to accept known_hosts
175 # # for hosts which have all private files I just use the same user
176 # # for other hosts, each one get\'s their own password.
177 # # for generating secure pass, and storing for server too:
180 # apg -m 50 -x 70 -n 1 -a 1 -M CLN >$f
181 # s sed -i "/^$host:/d" /p/c/filesystem/etc/exim4/passwd
182 # echo "$host:$(mkpasswd -m sha-512 -s <$f)" >>/p/c/filesystem/etc/exim4/passwd
183 # #reference: exim4_passwd_client(5)
184 # dir=/p/c/machine_specific/$host/filesystem/etc/exim4
186 # echo "mail.iankelling.org:$host:$(<$f)" > $dir/passwd.client
187 # # then run this script
189 # # dovecot password, i just need 1 as I\'m the only user
190 # mkdir /p/c/filesystem/etc/dovecot
191 # echo "iank:$(doveadm pw -s SHA512-CRYPT)::::::" >>/p/c/filesystem/etc/dovecot/users
193 ####### end perstent password instructions ######
197 # # Remove 1 level of comments in this section, set the domain var
198 # # for the domain you are setting up, then run this and copy dns settings
200 # domain=iankelling.org
201 # c /p/c/filesystem/etc/exim4
202 # # this has several bugs addressed in comments, but it was helpful
203 # # https://debian-administration.org/article/718/DKIM-signing_outgoing_mail_with_exim4
205 # openssl genrsa -out $domain-private.pem 2048
206 # # Then, to get the public key strings to put in bind:
208 # # selector is needed for having multiple keys for one domain.
209 # # I dun do that, so just use a static one: li
210 # # Debadmin page does not have v=, fastmail does, and this
211 # # says it\'s recommended in 3.6.1, default is DKIM1 anyways.
212 # # https://www.ietf.org/rfc/rfc6376.txt
213 # # Join and print all but first and last line.
214 # # last line: swap hold & pattern, remove newlines, print.
215 # # lines 2+: append to hold space
216 # echo "bind txt record: remember to truncate $domain so its relative to the bind zone"
218 # a._domainkey.$domain TXT (
219 # "v=DKIM1\059 k=rsa\059 p=$(openssl rsa -in $domain-private.pem -pubout |&sed -rn '${x;s/\n//g;s/^(.*)(.{240}$)/\1"\n"\2/p};3,$H')" )
221 # # sed explanation: skip the first few lines, then put them into the hold space, then
222 # # on the last line, back to the patern space, remove the newlines, then add a newline
223 # # at the last char - 240, because bind txt records need strings <=255 chars,
224 # # other dkim stuff at the begining is is 25 chars, and the pubkey is 393, so this
225 # # leaves us a bit of extra room at the end and a bunch at the beginning.
227 # # selector was also put into /etc/exim4/conf.d/main/000_local,
231 # # 2017-02 dmarc policies:
232 # # host -t txt _dmarc.gmail.com
233 # # yahoo: p=reject, hotmail: p=none, gmail: p=none, fastmail none for legacy reasons
234 # # there were articles claiming gmail would be changing
235 # # to p=reject, in early 2017, which didn\'t happen. I see no sources on them. It\'s
236 # # expected to cause problems
237 # # with a few old mailing lists, copying theirs for now.
239 # echo "dmarc dns, name: _dmarc value: v=DMARC1; p=none; rua=mailto:mailauth-reports@$domain"
243 # # 2017-02 spf policies:
244 # # host -t txt lists.fedoraproject.org
245 # # google ~all, hotmail ~all, yahoo: ?all, fastmail ?all, outlook ~all
246 # # i include fastmail\'s settings, per their instructions,
247 # # and follow their policy. In mail in a box, or similar instructions,
248 # # I\'ve seen recommended to not use a restrictive policy.
250 # # to check if dns has updated, you do
251 # host -a mesmtp._domainkey.$domain
254 # # setting it to iankelling.org would work the same, but this
255 # # is more flexible, I could change where mail.iankelling.org pointed.
257 # mx records, 2 records each, for * and empty domain
258 # pri 10 mail.iankelling.org
262 # from brc2, run dnsecgen then dsign, update named.local.conf, publish keys to registrar
264 # * functions & constants
267 m
() { printf "$pre %s\n" "$*"; "$@"; }
268 e
() { printf "$pre %s\n" "$*"; }
269 err
() { printf "$pre %s\n" "$*" >&2; exit 1; }
272 # This file is so if we fail in the middle and rerun, we dont lose state
273 if [[ -e /var
/local
/mail-setup-reload
]]; then
277 local tmp tmpdir dest
="$1"
278 local base
="${dest##*/}"
283 tmp
=$
(rsync
-ic $tmpdir/"$base" "$dest")
287 if [[ $dest == /etc
/systemd
/system
/* ]]; then
288 touch /var
/local
/mail-setup-reload
295 key
="$1" value
="$2" section
="$3"
296 file="/etc/radicale/config"
297 sed -ri "/ *\[$section\]/,/^ *\[[^]]+\]/{/^\s*${key}[[:space:]=]/d};/ *\[$section\]/a $key = $value" "$file"
301 # ignore services that dont exist
302 if systemctl
cat $service &>/dev
/null
; then
303 m systemctl stop
$service;
304 m systemctl disable
$service
310 m systemctl restart
$service
311 m systemctl
enable $service;
316 m systemctl
enable --now $service;
320 [[ $HOSTNAME == "$MAIL_HOST" ]]
322 e
() { printf "%s\n" "$*"; }
325 if systemctl is-active
$service >/dev
/null
; then
326 m systemctl restart
$service
332 if systemctl is-active
$service >/dev
/null
; then
333 m systemctl stop
$service
338 mxhost
=mx.iankelling.org
342 # old setup. left as comment for example
343 # mxhost=mail.messagingengine.com
345 # forward=ian@iankelling.org
347 smarthost
="$mxhost::$mxport"
348 uhome
=$
(eval echo ~
$u)
350 # Somehow on one machine, a file got written with 664 perms.
351 # just being defensive here.
354 source /a
/bin
/bash_unpublished
/source-state
355 if [[ ! $MAIL_HOST ]]; then
356 err
"\$MAIL_HOST not set"
362 kd|frodo|x2|x3|kw|sy
)
368 # * Install universal packages
370 if [[ $
(debian-codename-compat
) == bionic
]]; then
371 cat >/etc
/apt
/preferences.d
/spamassassin
<<'EOF'
372 Package: spamassassin sa-compile spamc
373 Pin: release n=focal,o=Ubuntu
378 # light version of exim does not have sasl auth support.
379 pi-nostart exim4 exim4-daemon-heavy spamassassin openvpn unbound clamav-daemon wireguard
381 # note: pyzor debian readme says you need to run some initialization command
383 pi spf-tools-perl p0f postgrey pyzor razor jq moreutils certbot
384 # bad packages that sometimes get automatically installed
385 pu openresolv resolvconf
390 if [[ $
(debian-codename
) == etiona
]]; then
391 # ip6tables stopped loading on boot. openvpn has reduced capability set,
392 # so running iptables as part of openvpn startup wont work. This should do it.
393 pi iptables-persistent
394 cat >/etc
/iptables
/rules.v6
<<'EOF'
401 m ip6tables
-S >/dev
/null
404 # our nostart pi fails to avoid enabling
407 # * user forward file
410 # afaik, these will get ignored on MAIL_HOST because they are routing to my own
411 # machine, but rm them is safer
412 rm -fv $uhome/.forward
/root
/.forward
415 # this can\'t be a symlink and has permission restrictions
416 # it might work in /etc/aliases, but this seems more proper.
417 e setting
$uhome/.forward to
$forward
418 install -m 644 {-o,-g}$u <(e
$forward) $uhome/.forward
422 # * Mail clean cronjob
424 i
/etc
/systemd
/system
/mailclean.timer
<<'EOF'
426 Description=Run mailclean daily
432 WantedBy=timers.target
435 i
/etc
/systemd
/system
/mailclean.service
<<EOF
437 Description=Delete and archive old mail files
438 After=multi-user.target
443 ExecStart=/usr/local/bin/sysd-mail-once mailclean /a/bin/distro-setup/mailclean
449 i
/etc
/default
/postgrey
<<'EOF'
450 POSTGREY_OPTS="--exim --unix=/var/run/postgrey/postgrey.sock --retry-window=4 --max-age=60"
455 m usermod
-a -G Debian-exim clamav
457 i
/etc
/systemd
/system
/clamav-daemon.service.d
/fix.conf
<<EOF
459 ExecStartPre=-/bin/mkdir /var/run/clamav
460 ExecStartPre=/bin/chown clamav /var/run/clamav
465 vpnser
=mailvpn.service
466 vpnser
=wg-quick@wgmail.service
470 bindpaths
="/etc/127.0.0.1-resolv:/run/systemd/resolve /etc/basic-nsswitch:/etc/resolved-nsswitch:norbind"
473 bindpaths
="/etc/10.173.8.1-resolv:/etc/127.0.0.1-resolv"
477 i
/etc
/systemd
/system
/wg-quick@wgmail.service.d
/override.conf
<<EOF
479 Requires=mailnn.service
480 After=network.target mailnn.service
481 JoinsNamespaceOf=mailnn.service
482 BindsTo=mailnn.service
486 # i dont think we need any of these, but it doesnt hurt to stay consistent
490 # https://selivan.github.io/2017/12/30/systemd-serice-always-restart.html
491 i
/etc
/systemd
/system
/mailvpn.service
<<EOF
493 Description=OpenVPN tunnel for mail
494 After=syslog.target network-online.target mailnn.service
495 Wants=network-online.target
496 Documentation=man:openvpn(8)
497 Documentation=https://community.openvpn.net/openvpn/wiki/Openvpn24ManPage
498 Documentation=https://community.openvpn.net/openvpn/wiki/HOWTO
499 # needed to continually restatr
500 JoinsNamespaceOf=mailnn.service
501 BindsTo=mailnn.service
502 StartLimitIntervalSec=0
506 RuntimeDirectory=openvpn-client
507 RuntimeDirectoryMode=0710
508 WorkingDirectory=/etc/openvpn/client
509 ExecStart=/usr/sbin/openvpn --suppress-timestamps --nobind --config /etc/openvpn/client/mail.conf
510 #CapabilityBoundingSet=CAP_IPC_LOCK CAP_NET_ADMIN CAP_NET_RAW CAP_SETGID CAP_SETUID CAP_SYS_CHROOT CAP_DAC_OVERRIDE
512 # DeviceAllow=/dev/null rw
513 # DeviceAllow=/dev/net/tun rw
515 # in the network namespace, we cant connect to systemd-resolved on 127.0.0.53,
517 # https://unix.stackexchange.com/questions/445782/how-to-allow-systemd-resolved-to-listen-to-an-interface-other-than-loopback
518 # there is a workaround there, but i dont think its really worth it,
519 # the mail server is fine with a static dns anyways.
520 # This thread is also interesting,
521 # https://github.com/slingamn/namespaced-openvpn/issues/7
522 # todo: the iptables rule at the bottom could be useful to prevent
523 # dns from leaking in my network namespaced vpn.
524 # I also like the idea of patching systemd-resolved so it
525 # will listen on other interfaces, but its not worth my time.
528 # time to sleep before restarting a service
532 WantedBy=multi-user.target
535 i
/etc
/systemd
/system
/mailnnroute.service
<<'EOF'
537 Description=Network routing for mailnn
538 After=syslog.target network-online.target mailnn.service
539 Wants=network-online.target
540 JoinsNamespaceOf=mailnn.service
541 BindsTo=mailnn.service
542 StartLimitIntervalSec=0
548 ExecStart=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns -n 10.173.8 start mail
549 ExecStop=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns stop mail
555 WantedBy=multi-user.target
559 i
/etc
/systemd
/system
/mailnn.service
<<'EOF'
561 Description=Network Namespace for mail vpn service that will live forever and cant fail
562 After=syslog.target network-online.target
563 Wants=network-online.target
568 ExecStart=/bin/sleep infinity
571 WantedBy=multi-user.target
577 rm -fv /etc
/systemd
/system
/openvpn-client-mail@.service
579 # We use a local unbound because systemd-resolved wont accept our
580 # request, it will only listen to 127.0.0.53 in the main network
581 # namespace, and rejected feature requests to change that (although I
582 # could change the code and recompile), but anyways, that could answer
583 # with things specific to the lan that aren't applicable in this
584 # namespace, and since unbound is a recursive resolver, it means we just
585 # use our own ip against dnsbl rate limits.
587 # If we ever notice this change, chattr +i on it
588 # trust-ad is used in t10+, glibc 2.31
590 i
/etc
/127.0.0.1-resolv/stub-resolv.conf
<<'EOF'
592 options edns0 trust-ad
595 i
/etc
/127.0.0.53-resolv/stub-resolv.conf
<<'EOF'
596 nameserver 127.0.0.53
597 options edns0 trust-ad
601 i
/etc
/10.173.8.1-resolv/stub-resolv.conf
<<'EOF'
602 nameserver 10.173.8.1
603 options edns0 trust-ad
606 # this is just a bug fix for trisquel.
607 f
=/etc
/apparmor.d
/usr.sbin.unbound
608 line
="/usr/sbin/unbound flags=(attach_disconnected) {"
609 if ! grep -qFx "$line" $f; then
610 badline
="/usr/sbin/unbound {"
611 if ! grep -qFx "$badline" $f; then
612 err expected line
in $f not found
614 sed -i "s,^$badline$,$line," $f
615 if systemctl is-active apparmor
&>/dev
/null
; then
616 m systemctl reload apparmor
620 # note: anything added to nn_progs needs corresponding rm
621 # down below in the host switch
624 # Note dovecots lmtp doesnt need to be in the same nn to accept delivery.
625 # Its in the nn so remote clients can connect to it.
626 nn_progs
+=(spamassassin dovecot
)
631 i
/etc
/systemd
/system
/unbound.service.d
/nn.conf
<<EOF
634 JoinsNamespaceOf=mailnn.service
635 BindsTo=mailnn.service
636 StartLimitIntervalSec=0
640 # note the nsswitch bind is actually not needed for bk, but
641 # its the same file so it does no harm.
648 # sooo, there are a few ways to get traffic from the mail network
649 # namespace to go over the wghole.
651 #1: unify the mail vpn and wghole
652 # into 1 network. this seems simple and logical, so I'm doing it.
653 # One general downside is tying things together, if I need to mess
654 # with one thing, it breaks the other. Oh well for now.
656 # 2. We can route 10.5.3.0/24 out of the mail nn and nat it into wghole.
658 # 3. We can setup the routing to happen on li, which seemed like I
659 # just needed to add 10.8.0.4/24 to AllowedIPs in at least the
660 # wghole clients, but I think that is kind of hacky and breaks ipv4
661 # routing within the mailvpn, it happened to work just because exim
662 # prefers ipv6 and that was also available in the mailvpn.
664 # 4. Put the hole interface into the mail network namespace. This
665 # doesn't work if the mail vpn is wg. For openvpn, it bypasses the
666 # vpn routing and establishes a direct connection. I only use the
667 # hole vpn for randomish things, it should be fine to join the mail
668 # nn for that. There should be some way to fix the routing issue
669 # by doing manual routing, but that doesn't seem like a good use of time.
671 # https://www.wireguard.com/netns/#
673 # for wireguard debugging
674 # echo module wireguard +p > /sys/kernel/debug/dynamic_debug/control
679 for unit
in ${nn_progs[@]}; do
680 i
/etc
/systemd
/system
/$unit.service.d
/nn.conf
<<EOF
682 # commented for old openvpn
684 After=network.target mailnn.service $vpnser
685 JoinsNamespaceOf=mailnn.service
686 BindsTo=mailnn.service
687 StartLimitIntervalSec=0
691 # note the nsswitch bind is actually not needed for bk, but
692 # its the same file so it does no harm.
701 for unit
in exim4 spamassassin dovecot unbound
; do
702 f
=/etc
/systemd
/system
/$unit.service.d
/nn.conf
711 # * spamassassin config
712 i
/etc
/sysctl.d
/80-iank-mail.conf
<<'EOF'
714 net.netfilter.nf_conntrack_tcp_timeout_close_wait = 120
720 i
/etc
/spamassassin
/mylocal.cf
<<'EOF'
721 # this is mylocal.cf because the normal local.cf has a bunch of upstream stuff i dont want to mess with
723 # /usr/share/doc/exim4-base/README.Debian.gz:
724 # SpamAssassin's default report should not be used in a add_header
725 # statement since it contains empty lines. (This triggers e.g. Amavis'
726 # warning "BAD HEADER SECTION, Improper folded header field made up
727 # entirely of whitespace".) This is a safe, terse alternative:
728 clear_report_template
729 report (_SCORE_ / _REQD_ requ) _TESTSSCORES(,)_ autolearn=_AUTOLEARN
730 uridnsbl_skip_domain iankelling.org
731 uridnsbl_skip_domain amnimal.ninja
732 uridnsbl_skip_domain expertpathologyreview.com
733 uridnsbl_skip_domain zroe.org
736 # 2020-10-19 remove old file. remove this when all hosts updated
737 rm -fv /etc
/systemd
/system
/spamddnsfix.
{timer
,service
}
739 i
/etc
/default
/spamassassin
<<'EOF'
740 # defaults plus debugging flags for an issue im having
741 OPTIONS="--create-prefs --max-children 5 --helper-home-dir"
742 PIDFILE="/var/run/spamd.pid"
744 NICE="--nicelevel 15"
747 ##### end spamassassin config
751 if [[ -e /p
/c
/filesystem
]]; then
752 # note, man openvpn implies we could just call mail-route on vpn startup/shutdown with
753 # systemd, buuut it can remake the tun device unexpectedly, i got this in the log
754 # after my internet was down for a bit:
755 # NOTE: Pulled options changed on restart, will need to close and reopen TUN/TAP device.
756 m
/a
/exe
/vpn-mk-client-cert
-b mailclient
-n mail li.iankelling.org
760 if [[ ! -e /etc
/openvpn
/client
/mail.conf
]]; then
761 echo "$0: error: first, on a system with /p/c/filesystem, run mail-setup, or the vpn-mk-client-cert line above this err" 2>&2
767 m rsync
-aiSAX --chown=root
:root
--chmod=g-s
/a
/bin
/ds
/mail-cert-cron
/usr
/local
/bin
769 i
/etc
/systemd
/system
/mailcert.service
<<'EOF'
771 Description=Mail cert rsync
772 After=multi-user.target
776 ExecStart=/usr/local/bin/sysd-mail-once mailcert /usr/local/bin/mail-cert-cron
778 i
/etc
/systemd
/system
/mailcert.timer
<<'EOF'
780 Description=Run mail-cert once a day
786 WantedBy=timers.target
790 wghost
=${HOSTNAME}wg.b8.nz
791 if $bhost_t && [[ ! -e /etc
/exim
4/certs
/$wghost/privkey.pem
]]; then
792 certbot
-n --manual-public-ip-logging-ok --eff-email --agree-tos -m letsencrypt@iankelling.org \
793 certonly
--manual --preferred-challenges=dns \
794 --manual-auth-hook /a
/bin
/ds
/le-dns-challenge \
795 --manual-cleanup-hook /a
/bin
/ds
/le-dns-challenge-cleanup \
796 --deploy-hook /a
/bin
/ds
/le-exim-deploy
-d $wghost
799 # * common exim4 config
802 # Make all system users be aliases. preventative
803 # measure for things like cron mail for user without alias
804 awk 'BEGIN { FS = ":" } ; $6 !~ /^\/home/ { print $1 }' /etc
/passwd|
while read -r user
; do
805 if [[ ! $user ]]; then
808 if ! grep -q "^$user:" /etc
/aliases
; then
809 echo "$user: root" |m
tee -a /etc
/aliases
813 if ! grep -q "^ncsoft:" /etc
/aliases
; then
814 echo "ncsoft: graceq2323@gmail.com" |m
tee -a /etc
/aliases
819 m gpasswd
-a iank adm
#needed for reading logs
821 ### make local bounces go to normal maildir
822 # local mail that bounces goes to /Maildir or /root/Maildir
823 dirs=(/m
/md
/bounces
/{cur
,tmp
,new
})
824 m mkdir
-p ${dirs[@]}
825 m chown iank
:iank
/m
/m
/md
826 m
ln -sfT /m
/md
/m
/iank
828 m chown
-R $u:Debian-exim
/m
/md
/bounces
829 m
chmod 775 ${dirs[@]}
830 m usermod
-a -G Debian-exim
$u
831 for d
in /Maildir
/root
/Maildir
; do
832 if [[ ! -L $d ]]; then
835 m
ln -sf -T /m
/md
/bounces
$d
838 # dkim, client passwd file
839 files
=(/p
/c
/machine_specific
/$HOSTNAME/filesystem
/etc
/exim
4/*)
840 f
=/p
/c
/filesystem
/etc
/exim
4/passwd.client
844 if (( ${#files[@]} )); then
845 m rsync
-ahhi --chown=root
:Debian-exim
--chmod=0640 \
846 ${files[@]} /etc
/exim4
849 # by default, only 10 days of logs are kept. increase that.
850 m
sed -ri 's/^(\s*rotate\s).*/\11000/' /etc
/logrotate.d
/exim4-base
853 ## https://blog.dhampir.no/content/make-exim4-on-debian-respect-forward-and-etcaliases-when-using-a-smarthost
854 # i only need .forwards, so just doing that one.
855 cd /etc
/exim
4/conf.d
/router
856 b
=userforward_higher_priority
857 # replace the router name so it is unique
858 sed -r s
/^
\\S
+:/$b:/ 600_exim4-config_userforward
>175_
$b
860 # todo, consider 'separate' in etc/exim4.conf, could it help on busy systems?
862 # alerts is basically the postmaster address
863 m
sed -i --follow-symlinks -f - /etc
/aliases
<<EOF
864 \$a root: alerts@iankelling.org
868 cat >/etc
/exim
4/conf.d
/rewrite
/34_iank_rewriting
<<'EOF'
869 ncsoft@zroe.org graceq2323@gmail.com hE
873 rm -fv /etc
/exim
4/conf.d
/retry
/37_retry
875 cat >/etc
/exim
4/conf.d
/retry
/17_retry
<<'EOF'
876 # Retry fast for my own domains
877 iankelling.org * F,1d,10m;F,14d,1h
878 amnimal.ninja * F,1d,10m;F,14d,1h
879 expertpathologyreview.com * F,1d,10m;F,14d,1h
880 je.b8.nz * F,1d,10m;F,14d,1h
881 zroe.org * F,1d,10m;F,14d,1h
882 eximbackup.b8.nz * F,1d,4m;F,14d,1h
886 rm -vf /etc
/exim
4/conf.d
/main
/000_localmacros
# old filename
887 cat >/etc
/exim
4/conf.d
/main
/000_local
<<EOF
888 MAIN_TLS_ENABLE = true
890 # require tls connections for all smarthosts
891 REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS = *
893 # debian exim config added this in 2016 or so?
894 # it's part of the smtp spec, to limit lines to 998 chars
895 # but a fair amount of legit mail does not adhere to it. I don't think
896 # this should be default, like it says in
897 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=828801
898 # todo: the bug for introducing this was about headers, but
899 # the fix maybe is for all lines? one says gmail rejects, the
900 # other says gmail does not reject. figure out and open a new bug.
901 IGNORE_SMTP_LINE_LENGTH_LIMIT = true
904 MAIN_LOG_SELECTOR = +all
906 # Based on spec, seems like a good idea to be nice.
907 smtp_return_error_details = true
909 # normally empty, I set this so I can set the envelope address
910 # when doing mail redelivery to invoke filters. Also allows
911 # me exiqgrep and stuff.
912 MAIN_TRUSTED_GROUPS = $u
914 # default is 10. when exim has been down for a bit, fsf mailserver
915 # will do a big send in one connection, then exim decides to put
916 # the messages in the queue instead of delivering them, to avoid
917 # spawning too many delivery processes. This is the same as the
918 # fsfs value. And the corresponding one for how many messages
919 # to send out in 1 connection remote_max_parallel = 256
920 smtp_accept_queue_per_connection = 500
927 # https://debian-administration.org/article/718/DKIM-signing_outgoing_mail_with_exim4
928 # and its best for this to align https://tools.ietf.org/html/rfc7489#page-8
929 # There could be some circumstance when the
930 # from: isnt our domain, but the envelope sender is
931 # and so still want to sign, but I cant think of any case.
932 DKIM_DOMAIN = \${lc:\${domain:\$rh_from:}}
933 # The file is based on the outgoing domain-name in the from-header.
935 DKIM_PRIVATE_KEY = \${if exists{/etc/exim4/\${dkim_domain}-private.pem} {/etc/exim4/\${dkim_domain}-private.pem}}
937 # most of the ones that gmail seems to use.
938 # Exim has horrible default of signing unincluded
939 # list- headers since they got mentioned in an
940 # rfc, but this messes up mailing lists, like gnu/debian which want to
941 # keep your dkim signature intact but add list- headers.
942 DKIM_SIGN_HEADERS = mime-version:in-reply-to:references:from:date:subject:to
944 domainlist local_hostnames = ! je.b8.nz : ! bk.b8.nz : *.b8.nz : b8.nz
946 hostlist iank_trusted = <; \\
950 72.14.176.105 ; 2600:3c00::f03c:91ff:fe6d:baf8 ; \\
951 # li_vpn_net li_vpn_net_ip6s
952 10.8.0.0/24; 2600:3c00:e000:280::/64 ; 2600:3c00:e002:3800::/56 ; \\
954 85.119.83.50 ; 2001:ba8:1f1:f0c9::2 ; \\
956 85.119.82.128 ; 2001:ba8:1f1:f09d::2 ; \\
957 # fsf_mit_net fsf_mit_net_ip6 fsf_net fsf_net_ip6 fsf_office_net
958 18.4.89.0/24 ; 2603:3005:71a:2e00::/64 ; 209.51.188.0/24 ; 2001:470:142::/48 ; 74.94.156.208/28
961 rm -fv /etc
/exim
4/rcpt_local_acl
# old path
963 i
/etc
/exim
4/conf.d
/local_deny_exceptions_acl
<<'EOF'
964 # This acl already exists in rcpt, this just makes it more widespread.
965 # See the comment there for its rationale. The reason it needs to be
966 # more widespread is that I've turned on sender verification, but cron
967 # emails can fail sender verification since I may be in a network that
968 # doesn't have my local dns.
972 # i setup a local programs smtp to mail.iankelling.org, this
973 # skips sender verification for it.
978 rm -fv /etc
/exim
4/data_local_acl
# old path
979 i
/etc
/exim
4/conf.d
/data_local_acl
<<'EOF'
980 # Except for the "condition =", this was
981 # a comment in the check_data acl. The comment about this not
982 # being suitable has been changed in newer exim versions. The only thing
983 # related I found was to
984 # add the condition =, cuz spamassassin has problems with big
985 # messages and spammers don't bother with big messages,
986 # but I've increased the size from 10k
987 # suggested in official docs, and 100k in the wiki example because
988 # those docs are rather old and I see a 110k spam message
989 # pretty quickly looking through my spam folder.
992 !hosts = +iank_trusted
993 remove_header = X-Spam_score: X-Spam_score_int : X-Spam_bar : X-Spam_report
996 !hosts = +iank_trusted
997 condition = ${if < {$message_size}{5000K}}
998 spam = Debian-exim:true
999 add_header = X-Spam_score_int: $spam_score_int
1000 add_header = X-Spam_score: $spam_score
1001 add_header = X-Spam_bar: $spam_bar
1002 add_header = X-Spam_report: $spam_report
1003 add_header = X-Spam_action: $spam_action
1006 condition = ${if def:malware_name}
1007 remove_header = Subject:
1008 add_header = Subject: [Clamav warning: $malware_name] $h_subject
1009 log_message = heuristic malware warning: $malware_name
1012 # spf = pass:fail:softfail:none:neutral:permerror:temperror
1013 # dmarc_status = reject:quarantine
1014 # add_header = Reply-to: dmarctest@iankelling.org
1018 i
/etc
/exim
4/conf.d
/router
/900_exim4-config_local_user
<<EOF
1019 ### router/900_exim4-config_local_user
1020 #################################
1022 # This router matches local user mailboxes. If the router fails, the error
1023 # message is "Unknown user".
1025 debug_print = "R: local_user for \$local_part@\$domain"
1027 domains = +local_domains
1028 # ian: default file except where mentioned.
1029 # ian: commented this. I get all local parts. for bk, an rcpt
1030 # check handles checking with dovecot, and the only router
1031 # after this is root.
1032 # local_parts = ! root
1033 transport = LOCAL_DELIVERY
1034 cannot_route_message = Unknown user
1035 # ian: added for + addressing.
1036 local_part_suffix = +*
1037 local_part_suffix_optional
1039 i
/etc
/exim
4/conf.d
/transport
/30_exim4-config_dovecot_lmtp
<<'EOF'
1042 socket = /var/run/dovecot/lmtp
1043 #maximum number of deliveries per batch, default 1
1048 i
/etc
/exim
4/conf.d
/transport
/30_remote_smtp_vpn
<<'EOF'
1049 # same as debians 30_exim4-config_remote_smtp, but
1050 # with interface added at the end.
1053 debug_print = "T: remote_smtp_vpn for $local_part@$domain"
1055 .ifndef IGNORE_SMTP_LINE_LENGTH_LIMIT
1056 message_size_limit = ${if > {$max_received_linelength}{998} {1}{0}}
1058 .ifdef REMOTE_SMTP_HOSTS_AVOID_TLS
1059 hosts_avoid_tls = REMOTE_SMTP_HOSTS_AVOID_TLS
1061 .ifdef REMOTE_SMTP_HEADERS_REWRITE
1062 headers_rewrite = REMOTE_SMTP_HEADERS_REWRITE
1064 .ifdef REMOTE_SMTP_RETURN_PATH
1065 return_path = REMOTE_SMTP_RETURN_PATH
1067 .ifdef REMOTE_SMTP_HELO_DATA
1068 helo_data=REMOTE_SMTP_HELO_DATA
1071 dkim_domain = DKIM_DOMAIN
1073 .ifdef DKIM_SELECTOR
1074 dkim_selector = DKIM_SELECTOR
1076 .ifdef DKIM_PRIVATE_KEY
1077 dkim_private_key = DKIM_PRIVATE_KEY
1080 dkim_canon = DKIM_CANON
1083 dkim_strict = DKIM_STRICT
1085 .ifdef DKIM_SIGN_HEADERS
1086 dkim_sign_headers = DKIM_SIGN_HEADERS
1088 .ifdef TLS_DH_MIN_BITS
1089 tls_dh_min_bits = TLS_DH_MIN_BITS
1091 .ifdef REMOTE_SMTP_TLS_CERTIFICATE
1092 tls_certificate = REMOTE_SMTP_TLS_CERTIFICATE
1094 .ifdef REMOTE_SMTP_PRIVATEKEY
1095 tls_privatekey = REMOTE_SMTP_PRIVATEKEY
1097 .ifdef REMOTE_SMTP_HOSTS_REQUIRE_TLS
1098 hosts_require_tls = REMOTE_SMTP_HOSTS_REQUIRE_TLS
1100 .ifdef REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
1101 headers_remove = REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
1103 interface = <; 10.8.0.4 ; 2600:3c00:e002:3800::4
1106 i
/etc
/exim
4/conf.d
/transport
/30_smarthost_dkim
<<'EOF'
1107 # ian: this is remote_smtp_smarthost plus the dkim parts from remote_smtp
1110 debug_print = "T: remote_smtp_smarthost for $local_part@$domain"
1113 .ifndef IGNORE_SMTP_LINE_LENGTH_LIMIT
1114 message_size_limit = ${if > {$max_received_linelength}{998} {1}{0}}
1116 hosts_try_auth = <; ${if exists{CONFDIR/passwd.client} \
1118 ${lookup{$host}nwildlsearch{CONFDIR/passwd.client}{$host_address}}\
1122 .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
1123 hosts_avoid_tls = REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
1125 .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS
1126 hosts_require_tls = REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS
1128 .ifdef REMOTE_SMTP_SMARTHOST_TLS_VERIFY_CERTIFICATES
1129 tls_verify_certificates = REMOTE_SMTP_SMARTHOST_TLS_VERIFY_CERTIFICATES
1131 .ifdef REMOTE_SMTP_SMARTHOST_TLS_VERIFY_HOSTS
1132 tls_verify_hosts = REMOTE_SMTP_SMARTHOST_TLS_VERIFY_HOST
1134 .ifdef REMOTE_SMTP_HEADERS_REWRITE
1135 headers_rewrite = REMOTE_SMTP_HEADERS_REWRITE
1137 .ifdef REMOTE_SMTP_RETURN_PATH
1138 return_path = REMOTE_SMTP_RETURN_PATH
1140 .ifdef REMOTE_SMTP_HELO_DATA
1141 helo_data=REMOTE_SMTP_HELO_DATA
1143 .ifdef TLS_DH_MIN_BITS
1144 tls_dh_min_bits = TLS_DH_MIN_BITS
1146 .ifdef REMOTE_SMTP_SMARTHOST_TLS_CERTIFICATE
1147 tls_certificate = REMOTE_SMTP_SMARTHOST_TLS_CERTIFICATE
1149 .ifdef REMOTE_SMTP_SMARTHOST_PRIVATEKEY
1150 tls_privatekey = REMOTE_SMTP_SMARTHOST_PRIVATEKEY
1152 .ifdef REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
1153 headers_remove = REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
1156 dkim_domain = DKIM_DOMAIN
1158 .ifdef DKIM_SELECTOR
1159 dkim_selector = DKIM_SELECTOR
1161 .ifdef DKIM_PRIVATE_KEY
1162 dkim_private_key = DKIM_PRIVATE_KEY
1165 dkim_canon = DKIM_CANON
1168 dkim_strict = DKIM_STRICT
1170 .ifdef DKIM_SIGN_HEADERS
1171 dkim_sign_headers = DKIM_SIGN_HEADERS
1176 cat >/etc
/exim
4/update-exim4.conf.conf
<<'EOF'
1177 # default stuff, i havent checked if its needed
1178 dc_minimaldns='false'
1181 dc_use_split_config='true'
1182 dc_mailname_in_oh='true'
1188 if ! mountpoint
/o
; then
1189 echo "error /o is not a mountpoint" >&2
1193 # davx/davdroid setup instructions at the bottom
1196 # http://radicale.org/user_documentation/
1197 # https://davdroid.bitfire.at/configuration/
1199 # note on debugging: if radicale can't bind to the address,
1200 # in the log it just says "Starting Radicale". If you run
1201 # it in the foreground, it will give more info. Background
1202 # plus debug does not help.
1203 # sudo -u radicale radicale -D -f
1205 # created password file with:
1206 # htpasswd -c /p/c/machine_specific/li/filesystem/etc/caldav-htpasswd
1207 # chmod 640 /p/c/machine_specific/li/filesystem/etc/caldav-htpasswd
1208 # # setup chgrp www-data in ./conflink
1212 i
/etc
/systemd
/system
/radicale.service.d
/override.conf
<<EOF
1214 # this unit is configured to start and stop whenever
1217 After=network.target network-online.target mailnn.service $vpnser
1220 Wants=network-online.target
1221 JoinsNamespaceOf=mailnn.service
1222 StartLimitIntervalSec=0
1226 BindPaths=$bindpaths
1228 # time to sleep before restarting a service
1237 # use persistent uid/gid
1238 IFS
=:; read -r _ _ uid _
< <(getent passwd radicale
); unset IFS
1239 IFS
=:; read -r _ _ gid _
< <(getent group radicale
); unset IFS
1240 if [[ $uid != 609 ]]; then
1241 m systemctl stop radicale ||
:
1242 m usermod
-u 609 radicale
1243 m groupmod
-g 609 radicale
1244 m usermod
-g 609 radicale
1246 m
find /o
/radicale
-xdev -exec chown
-h 609 {} +
1247 m
find /o
/radicale
-xdev -exec chgrp
-h 609 {} +
1250 # I moved /var/lib/radicale after it's initialization.
1251 # I did a sudo -u radicale git init in the collections subfolder
1252 # after it gets created, per the git docs.
1253 m
/a
/exe
/lnf
-T /o
/radicale
/var
/lib
/radicale
1255 # from https://www.williamjbowman.com/blog/2015/07/24/setting-up-webdav-caldav-and-carddav-servers/
1257 # more config is for li in distro-end
1259 # coment in this file says this is needed for it to run on startup
1260 sed -ri 's/^\s*#+\s*(ENABLE_RADICALE\s*=\s*yes\s*)/\1/' /etc
/default
/radicale
1262 # comments say default is 0.0.0.0:5232
1263 m setini hosts
10.8.0.4:5232 server
1264 # https://radicale.org/2.1.html
1265 m setini
type http_x_remote_user auth
1268 # disable power management feature, set to 240 min sync interval,
1269 # so it shouldn't be bad.
1271 # davdroid from f-druid.
1272 # login with url and user name
1273 # url https://cal.iankelling.org/ian
1275 # pass, see password manager for radicale
1277 # add account dialog:
1279 # set account name as ian@iankelling.org, per help text below the
1282 # switch to groups are per-contact categories,
1283 # per https://davdroid.bitfire.at/configuration/radicale/
1286 # After setting up account, I added one address book, named
1287 # ianaddr. calender was already created, named ian. checked boxes under
1290 # To restore from old phone to new phone, I wiped all data out, then copied over the newly created files. I think
1292 # ignorable background info:
1294 # opentasks uses the calendar file.
1296 # The address book I created got a uuid as a name for the file. Note
1297 # the .props file says if it's a calendar or addressbook.
1299 # When debugging, tailed /var/log/radicale/radicale.log and apache log,
1300 # both show the requests happening. Without creating the address book,
1301 # after creating a contact, a sync would delete it.
1303 # Address books correspond to .props files in the radicale dir.
1305 # Some background is here,
1306 # https://davdroid.bitfire.at/faq/entry/cant-manage-groups-on-device/
1307 # which shows separate vcard option is from rfc 6350, the other is 2426,
1308 # radicale page says it implements the former not the latter,
1309 # which conflicts with the documentation of which to select, but whatever.
1310 # http://radicale.org/technical_choices/
1311 # https://davdroid.bitfire.at/faq/entry/cant-manage-groups-on-device/
1313 # Note, url above says only cayanogenmod 13+ and omnirom can manage groups.
1315 # Note, radicale had built-in git support to track changes, but they
1316 # removed it in 2.0.
1322 # ** $MAIL_HOST|bk|je)
1325 # based on a little google and package search, just the dovecot
1326 # packages we need instead of dovecot-common.
1328 # dovecot-lmtpd is for exim to deliver to dovecot instead of maildir
1329 # directly. The reason to do this is to use dovecot\'s sieve, which
1330 # can generally do more than exims filters (a few things less) and
1331 # sieve has the benefit of being supported in postfix and
1332 # proprietary/weird environments, so there is more examples on the
1334 pi dovecot-core dovecot-imapd dovecot-sieve dovecot-lmtpd dovecot-sqlite sqlite3
1336 for f
in /p
/c
{/machine_specific
/$HOSTNAME,}/filesystem
/etc
/dovecot
/users
; do
1337 if [[ -e $f ]]; then
1338 m rsync
-ahhi --chown=root
:dovecot
--chmod=0640 $f /etc
/dovecot
/
1342 for f
in /p
/c
/subdir_files
/sieve
/*sieve
/a
/c
/subdir_files
/sieve
/*sieve
; do
1343 m sudo
-u $u /a
/exe
/lnf
-T $f $uhome/sieve
/${f##*/}
1346 # https://wiki.dovecot.org/SSL/DovecotConfiguration
1347 i
/etc
/dovecot
/dhparam
<<'EOF'
1348 -----BEGIN DH PARAMETERS-----
1349 MIIBCAKCAQEAoleil6SBxGqQKk7j0y2vV3Oklv6XupZKn7PkPv485QuFeFagifeS
1350 A+Jz6Wquqk5zhGyCu63Hp4wzGs4TyQqoLjkaWL6Ra/Bw3g3ofPEzMGEsV1Qdqde4
1351 jorwiwtr2i9E6TXQp0noT/7VFeHulIkayTeW8JulINdMHs+oLylv16McGCIrxbkM
1352 8D1PuO0TP/CNDs2QbRvJ1RjY3CeGpxMhrSHVgBCUMwnA2cvz3bYjI7UMYMMDPNrE
1353 PLrwsYzXGGCdJsO2vsmmqqgLsZiapYJlUNjfiyWLt7E2H6WzkNB3VIhIPfLqFDPK
1354 xioE3sYKdjOt+p6mlg3l8+OLtODEFPHDqwIBAg==
1355 -----END DH PARAMETERS-----
1358 if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
1360 ssl_cert = </etc/exim4/fullchain.pem
1361 ssl_key = </etc/exim4/privkey.pem
1365 ssl_cert = </etc/exim4/exim.crt
1366 ssl_key = </etc/exim4/exim.key
1370 # https://ssl-config.mozilla.org
1372 # this is the same as the certbot list, in my cert cronjob, I check if that has changed upstream.
1373 ssl_cipher_list = ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
1374 ssl_protocols = TLSv1.2
1375 ssl_prefer_server_ciphers = no
1376 ssl_dh_parameters_length = 2048
1379 #per https://wiki2.dovecot.org/Pigeonhole/Sieve/Configuration
1380 # default is just \$mail_plugins
1381 mail_plugins = \$mail_plugins sieve
1384 if dpkg
--compare-versions $
(dpkg-query
-f='${Version}\n' --show dovecot-core
) ge
1:2.3; then
1386 ssl_dh = </etc/dovecot/dhparam
1389 } >/etc
/dovecot
/local.conf
1395 # If we changed 90-sieve.conf and removed the active part of the
1396 # sieve option, we wouldn\'t need this, but I\'d rather not modify a
1397 # default config if not needed. This won\'t work as a symlink in /a/c
1399 m sudo
-u $u /a
/exe
/lnf
-T sieve
/main.sieve
$uhome/.dovecot.sieve
1401 if [[ ! -e $uhome/sieve
/personal.sieve
]]; then
1402 m
touch $uhome/sieve
/personal
{,end
}{,test}.sieve
1405 rm -fv /etc
/dovecot
/conf.d
/20-lmtp.conf
# file from prev version
1406 cat >>/etc
/dovecot
/local.conf
<<EOF
1407 # simple password file based login
1408 !include conf.d/auth-passwdfile.conf.ext
1410 # ian: %u is used for alerts user vs iank
1411 mail_location = maildir:/m/%u:LAYOUT=fs:INBOX=/m/%u/INBOX
1416 # For a normal setup with exim, we need something like this, which
1417 # removes the domain part
1418 # auth_username_format = %Ln
1420 # or else # Exim says something like
1421 # "LMTP error after RCPT ... 550 ... User doesn't exist someuser@somedomain"
1422 # Dovecot verbose log says something like
1423 # "auth-worker(9048): passwd(someuser@somedomain): unknown user"
1424 # reference: http://wiki.dovecot.org/LMTP/Exim
1426 # However, I use this to direct all mail to the same inbox.
1427 # A normal way to do this, which I did at first is to have
1428 # a router in exim almost at the end, eg 950,
1430 # debug_print = "R: catchall for \$local_part@\$domain"
1432 # domains = +local_domains
1435 # http://blog.alteholz.eu/2015/04/exim4-and-catchall-email-address/
1436 # with superflous options removed.
1437 # However, this causes the envelope to be rewritten,
1438 # which makes filtering into mailboxes a little less robust or more complicated,
1439 # so I've done it this way instead. it also requires
1440 # modifying the local router in exim.
1441 auth_username_format = $u
1447 chown
-R mail.
mail /m
/md
1449 f
=/etc
/dovecot
/conf.d
/10-auth.conf
1450 if [[ -e $f ]]; then
1451 mv $f $f-iank-disabled
1454 cat >>/etc
/dovecot
/local.conf
<<EOF
1455 !include /etc/dovecot/local.conf.ext
1457 # for debugging info, uncomment these.
1458 # logs go to syslog and to /var/log/mail.log
1464 # This downcases the localpart. default is case sensitive.
1465 # case sensitive local part will miss out on valid email when some person or system
1466 # mistakenly capitalizes things.
1467 auth_username_format = %Lu
1470 # make 147 only listen on localhost, plan to use for nextcloud.
1471 # copied from mailinabox
1472 service imap-login {
1473 inet_listener imap {
1477 # https://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_dovecot_authenticator.html
1479 unix_listener auth-client {
1487 sieve_before = /etc/dovecot/sieve-spam.sieve
1489 sieve = /m/sieve/%d/%n.sieve
1490 sieve_dir = /m/sieve/%d/%n
1494 # all taken from mailinabox.
1495 mail_location = maildir:/m/md/%d/%n
1497 mail_privileged_group = mail
1498 # By default Dovecot allows users to log in only with UID numbers 500 and above. mail is 8
1501 # todo: test these changes in the universal config
1502 # mailboxes taken from mailinabox but removed
1503 # settings duplicate to defaults
1522 special_use = \Archive
1526 auth_mechanisms = plain login
1529 i
/etc
/dovecot
/sieve-spam.sieve
<<'EOF'
1530 require ["regex", "fileinto", "imap4flags"];
1532 if allof (header :regex "X-Spam-Status" "^Yes") {
1538 i
/etc
/dovecot
/local.conf.ext
<<'EOF'
1541 args = /etc/dovecot/dovecot-sql.conf.ext
1545 args = /etc/dovecot/dovecot-sql.conf.ext
1550 i
/etc
/dovecot
/dovecot-sql.conf.ext
<<'EOF'
1553 connect = /m/rc/users.sqlite
1554 default_pass_scheme = SHA512-CRYPT
1555 password_query = SELECT email as user, password FROM users WHERE email='%u';
1556 user_query = SELECT email AS user, "mail" as uid, "mail" as gid, "/m/md/%d/%n" as home FROM users WHERE email='%u';
1557 iterate_query = SELECT email AS user FROM users;
1559 m
chmod 0600 /etc
/dovecot
/dovecot-sql.conf.ext
# per Dovecot instructions
1561 # db needs to be in a www-data writable directory
1562 db
=/m
/rc
/users.sqlite
1563 if [[ ! -s $db ]]; then
1565 m sqlite3
$db <<'EOF'
1566 CREATE TABLE users (
1567 id INTEGER PRIMARY KEY AUTOINCREMENT,
1568 email TEXT NOT NULL UNIQUE,
1569 password TEXT NOT NULL,
1571 privileges TEXT NOT NULL DEFAULT '');
1574 # example of adding a user:
1575 # hash: doveadm pw -s SHA512-CRYPT -p passhere
1576 # sqlite3 /m/rc/users.sqlite <<'EOF'
1577 #insert into users (email, password) values ('testignore@bk.b8.nz', 'hash');
1579 # update users set password = 'hash' where email = 'testignore@bk.b8.nz';
1581 # this should be at the end since it requires a valid dovecot config
1582 m sievec
/etc
/dovecot
/sieve-spam.sieve
1586 # roundcube uses this
1588 chown
mail.
mail /m
/sieve
1589 m pi dovecot-managesieved
1593 # * thunderbird autoconfig setup
1595 bkdomains
=(expertpathologyreview.com amnimal.ninja
)
1596 if [[ $HOSTNAME == bk
]]; then
1597 for domain
in ${bkdomains[@]}; do
1598 m
/a
/exe
/web-conf apache2 autoconfig.
$domain
1599 dir
=/var
/www
/autoconfig.
$domain/html
/mail
1601 # taken from mailinabox
1602 i
$dir/config-v1.1.xml
<<EOF
1603 <?xml version="1.0" encoding="UTF-8"?>
1604 <clientConfig version="1.1">
1605 <emailProvider id="$domain">
1606 <domain>$domain</domain>
1608 <displayName>$domain Mail</displayName>
1609 <displayShortName>$domain</displayShortName>
1611 <incomingServer type="imap">
1612 <hostname>mail2.iankelling.org</hostname>
1614 <socketType>SSL</socketType>
1615 <username>%EMAILADDRESS%</username>
1616 <authentication>password-cleartext</authentication>
1619 <outgoingServer type="smtp">
1620 <hostname>mail2.iankelling.org</hostname>
1622 <socketType>STARTTLS</socketType>
1623 <username>%EMAILADDRESS%</username>
1624 <authentication>password-cleartext</authentication>
1625 <addThisServer>true</addThisServer>
1626 <useGlobalPreferredServer>false</useGlobalPreferredServer>
1629 <documentation url="https://$domain/">
1630 <descr lang="en">$domain website.</descr>
1635 <loginPage url="https://$domain/roundcube" />
1636 <loginPageInfo url="https://$domain/roundcube" >
1637 <username>%EMAILADDRESS%</username>
1638 <usernameField id="rcmloginuser" name="_user" />
1639 <passwordField id="rcmloginpwd" name="_pass" />
1640 <loginButton id="rcmloginsubmit" />
1643 <clientConfigUpdate url="https://autoconfig.$domain/mail/config-v1.1.xml" />
1651 if [[ $HOSTNAME == bk
]]; then
1653 # zip according to /installer
1654 # which requires adding a line to /usr/local/lib/roundcubemail/config/config.inc.php
1655 # $config['enable_installer'] = true;
1656 pi roundcube roundcube-sqlite3 php-zip apache2 php-fpm
1658 ### begin composer install
1659 # https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md
1661 # sum="$(wget -q -O - https://composer.github.io/installer.sig)"
1662 # m php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
1663 # if [[ $sum != $(php -r "echo hash_file('sha384', 'composer-setup.php');") ]]; then
1664 # echo 'ERROR: Invalid composer installer checksum' >&2
1665 # rm -fv composer-setup.php
1668 # m php composer-setup.php --quiet
1669 # rm -fv composer-setup.php
1670 # m mv composer.phar /usr/local/bin
1672 # the above method gets composer2, carddav plugin at least doesnt work with that
1673 # yet, it was just released 10-24-2020.
1675 m wget
-nv -N https
://getcomposer.org
/composer-1.phar
1676 chmod +x composer-1.phar
1677 ### end composer install
1679 rcdirs
=(/usr
/local
/lib
/rcexpertpath
/usr
/local
/lib
/rcninja
)
1680 ncdirs
=(/var
/www
/ncexpertpath
/var
/www
/ncninja
)
1681 # point debian cronjob to our local install, preventing daily cron error
1683 # debian's cronjob will fail, remove both paths it uses just to be sure
1684 rm -fv /usr
/share
/roundcube
/bin
/cleandb.sh
/etc
/cron.d
/roundcube-core
1686 #### begin dl roundcube
1687 # note, im r2e subbed to https://github.com/roundcube/roundcubemail/releases.atom
1688 v
=1.4.11; f
=roundcubemail-
$v-complete.
tar.gz
1690 if [[ -e $f ]]; then
1691 timestamp
=$
(stat
-c %Y
$f)
1695 m wget
-nv -N https
://github.com
/roundcube
/roundcubemail
/releases
/download
/$v/$f
1696 new_timestamp
=$
(stat
-c %Y
$f)
1697 for rcdir
in ${rcdirs[@]}; do
1698 if [[ $timestamp != "$new_timestamp" ||
! -e "$rcdir/config/secret" ]]; then
1699 m
tar -C /usr
/local
/lib
--no-same-owner -zxf $f
1701 m
mv /usr
/local
/lib
/roundcubemail-
$v $rcdir
1704 #### end dl roundcube
1706 for ((i
=0; i
< ${#bkdomains[@]}; i
++)); do
1707 domain
=${bkdomains[i]}
1712 # copied from debians cronjob
1713 i
/etc
/cron.d
/$rcbase <<EOF
1714 # Roundcube database cleaning: finally removes all records that are
1715 # marked as deleted.
1716 0 5 * * * www-data $rcdir/bin/cleandb.sh >/dev/null
1719 m
/a
/exe
/web-conf
- apache2
$domain <<EOF
1720 Alias /roundcube $rcdir
1721 ### begin roundcube settings
1722 # taken from /etc/apache2/conf-available/roundcube.conf version 1.4.8+dfsg.1-1~bpo10+1
1724 Options +FollowSymLinks
1725 # This is needed to parse $rcdir/.htaccess.
1729 # Protecting basic directories:
1730 <Directory $rcdir/config>
1731 Options -FollowSymLinks
1734 ### end roundcube settings
1737 ### begin nextcloud settings
1738 Alias /nextcloud "$ncdir/"
1742 Options FollowSymLinks MultiViews
1744 <IfModule mod_dav.c>
1750 # based on install checker, links to
1751 # https://docs.nextcloud.com/server/19/admin_manual/issues/general_troubleshooting.html#service-discovery
1752 # their example was a bit wrong, I figured it out by adding
1753 # LogLevel warn rewrite:trace5
1754 # then watching the apache logs
1757 RewriteRule ^/\.well-known/host-meta /nextcloud/public.php?service=host-meta [QSA,L]
1758 RewriteRule ^/\.well-known/host-meta\.json /nextcloud/public.php?service=host-meta-json [QSA,L]
1759 RewriteRule ^/\.well-known/webfinger /nextcloud/public.php?service=webfinger [QSA,L]
1760 RewriteRule ^/\.well-known/carddav /nextcloud/remote.php/dav/ [R=301,L]
1761 RewriteRule ^/\.well-known/caldav /nextcloud/remote.php/dav/ [R=301,L]
1762 ### end nextcloud settings
1764 if [[ ! -e $rcdir/config
/secret
]]; then
1765 base64
</dev
/urandom |
head -c24 >$rcdir/config
/secret ||
[[ $?
== 141 ||
${PIPESTATUS[0]} == 32 ]]
1767 secret
=$
(cat $rcdir/config
/secret
)
1769 rclogdir
=/var
/log
/$rcbase
1770 rctmpdir
=/var
/tmp
/$rcbase
1771 rcdb
=/m
/rc
/$rcbase.sqlite
1772 # config from mailinabox
1773 i
$rcdir/config
/config.inc.php
<<EOF
1776 # debian creates this for us
1777 \$config['log_dir'] = '$rclogdir/';
1778 # debian also creates a temp dir, but it is under its install dir,
1779 # seems better to have our own.
1780 \$config['temp_dir'] = '$rctmpdir/';
1781 \$config['db_dsnw'] = 'sqlite:///$rcdb?mode=0640';
1782 \$config['default_host'] = 'ssl://localhost';
1783 \$config['default_port'] = 993;
1784 \$config['imap_conn_options'] = array(
1786 'verify_peer' => false,
1787 'verify_peer_name' => false,
1790 \$config['imap_timeout'] = 15;
1791 \$config['smtp_server'] = 'tls://127.0.0.1';
1792 \$config['smtp_conn_options'] = array(
1794 'verify_peer' => false,
1795 'verify_peer_name' => false,
1798 \$config['product_name'] = 'webmail';
1799 \$config['des_key'] = '$secret';
1800 \$config['plugins'] = array('archive', 'zipdownload', 'password', 'managesieve', 'jqueryui', 'carddav', 'html5_notifier');
1801 \$config['skin'] = 'elastic';
1802 \$config['login_autocomplete'] = 2;
1803 \$config['password_charset'] = 'UTF-8';
1804 \$config['junk_mbox'] = 'Spam';
1805 # disable builtin addressbook
1806 \$config['address_book_type'] = '';
1810 m mkdir
-p $rclogdir
1811 m
chmod 750 $rclogdir
1812 m chown www-data
:adm
$rclogdir
1813 # note: subscribed to updates:
1814 # r2e add rcmcarddav https://github.com/blind-coder/rcmcarddav/commits/master.atom ian@iankelling.org
1815 # r2e add roundcube https://github.com/roundcube/roundcubemail/releases.atom ian@iankelling.org
1816 m mkdir
-p $rctmpdir /m
/rc
1817 m chown
-R www-data.www-data
$rctmpdir /m
/rc
1818 m
chmod 750 $rctmpdir
1819 # Ensure the log file monitored by fail2ban exists, or else fail2ban can't start.
1820 # todo: setup fail2ban
1821 # todo: check for other mailinabox things
1822 m sudo
-u www-data
touch $rclogdir/errors.log
1824 #### begin carddav install
1825 # This is the official roundcube carddav repo.
1826 # Install doc suggests downloading with composer, but that
1827 # didnt work, it said some ldap package for roundcube was missing,
1828 # but I dont want to download some extra ldap thing.
1829 # https://github.com/blind-coder/rcmcarddav/blob/master/doc/INSTALL.md
1830 verf
=$rcdir/plugins
/carddav
/myversion
1834 if [[ -e $verf ]]; then
1835 if [[ $
(cat $verf) != "$v" ]]; then
1843 m
rm -rf $rcdir/plugins
/carddav
1845 m wget
-nv -O $tmpd/t.tgz https
://github.com
/blind-coder
/rcmcarddav
/releases
/download
/v
$v/carddav-v
$v.tgz
1849 m chown
-R www-data
:www-data
$rcdir/plugins
/carddav
1850 m
cd $rcdir/plugins
/carddav
1852 m sudo
-u www-data composer-1.phar update
--no-dev
1854 m sudo
-u www-data composer-1.phar
install --no-dev
1856 m chown
-R root
:root
$rcdir/plugins
/carddav
1860 # So, strangely, this worked in initial testing, but then
1861 # on first run it wouldn't show the existing contacts until
1862 # I went into the carddav settings and did "force immediate sync",
1863 # which seemed to fix things. Note, some of these settings
1864 # get initalized per/addressbook in the db, then need changing
1865 # there or through the settings menu.
1867 # About categories, see https://www.davx5.com/tested-with/nextcloud
1868 # https://github.com/blind-coder/rcmcarddav/blob/master/doc/GROUPS.md
1869 i
$rcdir/plugins
/carddav
/config.inc.php
<<EOF;
1871 \$prefs['_GLOBAL']['hide_preferences'] = false;
1872 \$prefs['davserver'] = array(
1873 # name in the UI is kind of dumb. This is just something short that seems to fit ok.
1875 'username' => '%u', // login username
1876 'password' => '%p', // login password
1877 'url' => 'https://$domain/nextcloud/remote.php/dav/addressbooks/users/%u/contacts',
1879 'readonly' => false,
1880 'refresh_time' => '00:10:00',
1881 'fixed' => array('username','password'),
1882 'use_categories' => false,
1887 #### end carddav install
1890 if [[ ! -d html5_notifier
]]; then
1891 m git clone https
://github.com
/stremlau
/html5_notifier
1893 cd $rcdir/plugins
/html5_notifier
1896 # todo: try out roundcube plugins: thunderbird labels
1898 # Password changing plugin settings
1899 cat $rcdir/plugins
/password
/config.inc.php.dist
- >$rcdir/plugins
/password
/config.inc.php
<<'EOF'
1900 # following are from mailinabox
1901 $config['password_minimum_length'] = 8;
1902 $config['password_db_dsn'] = 'sqlite:////m/rc/users.sqlite';
1903 $config['password_query'] = 'UPDATE users SET password=%D WHERE email=%u';
1904 $config['password_dovecotpw'] = '/usr/bin/doveadm pw';
1905 $config['password_dovecotpw_method'] = 'SHA512-CRYPT';
1906 $config['password_dovecotpw_with_method'] = true;
1908 # so PHP can use doveadm, for the password changing plugin
1909 m usermod
-a -G dovecot www-data
1910 m usermod
-a -G mail $u
1912 # so php can update passwords
1913 m chown www-data
:dovecot
/m
/rc
/users.sqlite
1914 m
chmod 664 /m
/rc
/users.sqlite
1916 # Run Roundcube database migration script (database is created if it does not exist)
1917 m
$rcdir/bin
/updatedb.sh
--dir $rcdir/SQL
--package roundcube
1918 m chown www-data
:www-data
$rcdb
1920 done # end loop over domains and rcdirs
1922 ### begin php setup for rc ###
1923 # Enable PHP modules.
1924 m phpenmod
-v php mcrypt imap
1925 # dpkg says this is required
1926 m a2enmod proxy_fcgi setenvif
1927 fpm
=$
(dpkg-query
-s php-fpm |
sed -nr 's/^Depends:.* (php[^ ]*-fpm)( .*|$)/\1/p') # eg: php7.3-fpm
1928 phpver
=$
(dpkg-query
-s php-fpm |
sed -nr 's/^Depends:.* php([^ ]*)-fpm( .*|$)/\1/p')
1930 # 3 useless guides on php fpm fcgi debian 10 later, i figure out from reading
1931 # /etc/apache2/conf-enabled/php7.3-fpm.conf
1932 m a2dismod php
$phpver
1933 # according to /install, we should set date.timezone,
1934 # but that is dumb, the system already has the right zone in
1935 # $rclogdir/errors.log
1936 # todo: consider other settings in
1937 # /a/opt/mailinabox/setup/nextcloud.sh
1938 i
/etc
/php
/$phpver/cli
/conf.d
/30-local.ini
<<'EOF'
1942 i
/etc
/php
/$phpver/fpm
/conf.d
/30-local.ini
<<'EOF'
1943 date.timezone = "America/New_York"
1945 upload_max_filesize = 2000M
1946 post_max_size = 2000M
1947 # install checker, nextcloud/settings/admin/overview
1950 m systemctl restart
$fpm
1951 # dunno if reload/restart is needed
1952 m systemctl reload apache2
1953 # note bk backups are defined in crontab outside this file
1954 ### end php setup for rc ###
1956 fi # end roundcube setup
1960 if [[ $HOSTNAME == bk
]]; then
1961 # from install checker, nextcloud/settings/admin/overview and
1962 # https://docs.nextcloud.com/server/19/admin_manual/installation/source_installation.html
1963 # curl from the web installer requirement, but i switched to cli
1964 # it recommends php-file info, but that is part of php7.3-common, already got installed
1966 m pi php-curl php-bz2 php-gmp php-bcmath php-imagick php-apcu
1968 # https://docs.nextcloud.com/server/19/admin_manual/installation/source_installation.html
1969 cat >/etc
/php
/$phpver/fpm
/pool.d
/localwww.conf
<<'EOF'
1974 for ((i
=0; i
< ${#bkdomains[@]}; i
++)); do
1975 domain
=${bkdomains[i]}
1979 if [[ ! -e $ncdir/index.php
]]; then
1980 # if we wanted to only install a specific version, use something like
1981 # file=latest-22.zip
1983 m wget
-nv -N https
://download.nextcloud.com
/server
/releases
/$file
1987 m chown
-R www-data.www-data nextcloud
1988 m
mv nextcloud
$ncdir
1990 m sudo
-u www-data php occ maintenance
:install --database sqlite
--admin-user iank
--admin-pass $nextcloud_admin_pass
1992 # note, strange this happend where updater did not increment the version var,
1993 # mine was stuck on 20. I manually updated it.
1995 if [[ ! -e config.php-orig
]]; then
1996 m
cp -a config.php config.php-orig
1998 cat config.php-orig
- >tmp.php
<<EOF
1999 # https://docs.nextcloud.com/server/19/admin_manual/configuration_server/email_configuration.html
2000 \$CONFIG["mail_smtpmode"] = "sendmail";
2001 \$CONFIG["mail_smtphost"] = "127.0.0.1";
2002 \$CONFIG["mail_smtpport"] = 25;
2003 \$CONFIG["mail_smtptimeout"] = 10;
2004 \$CONFIG["mail_smtpsecure"] = "";
2005 \$CONFIG["mail_smtpauth"] = false;
2006 \$CONFIG["mail_smtpauthtype"] = "LOGIN";
2007 \$CONFIG["mail_smtpname"] = "";
2008 \$CONFIG["mail_smtppassword"] = "";
2009 \$CONFIG["mail_domain"] = "$domain";
2011 # https://github.com/nextcloud/user_external#readme
2012 # plus mailinabox example
2013 \$CONFIG['user_backends'] = array(array('class' => 'OC_User_IMAP','arguments' => array('127.0.0.1', 143, null),),);
2016 # based on installer check
2017 # https://docs.nextcloud.com/server/19/admin_manual/configuration_server/caching_configuration.html
2018 \$CONFIG['memcache.local'] = '\OC\Memcache\APCu';
2020 \$CONFIG['overwrite.cli.url'] = 'https://$domain/nextcloud';
2021 \$CONFIG['htaccess.RewriteBase'] = '/nextcloud';
2022 \$CONFIG['trusted_domains'] = array (
2026 fwrite(STDOUT, "<?php\n\\\$CONFIG = ");
2027 var_export(\$CONFIG);
2028 fwrite(STDOUT, ";\n");
2030 m php tmp.php
>config.php
2032 m sudo
-u www-data php
$ncdir/occ maintenance
:update
:htaccess
2033 list
=$
(sudo
-u www-data php
$ncdir/occ
--output=json_pretty app
:list
)
2034 # user_external not compaible with nc 23
2035 for app
in contacts calendar
; do
2036 if [[ $
(printf "%s\n" "$list"| jq
".enabled.$app") == null
]]; then
2037 m sudo
-u www-data php
$ncdir/occ app
:install $app
2040 i
/etc
/systemd
/system
/$ncbase.service
<<EOF
2042 Description=ncup $ncbase
2043 After=multi-user.target
2047 ExecStart=/usr/local/bin/ncup $ncbase
2049 IOSchedulingClass=idle
2050 CPUSchedulingPolicy=idle
2052 i
/etc
/systemd
/system
/$ncbase.timer
<<EOF
2054 Description=ncup $ncbase timer
2060 WantedBy=timers.target
2062 systemctl
enable --now $ncbase.timer
2063 i
/usr
/local
/bin
/ncup
<<'EOFOUTER'
2065 if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
2066 shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4
2068 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR
2071 if ! php /var/www/$ncbase/updater/updater.phar -n; then
2072 echo failed nextcloud update for $ncbase >&2
2074 To: alerts@iankelling.org
2075 From: root@$(hostname -f)
2076 Subject: failed nextcloud update for $ncbase
2078 For logs, run: jr -u $ncbase
2083 mkdir
-p /var
/www
/cron-errors
2084 chown www-data.www-data
/var
/www
/cron-errors
2085 i
/etc
/cron.d
/$ncbase <<EOF
2086 PATH=/sbin:/usr/sbin:/usr/bin:/bin:/usr/local/bin
2088 # https://docs.nextcloud.com/server/20/admin_manual/configuration_server/background_jobs_configuration.html
2089 */5 * * * * www-data php -f $ncdir/cron.php --define apc.enable_cli=1 |& log-once nccron
2096 # * exim host conditional config
2100 all_dirs
=(/p
/c
/filesystem
)
2101 for x
in /p
/c
/machine_specific
/*.hosts
/a
/bin
/ds
/machine_specific
/*.hosts
; do
2102 if grep -qxF $HOSTNAME $x; then all_dirs
+=( ${x%.hosts} ); fi
2105 for d
in ${all_dirs[@]}; do
2106 f
=$d/etc
/exim
4/passwd
2107 if [[ -e $f ]]; then
2110 tmp
=($d/etc
/exim
4/*.pem
)
2111 if (( ${#tmp[@]} )); then
2116 if (( ${#files[@]} )); then
2117 sudo rsync
-ahhi --chown=root
:Debian-exim
--chmod=0640 ${files[@]} /etc
/exim
4/
2125 # avoid accepting mail for invalid users
2126 # https://wiki.dovecot.org/LMTP/Exim
2127 cat >>/etc
/exim
4/conf.d
/rcpt_local_acl
<<'EOF'
2129 message = invalid recipient
2130 domains = +local_domains
2131 !verify = recipient/callout=no_cache
2133 i
/etc
/exim
4/conf.d
/auth
/29_exim4-config_auth
<<'EOF'
2137 server_socket = /var/run/dovecot/auth-client
2138 server_set_id = $auth1
2143 i
/etc
/exim
4/conf.d
/auth
/29_exim4-config_auth
<<'EOF'
2144 # from 30_exim4-config_examples
2148 server_condition = "${if crypteq{$auth3}{${extract{1}{:}{${lookup{$auth2}lsearch{CONFDIR/passwd}{$value}{*:*}}}}}{1}{0}}"
2149 server_set_id = $auth2
2151 .ifndef AUTH_SERVER_ALLOW_NOTLS_PASSWORDS
2152 server_advertise_condition = ${if eq{$tls_in_cipher}{}{}{*}}
2157 # ** main daemon use non-default config file
2160 # to see the default comments in /etc/default/exim4:
2161 # s update-exim4defaults --force --init
2162 # which will overwrite any existing file
2163 i
/etc
/default
/exim4
<<'EOF'
2164 QUEUERUNNER='combined'
2166 COMMONOPTIONS='-C /etc/exim4/my.conf'
2167 UPEX4OPTS='-o /etc/exim4/my.conf'
2168 #E4BCD_PANICLOG_NOISE='malware acl condition: clamd /var/run/clamav/clamd\.ctl : unable to connect to UNIX socket'
2170 i
/etc
/exim
4/trusted_configs
<<'EOF'
2176 i
/etc
/default
/exim4
<<'EOF'
2177 QUEUERUNNER='combined'
2184 # ** $MAIL_HOST|bk|je)
2187 echo|i
/etc
/exim
4/conf.d
/router
/870_backup_local
2189 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2190 # note: some things we don't set that are here by default because they are unused.
2191 dc_local_interfaces=''
2192 dc_eximconfig_configtype='internet'
2193 dc_localdelivery='dovecot_lmtp'
2195 cat >>/etc
/exim
4/conf.d
/main
/000_local
<<EOF
2196 # recommended if dns is expected to work
2197 CHECK_RCPT_VERIFY_SENDER = true
2198 # default config comment says: If you enable this, you might reject legitimate mail,
2199 # but eggs has had this a long time, so that seems unlikely.
2200 CHECK_DATA_VERIFY_HEADER_SYNTAX = true
2201 CHECK_RCPT_SPF = true
2202 CHECK_RCPT_REVERSE_DNS = true
2203 CHECK_MAIL_HELO_ISSUED = true
2205 # enable 587 in addition to the default 25, so that
2206 # i can send mail where port 25 is firewalled by isp
2207 daemon_smtp_ports = 25 : 587
2208 # default of 25, can get stuck when catching up on mail
2209 smtp_accept_max = 400
2210 smtp_accept_reserve = 100
2211 smtp_reserve_hosts = +iank_trusted
2213 # options exim has to avoid having to alter the default config files
2214 CHECK_RCPT_LOCAL_ACL_FILE = /etc/exim4/conf.d/rcpt_local_acl
2215 CHECK_DATA_LOCAL_ACL_FILE = /etc/exim4/conf.d/data_local_acl
2216 LOCAL_DENY_EXCEPTIONS_LOCAL_ACL_FILE = /etc/exim4/conf.d/local_deny_exceptions_acl
2218 #dmarc_tld_file = /etc/public_suffix_list.dat
2225 cat >>/etc
/exim
4/conf.d
/main
/000_local
<<EOF
2226 # je.b8.nz will run out of memory with freshclam
2227 av_scanner = clamd:/var/run/clamav/clamd.ctl
2230 cat >> /etc
/exim
4/conf.d
/data_local_acl
<<'EOF'
2232 malware = */defer_ok
2233 !condition = ${if match {$malware_name}{\N^Heuristic\N}}
2234 message = This message was detected as possible malware ($malware_name).
2237 cat >/etc
/exim
4/conf.d
/main
/000_local-nn
<<EOF
2238 # MAIN_HARDCODE_PRIMARY_HOSTNAME might mess up the
2239 # smarthost config type, not sure.
2240 # failing message on mail-tester.com:
2241 # We check if there is a server (A Record) behind your hostname kd.
2242 # You may want to publish a DNS record (A type) for the hostname kd or use a different hostname in your mail software
2243 # https://serverfault.com/questions/46545/how-do-i-change-exim4s-primary-hostname-on-a-debian-box
2244 # and this one seemed appropriate from grepping config.
2245 # I originally set this to li.iankelling.org, but then ended up with errors when li tried to send
2246 # mail to kd, so this should basically be a name that no host has as their
2247 # canonical hostname since the actual host sits behind a nat and changes.
2248 MAIN_HARDCODE_PRIMARY_HOSTNAME = mail.iankelling.org
2249 # I used this to avoid sender verification, didnt work but it still
2250 # makes sense based on the spec.
2251 hosts_treat_as_local = defaultnn.b8.nz
2253 # Outside nn, we get the default cert location from a debian macro,
2254 # and the cert file is put in place by a certbot hook.
2255 MAIN_TLS_CERTIFICATE = /etc/exim4/fullchain.pem
2256 MAIN_TLS_PRIVATEKEY = /etc/exim4/privkey.pem
2259 i
/etc
/exim
4/conf.d
/router
/190_exim4-config_fsfsmarthost
<<'EOF'
2261 debug_print = "R: smarthost for $local_part@$domain"
2262 driver = manualroute
2263 domains = ! +local_domains
2264 # send most mail through eggs, helps fsfs sender reputation.
2265 # uncomment and optionally move to 188 file to send through my own servers again
2267 transport = smarthost_dkim
2268 route_list = * fencepost.gnu.org::587 byname
2269 host_find_failed = ignore
2270 same_domain_copy_routing = yes
2274 /a
/exe
/cedit defaultnn
/etc
/hosts
<<'EOF' || [[ $? == 1 ]]
2275 10.173.8.1 defaultnn.b8.nz
2281 i
/etc
/exim
4/conf.d
/router
/195_dnslookup_vpn
<<'EOF'
2282 # copied from /etc/exim4/conf.d/router/200_exim4-config_primary, but
2283 # use vpn transport. lower priority so it overrides the default route.
2284 # Use this in case our vpn fails, we dont send anything without it.
2285 .ifdef DCconfig_internet
2287 debug_print = "R: dnslookup for $local_part@$domain"
2289 domains = ! +local_domains
2290 transport = remote_smtp_vpn
2291 same_domain_copy_routing = yes
2292 ignore_target_hosts = <; 0.0.0.0 ; 127.0.0.0/8 ; 192.168.0.0/16 ; 172.16.0.0/12 ; 10.0.0.0/8 ; 169.254.0.0/16 ; 255.255.255.255 ; ::/128 ; ::1/128 ; fc00::/7 ; fe80::/10 ; 100::/64
2298 # note on backups: I used to do an automatic sshfs and restricted
2299 # permissions to a specific directory on the remote server, /bu/mnt,
2300 # which required using a dedicated user, but realized smtp will be
2301 # more reliable and less fuss. If I ever need that again, see the
2302 # history of this file, and bum in brc2.
2304 i
/etc
/exim
4/conf.d
/router
/890_backup_copy
<<EOF
2305 ### router/900_exim4-config_local_user
2306 #################################
2308 # todo, it would be nice to save sent email too,
2309 # but its not so important, they still exist in my head
2313 domains = +local_domains
2314 # b is just an arbirary short string
2315 data = b@eximbackup.b8.nz
2316 # note, to test this, i could temporarily allow testignore.
2317 # alerts avoids potential mail loop. root is already
2318 # redirected earlier, so that is just being overly cautious.
2319 local_parts = ! root : ! testignore : ! alerts
2323 driver = manualroute
2324 domains = eximbackup.b8.nz
2325 transport = backup_remote
2326 ignore_target_hosts = ${HOSTNAME}wg.b8.nz
2327 # note changes here also require change in passwd.client
2328 route_list = * eximbackup.b8.nz
2329 same_domain_copy_routing = yes
2334 i
/etc
/exim
4/conf.d
/transport
/30_backup_remote
<<'EOF'
2338 .ifndef IGNORE_SMTP_LINE_LENGTH_LIMIT
2339 message_size_limit = ${if > {$max_received_linelength}{998} {1}{0}}
2341 hosts_require_auth = *
2343 return_path = alerts@iankelling.org
2345 # manual return path because we dont want it to be the envelope sender
2346 # we got not the one we are using in this smtp transport
2347 headers_add = "Return-path: $sender_address"
2348 .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
2349 hosts_avoid_tls = REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
2351 .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS
2352 hosts_require_tls = REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS
2354 .ifdef REMOTE_SMTP_SMARTHOST_TLS_VERIFY_CERTIFICATES
2355 tls_verify_certificates = REMOTE_SMTP_SMARTHOST_TLS_VERIFY_CERTIFICATES
2357 .ifdef REMOTE_SMTP_SMARTHOST_TLS_VERIFY_HOSTS
2358 tls_verify_hosts = REMOTE_SMTP_SMARTHOST_TLS_VERIFY_HOST
2360 .ifdef REMOTE_SMTP_HEADERS_REWRITE
2361 headers_rewrite = REMOTE_SMTP_HEADERS_REWRITE
2363 .ifdef REMOTE_SMTP_HELO_DATA
2364 helo_data=REMOTE_SMTP_HELO_DATA
2366 .ifdef TLS_DH_MIN_BITS
2367 tls_dh_min_bits = TLS_DH_MIN_BITS
2369 .ifdef REMOTE_SMTP_SMARTHOST_TLS_CERTIFICATE
2370 tls_certificate = REMOTE_SMTP_SMARTHOST_TLS_CERTIFICATE
2372 .ifdef REMOTE_SMTP_SMARTHOST_PRIVATEKEY
2373 tls_privatekey = REMOTE_SMTP_SMARTHOST_PRIVATEKEY
2375 .ifdef REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
2376 headers_remove = REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
2381 # this avoids some error. i cant remember what. todo:
2382 # test it out and document why/if its needed.
2383 i
/etc
/exim
4/host_local_deny_exceptions
<<'EOF'
2388 # cron email from smarthost hosts will automatically be to
2389 # USER@FQDN. I redirect that to alerts@, on the smarthosts, but in
2390 # case that doesn't work, we still want to accept that mail, but not
2391 # from any host except the smarthosts. local_hostnames and this rule
2392 # is for that purpose.
2393 i
/etc
/exim
4/conf.d
/rcpt_local_acl
<<'EOF'
2396 domains = +local_hostnames
2399 echo|i
/etc
/exim
4/conf.d
/router
/880_universal_forward
2401 # for iank@fsf.org, i have mail.fsf.org forward it to fsf@iankelling.org.
2402 # and also have mail.iankelling.org whitelisted as a relay domain.
2403 # I could avoid that if I changed this to submit to 587 with a
2404 # password like a standard mua.
2405 i
/etc
/exim
4/conf.d
/router
/188_exim4-config_smarthost
<<'EOF'
2406 # ian: copied from /etc/exim4/conf.d/router/200_exim4-config_primary, and added senders = and
2407 # replaced DCsmarthost with hostname
2409 debug_print = "R: smarthost for $local_part@$domain"
2410 driver = manualroute
2411 domains = ! +local_domains
2413 transport = remote_smtp_smarthost
2414 route_list = * mail.fsf.org::587 byname
2415 host_find_failed = ignore
2416 same_domain_copy_routing = yes
2420 debug_print = "R: smarthost for $local_part@$domain"
2421 driver = manualroute
2422 domains = ! +local_domains
2423 senders = *@posteo.net
2424 transport = remote_smtp_smarthost
2425 route_list = * posteo.de::587 byname
2426 host_find_failed = ignore
2427 same_domain_copy_routing = yes
2432 # Greping /etc/exim4, unqualified mails this would end up as
2433 # a return path, so it should go somewhere we will see.
2434 # The debconf output about mailname is as follows:
2435 # The 'mail name' is the domain name used to 'qualify' mail addresses without a domain
2437 # This name will also be used by other programs. It should be the single, fully
2438 # qualified domain name (FQDN).
2439 # Thus, if a mail address on the local host is foo@example.org, the correct value for
2440 # this option would be example.org.
2441 # This name won\'t appear on From: lines of outgoing messages if rewriting is enabled.
2442 echo iankelling.org
> /etc
/mailname
2445 # mail.iankelling.org so local imap clients can connect with tls and
2446 # when they happen to not be local.
2447 # todo: this should be 10.8.0.4
2449 /a
/exe
/cedit nn
/etc
/hosts
<<'EOF' || [[ $? == 1 ]]
2450 # note: i put nn.b8.nz into bind for good measure
2451 10.173.8.2 nn.b8.nz mail.iankelling.org
2454 # note: systemd-resolved will consult /etc/hosts, dnsmasq wont. this assumes
2455 # weve configured this file in dnsmasq if we are using it.
2456 /a
/exe
/cedit
mail /etc
/dnsmasq-servers.conf
<<'EOF' || [[ $? == 1 ]]
2457 server=/mail.iankelling.org/127.0.1.1
2459 # I used to use debconf-set-selections + dpkg-reconfigure,
2460 # which then updates this file
2461 # but the process is slower than updating it directly and then I want to set other things in
2462 # update-exim4.conf.conf, so there's no point.
2463 # The file is documented in man update-exim4.conf,
2464 # except the man page is not perfect, read the bash script to be sure about things.
2466 # The debconf questions output is additional documentation that is not
2467 # easily accessible, but super long, along with the initial default comment in this
2468 # file, so I've saved that into ./mail-notes.conf.
2469 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2470 # man page: is used to build the local_domains list, together with "localhost"
2471 # this is duplicated in a later router.
2472 dc_other_hostnames='iankelling.org;zroe.org;r2e.iankelling.org;!je.b8.nz;!bk.b8.nz;*.b8.nz;b8.nz'
2476 # dmarc. not used currently
2477 f
=/etc
/cron.daily
/refresh-dmarc-tld-file
2481 wget -q -N https://publicsuffix.org/list/public_suffix_list.dat
2487 ## we use this host to monitor MAIL_HOST and host a mail server for someone
2490 echo|i
/etc
/exim
4/conf.d
/rcpt_local_acl
2491 echo|i
/etc
/exim
4/conf.d
/router
/880_universal_forward
2493 echo amnimal.ninja
> /etc
/mailname
2495 /a
/exe
/cedit nn
/etc
/hosts
<<'EOF' || [[ $? == 1 ]]
2499 sed -r -f - /etc
/init.d
/exim4
<<'EOF' | i /etc/init.d/exim4in
2500 s,/etc/default/exim4,/etc/default/exim4in,g
2501 s,/run/exim4/exim.pid,/run/exim4/eximin.pid,g
2502 s,(^[ #]*Provides:).*,\1 exim4in,
2503 s,(^[ #]*NAME=).*,\1"exim4in",
2505 chmod +x
/etc
/init.d
/exim4in
2506 i
/etc
/systemd
/system
/exim4in.service.d
/alwaysrestart.conf
<<'EOF'
2508 # needed to continually restart
2509 StartLimitIntervalSec=0
2513 # time to sleep before restarting a service
2517 i
/etc
/default
/exim4in
<<'EOF'
2518 # defaults but no queue runner and alternate config dir
2520 COMMONOPTIONS='-oP /run/exim4/eximin.pid'
2521 UPEX4OPTS='-d /etc/myexim4'
2524 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2525 # man page: is used to build the local_domains list, together with "localhost"
2526 dc_other_hostnames='amnimal.ninja;expertpathologyreview.com'
2532 echo je.b8.nz
> /etc
/mailname
2533 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2534 dc_other_hostnames='je.b8.nz'
2536 echo|i
/etc
/exim
4/conf.d
/router
/188_exim4-config_smarthost
2537 echo|i
/etc
/exim
4/conf.d
/router
/190_exim4-config_fsfsmarthost
2538 echo|i
/etc
/exim
4/conf.d
/rcpt_local_acl
2539 echo|i
/etc
/exim
4/conf.d
/router
/880_universal_forward
2541 # ** not MAIL_HOST|bk|je
2543 # this one should be removed for all non mail hosts, but
2544 # bk and je never become mail_host
2545 echo|i
/etc
/exim
4/conf.d
/router
/195_dnslookup_vpn
2547 echo|i
/etc
/exim
4/conf.d
/router
/188_exim4-config_smarthost
2548 echo|i
/etc
/exim
4/conf.d
/router
/190_exim4-config_fsfsmarthost
2549 echo|i
/etc
/exim
4/conf.d
/rcpt_local_acl
2550 echo|i
/etc
/exim
4/conf.d
/router
/890_backup_copy
2554 cat >>/etc
/exim
4/conf.d
/main
/000_local
<<EOF
2555 MAIN_TLS_CERTIFICATE = /etc/exim4/certs/$wghost/fullchain.pem
2556 MAIN_TLS_PRIVATEKEY = /etc/exim4/certs/$wghost/privkey.pem
2557 # so we can maintiain the originals of the backups.
2558 # we wouldnt want this if we were dealing with any other
2559 # local deliveries, but we sent all others to the smarthost
2560 # which then strips the headers.
2561 envelope_to_remove = false
2562 return_path_remove = false
2566 # catches things like cronjob email
2567 i
/etc
/exim
4/conf.d
/router
/880_universal_forward
<<'EOF'
2570 domains = +local_domains
2571 data = alerts@iankelling.org
2575 for unit
in ${nn_progs[@]}; do
2576 f
=/etc
/systemd
/system
/$unit.service.d
/nn.conf
2580 # dont i dont care if defaultnn section gets left, it wont
2582 echo |
/a
/exe
/cedit nn
/etc
/hosts ||
[[ $?
== 1 ]]
2583 echo |
/a
/exe
/cedit
mail /etc
/dnsmasq-servers.conf ||
[[ $?
== 1 ]]
2586 i
/etc
/exim
4/conf.d
/transport
/30_backup_maildir
<<EOF
2587 # modified debian maildir transport
2592 # note, no return path or envelope added
2594 directory_mode = 0700
2596 mode_fail_narrower = false
2600 i
/etc
/exim
4/conf.d
/router
/870_backup_local
<<EOF
2601 ### router/900_exim4-config_local_user
2602 #################################
2605 debug_print = "R: local_user for \$local_part@\$domain"
2607 domains = eximbackup.b8.nz
2608 transport = backup_maildir
2612 wgholeip
=$
(sed -rn 's/^ *Address *= *([^/]+).*/\1/p' /etc
/wireguard
/wghole.conf
)
2613 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2614 dc_other_hostnames='eximbackup.b8.nz'
2615 dc_local_interfaces='127.0.0.1;::1;$wgholeip'
2618 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2619 # Note: If theres like a temporary problem where mail gets sent to
2620 # one of these hosts, if exim isnt listening, it will be a temporary error
2621 # instead of a permanent 5xx.
2622 dc_local_interfaces='127.0.0.1;::1'
2625 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2626 dc_eximconfig_configtype='smarthost'
2627 dc_smarthost='$smarthost'
2630 hostname
-f |i
/etc
/mailname
2631 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2632 # The manpage incorrectly states this will do header rewriting, but
2633 # that only happens if we have dc_hide_mailname is set.
2634 dc_readhost='iankelling.org'
2635 # Only used in case of bounces.
2636 dc_localdelivery='maildir_home'
2644 # ** $MAILHOST|bk, things that belong at the end
2647 # config for the non-nn exim
2648 m rsync
-ra --delete /etc
/exim
4/ /etc
/myexim4
2649 cat >>/etc
/myexim
4/update-exim4.conf.conf
<<'EOF'
2650 dc_eximconfig_configtype='smarthost'
2651 dc_smarthost='nn.b8.nz'
2656 # config for the non-nn exim
2657 cat >/etc
/myexim
4/conf.d
/main
/000_local-nn
<<'EOF'
2658 MAIN_HARDCODE_PRIMARY_HOSTNAME = mail2.iankelling.org
2662 # for bk, we have a exim4in.service that will do this for us.
2663 m update-exim4.conf
-d /etc
/myexim4
2669 # ** bind mount setup
2670 # put spool dir in directory that spans multiple distros.
2671 # based on http://www.postfix.org/qmgr.8.html and my notes in gnus
2674 sdir
=/var
/spool
/exim4
2675 # we only do this if our system has $dir
2677 # this used to do a symlink, but, in the boot logs, /nocow would get mounted succesfully,
2678 # about 2 seconds later, exim starts, and immediately puts into paniclog:
2679 # honVi-0000u3-82 Failed to create directory "/var/spool/exim4/input": No such file or directory
2680 # so, im trying a bind mount to get rid of that.
2681 if [[ -e /nocow
]]; then
2682 if ! grep -Fx "/nocow/exim4 /var/spool/exim4 none bind 0 0" /etc
/fstab
; then
2683 echo "/nocow/exim4 /var/spool/exim4 none bind 0 0" >>/etc
/fstab
2685 i
/etc
/systemd
/system
/exim4.service.d
/override.conf
<<'EOF'
2687 # without local-fs on exim, we get these kind of errors in paniclog on shutdown:
2688 # Failed to create spool file /var/spool/exim4//input//1jCLxz-0008V4-V9-D: Permission denied
2689 After=local-fs.target
2691 if ! mountpoint
-q $sdir; then
2692 stopifactive exim4 exim4in
2693 if [[ -L $sdir ]]; then
2696 if [[ ! -e $dir && -d $sdir ]]; then
2699 if [[ ! -d $sdir ]]; then
2701 m
chmod 000 $sdir # only want it to be used when its mounted
2709 # ** exim/spool uid setup
2710 # i have the spool directory be common to distro multi-boot, so
2711 # we need the uid to be the same. 608 cuz it's kind of in the middle
2712 # of the free system uids.
2713 IFS
=:; read -r _ _ uid _
< <(getent passwd Debian-exim ||
:) ||
:; unset IFS
2714 IFS
=:; read -r _ _ gid _
< <(getent group Debian-exim ||
:) ||
:; unset IFS
2715 if [[ ! $uid ]]; then
2716 # from /var/lib/dpkg/info/exim4-base.postinst, plus uid and gid options
2717 m adduser
--uid 608 --system --group --quiet --home /var
/spool
/exim4 \
2718 --no-create-home --disabled-login --force-badname Debian-exim
2719 elif [[ $uid != 608 ]]; then
2720 stopifactive exim4 exim4in
2721 m usermod
-u 608 Debian-exim
2722 m groupmod
-g 608 Debian-exim
2723 m usermod
-g 608 Debian-exim
2724 m
find / /nocow
-path .
/var
/tmp
-prune -o -xdev -uid $uid -execdir chown
-h 608 {} +
2725 m
find / /nocow
-path .
/var
/tmp
-prune -o -xdev -gid $gid -execdir chgrp
-h 608 {} +
2728 # * start / stop services
2730 reifactive dnsmasq nscd
2733 m systemctl daemon-reload
2738 /a
/exe
/web-conf apache2 je.b8.nz
2741 /a
/exe
/web-conf apache2 mail2.iankelling.org
2745 m
/a
/bin
/ds
/mail-cert-cron
-1
2750 # todo, this should be done in distro-begin
2751 soff systemd-resolved
2752 ln -sf 127.0.0.1-resolv/stub-resolv.conf
/etc
/resolv.conf
2755 sstart mailnn mailnnroute
2756 # If these have changes, id rather manually restart it, id rather
2757 # not restart and cause temporary errors
2772 if ! systemctl is-active clamav-daemon
>/dev
/null
; then
2773 sstart clamav-daemon
2774 # note, this will cause paniclog entries because it takes like 45
2775 # seconds for clamav to start, i use ./epanic-clean to remove
2780 # start spamassassin/dovecot before exim.
2781 sre dovecot spamassassin
2782 # need to wait a bit before restarting exim, else I
2783 # get a paniclog entry like: spam acl condition: all spamd servers failed
2785 sstart mailclean.timer
2788 # < 2.1 (eg: in t9), uses a different data format which required manual
2789 # migration. dont start if we are running an old version.
2790 if dpkg
--compare-versions $
(dpkg
-s radicale |
awk '$1 == "Version:" { print $2 }') ge
2.1; then
2796 # last use of $reload happens in previous block
2797 rm -f /var
/local
/mail-setup-reload
2801 $MAIL_HOST|bk|je
) : ;;
2803 soff radicale mailclean.timer dovecot spamassassin
$vpnser mailnn clamav-daemon
2813 # * mail monitoring / testing
2815 # note, to test clamav, send an email with body that only contains
2816 # https://en.wikipedia.org/wiki/EICAR_test_file
2817 # which set malware_name to Eicar-Signature
2820 # note: cronjob "ian" also does some important monitoring
2821 # todo: this will sometimes cause an alert because mailtest-check will run
2822 # before we have setup network namespace and spamassassin
2823 cat >/etc
/cron.d
/mailtest
<<EOF
2825 PATH=/usr/bin:/bin:/usr/local/bin
2826 MAILTO=alerts@iankelling.org
2827 */5 * * * * $u send-test-forward |& log-once send-test-forward
2828 */10 * * * * root chmod -R g+rw /m/md/bounces |& log-once -1 bounces-chmod
2829 # im seeing some intermittent failures on the slow check, do it all the time
2830 # for now. It looks like a dns failure.
2831 #5-59/5 * * * * root mailtest-check |& log-once -1 mailtest-check
2832 #0 * * * * root mailtest-check slow |& log-once -1 mailtest-slow
2833 */5 * * * * root timeout 290 mailtest-check slow |& log-once -12 mailtest-check
2835 m sudo rsync
-ahhi --chown=root
:root
--chmod=0755 \
2836 /b
/ds
/mailtest-check
/b
/ds
/check-remote-mailqs
/usr
/local
/bin
/
2839 test_froms
=(ian@iankelling.org z@zroe.org iank@gnu.org
)
2840 test_to
="testignore@expertpathologyreview.com, testignore@je.b8.nz, testignore@amnimal.ninja, jtuttle@gnu.org"
2842 cat >>/etc
/cron.d
/mailtest
<<EOF
2843 2 * * * * $u check-remote-mailqs |& log-once check-remote-mailqs
2847 test_froms
=(testignore@expertpathologyreview.com testignore@amnimal.ninja
)
2848 test_to
="testignore@iankelling.org, testignore@zroe.org, testignore@je.b8.nz"
2851 test_froms
=(testignore@je.b8.nz
)
2852 test_to
="testignore@iankelling.org, testignore@zroe.org, testignore@expertpathologyreview.com, testignore@amnimal.ninja"
2855 cat >/usr
/local
/bin
/send-test-forward
<<'EOF'
2857 exiqgrep -o 260 -i -r '^(testignore@(iankelling\.org|zroe\.org|expertpathologyreview\.com|amnimal\.ninja|je\.b8\.nz)|jtuttle@gnu\.org)$' | xargs /sbin/exim -Mrm >/dev/null
2859 for test_from
in ${test_froms[@]}; do
2860 cat >>/usr
/local
/bin
/send-test-forward
<<EOFOUTER
2861 /usr/sbin/exim -f $test_from -t <<EOF
2864 Subject: test \$(date +%Y-%m-%dT%H:%M:%S%z) \$(date +%s)
2866 /usr/local/bin/send-test-forward
2870 m
chmod +x
/usr
/local
/bin
/send-test-forward
2873 rm -fv /etc
/cron.d
/mailtest
2880 m sudo
-u $u mkdir
-p /home
/$u/.cache
2881 set -- /m
/mucache
/home
/$u/.cache
/mu
/m
/.mu
/home
/$u/.mu
2886 if [[ ! -L $f ]]; then
2887 if [[ -e $f ]]; then
2890 m sudo
-u $u ln -sf -T $target $f
2895 # /etc/alias setup is debian specific, and exim postinst script sets up
2896 # an /etc/alias from root to the postmaster, based on the question
2897 # exim4-config exim4/dc_postmaster, as long as there exists an entry for
2898 # root, or there was no preexisting aliases file. postfix won\'t set up
2899 # a root to $postmaster alias if it\'s already installed. Easiest to
2900 # just set it ourselves.
2902 # debconf question for postmaster:
2903 # Mail for the 'postmaster', 'root', and other system accounts needs to be redirected
2904 # to the user account of the actual system administrator.
2905 # If this value is left empty, such mail will be saved in /var/mail/mail, which is not
2907 # Note that postmaster\'s mail should be read on the system to which it is directed,
2908 # rather than being forwarded elsewhere, so (at least one of) the users listed here
2909 # should not redirect their mail off this machine. A 'real-' prefix can be used to
2910 # force local delivery.
2911 # Multiple user names need to be separated by spaces.
2912 # Root and postmaster mail recipient:
2914 # duplicated in brc2
2918 (( $# == 1 )) ||
return 1
2919 cur
="$(awk '$2 == "/bu
/mnt
" {print $1}' /proc/mounts)"
2921 if [[ $cur == "$host:/bu/md" ]]; then
2924 fusermount
-u /bu
/mnt
2927 m sshfs bu@
$host:/bu
/home
/md
/bu
/mnt
-o reconnect
,ServerAliveInterval
=20,ServerAliveCountMax
=30 -o allow_other
2930 if mountpoint
-q /bu
/mnt
; then
2931 if ! timeout
-s 9 10 fusermount
-u /bu
/mnt
; then
2932 fusermount
-zu /bu
/mnt
2956 # eval: (outline-minor-mode)
2957 # outline-regexp: "\\( *\\)# [*]\\{1,8\\} "
2959 # this is combined with defining outline-level in init.el