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 disable
--now $service
309 m systemctl restart
$service
310 m systemctl
enable $service;
315 m systemctl
enable --now $service;
319 [[ $HOSTNAME == "$MAIL_HOST" ]]
321 e
() { printf "%s\n" "$*"; }
324 if systemctl is-active
$service >/dev
/null
; then
325 m systemctl restart
$service
331 if systemctl is-active
$service >/dev
/null
; then
332 m systemctl stop
$service
337 mxhost
=mx.iankelling.org
341 # old setup. left as comment for example
342 # mxhost=mail.messagingengine.com
344 # forward=ian@iankelling.org
346 smarthost
="$mxhost::$mxport"
347 uhome
=$
(eval echo ~
$u)
349 # Somehow on one machine, a file got written with 664 perms.
350 # just being defensive here.
353 source /a
/bin
/bash_unpublished
/source-state
354 if [[ ! $MAIL_HOST ]]; then
355 err
"\$MAIL_HOST not set"
361 kd|frodo|x2|x3|kw|sy
)
367 # * Install universal packages
370 # installs epanicclean
371 /a
/bin
/ds
/install-my-scripts
373 if [[ $
(debian-codename-compat
) == bionic
]]; then
374 cat >/etc
/apt
/preferences.d
/spamassassin
<<'EOF'
375 Package: spamassassin sa-compile spamc
376 Pin: release n=focal,o=Ubuntu
381 # light version of exim does not have sasl auth support.
382 pi-nostart exim4 exim4-daemon-heavy spamassassin openvpn unbound clamav-daemon wireguard
384 # note: pyzor debian readme says you need to run some initialization command
386 pi spf-tools-perl p0f postgrey pyzor razor jq moreutils certbot
387 # bad packages that sometimes get automatically installed
388 pu openresolv resolvconf
393 if [[ $
(debian-codename
) == etiona
]]; then
394 # ip6tables stopped loading on boot. openvpn has reduced capability set,
395 # so running iptables as part of openvpn startup wont work. This should do it.
396 pi iptables-persistent
397 cat >/etc
/iptables
/rules.v6
<<'EOF'
404 m ip6tables
-S >/dev
/null
407 # our nostart pi fails to avoid enabling
410 # * user forward file
413 # afaik, these will get ignored on MAIL_HOST because they are routing to my own
414 # machine, but rm them is safer
415 rm -fv $uhome/.forward
/root
/.forward
418 # this can\'t be a symlink and has permission restrictions
419 # it might work in /etc/aliases, but this seems more proper.
420 e setting
$uhome/.forward to
$forward
421 install -m 644 {-o,-g}$u <(e
$forward) $uhome/.forward
425 # * Mail clean cronjob
427 i
/etc
/systemd
/system
/mailclean.timer
<<'EOF'
429 Description=Run mailclean daily
435 WantedBy=timers.target
438 i
/etc
/systemd
/system
/mailclean.service
<<EOF
440 Description=Delete and archive old mail files
441 After=multi-user.target
446 ExecStart=/usr/local/bin/sysd-mail-once mailclean /a/bin/distro-setup/mailclean
452 i
/etc
/default
/postgrey
<<'EOF'
453 POSTGREY_OPTS="--exim --unix=/var/run/postgrey/postgrey.sock --retry-window=4 --max-age=60"
458 m usermod
-a -G Debian-exim clamav
460 i
/etc
/systemd
/system
/clamav-daemon.service.d
/fix.conf
<<EOF
462 ExecStartPre=-/bin/mkdir /var/run/clamav
463 ExecStartPre=/bin/chown clamav /var/run/clamav
469 #vpnser=mailvpn.service
470 # todo: this hangs if it cant resolv the endpoint. we
471 # want it to just retry in the background.
472 vpnser
=wg-quick@wgmail.service
476 rsync
-aiSAX --chown=root
:root
--chmod=g-s
/p
/c
/filesystem
/etc
/wireguard
/ /etc
/wireguard
477 bindpaths
="/etc/127.0.0.1-resolv:/run/systemd/resolve /etc/basic-nsswitch:/etc/resolved-nsswitch:norbind"
480 bindpaths
="/etc/10.173.8.1-resolv:/etc/127.0.0.1-resolv"
483 d
=/p
/c
/machine_specific
/$HOSTNAME/filesystem
/etc
/wireguard
/
485 rsync
-aiSAX --chown=root
:root
--chmod=g-s
$d /etc
/wireguard
490 i
/etc
/systemd
/system
/wg-quick@wgmail.service.d
/override.conf
<<EOF
492 Requires=mailnn.service
493 After=network.target mailnn.service
494 JoinsNamespaceOf=mailnn.service
495 BindsTo=mailnn.service
499 # i dont think we need any of these, but it doesnt hurt to stay consistent
503 # https://selivan.github.io/2017/12/30/systemd-serice-always-restart.html
504 i
/etc
/systemd
/system
/mailvpn.service
<<EOF
506 Description=OpenVPN tunnel for mail
507 After=syslog.target network-online.target mailnn.service
508 Wants=network-online.target
509 Documentation=man:openvpn(8)
510 Documentation=https://community.openvpn.net/openvpn/wiki/Openvpn24ManPage
511 Documentation=https://community.openvpn.net/openvpn/wiki/HOWTO
512 # needed to continually restatr
513 JoinsNamespaceOf=mailnn.service
514 BindsTo=mailnn.service
515 StartLimitIntervalSec=0
519 RuntimeDirectory=openvpn-client
520 RuntimeDirectoryMode=0710
521 WorkingDirectory=/etc/openvpn/client
522 ExecStart=/usr/sbin/openvpn --suppress-timestamps --nobind --config /etc/openvpn/client/mail.conf
523 #CapabilityBoundingSet=CAP_IPC_LOCK CAP_NET_ADMIN CAP_NET_RAW CAP_SETGID CAP_SETUID CAP_SYS_CHROOT CAP_DAC_OVERRIDE
525 # DeviceAllow=/dev/null rw
526 # DeviceAllow=/dev/net/tun rw
528 # in the network namespace, we cant connect to systemd-resolved on 127.0.0.53,
530 # https://unix.stackexchange.com/questions/445782/how-to-allow-systemd-resolved-to-listen-to-an-interface-other-than-loopback
531 # there is a workaround there, but i dont think its really worth it,
532 # the mail server is fine with a static dns anyways.
533 # This thread is also interesting,
534 # https://github.com/slingamn/namespaced-openvpn/issues/7
535 # todo: the iptables rule at the bottom could be useful to prevent
536 # dns from leaking in my network namespaced vpn.
537 # I also like the idea of patching systemd-resolved so it
538 # will listen on other interfaces, but its not worth my time.
541 # time to sleep before restarting a service
545 WantedBy=multi-user.target
548 i
/etc
/systemd
/system
/mailnnroute.service
<<'EOF'
550 Description=Network routing for mailnn
551 After=syslog.target network-online.target mailnn.service
552 Wants=network-online.target
553 JoinsNamespaceOf=mailnn.service
554 BindsTo=mailnn.service
555 StartLimitIntervalSec=0
561 ExecStart=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns -n 10.173.8 start mail
562 ExecStop=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns stop mail
568 WantedBy=multi-user.target
572 i
/etc
/systemd
/system
/mailnn.service
<<'EOF'
574 Description=Network Namespace for mail vpn service that will live forever and cant fail
575 After=syslog.target network-online.target
576 Wants=network-online.target
581 ExecStart=/bin/sleep infinity
584 WantedBy=multi-user.target
590 rm -fv /etc
/systemd
/system
/openvpn-client-mail@.service
592 # We use a local unbound because systemd-resolved wont accept our
593 # request, it will only listen to 127.0.0.53 in the main network
594 # namespace, and rejected feature requests to change that (although I
595 # could change the code and recompile), but anyways, that could answer
596 # with things specific to the lan that aren't applicable in this
597 # namespace, and since unbound is a recursive resolver, it means we just
598 # use our own ip against dnsbl rate limits.
600 # If we ever notice this change, chattr +i on it
601 # trust-ad is used in t10+, glibc 2.31
603 i
/etc
/127.0.0.1-resolv/stub-resolv.conf
<<'EOF'
605 options edns0 trust-ad
608 i
/etc
/127.0.0.53-resolv/stub-resolv.conf
<<'EOF'
609 nameserver 127.0.0.53
610 options edns0 trust-ad
614 i
/etc
/10.173.8.1-resolv/stub-resolv.conf
<<'EOF'
615 nameserver 10.173.8.1
616 options edns0 trust-ad
619 # this is just a bug fix for trisquel.
620 f
=/etc
/apparmor.d
/usr.sbin.unbound
621 line
="/usr/sbin/unbound flags=(attach_disconnected) {"
622 if ! grep -qFx "$line" $f; then
623 badline
="/usr/sbin/unbound {"
624 if ! grep -qFx "$badline" $f; then
625 err expected line
in $f not found
627 sed -i "s,^$badline$,$line," $f
628 if systemctl is-active apparmor
&>/dev
/null
; then
629 m systemctl reload apparmor
633 # note: anything added to nn_progs needs corresponding rm
634 # down below in the host switch
637 # Note dovecots lmtp doesnt need to be in the same nn to accept delivery.
638 # Its in the nn so remote clients can connect to it.
639 nn_progs
+=(spamassassin dovecot
)
644 i
/etc
/systemd
/system
/unbound.service.d
/nn.conf
<<EOF
647 JoinsNamespaceOf=mailnn.service
648 BindsTo=mailnn.service
649 StartLimitIntervalSec=0
653 # note the nsswitch bind is actually not needed for bk, but
654 # its the same file so it does no harm.
661 # sooo, there are a few ways to get traffic from the mail network
662 # namespace to go over the wghole.
664 #1: unify the mail vpn and wghole
665 # into 1 network. this seems simple and logical, so I'm doing it.
666 # One general downside is tying things together, if I need to mess
667 # with one thing, it breaks the other. Oh well for now.
669 # 2. We can route 10.5.3.0/24 out of the mail nn and nat it into wghole.
671 # 3. We can setup the routing to happen on li, which seemed like I
672 # just needed to add 10.8.0.4/24 to AllowedIPs in at least the
673 # wghole clients, but I think that is kind of hacky and breaks ipv4
674 # routing within the mailvpn, it happened to work just because exim
675 # prefers ipv6 and that was also available in the mailvpn.
677 # 4. Put the hole interface into the mail network namespace. This
678 # doesn't work if the mail vpn is wg. For openvpn, it bypasses the
679 # vpn routing and establishes a direct connection. I only use the
680 # hole vpn for randomish things, it should be fine to join the mail
681 # nn for that. There should be some way to fix the routing issue
682 # by doing manual routing, but that doesn't seem like a good use of time.
684 # https://www.wireguard.com/netns/#
686 # for wireguard debugging
687 # echo module wireguard +p > /sys/kernel/debug/dynamic_debug/control
692 for unit
in ${nn_progs[@]}; do
693 i
/etc
/systemd
/system
/$unit.service.d
/nn.conf
<<EOF
695 # commented for old openvpn
697 After=network.target mailnn.service $vpnser
698 JoinsNamespaceOf=mailnn.service
699 BindsTo=mailnn.service
700 StartLimitIntervalSec=0
704 # note the nsswitch bind is actually not needed for bk, but
705 # its the same file so it does no harm.
714 for unit
in exim4 spamassassin dovecot unbound
; do
715 f
=/etc
/systemd
/system
/$unit.service.d
/nn.conf
724 # * spamassassin config
725 i
/etc
/sysctl.d
/80-iank-mail.conf
<<'EOF'
727 net.netfilter.nf_conntrack_tcp_timeout_close_wait = 120
733 i
/etc
/spamassassin
/mylocal.cf
<<'EOF'
734 # this is mylocal.cf because the normal local.cf has a bunch of upstream stuff i dont want to mess with
736 # /usr/share/doc/exim4-base/README.Debian.gz:
737 # SpamAssassin's default report should not be used in a add_header
738 # statement since it contains empty lines. (This triggers e.g. Amavis'
739 # warning "BAD HEADER SECTION, Improper folded header field made up
740 # entirely of whitespace".) This is a safe, terse alternative:
741 clear_report_template
742 report (_SCORE_ / _REQD_ requ) _TESTSSCORES(,)_ autolearn=_AUTOLEARN
743 uridnsbl_skip_domain iankelling.org
744 uridnsbl_skip_domain amnimal.ninja
745 uridnsbl_skip_domain expertpathologyreview.com
746 uridnsbl_skip_domain zroe.org
749 # 2020-10-19 remove old file. remove this when all hosts updated
750 rm -fv /etc
/systemd
/system
/spamddnsfix.
{timer
,service
}
752 i
/etc
/default
/spamassassin
<<'EOF'
753 # defaults plus debugging flags for an issue im having
754 OPTIONS="--create-prefs --max-children 5 --helper-home-dir"
755 PIDFILE="/var/run/spamd.pid"
757 NICE="--nicelevel 15"
760 ##### end spamassassin config
764 if [[ -e /p
/c
/filesystem
]]; then
765 # note, man openvpn implies we could just call mail-route on vpn startup/shutdown with
766 # systemd, buuut it can remake the tun device unexpectedly, i got this in the log
767 # after my internet was down for a bit:
768 # NOTE: Pulled options changed on restart, will need to close and reopen TUN/TAP device.
769 m
/a
/exe
/vpn-mk-client-cert
-b mailclient
-n mail li.iankelling.org
773 if [[ ! -e /etc
/openvpn
/client
/mail.conf
]]; then
774 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
780 m rsync
-aiSAX --chown=root
:root
--chmod=g-s
/a
/bin
/ds
/mail-cert-cron
/usr
/local
/bin
782 i
/etc
/systemd
/system
/mailcert.service
<<'EOF'
784 Description=Mail cert rsync
785 After=multi-user.target
789 ExecStart=/usr/local/bin/sysd-mail-once mailcert /usr/local/bin/mail-cert-cron
791 i
/etc
/systemd
/system
/mailcert.timer
<<'EOF'
793 Description=Run mail-cert once a day
799 WantedBy=timers.target
803 wghost
=${HOSTNAME}wg.b8.nz
804 if $bhost_t && [[ ! -e /etc
/exim
4/certs
/$wghost/privkey.pem
]]; then
805 certbot
-n --manual-public-ip-logging-ok --eff-email --agree-tos -m letsencrypt@iankelling.org \
806 certonly
--manual --preferred-challenges=dns \
807 --manual-auth-hook /a
/bin
/ds
/le-dns-challenge \
808 --manual-cleanup-hook /a
/bin
/ds
/le-dns-challenge-cleanup \
809 --deploy-hook /a
/bin
/ds
/le-exim-deploy
-d $wghost
812 # * common exim4 config
815 # Make all system users be aliases. preventative
816 # measure for things like cron mail for user without alias
817 awk 'BEGIN { FS = ":" } ; $6 !~ /^\/home/ { print $1 }' /etc
/passwd|
while read -r user
; do
818 if [[ ! $user ]]; then
821 if ! grep -q "^$user:" /etc
/aliases
; then
822 echo "$user: root" |m
tee -a /etc
/aliases
826 if ! grep -q "^ncsoft:" /etc
/aliases
; then
827 echo "ncsoft: graceq2323@gmail.com" |m
tee -a /etc
/aliases
832 m gpasswd
-a iank adm
#needed for reading logs
834 ### make local bounces go to normal maildir
835 # local mail that bounces goes to /Maildir or /root/Maildir
836 dirs=(/m
/md
/bounces
/{cur
,tmp
,new
})
837 m mkdir
-p ${dirs[@]}
838 m chown iank
:iank
/m
/m
/md
839 m
ln -sfT /m
/md
/m
/iank
841 m chown
-R $u:Debian-exim
/m
/md
/bounces
842 m
chmod 775 ${dirs[@]}
843 m usermod
-a -G Debian-exim
$u
844 for d
in /Maildir
/root
/Maildir
; do
845 if [[ ! -L $d ]]; then
848 m
ln -sf -T /m
/md
/bounces
$d
851 # dkim, client passwd file
852 files
=(/p
/c
/machine_specific
/$HOSTNAME/filesystem
/etc
/exim
4/*)
853 f
=/p
/c
/filesystem
/etc
/exim
4/passwd.client
857 if (( ${#files[@]} )); then
858 m rsync
-ahhi --chown=root
:Debian-exim
--chmod=0640 \
859 ${files[@]} /etc
/exim4
862 # by default, only 10 days of logs are kept. increase that.
863 m
sed -ri 's/^(\s*rotate\s).*/\11000/' /etc
/logrotate.d
/exim4-base
866 ## https://blog.dhampir.no/content/make-exim4-on-debian-respect-forward-and-etcaliases-when-using-a-smarthost
867 # i only need .forwards, so just doing that one.
868 cd /etc
/exim
4/conf.d
/router
869 b
=userforward_higher_priority
870 # replace the router name so it is unique
871 sed -r s
/^
\\S
+:/$b:/ 600_exim4-config_userforward
>175_
$b
873 # todo, consider 'separate' in etc/exim4.conf, could it help on busy systems?
875 # alerts is basically the postmaster address
876 m
sed -i --follow-symlinks -f - /etc
/aliases
<<EOF
877 \$a root: alerts@iankelling.org
881 cat >/etc
/exim
4/conf.d
/rewrite
/34_iank_rewriting
<<'EOF'
882 ncsoft@zroe.org graceq2323@gmail.com hE
886 rm -fv /etc
/exim
4/conf.d
/retry
/37_retry
888 cat >/etc
/exim
4/conf.d
/retry
/17_retry
<<'EOF'
889 # Retry fast for my own domains
890 iankelling.org * F,1d,10m;F,14d,1h
891 amnimal.ninja * F,1d,10m;F,14d,1h
892 expertpathologyreview.com * F,1d,10m;F,14d,1h
893 je.b8.nz * F,1d,10m;F,14d,1h
894 zroe.org * F,1d,10m;F,14d,1h
895 eximbackup.b8.nz * F,1d,4m;F,14d,1h
899 rm -vf /etc
/exim
4/conf.d
/main
/000_localmacros
# old filename
900 cat >/etc
/exim
4/conf.d
/main
/000_local
<<EOF
901 MAIN_TLS_ENABLE = true
903 # require tls connections for all smarthosts
904 REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS = *
906 # debian exim config added this in 2016 or so?
907 # it's part of the smtp spec, to limit lines to 998 chars
908 # but a fair amount of legit mail does not adhere to it. I don't think
909 # this should be default, like it says in
910 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=828801
911 # todo: the bug for introducing this was about headers, but
912 # the fix maybe is for all lines? one says gmail rejects, the
913 # other says gmail does not reject. figure out and open a new bug.
914 IGNORE_SMTP_LINE_LENGTH_LIMIT = true
917 MAIN_LOG_SELECTOR = +all
919 # Based on spec, seems like a good idea to be nice.
920 smtp_return_error_details = true
922 # normally empty, I set this so I can set the envelope address
923 # when doing mail redelivery to invoke filters. Also allows
924 # me exiqgrep and stuff.
925 MAIN_TRUSTED_GROUPS = $u
927 # default is 10. when exim has been down for a bit, fsf mailserver
928 # will do a big send in one connection, then exim decides to put
929 # the messages in the queue instead of delivering them, to avoid
930 # spawning too many delivery processes. This is the same as the
931 # fsfs value. And the corresponding one for how many messages
932 # to send out in 1 connection remote_max_parallel = 256
933 smtp_accept_queue_per_connection = 500
940 # https://debian-administration.org/article/718/DKIM-signing_outgoing_mail_with_exim4
941 # and its best for this to align https://tools.ietf.org/html/rfc7489#page-8
942 # There could be some circumstance when the
943 # from: isnt our domain, but the envelope sender is
944 # and so still want to sign, but I cant think of any case.
945 DKIM_DOMAIN = \${lc:\${domain:\$rh_from:}}
946 # The file is based on the outgoing domain-name in the from-header.
948 DKIM_PRIVATE_KEY = \${if exists{/etc/exim4/\${dkim_domain}-private.pem} {/etc/exim4/\${dkim_domain}-private.pem}}
950 # most of the ones that gmail seems to use.
951 # Exim has horrible default of signing unincluded
952 # list- headers since they got mentioned in an
953 # rfc, but this messes up mailing lists, like gnu/debian which want to
954 # keep your dkim signature intact but add list- headers.
955 DKIM_SIGN_HEADERS = mime-version:in-reply-to:references:from:date:subject:to
957 domainlist local_hostnames = ! je.b8.nz : ! bk.b8.nz : *.b8.nz : b8.nz
959 hostlist iank_trusted = <; \\
963 72.14.176.105 ; 2600:3c00::f03c:91ff:fe6d:baf8 ; \\
964 # li_vpn_net li_vpn_net_ip6s
965 10.8.0.0/24; 2600:3c00:e000:280::/64 ; 2600:3c00:e002:3800::/56 ; \\
967 85.119.83.50 ; 2001:ba8:1f1:f0c9::2 ; \\
969 85.119.82.128 ; 2001:ba8:1f1:f09d::2 ; \\
970 # fsf_mit_net fsf_mit_net_ip6 fsf_net fsf_net_ip6 fsf_office_net
971 18.4.89.0/24 ; 2603:3005:71a:2e00::/64 ; 209.51.188.0/24 ; 2001:470:142::/48 ; 74.94.156.208/28
974 rm -fv /etc
/exim
4/rcpt_local_acl
# old path
976 i
/etc
/exim
4/conf.d
/local_deny_exceptions_acl
<<'EOF'
977 # This acl already exists in rcpt, this just makes it more widespread.
978 # See the comment there for its rationale. The reason it needs to be
979 # more widespread is that I've turned on sender verification, but cron
980 # emails can fail sender verification since I may be in a network that
981 # doesn't have my local dns.
985 # i setup a local programs smtp to mail.iankelling.org, this
986 # skips sender verification for it.
991 rm -fv /etc
/exim
4/data_local_acl
# old path
992 i
/etc
/exim
4/conf.d
/data_local_acl
<<'EOF'
993 # Except for the "condition =", this was
994 # a comment in the check_data acl. The comment about this not
995 # being suitable has been changed in newer exim versions. The only thing
996 # related I found was to
997 # add the condition =, cuz spamassassin has problems with big
998 # messages and spammers don't bother with big messages,
999 # but I've increased the size from 10k
1000 # suggested in official docs, and 100k in the wiki example because
1001 # those docs are rather old and I see a 110k spam message
1002 # pretty quickly looking through my spam folder.
1005 !hosts = +iank_trusted
1006 remove_header = X-Spam_score: X-Spam_score_int : X-Spam_bar : X-Spam_report
1009 !hosts = +iank_trusted
1010 condition = ${if < {$message_size}{5000K}}
1011 spam = Debian-exim:true
1012 add_header = X-Spam_score_int: $spam_score_int
1013 add_header = X-Spam_score: $spam_score
1014 add_header = X-Spam_bar: $spam_bar
1015 add_header = X-Spam_report: $spam_report
1016 add_header = X-Spam_action: $spam_action
1019 condition = ${if def:malware_name}
1020 remove_header = Subject:
1021 add_header = Subject: [Clamav warning: $malware_name] $h_subject
1022 log_message = heuristic malware warning: $malware_name
1025 # spf = pass:fail:softfail:none:neutral:permerror:temperror
1026 # dmarc_status = reject:quarantine
1027 # add_header = Reply-to: dmarctest@iankelling.org
1031 i
/etc
/exim
4/conf.d
/router
/900_exim4-config_local_user
<<EOF
1032 ### router/900_exim4-config_local_user
1033 #################################
1035 # This router matches local user mailboxes. If the router fails, the error
1036 # message is "Unknown user".
1038 debug_print = "R: local_user for \$local_part@\$domain"
1040 domains = +local_domains
1041 # ian: default file except where mentioned.
1042 # ian: commented this. I get all local parts. for bk, an rcpt
1043 # check handles checking with dovecot, and the only router
1044 # after this is root.
1045 # local_parts = ! root
1046 transport = LOCAL_DELIVERY
1047 cannot_route_message = Unknown user
1048 # ian: added for + addressing.
1049 local_part_suffix = +*
1050 local_part_suffix_optional
1052 i
/etc
/exim
4/conf.d
/transport
/30_exim4-config_dovecot_lmtp
<<'EOF'
1055 socket = /var/run/dovecot/lmtp
1056 #maximum number of deliveries per batch, default 1
1061 i
/etc
/exim
4/conf.d
/transport
/30_remote_smtp_vpn
<<'EOF'
1062 # same as debians 30_exim4-config_remote_smtp, but
1063 # with interface added at the end.
1066 debug_print = "T: remote_smtp_vpn for $local_part@$domain"
1068 .ifndef IGNORE_SMTP_LINE_LENGTH_LIMIT
1069 message_size_limit = ${if > {$max_received_linelength}{998} {1}{0}}
1071 .ifdef REMOTE_SMTP_HOSTS_AVOID_TLS
1072 hosts_avoid_tls = REMOTE_SMTP_HOSTS_AVOID_TLS
1074 .ifdef REMOTE_SMTP_HEADERS_REWRITE
1075 headers_rewrite = REMOTE_SMTP_HEADERS_REWRITE
1077 .ifdef REMOTE_SMTP_RETURN_PATH
1078 return_path = REMOTE_SMTP_RETURN_PATH
1080 .ifdef REMOTE_SMTP_HELO_DATA
1081 helo_data=REMOTE_SMTP_HELO_DATA
1084 dkim_domain = DKIM_DOMAIN
1086 .ifdef DKIM_SELECTOR
1087 dkim_selector = DKIM_SELECTOR
1089 .ifdef DKIM_PRIVATE_KEY
1090 dkim_private_key = DKIM_PRIVATE_KEY
1093 dkim_canon = DKIM_CANON
1096 dkim_strict = DKIM_STRICT
1098 .ifdef DKIM_SIGN_HEADERS
1099 dkim_sign_headers = DKIM_SIGN_HEADERS
1101 .ifdef TLS_DH_MIN_BITS
1102 tls_dh_min_bits = TLS_DH_MIN_BITS
1104 .ifdef REMOTE_SMTP_TLS_CERTIFICATE
1105 tls_certificate = REMOTE_SMTP_TLS_CERTIFICATE
1107 .ifdef REMOTE_SMTP_PRIVATEKEY
1108 tls_privatekey = REMOTE_SMTP_PRIVATEKEY
1110 .ifdef REMOTE_SMTP_HOSTS_REQUIRE_TLS
1111 hosts_require_tls = REMOTE_SMTP_HOSTS_REQUIRE_TLS
1113 .ifdef REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
1114 headers_remove = REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
1116 interface = <; 10.8.0.4 ; 2600:3c00:e002:3800::4
1119 i
/etc
/exim
4/conf.d
/transport
/30_smarthost_dkim
<<'EOF'
1120 # ian: this is remote_smtp_smarthost plus the dkim parts from remote_smtp
1123 debug_print = "T: remote_smtp_smarthost for $local_part@$domain"
1126 .ifndef IGNORE_SMTP_LINE_LENGTH_LIMIT
1127 message_size_limit = ${if > {$max_received_linelength}{998} {1}{0}}
1129 hosts_try_auth = <; ${if exists{CONFDIR/passwd.client} \
1131 ${lookup{$host}nwildlsearch{CONFDIR/passwd.client}{$host_address}}\
1135 .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
1136 hosts_avoid_tls = REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
1138 .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS
1139 hosts_require_tls = REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS
1141 .ifdef REMOTE_SMTP_SMARTHOST_TLS_VERIFY_CERTIFICATES
1142 tls_verify_certificates = REMOTE_SMTP_SMARTHOST_TLS_VERIFY_CERTIFICATES
1144 .ifdef REMOTE_SMTP_SMARTHOST_TLS_VERIFY_HOSTS
1145 tls_verify_hosts = REMOTE_SMTP_SMARTHOST_TLS_VERIFY_HOST
1147 .ifdef REMOTE_SMTP_HEADERS_REWRITE
1148 headers_rewrite = REMOTE_SMTP_HEADERS_REWRITE
1150 .ifdef REMOTE_SMTP_RETURN_PATH
1151 return_path = REMOTE_SMTP_RETURN_PATH
1153 .ifdef REMOTE_SMTP_HELO_DATA
1154 helo_data=REMOTE_SMTP_HELO_DATA
1156 .ifdef TLS_DH_MIN_BITS
1157 tls_dh_min_bits = TLS_DH_MIN_BITS
1159 .ifdef REMOTE_SMTP_SMARTHOST_TLS_CERTIFICATE
1160 tls_certificate = REMOTE_SMTP_SMARTHOST_TLS_CERTIFICATE
1162 .ifdef REMOTE_SMTP_SMARTHOST_PRIVATEKEY
1163 tls_privatekey = REMOTE_SMTP_SMARTHOST_PRIVATEKEY
1165 .ifdef REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
1166 headers_remove = REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
1169 dkim_domain = DKIM_DOMAIN
1171 .ifdef DKIM_SELECTOR
1172 dkim_selector = DKIM_SELECTOR
1174 .ifdef DKIM_PRIVATE_KEY
1175 dkim_private_key = DKIM_PRIVATE_KEY
1178 dkim_canon = DKIM_CANON
1181 dkim_strict = DKIM_STRICT
1183 .ifdef DKIM_SIGN_HEADERS
1184 dkim_sign_headers = DKIM_SIGN_HEADERS
1189 cat >/etc
/exim
4/update-exim4.conf.conf
<<'EOF'
1190 # default stuff, i havent checked if its needed
1191 dc_minimaldns='false'
1194 dc_use_split_config='true'
1195 dc_mailname_in_oh='true'
1201 if ! mountpoint
/o
; then
1202 echo "error /o is not a mountpoint" >&2
1206 # davx/davdroid setup instructions at the bottom
1209 # http://radicale.org/user_documentation/
1210 # https://davdroid.bitfire.at/configuration/
1212 # note on debugging: if radicale can't bind to the address,
1213 # in the log it just says "Starting Radicale". If you run
1214 # it in the foreground, it will give more info. Background
1215 # plus debug does not help.
1216 # sudo -u radicale radicale -D -f
1218 # created password file with:
1219 # htpasswd -c /p/c/machine_specific/li/filesystem/etc/caldav-htpasswd
1220 # chmod 640 /p/c/machine_specific/li/filesystem/etc/caldav-htpasswd
1221 # # setup chgrp www-data in ./conflink
1225 i
/etc
/systemd
/system
/radicale.service.d
/override.conf
<<EOF
1227 # this unit is configured to start and stop whenever
1230 After=network.target network-online.target mailnn.service $vpnser
1233 Wants=network-online.target
1234 JoinsNamespaceOf=mailnn.service
1235 StartLimitIntervalSec=0
1239 BindPaths=$bindpaths
1241 # time to sleep before restarting a service
1250 # use persistent uid/gid
1251 IFS
=:; read -r _ _ uid _
< <(getent passwd radicale
); unset IFS
1252 IFS
=:; read -r _ _ gid _
< <(getent group radicale
); unset IFS
1253 if [[ $uid != 609 ]]; then
1254 m systemctl stop radicale ||
:
1255 m usermod
-u 609 radicale
1256 m groupmod
-g 609 radicale
1257 m usermod
-g 609 radicale
1259 m
find /o
/radicale
-xdev -exec chown
-h 609 {} +
1260 m
find /o
/radicale
-xdev -exec chgrp
-h 609 {} +
1263 # I moved /var/lib/radicale after it's initialization.
1264 # I did a sudo -u radicale git init in the collections subfolder
1265 # after it gets created, per the git docs.
1266 m
/a
/exe
/lnf
-T /o
/radicale
/var
/lib
/radicale
1268 # from https://www.williamjbowman.com/blog/2015/07/24/setting-up-webdav-caldav-and-carddav-servers/
1270 # more config is for li in distro-end
1272 # coment in this file says this is needed for it to run on startup
1273 sed -ri 's/^\s*#+\s*(ENABLE_RADICALE\s*=\s*yes\s*)/\1/' /etc
/default
/radicale
1275 # comments say default is 0.0.0.0:5232
1276 m setini hosts
10.8.0.4:5232 server
1277 # https://radicale.org/2.1.html
1278 m setini
type http_x_remote_user auth
1281 # disable power management feature, set to 240 min sync interval,
1282 # so it shouldn't be bad.
1284 # davdroid from f-druid.
1285 # login with url and user name
1286 # url https://cal.iankelling.org/ian
1288 # pass, see password manager for radicale
1290 # add account dialog:
1292 # set account name as ian@iankelling.org, per help text below the
1295 # switch to groups are per-contact categories,
1296 # per https://davdroid.bitfire.at/configuration/radicale/
1299 # After setting up account, I added one address book, named
1300 # ianaddr. calender was already created, named ian. checked boxes under
1303 # To restore from old phone to new phone, I wiped all data out, then copied over the newly created files. I think
1305 # ignorable background info:
1307 # opentasks uses the calendar file.
1309 # The address book I created got a uuid as a name for the file. Note
1310 # the .props file says if it's a calendar or addressbook.
1312 # When debugging, tailed /var/log/radicale/radicale.log and apache log,
1313 # both show the requests happening. Without creating the address book,
1314 # after creating a contact, a sync would delete it.
1316 # Address books correspond to .props files in the radicale dir.
1318 # Some background is here,
1319 # https://davdroid.bitfire.at/faq/entry/cant-manage-groups-on-device/
1320 # which shows separate vcard option is from rfc 6350, the other is 2426,
1321 # radicale page says it implements the former not the latter,
1322 # which conflicts with the documentation of which to select, but whatever.
1323 # http://radicale.org/technical_choices/
1324 # https://davdroid.bitfire.at/faq/entry/cant-manage-groups-on-device/
1326 # Note, url above says only cayanogenmod 13+ and omnirom can manage groups.
1328 # Note, radicale had built-in git support to track changes, but they
1329 # removed it in 2.0.
1335 # ** $MAIL_HOST|bk|je)
1338 # based on a little google and package search, just the dovecot
1339 # packages we need instead of dovecot-common.
1341 # dovecot-lmtpd is for exim to deliver to dovecot instead of maildir
1342 # directly. The reason to do this is to use dovecot\'s sieve, which
1343 # can generally do more than exims filters (a few things less) and
1344 # sieve has the benefit of being supported in postfix and
1345 # proprietary/weird environments, so there is more examples on the
1347 pi dovecot-core dovecot-imapd dovecot-sieve dovecot-lmtpd dovecot-sqlite sqlite3
1349 for f
in /p
/c
{/machine_specific
/$HOSTNAME,}/filesystem
/etc
/dovecot
/users
; do
1350 if [[ -e $f ]]; then
1351 m rsync
-ahhi --chown=root
:dovecot
--chmod=0640 $f /etc
/dovecot
/
1355 for f
in /p
/c
/subdir_files
/sieve
/*sieve
/a
/c
/subdir_files
/sieve
/*sieve
; do
1356 m sudo
-u $u /a
/exe
/lnf
-T $f $uhome/sieve
/${f##*/}
1359 # https://wiki.dovecot.org/SSL/DovecotConfiguration
1360 i
/etc
/dovecot
/dhparam
<<'EOF'
1361 -----BEGIN DH PARAMETERS-----
1362 MIIBCAKCAQEAoleil6SBxGqQKk7j0y2vV3Oklv6XupZKn7PkPv485QuFeFagifeS
1363 A+Jz6Wquqk5zhGyCu63Hp4wzGs4TyQqoLjkaWL6Ra/Bw3g3ofPEzMGEsV1Qdqde4
1364 jorwiwtr2i9E6TXQp0noT/7VFeHulIkayTeW8JulINdMHs+oLylv16McGCIrxbkM
1365 8D1PuO0TP/CNDs2QbRvJ1RjY3CeGpxMhrSHVgBCUMwnA2cvz3bYjI7UMYMMDPNrE
1366 PLrwsYzXGGCdJsO2vsmmqqgLsZiapYJlUNjfiyWLt7E2H6WzkNB3VIhIPfLqFDPK
1367 xioE3sYKdjOt+p6mlg3l8+OLtODEFPHDqwIBAg==
1368 -----END DH PARAMETERS-----
1371 if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
1373 ssl_cert = </etc/exim4/fullchain.pem
1374 ssl_key = </etc/exim4/privkey.pem
1378 ssl_cert = </etc/exim4/exim.crt
1379 ssl_key = </etc/exim4/exim.key
1383 # https://ssl-config.mozilla.org
1385 # this is the same as the certbot list, in my cert cronjob, I check if that has changed upstream.
1386 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
1387 ssl_protocols = TLSv1.2
1388 ssl_prefer_server_ciphers = no
1389 ssl_dh_parameters_length = 2048
1392 #per https://wiki2.dovecot.org/Pigeonhole/Sieve/Configuration
1393 # default is just \$mail_plugins
1394 mail_plugins = \$mail_plugins sieve
1397 if dpkg
--compare-versions $
(dpkg-query
-f='${Version}\n' --show dovecot-core
) ge
1:2.3; then
1399 ssl_dh = </etc/dovecot/dhparam
1402 } >/etc
/dovecot
/local.conf
1408 # If we changed 90-sieve.conf and removed the active part of the
1409 # sieve option, we wouldn\'t need this, but I\'d rather not modify a
1410 # default config if not needed. This won\'t work as a symlink in /a/c
1412 m sudo
-u $u /a
/exe
/lnf
-T sieve
/main.sieve
$uhome/.dovecot.sieve
1414 if [[ ! -e $uhome/sieve
/personal.sieve
]]; then
1415 m
touch $uhome/sieve
/personal
{,end
}{,test}.sieve
1418 rm -fv /etc
/dovecot
/conf.d
/20-lmtp.conf
# file from prev version
1419 cat >>/etc
/dovecot
/local.conf
<<EOF
1420 # simple password file based login
1421 !include conf.d/auth-passwdfile.conf.ext
1423 # ian: %u is used for alerts user vs iank
1424 mail_location = maildir:/m/%u:LAYOUT=fs:INBOX=/m/%u/INBOX
1429 # For a normal setup with exim, we need something like this, which
1430 # removes the domain part
1431 # auth_username_format = %Ln
1433 # or else # Exim says something like
1434 # "LMTP error after RCPT ... 550 ... User doesn't exist someuser@somedomain"
1435 # Dovecot verbose log says something like
1436 # "auth-worker(9048): passwd(someuser@somedomain): unknown user"
1437 # reference: http://wiki.dovecot.org/LMTP/Exim
1439 # However, I use this to direct all mail to the same inbox.
1440 # A normal way to do this, which I did at first is to have
1441 # a router in exim almost at the end, eg 950,
1443 # debug_print = "R: catchall for \$local_part@\$domain"
1445 # domains = +local_domains
1448 # http://blog.alteholz.eu/2015/04/exim4-and-catchall-email-address/
1449 # with superflous options removed.
1450 # However, this causes the envelope to be rewritten,
1451 # which makes filtering into mailboxes a little less robust or more complicated,
1452 # so I've done it this way instead. it also requires
1453 # modifying the local router in exim.
1454 auth_username_format = $u
1460 chown
-R mail.
mail /m
/md
1462 f
=/etc
/dovecot
/conf.d
/10-auth.conf
1463 if [[ -e $f ]]; then
1464 mv $f $f-iank-disabled
1467 cat >>/etc
/dovecot
/local.conf
<<EOF
1468 !include /etc/dovecot/local.conf.ext
1470 # for debugging info, uncomment these.
1471 # logs go to syslog and to /var/log/mail.log
1477 # This downcases the localpart. default is case sensitive.
1478 # case sensitive local part will miss out on valid email when some person or system
1479 # mistakenly capitalizes things.
1480 auth_username_format = %Lu
1483 # make 147 only listen on localhost, plan to use for nextcloud.
1484 # copied from mailinabox
1485 service imap-login {
1486 inet_listener imap {
1490 # https://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_dovecot_authenticator.html
1492 unix_listener auth-client {
1500 sieve_before = /etc/dovecot/sieve-spam.sieve
1502 sieve = /m/sieve/%d/%n.sieve
1503 sieve_dir = /m/sieve/%d/%n
1507 # all taken from mailinabox.
1508 mail_location = maildir:/m/md/%d/%n
1510 mail_privileged_group = mail
1511 # By default Dovecot allows users to log in only with UID numbers 500 and above. mail is 8
1514 # todo: test these changes in the universal config
1515 # mailboxes taken from mailinabox but removed
1516 # settings duplicate to defaults
1535 special_use = \Archive
1539 auth_mechanisms = plain login
1542 i
/etc
/dovecot
/sieve-spam.sieve
<<'EOF'
1543 require ["regex", "fileinto", "imap4flags"];
1545 if allof (header :regex "X-Spam-Status" "^Yes") {
1551 i
/etc
/dovecot
/local.conf.ext
<<'EOF'
1554 args = /etc/dovecot/dovecot-sql.conf.ext
1558 args = /etc/dovecot/dovecot-sql.conf.ext
1563 i
/etc
/dovecot
/dovecot-sql.conf.ext
<<'EOF'
1566 connect = /m/rc/users.sqlite
1567 default_pass_scheme = SHA512-CRYPT
1568 password_query = SELECT email as user, password FROM users WHERE email='%u';
1569 user_query = SELECT email AS user, "mail" as uid, "mail" as gid, "/m/md/%d/%n" as home FROM users WHERE email='%u';
1570 iterate_query = SELECT email AS user FROM users;
1572 m
chmod 0600 /etc
/dovecot
/dovecot-sql.conf.ext
# per Dovecot instructions
1574 # db needs to be in a www-data writable directory
1575 db
=/m
/rc
/users.sqlite
1576 if [[ ! -s $db ]]; then
1578 m sqlite3
$db <<'EOF'
1579 CREATE TABLE users (
1580 id INTEGER PRIMARY KEY AUTOINCREMENT,
1581 email TEXT NOT NULL UNIQUE,
1582 password TEXT NOT NULL,
1584 privileges TEXT NOT NULL DEFAULT '');
1587 # example of adding a user:
1588 # hash: doveadm pw -s SHA512-CRYPT -p passhere
1589 # sqlite3 /m/rc/users.sqlite <<'EOF'
1590 #insert into users (email, password) values ('testignore@bk.b8.nz', 'hash');
1592 # update users set password = 'hash' where email = 'testignore@bk.b8.nz';
1594 # this should be at the end since it requires a valid dovecot config
1595 m sievec
/etc
/dovecot
/sieve-spam.sieve
1599 # roundcube uses this
1601 chown
mail.
mail /m
/sieve
1602 m pi dovecot-managesieved
1606 # * thunderbird autoconfig setup
1608 bkdomains
=(expertpathologyreview.com amnimal.ninja
)
1609 if [[ $HOSTNAME == bk
]]; then
1610 for domain
in ${bkdomains[@]}; do
1611 m
/a
/exe
/web-conf apache2 autoconfig.
$domain
1612 dir
=/var
/www
/autoconfig.
$domain/html
/mail
1614 # taken from mailinabox
1615 i
$dir/config-v1.1.xml
<<EOF
1616 <?xml version="1.0" encoding="UTF-8"?>
1617 <clientConfig version="1.1">
1618 <emailProvider id="$domain">
1619 <domain>$domain</domain>
1621 <displayName>$domain Mail</displayName>
1622 <displayShortName>$domain</displayShortName>
1624 <incomingServer type="imap">
1625 <hostname>mail2.iankelling.org</hostname>
1627 <socketType>SSL</socketType>
1628 <username>%EMAILADDRESS%</username>
1629 <authentication>password-cleartext</authentication>
1632 <outgoingServer type="smtp">
1633 <hostname>mail2.iankelling.org</hostname>
1635 <socketType>STARTTLS</socketType>
1636 <username>%EMAILADDRESS%</username>
1637 <authentication>password-cleartext</authentication>
1638 <addThisServer>true</addThisServer>
1639 <useGlobalPreferredServer>false</useGlobalPreferredServer>
1642 <documentation url="https://$domain/">
1643 <descr lang="en">$domain website.</descr>
1648 <loginPage url="https://$domain/roundcube" />
1649 <loginPageInfo url="https://$domain/roundcube" >
1650 <username>%EMAILADDRESS%</username>
1651 <usernameField id="rcmloginuser" name="_user" />
1652 <passwordField id="rcmloginpwd" name="_pass" />
1653 <loginButton id="rcmloginsubmit" />
1656 <clientConfigUpdate url="https://autoconfig.$domain/mail/config-v1.1.xml" />
1664 if [[ $HOSTNAME == bk
]]; then
1666 # zip according to /installer
1667 # which requires adding a line to /usr/local/lib/roundcubemail/config/config.inc.php
1668 # $config['enable_installer'] = true;
1669 pi roundcube roundcube-sqlite3 php-zip apache2 php-fpm
1671 ### begin composer install
1672 # https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md
1674 # sum="$(wget -q -O - https://composer.github.io/installer.sig)"
1675 # m php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
1676 # if [[ $sum != $(php -r "echo hash_file('sha384', 'composer-setup.php');") ]]; then
1677 # echo 'ERROR: Invalid composer installer checksum' >&2
1678 # rm -fv composer-setup.php
1681 # m php composer-setup.php --quiet
1682 # rm -fv composer-setup.php
1683 # m mv composer.phar /usr/local/bin
1685 # the above method gets composer2, carddav plugin at least doesnt work with that
1686 # yet, it was just released 10-24-2020.
1688 m wget
-nv -N https
://getcomposer.org
/composer-1.phar
1689 chmod +x composer-1.phar
1690 ### end composer install
1692 rcdirs
=(/usr
/local
/lib
/rcexpertpath
/usr
/local
/lib
/rcninja
)
1693 ncdirs
=(/var
/www
/ncexpertpath
/var
/www
/ncninja
)
1694 # point debian cronjob to our local install, preventing daily cron error
1696 # debian's cronjob will fail, remove both paths it uses just to be sure
1697 rm -fv /usr
/share
/roundcube
/bin
/cleandb.sh
/etc
/cron.d
/roundcube-core
1699 #### begin dl roundcube
1700 # note, im r2e subbed to https://github.com/roundcube/roundcubemail/releases.atom
1701 v
=1.4.11; f
=roundcubemail-
$v-complete.
tar.gz
1703 if [[ -e $f ]]; then
1704 timestamp
=$
(stat
-c %Y
$f)
1708 m wget
-nv -N https
://github.com
/roundcube
/roundcubemail
/releases
/download
/$v/$f
1709 new_timestamp
=$
(stat
-c %Y
$f)
1710 for rcdir
in ${rcdirs[@]}; do
1711 if [[ $timestamp != "$new_timestamp" ||
! -e "$rcdir/config/secret" ]]; then
1712 m
tar -C /usr
/local
/lib
--no-same-owner -zxf $f
1714 m
mv /usr
/local
/lib
/roundcubemail-
$v $rcdir
1717 #### end dl roundcube
1719 for ((i
=0; i
< ${#bkdomains[@]}; i
++)); do
1720 domain
=${bkdomains[i]}
1725 # copied from debians cronjob
1726 i
/etc
/cron.d
/$rcbase <<EOF
1727 # Roundcube database cleaning: finally removes all records that are
1728 # marked as deleted.
1729 0 5 * * * www-data $rcdir/bin/cleandb.sh >/dev/null
1732 m
/a
/exe
/web-conf
- apache2
$domain <<EOF
1733 Alias /roundcube $rcdir
1734 ### begin roundcube settings
1735 # taken from /etc/apache2/conf-available/roundcube.conf version 1.4.8+dfsg.1-1~bpo10+1
1737 Options +FollowSymLinks
1738 # This is needed to parse $rcdir/.htaccess.
1742 # Protecting basic directories:
1743 <Directory $rcdir/config>
1744 Options -FollowSymLinks
1747 ### end roundcube settings
1750 ### begin nextcloud settings
1751 Alias /nextcloud "$ncdir/"
1755 Options FollowSymLinks MultiViews
1757 <IfModule mod_dav.c>
1763 # based on install checker, links to
1764 # https://docs.nextcloud.com/server/19/admin_manual/issues/general_troubleshooting.html#service-discovery
1765 # their example was a bit wrong, I figured it out by adding
1766 # LogLevel warn rewrite:trace5
1767 # then watching the apache logs
1770 RewriteRule ^/\.well-known/host-meta /nextcloud/public.php?service=host-meta [QSA,L]
1771 RewriteRule ^/\.well-known/host-meta\.json /nextcloud/public.php?service=host-meta-json [QSA,L]
1772 RewriteRule ^/\.well-known/webfinger /nextcloud/public.php?service=webfinger [QSA,L]
1773 RewriteRule ^/\.well-known/carddav /nextcloud/remote.php/dav/ [R=301,L]
1774 RewriteRule ^/\.well-known/caldav /nextcloud/remote.php/dav/ [R=301,L]
1775 ### end nextcloud settings
1777 if [[ ! -e $rcdir/config
/secret
]]; then
1778 base64
</dev
/urandom |
head -c24 >$rcdir/config
/secret ||
[[ $?
== 141 ||
${PIPESTATUS[0]} == 32 ]]
1780 secret
=$
(cat $rcdir/config
/secret
)
1782 rclogdir
=/var
/log
/$rcbase
1783 rctmpdir
=/var
/tmp
/$rcbase
1784 rcdb
=/m
/rc
/$rcbase.sqlite
1785 # config from mailinabox
1786 i
$rcdir/config
/config.inc.php
<<EOF
1789 # debian creates this for us
1790 \$config['log_dir'] = '$rclogdir/';
1791 # debian also creates a temp dir, but it is under its install dir,
1792 # seems better to have our own.
1793 \$config['temp_dir'] = '$rctmpdir/';
1794 \$config['db_dsnw'] = 'sqlite:///$rcdb?mode=0640';
1795 \$config['default_host'] = 'ssl://localhost';
1796 \$config['default_port'] = 993;
1797 \$config['imap_conn_options'] = array(
1799 'verify_peer' => false,
1800 'verify_peer_name' => false,
1803 \$config['imap_timeout'] = 15;
1804 \$config['smtp_server'] = 'tls://127.0.0.1';
1805 \$config['smtp_conn_options'] = array(
1807 'verify_peer' => false,
1808 'verify_peer_name' => false,
1811 \$config['product_name'] = 'webmail';
1812 \$config['des_key'] = '$secret';
1813 \$config['plugins'] = array('archive', 'zipdownload', 'password', 'managesieve', 'jqueryui', 'carddav', 'html5_notifier');
1814 \$config['skin'] = 'elastic';
1815 \$config['login_autocomplete'] = 2;
1816 \$config['password_charset'] = 'UTF-8';
1817 \$config['junk_mbox'] = 'Spam';
1818 # disable builtin addressbook
1819 \$config['address_book_type'] = '';
1823 m mkdir
-p $rclogdir
1824 m
chmod 750 $rclogdir
1825 m chown www-data
:adm
$rclogdir
1826 # note: subscribed to updates:
1827 # r2e add rcmcarddav https://github.com/blind-coder/rcmcarddav/commits/master.atom ian@iankelling.org
1828 # r2e add roundcube https://github.com/roundcube/roundcubemail/releases.atom ian@iankelling.org
1829 m mkdir
-p $rctmpdir /m
/rc
1830 m chown
-R www-data.www-data
$rctmpdir /m
/rc
1831 m
chmod 750 $rctmpdir
1832 # Ensure the log file monitored by fail2ban exists, or else fail2ban can't start.
1833 # todo: setup fail2ban
1834 # todo: check for other mailinabox things
1835 m sudo
-u www-data
touch $rclogdir/errors.log
1837 #### begin carddav install
1838 # This is the official roundcube carddav repo.
1839 # Install doc suggests downloading with composer, but that
1840 # didnt work, it said some ldap package for roundcube was missing,
1841 # but I dont want to download some extra ldap thing.
1842 # https://github.com/blind-coder/rcmcarddav/blob/master/doc/INSTALL.md
1843 verf
=$rcdir/plugins
/carddav
/myversion
1847 if [[ -e $verf ]]; then
1848 if [[ $
(cat $verf) != "$v" ]]; then
1856 m
rm -rf $rcdir/plugins
/carddav
1858 m wget
-nv -O $tmpd/t.tgz https
://github.com
/blind-coder
/rcmcarddav
/releases
/download
/v
$v/carddav-v
$v.tgz
1862 m chown
-R www-data
:www-data
$rcdir/plugins
/carddav
1863 m
cd $rcdir/plugins
/carddav
1865 m sudo
-u www-data composer-1.phar update
--no-dev
1867 m sudo
-u www-data composer-1.phar
install --no-dev
1869 m chown
-R root
:root
$rcdir/plugins
/carddav
1873 # So, strangely, this worked in initial testing, but then
1874 # on first run it wouldn't show the existing contacts until
1875 # I went into the carddav settings and did "force immediate sync",
1876 # which seemed to fix things. Note, some of these settings
1877 # get initalized per/addressbook in the db, then need changing
1878 # there or through the settings menu.
1880 # About categories, see https://www.davx5.com/tested-with/nextcloud
1881 # https://github.com/blind-coder/rcmcarddav/blob/master/doc/GROUPS.md
1882 i
$rcdir/plugins
/carddav
/config.inc.php
<<EOF;
1884 \$prefs['_GLOBAL']['hide_preferences'] = false;
1885 \$prefs['davserver'] = array(
1886 # name in the UI is kind of dumb. This is just something short that seems to fit ok.
1888 'username' => '%u', // login username
1889 'password' => '%p', // login password
1890 'url' => 'https://$domain/nextcloud/remote.php/dav/addressbooks/users/%u/contacts',
1892 'readonly' => false,
1893 'refresh_time' => '00:10:00',
1894 'fixed' => array('username','password'),
1895 'use_categories' => false,
1900 #### end carddav install
1903 if [[ ! -d html5_notifier
]]; then
1904 m git clone https
://github.com
/stremlau
/html5_notifier
1906 cd $rcdir/plugins
/html5_notifier
1909 # todo: try out roundcube plugins: thunderbird labels
1911 # Password changing plugin settings
1912 cat $rcdir/plugins
/password
/config.inc.php.dist
- >$rcdir/plugins
/password
/config.inc.php
<<'EOF'
1913 # following are from mailinabox
1914 $config['password_minimum_length'] = 8;
1915 $config['password_db_dsn'] = 'sqlite:////m/rc/users.sqlite';
1916 $config['password_query'] = 'UPDATE users SET password=%D WHERE email=%u';
1917 $config['password_dovecotpw'] = '/usr/bin/doveadm pw';
1918 $config['password_dovecotpw_method'] = 'SHA512-CRYPT';
1919 $config['password_dovecotpw_with_method'] = true;
1921 # so PHP can use doveadm, for the password changing plugin
1922 m usermod
-a -G dovecot www-data
1923 m usermod
-a -G mail $u
1925 # so php can update passwords
1926 m chown www-data
:dovecot
/m
/rc
/users.sqlite
1927 m
chmod 664 /m
/rc
/users.sqlite
1929 # Run Roundcube database migration script (database is created if it does not exist)
1930 m
$rcdir/bin
/updatedb.sh
--dir $rcdir/SQL
--package roundcube
1931 m chown www-data
:www-data
$rcdb
1933 done # end loop over domains and rcdirs
1935 ### begin php setup for rc ###
1936 # Enable PHP modules.
1937 m phpenmod
-v php mcrypt imap
1938 # dpkg says this is required
1939 m a2enmod proxy_fcgi setenvif
1940 fpm
=$
(dpkg-query
-s php-fpm |
sed -nr 's/^Depends:.* (php[^ ]*-fpm)( .*|$)/\1/p') # eg: php7.3-fpm
1941 phpver
=$
(dpkg-query
-s php-fpm |
sed -nr 's/^Depends:.* php([^ ]*)-fpm( .*|$)/\1/p')
1943 # 3 useless guides on php fpm fcgi debian 10 later, i figure out from reading
1944 # /etc/apache2/conf-enabled/php7.3-fpm.conf
1945 m a2dismod php
$phpver
1946 # according to /install, we should set date.timezone,
1947 # but that is dumb, the system already has the right zone in
1948 # $rclogdir/errors.log
1949 # todo: consider other settings in
1950 # /a/opt/mailinabox/setup/nextcloud.sh
1951 i
/etc
/php
/$phpver/cli
/conf.d
/30-local.ini
<<'EOF'
1955 i
/etc
/php
/$phpver/fpm
/conf.d
/30-local.ini
<<'EOF'
1956 date.timezone = "America/New_York"
1958 upload_max_filesize = 2000M
1959 post_max_size = 2000M
1960 # install checker, nextcloud/settings/admin/overview
1963 m systemctl restart
$fpm
1964 # dunno if reload/restart is needed
1965 m systemctl reload apache2
1966 # note bk backups are defined in crontab outside this file
1967 ### end php setup for rc ###
1969 fi # end roundcube setup
1973 if [[ $HOSTNAME == bk
]]; then
1974 # from install checker, nextcloud/settings/admin/overview and
1975 # https://docs.nextcloud.com/server/19/admin_manual/installation/source_installation.html
1976 # curl from the web installer requirement, but i switched to cli
1977 # it recommends php-file info, but that is part of php7.3-common, already got installed
1979 m pi php-curl php-bz2 php-gmp php-bcmath php-imagick php-apcu
1981 # https://docs.nextcloud.com/server/19/admin_manual/installation/source_installation.html
1982 cat >/etc
/php
/$phpver/fpm
/pool.d
/localwww.conf
<<'EOF'
1987 for ((i
=0; i
< ${#bkdomains[@]}; i
++)); do
1988 domain
=${bkdomains[i]}
1992 if [[ ! -e $ncdir/index.php
]]; then
1993 # if we wanted to only install a specific version, use something like
1994 # file=latest-22.zip
1996 m wget
-nv -N https
://download.nextcloud.com
/server
/releases
/$file
2000 m chown
-R www-data.www-data nextcloud
2001 m
mv nextcloud
$ncdir
2003 m sudo
-u www-data php occ maintenance
:install --database sqlite
--admin-user iank
--admin-pass $nextcloud_admin_pass
2005 # note, strange this happend where updater did not increment the version var,
2006 # mine was stuck on 20. I manually updated it.
2008 if [[ ! -e config.php-orig
]]; then
2009 m
cp -a config.php config.php-orig
2011 cat config.php-orig
- >tmp.php
<<EOF
2012 # https://docs.nextcloud.com/server/19/admin_manual/configuration_server/email_configuration.html
2013 \$CONFIG["mail_smtpmode"] = "sendmail";
2014 \$CONFIG["mail_smtphost"] = "127.0.0.1";
2015 \$CONFIG["mail_smtpport"] = 25;
2016 \$CONFIG["mail_smtptimeout"] = 10;
2017 \$CONFIG["mail_smtpsecure"] = "";
2018 \$CONFIG["mail_smtpauth"] = false;
2019 \$CONFIG["mail_smtpauthtype"] = "LOGIN";
2020 \$CONFIG["mail_smtpname"] = "";
2021 \$CONFIG["mail_smtppassword"] = "";
2022 \$CONFIG["mail_domain"] = "$domain";
2024 # https://github.com/nextcloud/user_external#readme
2025 # plus mailinabox example
2026 #\$CONFIG['user_backends'] = array(array('class' => 'OC_User_IMAP','arguments' => array('127.0.0.1', 143, null),),);
2029 # based on installer check
2030 # https://docs.nextcloud.com/server/19/admin_manual/configuration_server/caching_configuration.html
2031 \$CONFIG['memcache.local'] = '\OC\Memcache\APCu';
2033 \$CONFIG['overwrite.cli.url'] = 'https://$domain/nextcloud';
2034 \$CONFIG['htaccess.RewriteBase'] = '/nextcloud';
2035 \$CONFIG['trusted_domains'] = array (
2039 fwrite(STDOUT, "<?php\n\\\$CONFIG = ");
2040 var_export(\$CONFIG);
2041 fwrite(STDOUT, ";\n");
2043 m php tmp.php
>config.php
2045 m sudo
-u www-data php
$ncdir/occ maintenance
:update
:htaccess
2046 list
=$
(sudo
-u www-data php
$ncdir/occ
--output=json_pretty app
:list
)
2047 # user_external not compaible with nc 23
2048 for app
in contacts calendar
; do
2049 if [[ $
(printf "%s\n" "$list"| jq
".enabled.$app") == null
]]; then
2050 m sudo
-u www-data php
$ncdir/occ app
:install $app
2053 i
/etc
/systemd
/system
/$ncbase.service
<<EOF
2055 Description=ncup $ncbase
2056 After=multi-user.target
2060 ExecStart=/usr/local/bin/ncup $ncbase
2062 IOSchedulingClass=idle
2063 CPUSchedulingPolicy=idle
2065 i
/etc
/systemd
/system
/$ncbase.timer
<<EOF
2067 Description=ncup $ncbase timer
2073 WantedBy=timers.target
2075 systemctl
enable --now $ncbase.timer
2076 i
/usr
/local
/bin
/ncup
<<'EOFOUTER'
2078 if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
2079 shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4
2081 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR
2084 if ! php /var/www/$ncbase/updater/updater.phar -n; then
2085 echo failed nextcloud update for $ncbase >&2
2087 To: alerts@iankelling.org
2088 From: root@$(hostname -f)
2089 Subject: failed nextcloud update for $ncbase
2091 For logs, run: jr -u $ncbase
2096 mkdir
-p /var
/www
/cron-errors
2097 chown www-data.www-data
/var
/www
/cron-errors
2098 i
/etc
/cron.d
/$ncbase <<EOF
2099 PATH=/sbin:/usr/sbin:/usr/bin:/bin:/usr/local/bin
2101 # https://docs.nextcloud.com/server/20/admin_manual/configuration_server/background_jobs_configuration.html
2102 */5 * * * * www-data php -f $ncdir/cron.php --define apc.enable_cli=1 |& log-once nccron
2109 # * exim host conditional config
2113 all_dirs
=(/p
/c
/filesystem
)
2114 for x
in /p
/c
/machine_specific
/*.hosts
/a
/bin
/ds
/machine_specific
/*.hosts
; do
2115 if grep -qxF $HOSTNAME $x; then all_dirs
+=( ${x%.hosts} ); fi
2118 for d
in ${all_dirs[@]}; do
2119 f
=$d/etc
/exim
4/passwd
2120 if [[ -e $f ]]; then
2123 tmp
=($d/etc
/exim
4/*.pem
)
2124 if (( ${#tmp[@]} )); then
2129 if (( ${#files[@]} )); then
2130 sudo rsync
-ahhi --chown=root
:Debian-exim
--chmod=0640 ${files[@]} /etc
/exim
4/
2138 # avoid accepting mail for invalid users
2139 # https://wiki.dovecot.org/LMTP/Exim
2140 cat >>/etc
/exim
4/conf.d
/rcpt_local_acl
<<'EOF'
2142 message = invalid recipient
2143 domains = +local_domains
2144 !verify = recipient/callout=no_cache
2146 i
/etc
/exim
4/conf.d
/auth
/29_exim4-config_auth
<<'EOF'
2150 server_socket = /var/run/dovecot/auth-client
2151 server_set_id = $auth1
2156 i
/etc
/exim
4/conf.d
/auth
/29_exim4-config_auth
<<'EOF'
2157 # from 30_exim4-config_examples
2161 server_condition = "${if crypteq{$auth3}{${extract{1}{:}{${lookup{$auth2}lsearch{CONFDIR/passwd}{$value}{*:*}}}}}{1}{0}}"
2162 server_set_id = $auth2
2164 .ifndef AUTH_SERVER_ALLOW_NOTLS_PASSWORDS
2165 server_advertise_condition = ${if eq{$tls_in_cipher}{}{}{*}}
2170 # ** main daemon use non-default config file
2173 # to see the default comments in /etc/default/exim4:
2174 # s update-exim4defaults --force --init
2175 # which will overwrite any existing file
2176 i
/etc
/default
/exim4
<<'EOF'
2177 QUEUERUNNER='combined'
2179 COMMONOPTIONS='-C /etc/exim4/my.conf'
2180 UPEX4OPTS='-o /etc/exim4/my.conf'
2181 #E4BCD_PANICLOG_NOISE='malware acl condition: clamd /var/run/clamav/clamd\.ctl : unable to connect to UNIX socket'
2183 i
/etc
/exim
4/trusted_configs
<<'EOF'
2189 i
/etc
/default
/exim4
<<'EOF'
2190 QUEUERUNNER='combined'
2197 # ** $MAIL_HOST|bk|je)
2200 echo|i
/etc
/exim
4/conf.d
/router
/870_backup_local
2202 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2203 # note: some things we don't set that are here by default because they are unused.
2204 dc_local_interfaces=''
2205 dc_eximconfig_configtype='internet'
2206 dc_localdelivery='dovecot_lmtp'
2208 cat >>/etc
/exim
4/conf.d
/main
/000_local
<<EOF
2209 # recommended if dns is expected to work
2210 CHECK_RCPT_VERIFY_SENDER = true
2211 # default config comment says: If you enable this, you might reject legitimate mail,
2212 # but eggs has had this a long time, so that seems unlikely.
2213 CHECK_DATA_VERIFY_HEADER_SYNTAX = true
2214 CHECK_RCPT_SPF = true
2215 CHECK_RCPT_REVERSE_DNS = true
2216 CHECK_MAIL_HELO_ISSUED = true
2218 # enable 587 in addition to the default 25, so that
2219 # i can send mail where port 25 is firewalled by isp
2220 daemon_smtp_ports = 25 : 587
2221 # default of 25, can get stuck when catching up on mail
2222 smtp_accept_max = 400
2223 smtp_accept_reserve = 100
2224 smtp_reserve_hosts = +iank_trusted
2226 # options exim has to avoid having to alter the default config files
2227 CHECK_RCPT_LOCAL_ACL_FILE = /etc/exim4/conf.d/rcpt_local_acl
2228 CHECK_DATA_LOCAL_ACL_FILE = /etc/exim4/conf.d/data_local_acl
2229 LOCAL_DENY_EXCEPTIONS_LOCAL_ACL_FILE = /etc/exim4/conf.d/local_deny_exceptions_acl
2231 #dmarc_tld_file = /etc/public_suffix_list.dat
2238 cat >>/etc
/exim
4/conf.d
/main
/000_local
<<EOF
2239 # je.b8.nz will run out of memory with freshclam
2240 av_scanner = clamd:/var/run/clamav/clamd.ctl
2243 cat >> /etc
/exim
4/conf.d
/data_local_acl
<<'EOF'
2245 malware = */defer_ok
2246 !condition = ${if match {$malware_name}{\N^Heuristic\N}}
2247 message = This message was detected as possible malware ($malware_name).
2250 cat >/etc
/exim
4/conf.d
/main
/000_local-nn
<<EOF
2251 # MAIN_HARDCODE_PRIMARY_HOSTNAME might mess up the
2252 # smarthost config type, not sure.
2253 # failing message on mail-tester.com:
2254 # We check if there is a server (A Record) behind your hostname kd.
2255 # You may want to publish a DNS record (A type) for the hostname kd or use a different hostname in your mail software
2256 # https://serverfault.com/questions/46545/how-do-i-change-exim4s-primary-hostname-on-a-debian-box
2257 # and this one seemed appropriate from grepping config.
2258 # I originally set this to li.iankelling.org, but then ended up with errors when li tried to send
2259 # mail to kd, so this should basically be a name that no host has as their
2260 # canonical hostname since the actual host sits behind a nat and changes.
2261 MAIN_HARDCODE_PRIMARY_HOSTNAME = mail.iankelling.org
2262 # I used this to avoid sender verification, didnt work but it still
2263 # makes sense based on the spec.
2264 hosts_treat_as_local = defaultnn.b8.nz
2266 # Outside nn, we get the default cert location from a debian macro,
2267 # and the cert file is put in place by a certbot hook.
2268 MAIN_TLS_CERTIFICATE = /etc/exim4/fullchain.pem
2269 MAIN_TLS_PRIVATEKEY = /etc/exim4/privkey.pem
2272 i
/etc
/exim
4/conf.d
/router
/190_exim4-config_fsfsmarthost
<<'EOF'
2274 debug_print = "R: smarthost for $local_part@$domain"
2275 driver = manualroute
2276 domains = ! +local_domains
2277 # send most mail through eggs, helps fsfs sender reputation.
2278 # uncomment and optionally move to 188 file to send through my own servers again
2280 transport = smarthost_dkim
2281 route_list = * fencepost.gnu.org::587 byname
2282 host_find_failed = ignore
2283 same_domain_copy_routing = yes
2287 /a
/exe
/cedit defaultnn
/etc
/hosts
<<'EOF' || [[ $? == 1 ]]
2288 10.173.8.1 defaultnn.b8.nz
2294 i
/etc
/exim
4/conf.d
/router
/195_dnslookup_vpn
<<'EOF'
2295 # copied from /etc/exim4/conf.d/router/200_exim4-config_primary, but
2296 # use vpn transport. lower priority so it overrides the default route.
2297 # Use this in case our vpn fails, we dont send anything without it.
2298 .ifdef DCconfig_internet
2300 debug_print = "R: dnslookup for $local_part@$domain"
2302 domains = ! +local_domains
2303 transport = remote_smtp_vpn
2304 same_domain_copy_routing = yes
2305 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
2311 # note on backups: I used to do an automatic sshfs and restricted
2312 # permissions to a specific directory on the remote server, /bu/mnt,
2313 # which required using a dedicated user, but realized smtp will be
2314 # more reliable and less fuss. If I ever need that again, see the
2315 # history of this file, and bum in brc2.
2317 i
/etc
/exim
4/conf.d
/router
/890_backup_copy
<<EOF
2318 ### router/900_exim4-config_local_user
2319 #################################
2321 # todo, it would be nice to save sent email too,
2322 # but its not so important, they still exist in my head
2326 domains = +local_domains
2327 # b is just an arbirary short string
2328 data = b@eximbackup.b8.nz
2329 # note, to test this, i could temporarily allow testignore.
2330 # alerts avoids potential mail loop. root is already
2331 # redirected earlier, so that is just being overly cautious.
2332 local_parts = ! root : ! testignore : ! alerts
2336 driver = manualroute
2337 domains = eximbackup.b8.nz
2338 transport = backup_remote
2339 ignore_target_hosts = ${HOSTNAME}wg.b8.nz
2340 # note changes here also require change in passwd.client
2341 route_list = * eximbackup.b8.nz
2342 same_domain_copy_routing = yes
2347 i
/etc
/exim
4/conf.d
/transport
/30_backup_remote
<<'EOF'
2351 .ifndef IGNORE_SMTP_LINE_LENGTH_LIMIT
2352 message_size_limit = ${if > {$max_received_linelength}{998} {1}{0}}
2354 hosts_require_auth = *
2356 return_path = alerts@iankelling.org
2358 # manual return path because we dont want it to be the envelope sender
2359 # we got not the one we are using in this smtp transport
2360 headers_add = "Return-path: $sender_address"
2361 .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
2362 hosts_avoid_tls = REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
2364 .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS
2365 hosts_require_tls = REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS
2367 .ifdef REMOTE_SMTP_SMARTHOST_TLS_VERIFY_CERTIFICATES
2368 tls_verify_certificates = REMOTE_SMTP_SMARTHOST_TLS_VERIFY_CERTIFICATES
2370 .ifdef REMOTE_SMTP_SMARTHOST_TLS_VERIFY_HOSTS
2371 tls_verify_hosts = REMOTE_SMTP_SMARTHOST_TLS_VERIFY_HOST
2373 .ifdef REMOTE_SMTP_HEADERS_REWRITE
2374 headers_rewrite = REMOTE_SMTP_HEADERS_REWRITE
2376 .ifdef REMOTE_SMTP_HELO_DATA
2377 helo_data=REMOTE_SMTP_HELO_DATA
2379 .ifdef TLS_DH_MIN_BITS
2380 tls_dh_min_bits = TLS_DH_MIN_BITS
2382 .ifdef REMOTE_SMTP_SMARTHOST_TLS_CERTIFICATE
2383 tls_certificate = REMOTE_SMTP_SMARTHOST_TLS_CERTIFICATE
2385 .ifdef REMOTE_SMTP_SMARTHOST_PRIVATEKEY
2386 tls_privatekey = REMOTE_SMTP_SMARTHOST_PRIVATEKEY
2388 .ifdef REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
2389 headers_remove = REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
2394 # this avoids some error. i cant remember what. todo:
2395 # test it out and document why/if its needed.
2396 i
/etc
/exim
4/host_local_deny_exceptions
<<'EOF'
2401 # cron email from smarthost hosts will automatically be to
2402 # USER@FQDN. I redirect that to alerts@, on the smarthosts, but in
2403 # case that doesn't work, we still want to accept that mail, but not
2404 # from any host except the smarthosts. local_hostnames and this rule
2405 # is for that purpose.
2406 i
/etc
/exim
4/conf.d
/rcpt_local_acl
<<'EOF'
2409 domains = +local_hostnames
2412 echo|i
/etc
/exim
4/conf.d
/router
/880_universal_forward
2414 # for iank@fsf.org, i have mail.fsf.org forward it to fsf@iankelling.org.
2415 # and also have mail.iankelling.org whitelisted as a relay domain.
2416 # I could avoid that if I changed this to submit to 587 with a
2417 # password like a standard mua.
2418 i
/etc
/exim
4/conf.d
/router
/188_exim4-config_smarthost
<<'EOF'
2419 # ian: copied from /etc/exim4/conf.d/router/200_exim4-config_primary, and added senders = and
2420 # replaced DCsmarthost with hostname
2422 debug_print = "R: smarthost for $local_part@$domain"
2423 driver = manualroute
2424 domains = ! +local_domains
2426 transport = remote_smtp_smarthost
2427 route_list = * mail.fsf.org::587 byname
2428 host_find_failed = ignore
2429 same_domain_copy_routing = yes
2433 debug_print = "R: smarthost for $local_part@$domain"
2434 driver = manualroute
2435 domains = ! +local_domains
2436 senders = *@posteo.net
2437 transport = remote_smtp_smarthost
2438 route_list = * posteo.de::587 byname
2439 host_find_failed = ignore
2440 same_domain_copy_routing = yes
2445 # Greping /etc/exim4, unqualified mails this would end up as
2446 # a return path, so it should go somewhere we will see.
2447 # The debconf output about mailname is as follows:
2448 # The 'mail name' is the domain name used to 'qualify' mail addresses without a domain
2450 # This name will also be used by other programs. It should be the single, fully
2451 # qualified domain name (FQDN).
2452 # Thus, if a mail address on the local host is foo@example.org, the correct value for
2453 # this option would be example.org.
2454 # This name won\'t appear on From: lines of outgoing messages if rewriting is enabled.
2455 echo iankelling.org
> /etc
/mailname
2458 # mail.iankelling.org so local imap clients can connect with tls and
2459 # when they happen to not be local.
2460 # todo: this should be 10.8.0.4
2462 /a
/exe
/cedit nn
/etc
/hosts
<<'EOF' || [[ $? == 1 ]]
2463 # note: i put nn.b8.nz into bind for good measure
2464 10.173.8.2 nn.b8.nz mx.iankelling.org
2467 # note: systemd-resolved will consult /etc/hosts, dnsmasq wont. this assumes
2468 # weve configured this file in dnsmasq if we are using it.
2469 /a
/exe
/cedit
mail /etc
/dnsmasq-servers.conf
<<'EOF' || [[ $? == 1 ]]
2470 server=/mx.iankelling.org/127.0.1.1
2472 # I used to use debconf-set-selections + dpkg-reconfigure,
2473 # which then updates this file
2474 # but the process is slower than updating it directly and then I want to set other things in
2475 # update-exim4.conf.conf, so there's no point.
2476 # The file is documented in man update-exim4.conf,
2477 # except the man page is not perfect, read the bash script to be sure about things.
2479 # The debconf questions output is additional documentation that is not
2480 # easily accessible, but super long, along with the initial default comment in this
2481 # file, so I've saved that into ./mail-notes.conf.
2482 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2483 # man page: is used to build the local_domains list, together with "localhost"
2484 # this is duplicated in a later router.
2485 dc_other_hostnames='iankelling.org;zroe.org;r2e.iankelling.org;!je.b8.nz;!bk.b8.nz;*.b8.nz;b8.nz'
2489 # dmarc. not used currently
2490 f
=/etc
/cron.daily
/refresh-dmarc-tld-file
2494 wget -q -N https://publicsuffix.org/list/public_suffix_list.dat
2500 ## we use this host to monitor MAIL_HOST and host a mail server for someone
2503 echo|i
/etc
/exim
4/conf.d
/rcpt_local_acl
2504 echo|i
/etc
/exim
4/conf.d
/router
/880_universal_forward
2506 echo amnimal.ninja
> /etc
/mailname
2508 /a
/exe
/cedit nn
/etc
/hosts
<<'EOF' || [[ $? == 1 ]]
2512 sed -r -f - /etc
/init.d
/exim4
<<'EOF' | i /etc/init.d/exim4in
2513 s,/etc/default/exim4,/etc/default/exim4in,g
2514 s,/run/exim4/exim.pid,/run/exim4/eximin.pid,g
2515 s,(^[ #]*Provides:).*,\1 exim4in,
2516 s,(^[ #]*NAME=).*,\1"exim4in",
2518 chmod +x
/etc
/init.d
/exim4in
2519 i
/etc
/systemd
/system
/exim4in.service.d
/alwaysrestart.conf
<<'EOF'
2521 # needed to continually restart
2522 StartLimitIntervalSec=0
2526 # time to sleep before restarting a service
2530 i
/etc
/default
/exim4in
<<'EOF'
2531 # defaults but no queue runner and alternate config dir
2533 COMMONOPTIONS='-oP /run/exim4/eximin.pid'
2534 UPEX4OPTS='-d /etc/myexim4'
2537 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2538 # man page: is used to build the local_domains list, together with "localhost"
2539 dc_other_hostnames='amnimal.ninja;expertpathologyreview.com'
2545 echo je.b8.nz
> /etc
/mailname
2546 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2547 dc_other_hostnames='je.b8.nz'
2549 echo|i
/etc
/exim
4/conf.d
/router
/188_exim4-config_smarthost
2550 echo|i
/etc
/exim
4/conf.d
/router
/190_exim4-config_fsfsmarthost
2551 echo|i
/etc
/exim
4/conf.d
/rcpt_local_acl
2552 echo|i
/etc
/exim
4/conf.d
/router
/880_universal_forward
2554 # ** not MAIL_HOST|bk|je
2556 # this one should be removed for all non mail hosts, but
2557 # bk and je never become mail_host
2558 echo|i
/etc
/exim
4/conf.d
/router
/195_dnslookup_vpn
2560 echo|i
/etc
/exim
4/conf.d
/router
/188_exim4-config_smarthost
2561 echo|i
/etc
/exim
4/conf.d
/router
/190_exim4-config_fsfsmarthost
2562 echo|i
/etc
/exim
4/conf.d
/rcpt_local_acl
2563 echo|i
/etc
/exim
4/conf.d
/router
/890_backup_copy
2564 echo|i
/etc
/exim
4/conf.d
/main
/000_local-nn
2568 cat >>/etc
/exim
4/conf.d
/main
/000_local
<<EOF
2569 MAIN_TLS_CERTIFICATE = /etc/exim4/certs/$wghost/fullchain.pem
2570 MAIN_TLS_PRIVATEKEY = /etc/exim4/certs/$wghost/privkey.pem
2571 # so we can maintiain the originals of the backups.
2572 # we wouldnt want this if we were dealing with any other
2573 # local deliveries, but we sent all others to the smarthost
2574 # which then strips the headers.
2575 envelope_to_remove = false
2576 return_path_remove = false
2580 # catches things like cronjob email
2581 i
/etc
/exim
4/conf.d
/router
/880_universal_forward
<<'EOF'
2584 domains = +local_domains
2585 data = alerts@iankelling.org
2589 for unit
in ${nn_progs[@]}; do
2590 f
=/etc
/systemd
/system
/$unit.service.d
/nn.conf
2594 # dont i dont care if defaultnn section gets left, it wont
2596 echo |
/a
/exe
/cedit nn
/etc
/hosts ||
[[ $?
== 1 ]]
2597 echo |
/a
/exe
/cedit
mail /etc
/dnsmasq-servers.conf ||
[[ $?
== 1 ]]
2600 i
/etc
/exim
4/conf.d
/transport
/30_backup_maildir
<<EOF
2601 # modified debian maildir transport
2606 # note, no return path or envelope added
2608 directory_mode = 0700
2610 mode_fail_narrower = false
2614 i
/etc
/exim
4/conf.d
/router
/870_backup_local
<<EOF
2615 ### router/900_exim4-config_local_user
2616 #################################
2619 debug_print = "R: local_user for \$local_part@\$domain"
2621 domains = eximbackup.b8.nz
2622 transport = backup_maildir
2625 wgholeip
=$
(sed -rn 's/^ *Address *= *([^/]+).*/\1/p' /etc
/wireguard
/wghole.conf
)
2626 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2627 dc_other_hostnames='eximbackup.b8.nz'
2628 dc_local_interfaces='127.0.0.1;::1;$wgholeip'
2632 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2633 # Note: If theres like a temporary problem where mail gets sent to
2634 # one of these hosts, if exim isnt listening, it will be a temporary error
2635 # instead of a permanent 5xx.
2636 dc_local_interfaces='127.0.0.1;::1'
2639 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2640 dc_eximconfig_configtype='smarthost'
2641 dc_smarthost='$smarthost'
2644 hostname
-f |i
/etc
/mailname
2645 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2646 # The manpage incorrectly states this will do header rewriting, but
2647 # that only happens if we have dc_hide_mailname is set.
2648 dc_readhost='iankelling.org'
2649 # Only used in case of bounces.
2650 dc_localdelivery='maildir_home'
2658 # ** $MAILHOST|bk, things that belong at the end
2661 # config for the non-nn exim
2662 m rsync
-ra --delete /etc
/exim
4/ /etc
/myexim4
2663 cat >>/etc
/myexim
4/update-exim4.conf.conf
<<'EOF'
2664 dc_eximconfig_configtype='smarthost'
2665 dc_smarthost='nn.b8.nz'
2670 # config for the non-nn exim
2671 cat >/etc
/myexim
4/conf.d
/main
/000_local-nn
<<'EOF'
2672 MAIN_HARDCODE_PRIMARY_HOSTNAME = mail2.iankelling.org
2676 # for bk, we have a exim4in.service that will do this for us.
2677 m update-exim4.conf
-d /etc
/myexim4
2683 # ** bind mount setup
2684 # put spool dir in directory that spans multiple distros.
2685 # based on http://www.postfix.org/qmgr.8.html and my notes in gnus
2688 sdir
=/var
/spool
/exim4
2689 # we only do this if our system has $dir
2691 # this used to do a symlink, but, in the boot logs, /nocow would get mounted succesfully,
2692 # about 2 seconds later, exim starts, and immediately puts into paniclog:
2693 # honVi-0000u3-82 Failed to create directory "/var/spool/exim4/input": No such file or directory
2694 # so, im trying a bind mount to get rid of that.
2695 if [[ -e /nocow
]]; then
2696 if ! grep -Fx "/nocow/exim4 /var/spool/exim4 none bind 0 0" /etc
/fstab
; then
2697 echo "/nocow/exim4 /var/spool/exim4 none bind 0 0" >>/etc
/fstab
2699 i
/etc
/systemd
/system
/exim4.service.d
/override.conf
<<'EOF'
2701 # without local-fs on exim, we get these kind of errors in paniclog on shutdown:
2702 # Failed to create spool file /var/spool/exim4//input//1jCLxz-0008V4-V9-D: Permission denied
2703 After=local-fs.target
2705 if ! mountpoint
-q $sdir; then
2706 stopifactive exim4 exim4in
2707 if [[ -L $sdir ]]; then
2710 if [[ ! -e $dir && -d $sdir ]]; then
2713 if [[ ! -d $sdir ]]; then
2715 m
chmod 000 $sdir # only want it to be used when its mounted
2723 # ** exim/spool uid setup
2724 # i have the spool directory be common to distro multi-boot, so
2725 # we need the uid to be the same. 608 cuz it's kind of in the middle
2726 # of the free system uids.
2727 IFS
=:; read -r _ _ uid _
< <(getent passwd Debian-exim ||
:) ||
:; unset IFS
2728 IFS
=:; read -r _ _ gid _
< <(getent group Debian-exim ||
:) ||
:; unset IFS
2729 if [[ ! $uid ]]; then
2730 # from /var/lib/dpkg/info/exim4-base.postinst, plus uid and gid options
2731 m adduser
--uid 608 --system --group --quiet --home /var
/spool
/exim4 \
2732 --no-create-home --disabled-login --force-badname Debian-exim
2733 elif [[ $uid != 608 ]]; then
2734 stopifactive exim4 exim4in
2735 m usermod
-u 608 Debian-exim
2736 m groupmod
-g 608 Debian-exim
2737 m usermod
-g 608 Debian-exim
2738 m
find / /nocow
-path .
/var
/tmp
-prune -o -xdev -uid $uid -execdir chown
-h 608 {} +
2739 m
find / /nocow
-path .
/var
/tmp
-prune -o -xdev -gid $gid -execdir chgrp
-h 608 {} +
2742 # * start / stop services
2744 reifactive dnsmasq nscd
2747 m systemctl daemon-reload
2750 sstart epanicclean.timer
2754 /a
/exe
/web-conf apache2 je.b8.nz
2757 /a
/exe
/web-conf apache2 mail2.iankelling.org
2761 m
/a
/bin
/ds
/mail-cert-cron
-1
2766 # todo, this should be done in distro-begin
2767 soff systemd-resolved
2768 ln -sf 127.0.0.1-resolv/stub-resolv.conf
/etc
/resolv.conf
2771 sstart mailnn mailnnroute
2774 # we use dns to start wg
2782 # If these have changes, id rather manually restart it, id rather
2783 # not restart and cause temporary errors
2789 if ! systemctl is-active clamav-daemon
>/dev
/null
; then
2790 sstart clamav-daemon
2791 out
=$
(rsync
-aiSAX --chown=root
:root
--chmod=g-s
/a
/bin
/ds
/filesystem
/etc
/systemd
/system
/epanicclean.
{timer
,service
} /etc
/systemd
/system
)
2796 # note, this will cause paniclog entries because it takes like 45
2797 # seconds for clamav to start, i use ./epanic-clean to remove
2802 # start spamassassin/dovecot before exim.
2803 sre dovecot spamassassin
2804 # need to wait a bit before restarting exim, else I
2805 # get a paniclog entry like: spam acl condition: all spamd servers failed
2807 sstart mailclean.timer
2810 # < 2.1 (eg: in t9), uses a different data format which required manual
2811 # migration. dont start if we are running an old version.
2812 if dpkg
--compare-versions $
(dpkg
-s radicale |
awk '$1 == "Version:" { print $2 }') ge
2.1; then
2818 # last use of $reload happens in previous block
2819 rm -f /var
/local
/mail-setup-reload
2823 $MAIL_HOST|bk|je
) : ;;
2825 soff radicale mailclean.timer dovecot spamassassin
$vpnser mailnn clamav-daemon
2835 # * mail monitoring / testing
2837 # note, to test clamav, send an email with body that only contains
2838 # https://en.wikipedia.org/wiki/EICAR_test_file
2839 # which set malware_name to Eicar-Signature
2842 # note: cronjob "ian" also does some important monitoring
2843 # todo: this will sometimes cause an alert because mailtest-check will run
2844 # before we have setup network namespace and spamassassin
2845 cat >/etc
/cron.d
/mailtest
<<EOF
2847 PATH=/usr/bin:/bin:/usr/local/bin
2848 MAILTO=alerts@iankelling.org
2849 */5 * * * * $u send-test-forward |& log-once send-test-forward
2850 */10 * * * * root chmod -R g+rw /m/md/bounces |& log-once -1 bounces-chmod
2851 # im seeing some intermittent failures on the slow check, do it all the time
2852 # for now. It looks like a dns failure.
2853 #5-59/5 * * * * root mailtest-check |& log-once -1 mailtest-check
2854 #0 * * * * root mailtest-check slow |& log-once -1 mailtest-slow
2855 */5 * * * * root timeout 290 mailtest-check slow |& log-once -12 mailtest-check
2857 m sudo rsync
-ahhi --chown=root
:root
--chmod=0755 \
2858 /b
/ds
/mailtest-check
/b
/ds
/check-remote-mailqs
/usr
/local
/bin
/
2861 test_froms
=(ian@iankelling.org z@zroe.org iank@gnu.org
)
2862 test_to
="testignore@expertpathologyreview.com, testignore@je.b8.nz, testignore@amnimal.ninja, jtuttle@gnu.org"
2864 cat >>/etc
/cron.d
/mailtest
<<EOF
2865 2 * * * * $u check-remote-mailqs |& log-once check-remote-mailqs
2869 test_froms
=(testignore@expertpathologyreview.com testignore@amnimal.ninja
)
2870 test_to
="testignore@iankelling.org, testignore@zroe.org, testignore@je.b8.nz"
2873 test_froms
=(testignore@je.b8.nz
)
2874 test_to
="testignore@iankelling.org, testignore@zroe.org, testignore@expertpathologyreview.com, testignore@amnimal.ninja"
2877 cat >/usr
/local
/bin
/send-test-forward
<<'EOF'
2880 /sbin/exiqgrep -o 260 -i -r '^(testignore@(iankelling\.org|zroe\.org|expertpathologyreview\.com|amnimal\.ninja|je\.b8\.nz)|jtuttle@gnu\.org)$')
2881 if (( ${#olds[@]} )); then
2882 /sbin/exim -Mrm "${olds[@]}" >/dev/null
2885 for test_from
in ${test_froms[@]}; do
2886 cat >>/usr
/local
/bin
/send-test-forward
<<EOFOUTER
2887 /usr/sbin/exim -f $test_from -t <<EOF
2890 Subject: test \$(date +%Y-%m-%dT%H:%M:%S%z) \$(date +%s)
2892 /usr/local/bin/send-test-forward
2896 m
chmod +x
/usr
/local
/bin
/send-test-forward
2899 rm -fv /etc
/cron.d
/mailtest
2906 m sudo
-u $u mkdir
-p /home
/$u/.cache
2907 set -- /m
/mucache
/home
/$u/.cache
/mu
/m
/.mu
/home
/$u/.mu
2912 if [[ ! -L $f ]]; then
2913 if [[ -e $f ]]; then
2916 m sudo
-u $u ln -sf -T $target $f
2921 # /etc/alias setup is debian specific, and exim postinst script sets up
2922 # an /etc/alias from root to the postmaster, based on the question
2923 # exim4-config exim4/dc_postmaster, as long as there exists an entry for
2924 # root, or there was no preexisting aliases file. postfix won\'t set up
2925 # a root to $postmaster alias if it\'s already installed. Easiest to
2926 # just set it ourselves.
2928 # debconf question for postmaster:
2929 # Mail for the 'postmaster', 'root', and other system accounts needs to be redirected
2930 # to the user account of the actual system administrator.
2931 # If this value is left empty, such mail will be saved in /var/mail/mail, which is not
2933 # Note that postmaster\'s mail should be read on the system to which it is directed,
2934 # rather than being forwarded elsewhere, so (at least one of) the users listed here
2935 # should not redirect their mail off this machine. A 'real-' prefix can be used to
2936 # force local delivery.
2937 # Multiple user names need to be separated by spaces.
2938 # Root and postmaster mail recipient:
2944 # eval: (outline-minor-mode)
2945 # outline-regexp: "\\( *\\)# [*]\\{1,8\\} "
2947 # this is combined with defining outline-level in init.el