3 # Copyright (C) 2019 Ian Kelling
4 # SPDX-License-Identifier: AGPL-3.0-or-later
6 # todo: sandbox / harden exim:
7 # 1. stop it from running as root. how?
8 # https://www.exim.org/exim-html-current/doc/html/spec_html/ch-security_considerations.html
9 # * avoid using .forward files, remove that router
10 # * set deliver_drop_privilege
11 # * set user to run as Debian-exim in systemd
12 # * set port to something like 2500, and forward 25 to 2500 with iptables. same for 587.
13 # https://superuser.com/questions/710253/allow-non-root-process-to-bind-to-port-80-and-443/1334552#1334552
14 # * consider whether other routers like postmaster need modification / removal.
15 # 2. restrict its filesystem access from within systemd
17 # todo: harden dovecot. need to do some research. one way is for it to only listen on a wireguard vpn interface, so only clients that are on the vpn can access it.
18 # todo: consider hardening cups listening on 0.0.0.0
19 # todo: stop/disable local apache, and rpc.mountd, and kdeconnect when not in use.
20 # todo: check that spamd and unbound only listen locally.
22 # todo: hosts should only allow external mail that is authed and
23 # destined for backup route. it is a minor issue since traffic is
24 # limited to the wghole network.
26 # todo: emailing info@amnimal.ninja produces a bounce, user doesn't exist
27 # instead of a simple rejection like it should.
29 # todo: auto restart of je on checkrestart
31 # todo: run mailping test after running, or otherwise
32 # clear out terminal alert
34 # todo: reinstall bk with bigger filesystem
36 # todo: on bk, dont send email if mailvpn is not up
38 # todo: mailtest-check should check on bk too
40 # todo: disable postgrey
42 # todo: in testforward-check, we should also look
44 # todo: test that bounces dont help create valid mailtest-check
46 # todo: move mail stuff in distro-end into this file
48 # todo: consider rotating dkim & publishing key so every past email I sent
49 # isnt necessarily signed
51 # todo: consider how to get clamav out of Debian-exim group
52 # so it cant read/write the whole mail spool, for better
55 # todo: create a cronjob to update or warn on expiring dnssec keys
57 # todo: we should test failed mail daily or so
58 # failed cronjob, failed sysd-log-once,
59 # a local bounce from a cronjob, a local bounce
60 # to a bad remote address, perhaps a local failure
61 # when the sending daemon is down.
62 # And send an alert email if no alerts have been sent
63 # in 2 or 3 days or something. todo, test cron mail on li.
65 # todo: look at mailinabox extra dns records, note these changelogs:
66 # - 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.
67 # - 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.
70 # todo: mailtest-check failure on remote hosts is not going to alert me.
72 # todo: test mail failure as well as success.
74 # todo: validate that mailtest-check is doing dnsbl checks.
76 # background: I want to run exim in a network namespace so it can send
77 # and receive through a vpn. This is needed so it can do ipv6, because
78 # outside the namespace if we dont have ipv6, to send ipv6 through the
79 # vpn, we have to send all our ipv6 through the vpn. I did this for a
80 # long time, it was fine, but it causes various pains, like increased
81 # latency, increased recaptcha because my ip is from a data center, just
82 # various issues I dont want on all the time. The problem with the
83 # namespace is that all kinds of programs want to invoke exim, but they
84 # wont be in the namespace. I could replace exim with a wrapper that
85 # jumps into the namespace, i tried that, it works fine. One remaining
86 # problem was that I would have needed to hook into exim upgrades to
87 # move exim and replace it with my wrapper script. Also, my script to
88 # join the namespace is not super reliable because it uses a pgrep.
89 # Instead, I should have created a systemd service for a process that
90 # will never die and just writes its pid somewhere convenient.
95 # user ALL=(ALL) /usr/sbin/exim4
97 # move exim4 to eximian, use this script for exim4:
100 # if ip a show veth1-mail &>/dev/null; then
101 # /usr/sbin/eximian "$@"
105 # if [[ $USER && $USER != root ]]; then
108 # pid=$(pgrep -f "/usr/sbin/openvpn .* --config /etc/openvpn/.*mail.conf")
110 # sudo nsenter -t $pid -n -m sudo -u $USER /usr/sbin/eximian "$@"
112 # nsenter -t $pid -n -m /usr/sbin/eximian "$@"
116 # an alternate solution: there is a small setguid program for
117 # network namespaces in my bookmarks.
119 # However, the solution I went with is: have 2 exim
120 # configs. A nonstandard location for the daemon that runs
121 # in the namespace. For all other invocations, it uses
122 # the default config location, which is altered to be
123 # in a smarthost config which sends mail to the deaemon.
125 # I have a bash function, enn to invoke exim like the daemon is running.
126 # and mailbash to just enter its network namespace.
128 if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
132 if [[ -s /usr
/local
/lib
/err
]]; then
133 source /usr
/local
/lib
/err
134 elif [[ -s /a
/bin
/errhandle
/err
]]; then
135 source /a
/bin
/errhandle
/err
137 err
"no err tracing script found"
139 source /a
/bin
/distro-functions
/src
/identify-distros
140 source /a
/bin
/distro-functions
/src
/package-manager-abstractions
142 # has nextcloud_admin_pass in it
143 f
=/p
/c
/machine_specific
/$HOSTNAME/mail
145 # shellcheck source=/p/c/machine_specific/bk/mail
150 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
158 Usage: ${0##*/} anything_here_to_debug
159 Setup exim4 & dovecot & related things
161 -h|--help Print help and exit.
166 # debug output if we pass any arg
172 ####### instructions for icedove #####
173 # Incoming mail server: mail.iankelling.org, port 143, username iank, connection security starttls, authentication method normal password,
174 # then click advanced so it accepts it.
175 # we could also just use 127.0.0.1 with no ssl
177 # hamburger -> preferences -> preferences -> advanced tab -> config editor button -> security.ssl.enable_ocsp_must_staple = false
178 # background: dovecot does not yet have ocsp stapling support
179 # reference: https://community.letsencrypt.org/t/simple-guide-using-lets-encrypt-ssl-certs-with-dovecot/2921
181 # for phone, k9mail, same thing but username alerts, pass in ivy-pass.
182 # also, bk.b8.nz for secondary alerts, username is iank. same alerts pass.
183 # fetching mail settings: folder poll frequency 10 minutes
187 # * perstent password instructions
188 # Note: for cert cron, we need to manually run first to accept known_hosts
191 # # for hosts which have all private files I just use the same user
192 # # for other hosts, each one get\'s their own password.
193 # # for generating secure pass, and storing for server too:
196 # apg -m 50 -x 70 -n 1 -a 1 -M CLN >$f
197 # s sed -i "/^$host:/d" /p/c/filesystem/etc/exim4/passwd
198 # echo "$host:$(mkpasswd -m sha-512 -s <$f)" >>/p/c/filesystem/etc/exim4/passwd
199 # #reference: exim4_passwd_client(5)
200 # dir=/p/c/machine_specific/$host/filesystem/etc/exim4
202 # echo "mail.iankelling.org:$host:$(<$f)" > $dir/passwd.client
203 # # then run this script
205 # # dovecot password, i just need 1 as I\'m the only user
206 # mkdir /p/c/filesystem/etc/dovecot
207 # echo "iank:$(doveadm pw -s SHA512-CRYPT)::::::" >>/p/c/filesystem/etc/dovecot/users
209 ####### end perstent password instructions ######
213 # # Remove 1 level of comments in this section, set the domain var
214 # # for the domain you are setting up, then run this and copy dns settings
216 # domain=iankelling.org
217 # c /p/c/filesystem/etc/exim4
218 # # this has several bugs addressed in comments, but it was helpful
219 # # https://debian-administration.org/article/718/DKIM-signing_outgoing_mail_with_exim4
221 # openssl genrsa -out $domain-private.pem 2048
222 # # Then, to get the public key strings to put in bind:
224 # # selector is needed for having multiple keys for one domain.
225 # # I dun do that, so just use a static one: li
226 # # Debadmin page does not have v=, fastmail does, and this
227 # # says it\'s recommended in 3.6.1, default is DKIM1 anyways.
228 # # https://www.ietf.org/rfc/rfc6376.txt
229 # # Join and print all but first and last line.
230 # # last line: swap hold & pattern, remove newlines, print.
231 # # lines 2+: append to hold space
232 # echo "bind txt record: remember to truncate $domain so its relative to the bind zone"
234 # a._domainkey.$domain TXT (
235 # "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')" )
237 # # sed explanation: skip the first few lines, then put them into the hold space, then
238 # # on the last line, back to the patern space, remove the newlines, then add a newline
239 # # at the last char - 240, because bind txt records need strings <=255 chars,
240 # # other dkim stuff at the begining is is 25 chars, and the pubkey is 393, so this
241 # # leaves us a bit of extra room at the end and a bunch at the beginning.
243 # # selector was also put into /etc/exim4/conf.d/main/000_local,
247 # # 2017-02 dmarc policies:
248 # # host -t txt _dmarc.gmail.com
249 # # yahoo: p=reject, hotmail: p=none, gmail: p=none, fastmail none for legacy reasons
250 # # there were articles claiming gmail would be changing
251 # # to p=reject, in early 2017, which didn\'t happen. I see no sources on them. It\'s
252 # # expected to cause problems
253 # # with a few old mailing lists, copying theirs for now.
255 # echo "dmarc dns, name: _dmarc value: v=DMARC1; p=none; rua=mailto:mailauth-reports@$domain"
259 # # 2017-02 spf policies:
260 # # host -t txt lists.fedoraproject.org
261 # # google ~all, hotmail ~all, yahoo: ?all, fastmail ?all, outlook ~all
262 # # i include fastmail\'s settings, per their instructions,
263 # # and follow their policy. In mail in a box, or similar instructions,
264 # # I\'ve seen recommended to not use a restrictive policy.
266 # # to check if dns has updated, you do
267 # host -a mesmtp._domainkey.$domain
270 # # setting it to iankelling.org would work the same, but this
271 # # is more flexible, I could change where mail.iankelling.org pointed.
273 # mx records, 2 records each, for * and empty domain
274 # pri 10 mail.iankelling.org
278 # from brc2, run dnsecgen then dsign, update named.local.conf, publish keys to registrar
280 # * functions & constants
283 m
() { printf "$pre %s\n" "$*"; "$@"; }
284 e
() { printf "$pre %s\n" "$*"; }
285 err
() { printf "$pre %s\n" "$*" >&2; exit 1; }
288 # This file is so if we fail in the middle and rerun, we dont lose state
289 if [[ -e /var
/local
/mail-setup-reload
]]; then
293 local tmp tmpdir dest
="$1"
294 local base
="${dest##*/}"
299 tmp
=$
(rsync
-ic $tmpdir/"$base" "$dest")
303 if [[ $dest == /etc
/systemd
/system
/* ]]; then
304 touch /var
/local
/mail-setup-reload
311 key
="$1" value
="$2" section
="$3"
312 file="/etc/radicale/config"
313 sed -ri "/ *\[$section\]/,/^ *\[[^]]+\]/{/^\s*${key}[[:space:]=]/d};/ *\[$section\]/a $key = $value" "$file"
317 # ignore services that dont exist
318 if systemctl
cat $service &>/dev
/null
; then
319 m systemctl disable
--now $service
325 m systemctl restart
$service
326 m systemctl
enable $service;
330 [[ $HOSTNAME == "$MAIL_HOST" ]]
332 e
() { printf "%s\n" "$*"; }
335 if systemctl is-active
$service >/dev
/null
; then
336 m systemctl restart
$service
342 if systemctl is-active
$service >/dev
/null
; then
343 m systemctl stop
$service
348 mxhost
=mx.iankelling.org
352 # old setup. left as comment for example
353 # mxhost=mail.messagingengine.com
355 # forward=ian@iankelling.org
357 smarthost
="$mxhost::$mxport"
358 uhome
=$
(eval echo ~
$u)
360 # Somehow on one machine, a file got written with 664 perms.
361 # just being defensive here.
364 source /a
/bin
/bash_unpublished
/source-state
365 if [[ ! $MAIL_HOST ]]; then
366 err
"\$MAIL_HOST not set"
372 kd|frodo|x2|x3|kw|sy
)
378 # * Install universal packages
381 # installs epanicclean
382 /a
/bin
/ds
/install-my-scripts
384 if [[ $
(debian-codename-compat
) == bionic
]]; then
385 cat >/etc
/apt
/preferences.d
/spamassassin
<<'EOF'
386 Package: spamassassin sa-compile spamc
387 Pin: release n=focal,o=Ubuntu
392 # light version of exim does not have sasl auth support.
393 pi-nostart exim4 exim4-daemon-heavy spamassassin openvpn unbound clamav-daemon wireguard
395 # note: pyzor debian readme says you need to run some initialization command
397 pi spf-tools-perl p0f postgrey pyzor razor jq moreutils certbot
398 # bad packages that sometimes get automatically installed
399 pu openresolv resolvconf
404 if [[ $
(debian-codename
) == etiona
]]; then
405 # ip6tables stopped loading on boot. openvpn has reduced capability set,
406 # so running iptables as part of openvpn startup wont work. This should do it.
407 pi iptables-persistent
408 cat >/etc
/iptables
/rules.v6
<<'EOF'
415 m ip6tables
-S >/dev
/null
418 # our nostart pi fails to avoid enabling
421 # * user forward file
424 # afaik, these will get ignored on MAIL_HOST because they are routing to my own
425 # machine, but rm them is safer
426 rm -fv $uhome/.forward
/root
/.forward
429 # this can\'t be a symlink and has permission restrictions
430 # it might work in /etc/aliases, but this seems more proper.
431 e setting
$uhome/.forward to
$forward
432 install -m 644 {-o,-g}$u <(e
$forward) $uhome/.forward
436 # * Mail clean cronjob
438 i
/etc
/systemd
/system
/mailclean.timer
<<'EOF'
440 Description=Run mailclean daily
446 WantedBy=timers.target
449 i
/etc
/systemd
/system
/mailclean.service
<<EOF
451 Description=Delete and archive old mail files
452 After=multi-user.target
457 ExecStart=/usr/local/bin/sysd-mail-once mailclean /a/bin/distro-setup/mailclean
463 i
/etc
/default
/postgrey
<<'EOF'
464 POSTGREY_OPTS="--exim --unix=/var/run/postgrey/postgrey.sock --retry-window=4 --max-age=60"
469 m usermod
-a -G Debian-exim clamav
471 i
/etc
/systemd
/system
/clamav-daemon.service.d
/fix.conf
<<EOF
473 ExecStartPre=-/bin/mkdir /var/run/clamav
474 ExecStartPre=/bin/chown clamav /var/run/clamav
480 #vpnser=mailvpn.service
481 # todo: this hangs if it cant resolv the endpoint. we
482 # want it to just retry in the background.
483 vpnser
=wg-quick@wgmail.service
487 rsync
-aiSAX --chown=root
:root
--chmod=g-s
/p
/c
/filesystem
/etc
/wireguard
/ /etc
/wireguard
488 bindpaths
="/etc/127.0.0.1-resolv:/run/systemd/resolve /etc/basic-nsswitch:/etc/resolved-nsswitch:norbind"
491 bindpaths
="/etc/10.173.8.1-resolv:/etc/127.0.0.1-resolv"
494 d
=/p
/c
/machine_specific
/$HOSTNAME/filesystem
/etc
/wireguard
/
496 rsync
-aiSAX --chown=root
:root
--chmod=g-s
$d /etc
/wireguard
501 i
/etc
/systemd
/system
/wg-quick@wgmail.service.d
/override.conf
<<EOF
503 Requires=mailnn.service
504 After=network.target mailnn.service
505 JoinsNamespaceOf=mailnn.service
506 BindsTo=mailnn.service
510 # i dont think we need any of these, but it doesnt hurt to stay consistent
514 # https://selivan.github.io/2017/12/30/systemd-serice-always-restart.html
515 i
/etc
/systemd
/system
/mailvpn.service
<<EOF
517 Description=OpenVPN tunnel for mail
518 After=syslog.target network-online.target mailnn.service
519 Wants=network-online.target
520 Documentation=man:openvpn(8)
521 Documentation=https://community.openvpn.net/openvpn/wiki/Openvpn24ManPage
522 Documentation=https://community.openvpn.net/openvpn/wiki/HOWTO
523 # needed to continually restatr
524 JoinsNamespaceOf=mailnn.service
525 BindsTo=mailnn.service
526 StartLimitIntervalSec=0
530 RuntimeDirectory=openvpn-client
531 RuntimeDirectoryMode=0710
532 WorkingDirectory=/etc/openvpn/client
533 ExecStart=/usr/sbin/openvpn --suppress-timestamps --nobind --config /etc/openvpn/client/mail.conf
534 #CapabilityBoundingSet=CAP_IPC_LOCK CAP_NET_ADMIN CAP_NET_RAW CAP_SETGID CAP_SETUID CAP_SYS_CHROOT CAP_DAC_OVERRIDE
536 # DeviceAllow=/dev/null rw
537 # DeviceAllow=/dev/net/tun rw
539 # in the network namespace, we cant connect to systemd-resolved on 127.0.0.53,
541 # https://unix.stackexchange.com/questions/445782/how-to-allow-systemd-resolved-to-listen-to-an-interface-other-than-loopback
542 # there is a workaround there, but i dont think its really worth it,
543 # the mail server is fine with a static dns anyways.
544 # This thread is also interesting,
545 # https://github.com/slingamn/namespaced-openvpn/issues/7
546 # todo: the iptables rule at the bottom could be useful to prevent
547 # dns from leaking in my network namespaced vpn.
548 # I also like the idea of patching systemd-resolved so it
549 # will listen on other interfaces, but its not worth my time.
552 # time to sleep before restarting a service
556 WantedBy=multi-user.target
559 i
/etc
/systemd
/system
/mailnnroute.service
<<'EOF'
561 Description=Network routing for mailnn
562 After=syslog.target network-online.target mailnn.service
563 Wants=network-online.target
564 JoinsNamespaceOf=mailnn.service
565 BindsTo=mailnn.service
566 StartLimitIntervalSec=0
572 ExecStart=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns -n 10.173.8 start mail
573 ExecStop=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns stop mail
579 WantedBy=multi-user.target
583 i
/etc
/systemd
/system
/mailnn.service
<<'EOF'
585 Description=Network Namespace for mail vpn service that will live forever and cant fail
586 After=syslog.target network-online.target
587 Wants=network-online.target
592 ExecStart=/bin/sleep infinity
595 WantedBy=multi-user.target
598 i
/etc
/systemd
/system
/mailbindwatchdog.service
<<EOF
600 Description=Watchdog to restart services relying on systemd-resolved dir
601 After=syslog.target network-online.target
602 Wants=network-online.target
603 BindsTo=mailnn.service
607 ExecStart=/usr/local/bin/mailbindwatchdog $vpnser ${nn_progs[@]} unbound.service radicale.service
609 # time to sleep before restarting a service
613 WantedBy=multi-user.target
619 rm -fv /etc
/systemd
/system
/openvpn-client-mail@.service
621 # We use a local unbound because systemd-resolved wont accept our
622 # request, it will only listen to 127.0.0.53 in the main network
623 # namespace, and rejected feature requests to change that (although I
624 # could change the code and recompile), but anyways, that could answer
625 # with things specific to the lan that aren't applicable in this
626 # namespace, and since unbound is a recursive resolver, it means we just
627 # use our own ip against dnsbl rate limits.
629 # If we ever notice this change, chattr +i on it
630 # trust-ad is used in t10+, glibc 2.31
632 i
/etc
/127.0.0.1-resolv/stub-resolv.conf
<<'EOF'
634 options edns0 trust-ad
637 i
/etc
/127.0.0.53-resolv/stub-resolv.conf
<<'EOF'
638 nameserver 127.0.0.53
639 options edns0 trust-ad
643 i
/etc
/10.173.8.1-resolv/stub-resolv.conf
<<'EOF'
644 nameserver 10.173.8.1
645 options edns0 trust-ad
648 # this is just a bug fix for trisquel.
649 f
=/etc
/apparmor.d
/usr.sbin.unbound
650 line
="/usr/sbin/unbound flags=(attach_disconnected) {"
651 if ! grep -qFx "$line" $f; then
652 badline
="/usr/sbin/unbound {"
653 if ! grep -qFx "$badline" $f; then
654 err expected line
in $f not found
656 sed -i "s,^$badline$,$line," $f
657 if systemctl is-active apparmor
&>/dev
/null
; then
658 m systemctl reload apparmor
662 # note: anything added to nn_progs needs corresponding rm
663 # down below in the host switch
666 # Note dovecots lmtp doesnt need to be in the same nn to accept delivery.
667 # Its in the nn so remote clients can connect to it.
668 nn_progs
+=(spamassassin dovecot
)
673 i
/etc
/systemd
/system
/unbound.service.d
/nn.conf
<<EOF
676 JoinsNamespaceOf=mailnn.service
677 BindsTo=mailnn.service
678 StartLimitIntervalSec=0
682 # note the nsswitch bind is actually not needed for bk, but
683 # its the same file so it does no harm.
690 # sooo, there are a few ways to get traffic from the mail network
691 # namespace to go over the wghole.
693 #1: unify the mail vpn and wghole
694 # into 1 network. this seems simple and logical, so I'm doing it.
695 # One general downside is tying things together, if I need to mess
696 # with one thing, it breaks the other. Oh well for now.
698 # 2. We can route 10.5.3.0/24 out of the mail nn and nat it into wghole.
700 # 3. We can setup the routing to happen on li, which seemed like I
701 # just needed to add 10.8.0.4/24 to AllowedIPs in at least the
702 # wghole clients, but I think that is kind of hacky and breaks ipv4
703 # routing within the mailvpn, it happened to work just because exim
704 # prefers ipv6 and that was also available in the mailvpn.
706 # 4. Put the hole interface into the mail network namespace. This
707 # doesn't work if the mail vpn is wg. For openvpn, it bypasses the
708 # vpn routing and establishes a direct connection. I only use the
709 # hole vpn for randomish things, it should be fine to join the mail
710 # nn for that. There should be some way to fix the routing issue
711 # by doing manual routing, but that doesn't seem like a good use of time.
713 # https://www.wireguard.com/netns/#
715 # for wireguard debugging
716 # echo module wireguard +p > /sys/kernel/debug/dynamic_debug/control
721 for unit
in ${nn_progs[@]}; do
722 i
/etc
/systemd
/system
/$unit.service.d
/nn.conf
<<EOF
724 # commented for old openvpn
726 After=network.target mailnn.service $vpnser
727 JoinsNamespaceOf=mailnn.service
728 BindsTo=mailnn.service
729 StartLimitIntervalSec=0
733 # note the nsswitch bind is actually not needed for bk, but
734 # its the same file so it does no harm.
743 for unit
in exim4 spamassassin dovecot unbound
; do
744 f
=/etc
/systemd
/system
/$unit.service.d
/nn.conf
753 # * spamassassin config
754 i
/etc
/sysctl.d
/80-iank-mail.conf
<<'EOF'
756 net.netfilter.nf_conntrack_tcp_timeout_close_wait = 120
762 i
/etc
/spamassassin
/mylocal.cf
<<'EOF'
763 # this is mylocal.cf because the normal local.cf has a bunch of upstream stuff i dont want to mess with
765 # /usr/share/doc/exim4-base/README.Debian.gz:
766 # SpamAssassin's default report should not be used in a add_header
767 # statement since it contains empty lines. (This triggers e.g. Amavis'
768 # warning "BAD HEADER SECTION, Improper folded header field made up
769 # entirely of whitespace".) This is a safe, terse alternative:
770 clear_report_template
771 report (_SCORE_ / _REQD_ requ) _TESTSSCORES(,)_ autolearn=_AUTOLEARN
772 uridnsbl_skip_domain iankelling.org
773 uridnsbl_skip_domain amnimal.ninja
774 uridnsbl_skip_domain expertpathologyreview.com
775 uridnsbl_skip_domain zroe.org
778 # 2020-10-19 remove old file. remove this when all hosts updated
779 rm -fv /etc
/systemd
/system
/spamddnsfix.
{timer
,service
}
781 i
/etc
/default
/spamassassin
<<'EOF'
782 # defaults plus debugging flags for an issue im having
783 OPTIONS="--create-prefs --max-children 5 --helper-home-dir"
784 PIDFILE="/var/run/spamd.pid"
786 NICE="--nicelevel 15"
789 ##### end spamassassin config
793 if [[ -e /p
/c
/filesystem
]]; then
794 # note, man openvpn implies we could just call mail-route on vpn startup/shutdown with
795 # systemd, buuut it can remake the tun device unexpectedly, i got this in the log
796 # after my internet was down for a bit:
797 # NOTE: Pulled options changed on restart, will need to close and reopen TUN/TAP device.
798 m
/a
/exe
/vpn-mk-client-cert
-b mailclient
-n mail li.iankelling.org
802 if [[ ! -e /etc
/openvpn
/client
/mail.conf
]]; then
803 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
809 m rsync
-aiSAX --chown=root
:root
--chmod=g-s
/a
/bin
/ds
/mail-cert-cron
/usr
/local
/bin
811 i
/etc
/systemd
/system
/mailcert.service
<<'EOF'
813 Description=Mail cert rsync
814 After=multi-user.target
818 ExecStart=/usr/local/bin/sysd-mail-once mailcert /usr/local/bin/mail-cert-cron
820 i
/etc
/systemd
/system
/mailcert.timer
<<'EOF'
822 Description=Run mail-cert once a day
828 WantedBy=timers.target
832 wghost
=${HOSTNAME}wg.b8.nz
833 if $bhost_t && [[ ! -e /etc
/exim
4/certs
/$wghost/privkey.pem
]]; then
834 certbot
-n --manual-public-ip-logging-ok --eff-email --agree-tos -m letsencrypt@iankelling.org \
835 certonly
--manual --preferred-challenges=dns \
836 --manual-auth-hook /a
/bin
/ds
/le-dns-challenge \
837 --manual-cleanup-hook /a
/bin
/ds
/le-dns-challenge-cleanup \
838 --deploy-hook /a
/bin
/ds
/le-exim-deploy
-d $wghost
841 # * common exim4 config
844 # Make all system users be aliases. preventative
845 # measure for things like cron mail for user without alias
846 awk 'BEGIN { FS = ":" } ; $6 !~ /^\/home/ { print $1 }' /etc
/passwd|
while read -r user
; do
847 if [[ ! $user ]]; then
850 if ! grep -q "^$user:" /etc
/aliases
; then
851 echo "$user: root" |m
tee -a /etc
/aliases
855 if ! grep -q "^ncsoft:" /etc
/aliases
; then
856 echo "ncsoft: graceq2323@gmail.com" |m
tee -a /etc
/aliases
861 m gpasswd
-a iank adm
#needed for reading logs
863 ### make local bounces go to normal maildir
864 # local mail that bounces goes to /Maildir or /root/Maildir
865 dirs=(/m
/md
/bounces
/{cur
,tmp
,new
})
866 m mkdir
-p ${dirs[@]}
867 m chown iank
:iank
/m
/m
/md
868 m
ln -sfT /m
/md
/m
/iank
870 m chown
-R $u:Debian-exim
/m
/md
/bounces
871 m
chmod 775 ${dirs[@]}
872 m usermod
-a -G Debian-exim
$u
873 for d
in /Maildir
/root
/Maildir
; do
874 if [[ ! -L $d ]]; then
877 m
ln -sf -T /m
/md
/bounces
$d
880 # dkim, client passwd file
881 files
=(/p
/c
/machine_specific
/$HOSTNAME/filesystem
/etc
/exim
4/*)
882 f
=/p
/c
/filesystem
/etc
/exim
4/passwd.client
886 if (( ${#files[@]} )); then
887 m rsync
-ahhi --chown=root
:Debian-exim
--chmod=0640 \
888 ${files[@]} /etc
/exim4
891 # by default, only 10 days of logs are kept. increase that.
892 m
sed -ri 's/^(\s*rotate\s).*/\11000/' /etc
/logrotate.d
/exim4-base
895 ## https://blog.dhampir.no/content/make-exim4-on-debian-respect-forward-and-etcaliases-when-using-a-smarthost
896 # i only need .forwards, so just doing that one.
897 cd /etc
/exim
4/conf.d
/router
898 b
=userforward_higher_priority
899 # replace the router name so it is unique
900 sed -r s
/^
\\S
+:/$b:/ 600_exim4-config_userforward
>175_
$b
902 # todo, consider 'separate' in etc/exim4.conf, could it help on busy systems?
904 # alerts is basically the postmaster address
905 m
sed -i --follow-symlinks -f - /etc
/aliases
<<EOF
906 \$a root: alerts@iankelling.org
910 cat >/etc
/exim
4/conf.d
/rewrite
/34_iank_rewriting
<<'EOF'
911 ncsoft@zroe.org graceq2323@gmail.com hE
915 rm -fv /etc
/exim
4/conf.d
/retry
/37_retry
917 cat >/etc
/exim
4/conf.d
/retry
/17_retry
<<'EOF'
918 # Retry fast for my own domains
919 iankelling.org * F,1d,10m;F,14d,1h
920 amnimal.ninja * F,1d,10m;F,14d,1h
921 expertpathologyreview.com * F,1d,10m;F,14d,1h
922 je.b8.nz * F,1d,10m;F,14d,1h
923 zroe.org * F,1d,10m;F,14d,1h
924 eximbackup.b8.nz * F,1d,4m;F,14d,1h
928 rm -vf /etc
/exim
4/conf.d
/main
/000_localmacros
# old filename
929 cat >/etc
/exim
4/conf.d
/main
/000_local
<<EOF
930 MAIN_TLS_ENABLE = true
932 # require tls connections for all smarthosts
933 REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS = *
935 # debian exim config added this in 2016 or so?
936 # it's part of the smtp spec, to limit lines to 998 chars
937 # but a fair amount of legit mail does not adhere to it. I don't think
938 # this should be default, like it says in
939 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=828801
940 # todo: the bug for introducing this was about headers, but
941 # the fix maybe is for all lines? one says gmail rejects, the
942 # other says gmail does not reject. figure out and open a new bug.
943 IGNORE_SMTP_LINE_LENGTH_LIMIT = true
946 MAIN_LOG_SELECTOR = +all
948 # Based on spec, seems like a good idea to be nice.
949 smtp_return_error_details = true
951 # normally empty, I set this so I can set the envelope address
952 # when doing mail redelivery to invoke filters. Also allows
953 # me exiqgrep and stuff.
954 MAIN_TRUSTED_GROUPS = $u
956 # default is 10. when exim has been down for a bit, fsf mailserver
957 # will do a big send in one connection, then exim decides to put
958 # the messages in the queue instead of delivering them, to avoid
959 # spawning too many delivery processes. This is the same as the
960 # fsfs value. And the corresponding one for how many messages
961 # to send out in 1 connection remote_max_parallel = 256
962 smtp_accept_queue_per_connection = 500
969 # https://debian-administration.org/article/718/DKIM-signing_outgoing_mail_with_exim4
970 # and its best for this to align https://tools.ietf.org/html/rfc7489#page-8
971 # There could be some circumstance when the
972 # from: isnt our domain, but the envelope sender is
973 # and so still want to sign, but I cant think of any case.
974 DKIM_DOMAIN = \${lc:\${domain:\$rh_from:}}
975 # The file is based on the outgoing domain-name in the from-header.
977 DKIM_PRIVATE_KEY = \${if exists{/etc/exim4/\${dkim_domain}-private.pem} {/etc/exim4/\${dkim_domain}-private.pem}}
979 # most of the ones that gmail seems to use.
980 # Exim has horrible default of signing unincluded
981 # list- headers since they got mentioned in an
982 # rfc, but this messes up mailing lists, like gnu/debian which want to
983 # keep your dkim signature intact but add list- headers.
984 DKIM_SIGN_HEADERS = mime-version:in-reply-to:references:from:date:subject:to
986 domainlist local_hostnames = ! je.b8.nz : ! bk.b8.nz : *.b8.nz : b8.nz
988 hostlist iank_trusted = <; \\
992 72.14.176.105 ; 2600:3c00::f03c:91ff:fe6d:baf8 ; \\
993 # li_vpn_net li_vpn_net_ip6s
994 10.8.0.0/24; 2600:3c00:e000:280::/64 ; 2600:3c00:e002:3800::/56 ; \\
996 85.119.83.50 ; 2001:ba8:1f1:f0c9::2 ; \\
998 85.119.82.128 ; 2001:ba8:1f1:f09d::2 ; \\
999 # fsf_mit_net fsf_mit_net_ip6 fsf_net fsf_net_ip6 fsf_office_net
1000 18.4.89.0/24 ; 2603:3005:71a:2e00::/64 ; 209.51.188.0/24 ; 2001:470:142::/48 ; 74.94.156.208/28
1003 rm -fv /etc
/exim
4/rcpt_local_acl
# old path
1005 i
/etc
/exim
4/conf.d
/local_deny_exceptions_acl
<<'EOF'
1006 # This acl already exists in rcpt, this just makes it more widespread.
1007 # See the comment there for its rationale. The reason it needs to be
1008 # more widespread is that I've turned on sender verification, but cron
1009 # emails can fail sender verification since I may be in a network that
1010 # doesn't have my local dns.
1014 # i setup a local programs smtp to mail.iankelling.org, this
1015 # skips sender verification for it.
1020 rm -fv /etc
/exim
4/data_local_acl
# old path
1021 i
/etc
/exim
4/conf.d
/data_local_acl
<<'EOF'
1022 # Except for the "condition =", this was
1023 # a comment in the check_data acl. The comment about this not
1024 # being suitable has been changed in newer exim versions. The only thing
1025 # related I found was to
1026 # add the condition =, cuz spamassassin has problems with big
1027 # messages and spammers don't bother with big messages,
1028 # but I've increased the size from 10k
1029 # suggested in official docs, and 100k in the wiki example because
1030 # those docs are rather old and I see a 110k spam message
1031 # pretty quickly looking through my spam folder.
1034 !hosts = +iank_trusted
1035 remove_header = X-Spam_score: X-Spam_score_int : X-Spam_bar : X-Spam_report
1038 !hosts = +iank_trusted
1039 condition = ${if < {$message_size}{5000K}}
1040 spam = Debian-exim:true
1041 add_header = X-Spam_score_int: $spam_score_int
1042 add_header = X-Spam_score: $spam_score
1043 add_header = X-Spam_bar: $spam_bar
1044 add_header = X-Spam_report: $spam_report
1045 add_header = X-Spam_action: $spam_action
1048 condition = ${if def:malware_name}
1049 remove_header = Subject:
1050 add_header = Subject: [Clamav warning: $malware_name] $h_subject
1051 log_message = heuristic malware warning: $malware_name
1054 # spf = pass:fail:softfail:none:neutral:permerror:temperror
1055 # dmarc_status = reject:quarantine
1056 # add_header = Reply-to: dmarctest@iankelling.org
1060 i
/etc
/exim
4/conf.d
/router
/900_exim4-config_local_user
<<EOF
1061 ### router/900_exim4-config_local_user
1062 #################################
1064 # This router matches local user mailboxes. If the router fails, the error
1065 # message is "Unknown user".
1067 debug_print = "R: local_user for \$local_part@\$domain"
1069 domains = +local_domains
1070 # ian: default file except where mentioned.
1071 # ian: commented this. I get all local parts. for bk, an rcpt
1072 # check handles checking with dovecot, and the only router
1073 # after this is root.
1074 # local_parts = ! root
1075 transport = LOCAL_DELIVERY
1076 cannot_route_message = Unknown user
1077 # ian: added for + addressing.
1078 local_part_suffix = +*
1079 local_part_suffix_optional
1081 i
/etc
/exim
4/conf.d
/transport
/30_exim4-config_dovecot_lmtp
<<'EOF'
1084 socket = /var/run/dovecot/lmtp
1085 #maximum number of deliveries per batch, default 1
1090 i
/etc
/exim
4/conf.d
/transport
/30_remote_smtp_vpn
<<'EOF'
1091 # same as debians 30_exim4-config_remote_smtp, but
1092 # with interface added at the end.
1095 debug_print = "T: remote_smtp_vpn for $local_part@$domain"
1097 .ifndef IGNORE_SMTP_LINE_LENGTH_LIMIT
1098 message_size_limit = ${if > {$max_received_linelength}{998} {1}{0}}
1100 .ifdef REMOTE_SMTP_HOSTS_AVOID_TLS
1101 hosts_avoid_tls = REMOTE_SMTP_HOSTS_AVOID_TLS
1103 .ifdef REMOTE_SMTP_HEADERS_REWRITE
1104 headers_rewrite = REMOTE_SMTP_HEADERS_REWRITE
1106 .ifdef REMOTE_SMTP_RETURN_PATH
1107 return_path = REMOTE_SMTP_RETURN_PATH
1109 .ifdef REMOTE_SMTP_HELO_DATA
1110 helo_data=REMOTE_SMTP_HELO_DATA
1113 dkim_domain = DKIM_DOMAIN
1115 .ifdef DKIM_SELECTOR
1116 dkim_selector = DKIM_SELECTOR
1118 .ifdef DKIM_PRIVATE_KEY
1119 dkim_private_key = DKIM_PRIVATE_KEY
1122 dkim_canon = DKIM_CANON
1125 dkim_strict = DKIM_STRICT
1127 .ifdef DKIM_SIGN_HEADERS
1128 dkim_sign_headers = DKIM_SIGN_HEADERS
1130 .ifdef TLS_DH_MIN_BITS
1131 tls_dh_min_bits = TLS_DH_MIN_BITS
1133 .ifdef REMOTE_SMTP_TLS_CERTIFICATE
1134 tls_certificate = REMOTE_SMTP_TLS_CERTIFICATE
1136 .ifdef REMOTE_SMTP_PRIVATEKEY
1137 tls_privatekey = REMOTE_SMTP_PRIVATEKEY
1139 .ifdef REMOTE_SMTP_HOSTS_REQUIRE_TLS
1140 hosts_require_tls = REMOTE_SMTP_HOSTS_REQUIRE_TLS
1142 .ifdef REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
1143 headers_remove = REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
1145 interface = <; 10.8.0.4 ; 2600:3c00:e002:3800::4
1148 i
/etc
/exim
4/conf.d
/transport
/30_smarthost_dkim
<<'EOF'
1149 # ian: this is remote_smtp_smarthost plus the dkim parts from remote_smtp
1152 debug_print = "T: remote_smtp_smarthost for $local_part@$domain"
1155 .ifndef IGNORE_SMTP_LINE_LENGTH_LIMIT
1156 message_size_limit = ${if > {$max_received_linelength}{998} {1}{0}}
1158 hosts_try_auth = <; ${if exists{CONFDIR/passwd.client} \
1160 ${lookup{$host}nwildlsearch{CONFDIR/passwd.client}{$host_address}}\
1164 .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
1165 hosts_avoid_tls = REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
1167 .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS
1168 hosts_require_tls = REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS
1170 .ifdef REMOTE_SMTP_SMARTHOST_TLS_VERIFY_CERTIFICATES
1171 tls_verify_certificates = REMOTE_SMTP_SMARTHOST_TLS_VERIFY_CERTIFICATES
1173 .ifdef REMOTE_SMTP_SMARTHOST_TLS_VERIFY_HOSTS
1174 tls_verify_hosts = REMOTE_SMTP_SMARTHOST_TLS_VERIFY_HOST
1176 .ifdef REMOTE_SMTP_HEADERS_REWRITE
1177 headers_rewrite = REMOTE_SMTP_HEADERS_REWRITE
1179 .ifdef REMOTE_SMTP_RETURN_PATH
1180 return_path = REMOTE_SMTP_RETURN_PATH
1182 .ifdef REMOTE_SMTP_HELO_DATA
1183 helo_data=REMOTE_SMTP_HELO_DATA
1185 .ifdef TLS_DH_MIN_BITS
1186 tls_dh_min_bits = TLS_DH_MIN_BITS
1188 .ifdef REMOTE_SMTP_SMARTHOST_TLS_CERTIFICATE
1189 tls_certificate = REMOTE_SMTP_SMARTHOST_TLS_CERTIFICATE
1191 .ifdef REMOTE_SMTP_SMARTHOST_PRIVATEKEY
1192 tls_privatekey = REMOTE_SMTP_SMARTHOST_PRIVATEKEY
1194 .ifdef REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
1195 headers_remove = REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
1198 dkim_domain = DKIM_DOMAIN
1200 .ifdef DKIM_SELECTOR
1201 dkim_selector = DKIM_SELECTOR
1203 .ifdef DKIM_PRIVATE_KEY
1204 dkim_private_key = DKIM_PRIVATE_KEY
1207 dkim_canon = DKIM_CANON
1210 dkim_strict = DKIM_STRICT
1212 .ifdef DKIM_SIGN_HEADERS
1213 dkim_sign_headers = DKIM_SIGN_HEADERS
1218 cat >/etc
/exim
4/update-exim4.conf.conf
<<'EOF'
1219 # default stuff, i havent checked if its needed
1220 dc_minimaldns='false'
1223 dc_use_split_config='true'
1224 dc_mailname_in_oh='true'
1230 if ! mountpoint
/o
; then
1231 echo "error /o is not a mountpoint" >&2
1235 # davx/davdroid setup instructions at the bottom
1238 # http://radicale.org/user_documentation/
1239 # https://davdroid.bitfire.at/configuration/
1241 # note on debugging: if radicale can't bind to the address,
1242 # in the log it just says "Starting Radicale". If you run
1243 # it in the foreground, it will give more info. Background
1244 # plus debug does not help.
1245 # sudo -u radicale radicale -D -f
1247 # created password file with:
1248 # htpasswd -c /p/c/machine_specific/li/filesystem/etc/caldav-htpasswd
1249 # chmod 640 /p/c/machine_specific/li/filesystem/etc/caldav-htpasswd
1250 # # setup chgrp www-data in ./conflink
1254 i
/etc
/systemd
/system
/radicale.service.d
/override.conf
<<EOF
1256 # this unit is configured to start and stop whenever
1259 After=network.target network-online.target mailnn.service $vpnser
1262 Wants=network-online.target
1263 JoinsNamespaceOf=mailnn.service
1264 StartLimitIntervalSec=0
1268 BindPaths=$bindpaths
1270 # time to sleep before restarting a service
1279 # use persistent uid/gid
1280 IFS
=:; read -r _ _ uid _
< <(getent passwd radicale
); unset IFS
1281 IFS
=:; read -r _ _ gid _
< <(getent group radicale
); unset IFS
1282 if [[ $uid != 609 ]]; then
1283 m systemctl stop radicale ||
:
1284 m usermod
-u 609 radicale
1285 m groupmod
-g 609 radicale
1286 m usermod
-g 609 radicale
1288 m
find /o
/radicale
-xdev -exec chown
-h 609 {} +
1289 m
find /o
/radicale
-xdev -exec chgrp
-h 609 {} +
1292 # I moved /var/lib/radicale after it's initialization.
1293 # I did a sudo -u radicale git init in the collections subfolder
1294 # after it gets created, per the git docs.
1295 m
/a
/exe
/lnf
-T /o
/radicale
/var
/lib
/radicale
1297 # from https://www.williamjbowman.com/blog/2015/07/24/setting-up-webdav-caldav-and-carddav-servers/
1299 # more config is for li in distro-end
1301 # coment in this file says this is needed for it to run on startup
1302 sed -ri 's/^\s*#+\s*(ENABLE_RADICALE\s*=\s*yes\s*)/\1/' /etc
/default
/radicale
1304 # comments say default is 0.0.0.0:5232
1305 m setini hosts
10.8.0.4:5232 server
1306 # https://radicale.org/2.1.html
1307 m setini
type http_x_remote_user auth
1310 # disable power management feature, set to 240 min sync interval,
1311 # so it shouldn't be bad.
1313 # davdroid from f-druid.
1314 # login with url and user name
1315 # url https://cal.iankelling.org/ian
1317 # pass, see password manager for radicale
1319 # add account dialog:
1321 # set account name as ian@iankelling.org, per help text below the
1324 # switch to groups are per-contact categories,
1325 # per https://davdroid.bitfire.at/configuration/radicale/
1328 # After setting up account, I added one address book, named
1329 # ianaddr. calender was already created, named ian. checked boxes under
1332 # To restore from old phone to new phone, I wiped all data out, then copied over the newly created files. I think
1334 # ignorable background info:
1336 # opentasks uses the calendar file.
1338 # The address book I created got a uuid as a name for the file. Note
1339 # the .props file says if it's a calendar or addressbook.
1341 # When debugging, tailed /var/log/radicale/radicale.log and apache log,
1342 # both show the requests happening. Without creating the address book,
1343 # after creating a contact, a sync would delete it.
1345 # Address books correspond to .props files in the radicale dir.
1347 # Some background is here,
1348 # https://davdroid.bitfire.at/faq/entry/cant-manage-groups-on-device/
1349 # which shows separate vcard option is from rfc 6350, the other is 2426,
1350 # radicale page says it implements the former not the latter,
1351 # which conflicts with the documentation of which to select, but whatever.
1352 # http://radicale.org/technical_choices/
1353 # https://davdroid.bitfire.at/faq/entry/cant-manage-groups-on-device/
1355 # Note, url above says only cayanogenmod 13+ and omnirom can manage groups.
1357 # Note, radicale had built-in git support to track changes, but they
1358 # removed it in 2.0.
1364 # ** $MAIL_HOST|bk|je)
1367 # based on a little google and package search, just the dovecot
1368 # packages we need instead of dovecot-common.
1370 # dovecot-lmtpd is for exim to deliver to dovecot instead of maildir
1371 # directly. The reason to do this is to use dovecot\'s sieve, which
1372 # can generally do more than exims filters (a few things less) and
1373 # sieve has the benefit of being supported in postfix and
1374 # proprietary/weird environments, so there is more examples on the
1376 pi dovecot-core dovecot-imapd dovecot-sieve dovecot-lmtpd dovecot-sqlite sqlite3
1378 for f
in /p
/c
{/machine_specific
/$HOSTNAME,}/filesystem
/etc
/dovecot
/users
; do
1379 if [[ -e $f ]]; then
1380 m rsync
-ahhi --chown=root
:dovecot
--chmod=0640 $f /etc
/dovecot
/
1384 for f
in /p
/c
/subdir_files
/sieve
/*sieve
/a
/c
/subdir_files
/sieve
/*sieve
; do
1385 m sudo
-u $u /a
/exe
/lnf
-T $f $uhome/sieve
/${f##*/}
1388 # https://wiki.dovecot.org/SSL/DovecotConfiguration
1389 i
/etc
/dovecot
/dhparam
<<'EOF'
1390 -----BEGIN DH PARAMETERS-----
1391 MIIBCAKCAQEAoleil6SBxGqQKk7j0y2vV3Oklv6XupZKn7PkPv485QuFeFagifeS
1392 A+Jz6Wquqk5zhGyCu63Hp4wzGs4TyQqoLjkaWL6Ra/Bw3g3ofPEzMGEsV1Qdqde4
1393 jorwiwtr2i9E6TXQp0noT/7VFeHulIkayTeW8JulINdMHs+oLylv16McGCIrxbkM
1394 8D1PuO0TP/CNDs2QbRvJ1RjY3CeGpxMhrSHVgBCUMwnA2cvz3bYjI7UMYMMDPNrE
1395 PLrwsYzXGGCdJsO2vsmmqqgLsZiapYJlUNjfiyWLt7E2H6WzkNB3VIhIPfLqFDPK
1396 xioE3sYKdjOt+p6mlg3l8+OLtODEFPHDqwIBAg==
1397 -----END DH PARAMETERS-----
1400 if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
1402 ssl_cert = </etc/exim4/fullchain.pem
1403 ssl_key = </etc/exim4/privkey.pem
1407 ssl_cert = </etc/exim4/exim.crt
1408 ssl_key = </etc/exim4/exim.key
1412 # https://ssl-config.mozilla.org
1414 # this is the same as the certbot list, in my cert cronjob, I check if that has changed upstream.
1415 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
1416 ssl_protocols = TLSv1.2
1417 ssl_prefer_server_ciphers = no
1418 ssl_dh_parameters_length = 2048
1421 #per https://wiki2.dovecot.org/Pigeonhole/Sieve/Configuration
1422 # default is just \$mail_plugins
1423 mail_plugins = \$mail_plugins sieve
1426 if dpkg
--compare-versions $
(dpkg-query
-f='${Version}\n' --show dovecot-core
) ge
1:2.3; then
1428 ssl_dh = </etc/dovecot/dhparam
1431 } >/etc
/dovecot
/local.conf
1437 # If we changed 90-sieve.conf and removed the active part of the
1438 # sieve option, we wouldn\'t need this, but I\'d rather not modify a
1439 # default config if not needed. This won\'t work as a symlink in /a/c
1441 m sudo
-u $u /a
/exe
/lnf
-T sieve
/main.sieve
$uhome/.dovecot.sieve
1443 if [[ ! -e $uhome/sieve
/personal.sieve
]]; then
1444 m
touch $uhome/sieve
/personal
{,end
}{,test}.sieve
1447 rm -fv /etc
/dovecot
/conf.d
/20-lmtp.conf
# file from prev version
1448 cat >>/etc
/dovecot
/local.conf
<<EOF
1449 # simple password file based login
1450 !include conf.d/auth-passwdfile.conf.ext
1452 # ian: %u is used for alerts user vs iank
1453 mail_location = maildir:/m/%u:LAYOUT=fs:INBOX=/m/%u/INBOX
1458 # For a normal setup with exim, we need something like this, which
1459 # removes the domain part
1460 # auth_username_format = %Ln
1462 # or else # Exim says something like
1463 # "LMTP error after RCPT ... 550 ... User doesn't exist someuser@somedomain"
1464 # Dovecot verbose log says something like
1465 # "auth-worker(9048): passwd(someuser@somedomain): unknown user"
1466 # reference: http://wiki.dovecot.org/LMTP/Exim
1468 # However, I use this to direct all mail to the same inbox.
1469 # A normal way to do this, which I did at first is to have
1470 # a router in exim almost at the end, eg 950,
1472 # debug_print = "R: catchall for \$local_part@\$domain"
1474 # domains = +local_domains
1477 # http://blog.alteholz.eu/2015/04/exim4-and-catchall-email-address/
1478 # with superflous options removed.
1479 # However, this causes the envelope to be rewritten,
1480 # which makes filtering into mailboxes a little less robust or more complicated,
1481 # so I've done it this way instead. it also requires
1482 # modifying the local router in exim.
1483 auth_username_format = $u
1489 chown
-R mail.
mail /m
/md
1491 f
=/etc
/dovecot
/conf.d
/10-auth.conf
1492 if [[ -e $f ]]; then
1493 mv $f $f-iank-disabled
1496 cat >>/etc
/dovecot
/local.conf
<<EOF
1497 !include /etc/dovecot/local.conf.ext
1499 # for debugging info, uncomment these.
1500 # logs go to syslog and to /var/log/mail.log
1506 # This downcases the localpart. default is case sensitive.
1507 # case sensitive local part will miss out on valid email when some person or system
1508 # mistakenly capitalizes things.
1509 auth_username_format = %Lu
1512 # make 147 only listen on localhost, plan to use for nextcloud.
1513 # copied from mailinabox
1514 service imap-login {
1515 inet_listener imap {
1519 # https://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_dovecot_authenticator.html
1521 unix_listener auth-client {
1529 sieve_before = /etc/dovecot/sieve-spam.sieve
1531 sieve = /m/sieve/%d/%n.sieve
1532 sieve_dir = /m/sieve/%d/%n
1536 # all taken from mailinabox.
1537 mail_location = maildir:/m/md/%d/%n
1539 mail_privileged_group = mail
1540 # By default Dovecot allows users to log in only with UID numbers 500 and above. mail is 8
1543 # todo: test these changes in the universal config
1544 # mailboxes taken from mailinabox but removed
1545 # settings duplicate to defaults
1564 special_use = \Archive
1568 auth_mechanisms = plain login
1571 i
/etc
/dovecot
/sieve-spam.sieve
<<'EOF'
1572 require ["regex", "fileinto", "imap4flags"];
1574 if allof (header :regex "X-Spam-Status" "^Yes") {
1580 i
/etc
/dovecot
/local.conf.ext
<<'EOF'
1583 args = /etc/dovecot/dovecot-sql.conf.ext
1587 args = /etc/dovecot/dovecot-sql.conf.ext
1592 i
/etc
/dovecot
/dovecot-sql.conf.ext
<<'EOF'
1595 connect = /m/rc/users.sqlite
1596 default_pass_scheme = SHA512-CRYPT
1597 password_query = SELECT email as user, password FROM users WHERE email='%u';
1598 user_query = SELECT email AS user, "mail" as uid, "mail" as gid, "/m/md/%d/%n" as home FROM users WHERE email='%u';
1599 iterate_query = SELECT email AS user FROM users;
1601 m
chmod 0600 /etc
/dovecot
/dovecot-sql.conf.ext
# per Dovecot instructions
1603 # db needs to be in a www-data writable directory
1604 db
=/m
/rc
/users.sqlite
1605 if [[ ! -s $db ]]; then
1607 m sqlite3
$db <<'EOF'
1608 CREATE TABLE users (
1609 id INTEGER PRIMARY KEY AUTOINCREMENT,
1610 email TEXT NOT NULL UNIQUE,
1611 password TEXT NOT NULL,
1613 privileges TEXT NOT NULL DEFAULT '');
1616 # example of adding a user:
1617 # hash: doveadm pw -s SHA512-CRYPT -p passhere
1618 # sqlite3 /m/rc/users.sqlite <<'EOF'
1619 #insert into users (email, password) values ('testignore@bk.b8.nz', 'hash');
1621 # update users set password = 'hash' where email = 'testignore@bk.b8.nz';
1623 # this should be at the end since it requires a valid dovecot config
1624 m sievec
/etc
/dovecot
/sieve-spam.sieve
1628 # roundcube uses this
1630 chown
mail.
mail /m
/sieve
1631 m pi dovecot-managesieved
1635 # * thunderbird autoconfig setup
1637 bkdomains
=(expertpathologyreview.com amnimal.ninja
)
1638 if [[ $HOSTNAME == bk
]]; then
1639 for domain
in ${bkdomains[@]}; do
1640 m
/a
/exe
/web-conf apache2 autoconfig.
$domain
1641 dir
=/var
/www
/autoconfig.
$domain/html
/mail
1643 # taken from mailinabox
1644 i
$dir/config-v1.1.xml
<<EOF
1645 <?xml version="1.0" encoding="UTF-8"?>
1646 <clientConfig version="1.1">
1647 <emailProvider id="$domain">
1648 <domain>$domain</domain>
1650 <displayName>$domain Mail</displayName>
1651 <displayShortName>$domain</displayShortName>
1653 <incomingServer type="imap">
1654 <hostname>mail2.iankelling.org</hostname>
1656 <socketType>SSL</socketType>
1657 <username>%EMAILADDRESS%</username>
1658 <authentication>password-cleartext</authentication>
1661 <outgoingServer type="smtp">
1662 <hostname>mail2.iankelling.org</hostname>
1664 <socketType>STARTTLS</socketType>
1665 <username>%EMAILADDRESS%</username>
1666 <authentication>password-cleartext</authentication>
1667 <addThisServer>true</addThisServer>
1668 <useGlobalPreferredServer>false</useGlobalPreferredServer>
1671 <documentation url="https://$domain/">
1672 <descr lang="en">$domain website.</descr>
1677 <loginPage url="https://$domain/roundcube" />
1678 <loginPageInfo url="https://$domain/roundcube" >
1679 <username>%EMAILADDRESS%</username>
1680 <usernameField id="rcmloginuser" name="_user" />
1681 <passwordField id="rcmloginpwd" name="_pass" />
1682 <loginButton id="rcmloginsubmit" />
1685 <clientConfigUpdate url="https://autoconfig.$domain/mail/config-v1.1.xml" />
1693 if [[ $HOSTNAME == bk
]]; then
1695 # zip according to /installer
1696 # which requires adding a line to /usr/local/lib/roundcubemail/config/config.inc.php
1697 # $config['enable_installer'] = true;
1698 pi roundcube roundcube-sqlite3 php-zip apache2 php-fpm
1700 ### begin composer install
1701 # https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md
1703 # sum="$(wget -q -O - https://composer.github.io/installer.sig)"
1704 # m php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
1705 # if [[ $sum != $(php -r "echo hash_file('sha384', 'composer-setup.php');") ]]; then
1706 # echo 'ERROR: Invalid composer installer checksum' >&2
1707 # rm -fv composer-setup.php
1710 # m php composer-setup.php --quiet
1711 # rm -fv composer-setup.php
1712 # m mv composer.phar /usr/local/bin
1714 # the above method gets composer2, carddav plugin at least doesnt work with that
1715 # yet, it was just released 10-24-2020.
1717 m wget
-nv -N https
://getcomposer.org
/composer-1.phar
1718 chmod +x composer-1.phar
1719 ### end composer install
1721 rcdirs
=(/usr
/local
/lib
/rcexpertpath
/usr
/local
/lib
/rcninja
)
1722 ncdirs
=(/var
/www
/ncexpertpath
/var
/www
/ncninja
)
1723 # point debian cronjob to our local install, preventing daily cron error
1725 # debian's cronjob will fail, remove both paths it uses just to be sure
1726 rm -fv /usr
/share
/roundcube
/bin
/cleandb.sh
/etc
/cron.d
/roundcube-core
1728 #### begin dl roundcube
1729 # note, im r2e subbed to https://github.com/roundcube/roundcubemail/releases.atom
1730 v
=1.4.11; f
=roundcubemail-
$v-complete.
tar.gz
1732 if [[ -e $f ]]; then
1733 timestamp
=$
(stat
-c %Y
$f)
1737 m wget
-nv -N https
://github.com
/roundcube
/roundcubemail
/releases
/download
/$v/$f
1738 new_timestamp
=$
(stat
-c %Y
$f)
1739 for rcdir
in ${rcdirs[@]}; do
1740 if [[ $timestamp != "$new_timestamp" ||
! -e "$rcdir/config/secret" ]]; then
1741 m
tar -C /usr
/local
/lib
--no-same-owner -zxf $f
1743 m
mv /usr
/local
/lib
/roundcubemail-
$v $rcdir
1746 #### end dl roundcube
1748 for ((i
=0; i
< ${#bkdomains[@]}; i
++)); do
1749 domain
=${bkdomains[i]}
1754 # copied from debians cronjob
1755 i
/etc
/cron.d
/$rcbase <<EOF
1756 # Roundcube database cleaning: finally removes all records that are
1757 # marked as deleted.
1758 0 5 * * * www-data $rcdir/bin/cleandb.sh >/dev/null
1761 m
/a
/exe
/web-conf
- apache2
$domain <<EOF
1762 Alias /roundcube $rcdir
1763 ### begin roundcube settings
1764 # taken from /etc/apache2/conf-available/roundcube.conf version 1.4.8+dfsg.1-1~bpo10+1
1766 Options +FollowSymLinks
1767 # This is needed to parse $rcdir/.htaccess.
1771 # Protecting basic directories:
1772 <Directory $rcdir/config>
1773 Options -FollowSymLinks
1776 ### end roundcube settings
1779 ### begin nextcloud settings
1780 Alias /nextcloud "$ncdir/"
1784 Options FollowSymLinks MultiViews
1786 <IfModule mod_dav.c>
1792 # based on install checker, links to
1793 # https://docs.nextcloud.com/server/19/admin_manual/issues/general_troubleshooting.html#service-discovery
1794 # their example was a bit wrong, I figured it out by adding
1795 # LogLevel warn rewrite:trace5
1796 # then watching the apache logs
1799 RewriteRule ^/\.well-known/host-meta /nextcloud/public.php?service=host-meta [QSA,L]
1800 RewriteRule ^/\.well-known/host-meta\.json /nextcloud/public.php?service=host-meta-json [QSA,L]
1801 RewriteRule ^/\.well-known/webfinger /nextcloud/public.php?service=webfinger [QSA,L]
1802 RewriteRule ^/\.well-known/carddav /nextcloud/remote.php/dav/ [R=301,L]
1803 RewriteRule ^/\.well-known/caldav /nextcloud/remote.php/dav/ [R=301,L]
1804 ### end nextcloud settings
1806 if [[ ! -e $rcdir/config
/secret
]]; then
1807 base64
</dev
/urandom |
head -c24 >$rcdir/config
/secret ||
[[ $?
== 141 ||
${PIPESTATUS[0]} == 32 ]]
1809 secret
=$
(cat $rcdir/config
/secret
)
1811 rclogdir
=/var
/log
/$rcbase
1812 rctmpdir
=/var
/tmp
/$rcbase
1813 rcdb
=/m
/rc
/$rcbase.sqlite
1814 # config from mailinabox
1815 i
$rcdir/config
/config.inc.php
<<EOF
1818 # debian creates this for us
1819 \$config['log_dir'] = '$rclogdir/';
1820 # debian also creates a temp dir, but it is under its install dir,
1821 # seems better to have our own.
1822 \$config['temp_dir'] = '$rctmpdir/';
1823 \$config['db_dsnw'] = 'sqlite:///$rcdb?mode=0640';
1824 \$config['default_host'] = 'ssl://localhost';
1825 \$config['default_port'] = 993;
1826 \$config['imap_conn_options'] = array(
1828 'verify_peer' => false,
1829 'verify_peer_name' => false,
1832 \$config['imap_timeout'] = 15;
1833 \$config['smtp_server'] = 'tls://127.0.0.1';
1834 \$config['smtp_conn_options'] = array(
1836 'verify_peer' => false,
1837 'verify_peer_name' => false,
1840 \$config['product_name'] = 'webmail';
1841 \$config['des_key'] = '$secret';
1842 \$config['plugins'] = array('archive', 'zipdownload', 'password', 'managesieve', 'jqueryui', 'carddav', 'html5_notifier');
1843 \$config['skin'] = 'elastic';
1844 \$config['login_autocomplete'] = 2;
1845 \$config['password_charset'] = 'UTF-8';
1846 \$config['junk_mbox'] = 'Spam';
1847 # disable builtin addressbook
1848 \$config['address_book_type'] = '';
1852 m mkdir
-p $rclogdir
1853 m
chmod 750 $rclogdir
1854 m chown www-data
:adm
$rclogdir
1855 # note: subscribed to updates:
1856 # r2e add rcmcarddav https://github.com/blind-coder/rcmcarddav/commits/master.atom ian@iankelling.org
1857 # r2e add roundcube https://github.com/roundcube/roundcubemail/releases.atom ian@iankelling.org
1858 m mkdir
-p $rctmpdir /m
/rc
1859 m chown
-R www-data.www-data
$rctmpdir /m
/rc
1860 m
chmod 750 $rctmpdir
1861 # Ensure the log file monitored by fail2ban exists, or else fail2ban can't start.
1862 # todo: setup fail2ban
1863 # todo: check for other mailinabox things
1864 m sudo
-u www-data
touch $rclogdir/errors.log
1866 #### begin carddav install
1867 # This is the official roundcube carddav repo.
1868 # Install doc suggests downloading with composer, but that
1869 # didnt work, it said some ldap package for roundcube was missing,
1870 # but I dont want to download some extra ldap thing.
1871 # https://github.com/blind-coder/rcmcarddav/blob/master/doc/INSTALL.md
1872 verf
=$rcdir/plugins
/carddav
/myversion
1876 if [[ -e $verf ]]; then
1877 if [[ $
(cat $verf) != "$v" ]]; then
1885 m
rm -rf $rcdir/plugins
/carddav
1887 m wget
-nv -O $tmpd/t.tgz https
://github.com
/blind-coder
/rcmcarddav
/releases
/download
/v
$v/carddav-v
$v.tgz
1891 m chown
-R www-data
:www-data
$rcdir/plugins
/carddav
1892 m
cd $rcdir/plugins
/carddav
1894 m sudo
-u www-data composer-1.phar update
--no-dev
1896 m sudo
-u www-data composer-1.phar
install --no-dev
1898 m chown
-R root
:root
$rcdir/plugins
/carddav
1902 # So, strangely, this worked in initial testing, but then
1903 # on first run it wouldn't show the existing contacts until
1904 # I went into the carddav settings and did "force immediate sync",
1905 # which seemed to fix things. Note, some of these settings
1906 # get initalized per/addressbook in the db, then need changing
1907 # there or through the settings menu.
1909 # About categories, see https://www.davx5.com/tested-with/nextcloud
1910 # https://github.com/blind-coder/rcmcarddav/blob/master/doc/GROUPS.md
1911 i
$rcdir/plugins
/carddav
/config.inc.php
<<EOF;
1913 \$prefs['_GLOBAL']['hide_preferences'] = false;
1914 \$prefs['davserver'] = array(
1915 # name in the UI is kind of dumb. This is just something short that seems to fit ok.
1917 'username' => '%u', // login username
1918 'password' => '%p', // login password
1919 'url' => 'https://$domain/nextcloud/remote.php/dav/addressbooks/users/%u/contacts',
1921 'readonly' => false,
1922 'refresh_time' => '00:10:00',
1923 'fixed' => array('username','password'),
1924 'use_categories' => false,
1929 #### end carddav install
1932 if [[ ! -d html5_notifier
]]; then
1933 m git clone https
://github.com
/stremlau
/html5_notifier
1935 cd $rcdir/plugins
/html5_notifier
1938 # todo: try out roundcube plugins: thunderbird labels
1940 # Password changing plugin settings
1941 cat $rcdir/plugins
/password
/config.inc.php.dist
- >$rcdir/plugins
/password
/config.inc.php
<<'EOF'
1942 # following are from mailinabox
1943 $config['password_minimum_length'] = 8;
1944 $config['password_db_dsn'] = 'sqlite:////m/rc/users.sqlite';
1945 $config['password_query'] = 'UPDATE users SET password=%D WHERE email=%u';
1946 $config['password_dovecotpw'] = '/usr/bin/doveadm pw';
1947 $config['password_dovecotpw_method'] = 'SHA512-CRYPT';
1948 $config['password_dovecotpw_with_method'] = true;
1950 # so PHP can use doveadm, for the password changing plugin
1951 m usermod
-a -G dovecot www-data
1952 m usermod
-a -G mail $u
1954 # so php can update passwords
1955 m chown www-data
:dovecot
/m
/rc
/users.sqlite
1956 m
chmod 664 /m
/rc
/users.sqlite
1958 # Run Roundcube database migration script (database is created if it does not exist)
1959 m
$rcdir/bin
/updatedb.sh
--dir $rcdir/SQL
--package roundcube
1960 m chown www-data
:www-data
$rcdb
1962 done # end loop over domains and rcdirs
1964 ### begin php setup for rc ###
1965 # Enable PHP modules.
1966 m phpenmod
-v php mcrypt imap
1967 # dpkg says this is required
1968 m a2enmod proxy_fcgi setenvif
1969 fpm
=$
(dpkg-query
-s php-fpm |
sed -nr 's/^Depends:.* (php[^ ]*-fpm)( .*|$)/\1/p') # eg: php7.3-fpm
1970 phpver
=$
(dpkg-query
-s php-fpm |
sed -nr 's/^Depends:.* php([^ ]*)-fpm( .*|$)/\1/p')
1972 # 3 useless guides on php fpm fcgi debian 10 later, i figure out from reading
1973 # /etc/apache2/conf-enabled/php7.3-fpm.conf
1974 m a2dismod php
$phpver
1975 # according to /install, we should set date.timezone,
1976 # but that is dumb, the system already has the right zone in
1977 # $rclogdir/errors.log
1978 # todo: consider other settings in
1979 # /a/opt/mailinabox/setup/nextcloud.sh
1980 i
/etc
/php
/$phpver/cli
/conf.d
/30-local.ini
<<'EOF'
1984 i
/etc
/php
/$phpver/fpm
/conf.d
/30-local.ini
<<'EOF'
1985 date.timezone = "America/New_York"
1987 upload_max_filesize = 2000M
1988 post_max_size = 2000M
1989 # install checker, nextcloud/settings/admin/overview
1992 m systemctl restart
$fpm
1993 # dunno if reload/restart is needed
1994 m systemctl reload apache2
1995 # note bk backups are defined in crontab outside this file
1996 ### end php setup for rc ###
1998 fi # end roundcube setup
2002 if [[ $HOSTNAME == bk
]]; then
2003 # from install checker, nextcloud/settings/admin/overview and
2004 # https://docs.nextcloud.com/server/19/admin_manual/installation/source_installation.html
2005 # curl from the web installer requirement, but i switched to cli
2006 # it recommends php-file info, but that is part of php7.3-common, already got installed
2008 m pi php-curl php-bz2 php-gmp php-bcmath php-imagick php-apcu
2010 # https://docs.nextcloud.com/server/19/admin_manual/installation/source_installation.html
2011 cat >/etc
/php
/$phpver/fpm
/pool.d
/localwww.conf
<<'EOF'
2016 for ((i
=0; i
< ${#bkdomains[@]}; i
++)); do
2017 domain
=${bkdomains[i]}
2021 if [[ ! -e $ncdir/index.php
]]; then
2022 # if we wanted to only install a specific version, use something like
2023 # file=latest-22.zip
2025 m wget
-nv -N https
://download.nextcloud.com
/server
/releases
/$file
2029 m chown
-R www-data.www-data nextcloud
2030 m
mv nextcloud
$ncdir
2032 m sudo
-u www-data php occ maintenance
:install --database sqlite
--admin-user iank
--admin-pass $nextcloud_admin_pass
2034 # note, strange this happend where updater did not increment the version var,
2035 # mine was stuck on 20. I manually updated it.
2037 if [[ ! -e config.php-orig
]]; then
2038 m
cp -a config.php config.php-orig
2040 cat config.php-orig
- >tmp.php
<<EOF
2041 # https://docs.nextcloud.com/server/19/admin_manual/configuration_server/email_configuration.html
2042 \$CONFIG["mail_smtpmode"] = "sendmail";
2043 \$CONFIG["mail_smtphost"] = "127.0.0.1";
2044 \$CONFIG["mail_smtpport"] = 25;
2045 \$CONFIG["mail_smtptimeout"] = 10;
2046 \$CONFIG["mail_smtpsecure"] = "";
2047 \$CONFIG["mail_smtpauth"] = false;
2048 \$CONFIG["mail_smtpauthtype"] = "LOGIN";
2049 \$CONFIG["mail_smtpname"] = "";
2050 \$CONFIG["mail_smtppassword"] = "";
2051 \$CONFIG["mail_domain"] = "$domain";
2053 # https://github.com/nextcloud/user_external#readme
2054 # plus mailinabox example
2055 #\$CONFIG['user_backends'] = array(array('class' => 'OC_User_IMAP','arguments' => array('127.0.0.1', 143, null),),);
2058 # based on installer check
2059 # https://docs.nextcloud.com/server/19/admin_manual/configuration_server/caching_configuration.html
2060 \$CONFIG['memcache.local'] = '\OC\Memcache\APCu';
2062 \$CONFIG['overwrite.cli.url'] = 'https://$domain/nextcloud';
2063 \$CONFIG['htaccess.RewriteBase'] = '/nextcloud';
2064 \$CONFIG['trusted_domains'] = array (
2068 fwrite(STDOUT, "<?php\n\\\$CONFIG = ");
2069 var_export(\$CONFIG);
2070 fwrite(STDOUT, ";\n");
2072 m php tmp.php
>config.php
2074 m sudo
-u www-data php
$ncdir/occ maintenance
:update
:htaccess
2075 list
=$
(sudo
-u www-data php
$ncdir/occ
--output=json_pretty app
:list
)
2076 # user_external not compaible with nc 23
2077 for app
in contacts calendar
; do
2078 if [[ $
(printf "%s\n" "$list"| jq
".enabled.$app") == null
]]; then
2079 m sudo
-u www-data php
$ncdir/occ app
:install $app
2082 i
/etc
/systemd
/system
/$ncbase.service
<<EOF
2084 Description=ncup $ncbase
2085 After=multi-user.target
2089 ExecStart=/usr/local/bin/ncup $ncbase
2091 IOSchedulingClass=idle
2092 CPUSchedulingPolicy=idle
2094 i
/etc
/systemd
/system
/$ncbase.timer
<<EOF
2096 Description=ncup $ncbase timer
2102 WantedBy=timers.target
2104 systemctl
enable --now $ncbase.timer
2105 i
/usr
/local
/bin
/ncup
<<'EOFOUTER'
2107 if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
2108 shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4
2110 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR
2113 if ! php /var/www/$ncbase/updater/updater.phar -n; then
2114 echo failed nextcloud update for $ncbase >&2
2116 To: alerts@iankelling.org
2117 From: root@$(hostname -f)
2118 Subject: failed nextcloud update for $ncbase
2120 For logs, run: jr -u $ncbase
2125 mkdir
-p /var
/www
/cron-errors
2126 chown www-data.www-data
/var
/www
/cron-errors
2127 i
/etc
/cron.d
/$ncbase <<EOF
2128 PATH=/sbin:/usr/sbin:/usr/bin:/bin:/usr/local/bin
2130 # https://docs.nextcloud.com/server/20/admin_manual/configuration_server/background_jobs_configuration.html
2131 */5 * * * * www-data php -f $ncdir/cron.php --define apc.enable_cli=1 |& log-once nccron
2138 # * exim host conditional config
2142 all_dirs
=(/p
/c
/filesystem
)
2143 for x
in /p
/c
/machine_specific
/*.hosts
/a
/bin
/ds
/machine_specific
/*.hosts
; do
2144 if grep -qxF $HOSTNAME $x; then all_dirs
+=( ${x%.hosts} ); fi
2147 for d
in ${all_dirs[@]}; do
2148 f
=$d/etc
/exim
4/passwd
2149 if [[ -e $f ]]; then
2152 tmp
=($d/etc
/exim
4/*.pem
)
2153 if (( ${#tmp[@]} )); then
2158 if (( ${#files[@]} )); then
2159 sudo rsync
-ahhi --chown=root
:Debian-exim
--chmod=0640 ${files[@]} /etc
/exim
4/
2167 # avoid accepting mail for invalid users
2168 # https://wiki.dovecot.org/LMTP/Exim
2169 cat >>/etc
/exim
4/conf.d
/rcpt_local_acl
<<'EOF'
2171 message = invalid recipient
2172 domains = +local_domains
2173 !verify = recipient/callout=no_cache
2175 i
/etc
/exim
4/conf.d
/auth
/29_exim4-config_auth
<<'EOF'
2179 server_socket = /var/run/dovecot/auth-client
2180 server_set_id = $auth1
2185 i
/etc
/exim
4/conf.d
/auth
/29_exim4-config_auth
<<'EOF'
2186 # from 30_exim4-config_examples
2190 server_condition = "${if crypteq{$auth3}{${extract{1}{:}{${lookup{$auth2}lsearch{CONFDIR/passwd}{$value}{*:*}}}}}{1}{0}}"
2191 server_set_id = $auth2
2193 .ifndef AUTH_SERVER_ALLOW_NOTLS_PASSWORDS
2194 server_advertise_condition = ${if eq{$tls_in_cipher}{}{}{*}}
2199 # ** main daemon use non-default config file
2202 # to see the default comments in /etc/default/exim4:
2203 # s update-exim4defaults --force --init
2204 # which will overwrite any existing file
2205 i
/etc
/default
/exim4
<<'EOF'
2206 QUEUERUNNER='combined'
2208 COMMONOPTIONS='-C /etc/exim4/my.conf'
2209 UPEX4OPTS='-o /etc/exim4/my.conf'
2210 #E4BCD_PANICLOG_NOISE='malware acl condition: clamd /var/run/clamav/clamd\.ctl : unable to connect to UNIX socket'
2212 i
/etc
/exim
4/trusted_configs
<<'EOF'
2218 i
/etc
/default
/exim4
<<'EOF'
2219 QUEUERUNNER='combined'
2226 # ** $MAIL_HOST|bk|je)
2229 echo|i
/etc
/exim
4/conf.d
/router
/870_backup_local
2231 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2232 # note: some things we don't set that are here by default because they are unused.
2233 dc_local_interfaces=''
2234 dc_eximconfig_configtype='internet'
2235 dc_localdelivery='dovecot_lmtp'
2237 cat >>/etc
/exim
4/conf.d
/main
/000_local
<<EOF
2238 # recommended if dns is expected to work
2239 CHECK_RCPT_VERIFY_SENDER = true
2240 # default config comment says: If you enable this, you might reject legitimate mail,
2241 # but eggs has had this a long time, so that seems unlikely.
2242 CHECK_DATA_VERIFY_HEADER_SYNTAX = true
2243 CHECK_RCPT_SPF = true
2244 CHECK_RCPT_REVERSE_DNS = true
2245 CHECK_MAIL_HELO_ISSUED = true
2247 # enable 587 in addition to the default 25, so that
2248 # i can send mail where port 25 is firewalled by isp
2249 daemon_smtp_ports = 25 : 587
2250 # default of 25, can get stuck when catching up on mail
2251 smtp_accept_max = 400
2252 smtp_accept_reserve = 100
2253 smtp_reserve_hosts = +iank_trusted
2255 # options exim has to avoid having to alter the default config files
2256 CHECK_RCPT_LOCAL_ACL_FILE = /etc/exim4/conf.d/rcpt_local_acl
2257 CHECK_DATA_LOCAL_ACL_FILE = /etc/exim4/conf.d/data_local_acl
2258 LOCAL_DENY_EXCEPTIONS_LOCAL_ACL_FILE = /etc/exim4/conf.d/local_deny_exceptions_acl
2260 #dmarc_tld_file = /etc/public_suffix_list.dat
2267 cat >>/etc
/exim
4/conf.d
/main
/000_local
<<EOF
2268 # je.b8.nz will run out of memory with freshclam
2269 av_scanner = clamd:/var/run/clamav/clamd.ctl
2272 cat >> /etc
/exim
4/conf.d
/data_local_acl
<<'EOF'
2274 malware = */defer_ok
2275 !condition = ${if match {$malware_name}{\N^Heuristic\N}}
2276 message = This message was detected as possible malware ($malware_name).
2279 cat >/etc
/exim
4/conf.d
/main
/000_local-nn
<<EOF
2280 # MAIN_HARDCODE_PRIMARY_HOSTNAME might mess up the
2281 # smarthost config type, not sure.
2282 # failing message on mail-tester.com:
2283 # We check if there is a server (A Record) behind your hostname kd.
2284 # You may want to publish a DNS record (A type) for the hostname kd or use a different hostname in your mail software
2285 # https://serverfault.com/questions/46545/how-do-i-change-exim4s-primary-hostname-on-a-debian-box
2286 # and this one seemed appropriate from grepping config.
2287 # I originally set this to li.iankelling.org, but then ended up with errors when li tried to send
2288 # mail to kd, so this should basically be a name that no host has as their
2289 # canonical hostname since the actual host sits behind a nat and changes.
2290 MAIN_HARDCODE_PRIMARY_HOSTNAME = mail.iankelling.org
2291 # I used this to avoid sender verification, didnt work but it still
2292 # makes sense based on the spec.
2293 hosts_treat_as_local = defaultnn.b8.nz
2295 # Outside nn, we get the default cert location from a debian macro,
2296 # and the cert file is put in place by a certbot hook.
2297 MAIN_TLS_CERTIFICATE = /etc/exim4/fullchain.pem
2298 MAIN_TLS_PRIVATEKEY = /etc/exim4/privkey.pem
2301 i
/etc
/exim
4/conf.d
/router
/190_exim4-config_fsfsmarthost
<<'EOF'
2303 debug_print = "R: smarthost for $local_part@$domain"
2304 driver = manualroute
2305 domains = ! +local_domains
2306 # send most mail through eggs, helps fsfs sender reputation.
2307 # uncomment and optionally move to 188 file to send through my own servers again
2309 transport = smarthost_dkim
2310 route_list = * fencepost.gnu.org::587 byname
2311 host_find_failed = ignore
2312 same_domain_copy_routing = yes
2316 /a
/exe
/cedit defaultnn
/etc
/hosts
<<'EOF' || [[ $? == 1 ]]
2317 10.173.8.1 defaultnn.b8.nz
2323 i
/etc
/exim
4/conf.d
/router
/195_dnslookup_vpn
<<'EOF'
2324 # copied from /etc/exim4/conf.d/router/200_exim4-config_primary, but
2325 # use vpn transport. lower priority so it overrides the default route.
2326 # Use this in case our vpn fails, we dont send anything without it.
2327 .ifdef DCconfig_internet
2329 debug_print = "R: dnslookup for $local_part@$domain"
2331 domains = ! +local_domains
2332 transport = remote_smtp_vpn
2333 same_domain_copy_routing = yes
2334 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
2340 # note on backups: I used to do an automatic sshfs and restricted
2341 # permissions to a specific directory on the remote server, /bu/mnt,
2342 # which required using a dedicated user, but realized smtp will be
2343 # more reliable and less fuss. If I ever need that again, see the
2344 # history of this file, and bum in brc2.
2346 i
/etc
/exim
4/conf.d
/router
/890_backup_copy
<<EOF
2347 ### router/900_exim4-config_local_user
2348 #################################
2350 # todo, it would be nice to save sent email too,
2351 # but its not so important, they still exist in my head
2355 domains = +local_domains
2356 # b is just an arbirary short string
2357 data = b@eximbackup.b8.nz
2358 # note, to test this, i could temporarily allow testignore.
2359 # alerts avoids potential mail loop. root is already
2360 # redirected earlier, so that is just being overly cautious.
2361 local_parts = ! root : ! testignore : ! alerts
2365 driver = manualroute
2366 domains = eximbackup.b8.nz
2367 transport = backup_remote
2368 ignore_target_hosts = ${HOSTNAME}wg.b8.nz
2369 # note changes here also require change in passwd.client
2370 route_list = * eximbackup.b8.nz
2371 same_domain_copy_routing = yes
2376 i
/etc
/exim
4/conf.d
/transport
/30_backup_remote
<<'EOF'
2380 .ifndef IGNORE_SMTP_LINE_LENGTH_LIMIT
2381 message_size_limit = ${if > {$max_received_linelength}{998} {1}{0}}
2383 hosts_require_auth = *
2385 return_path = alerts@iankelling.org
2387 # manual return path because we dont want it to be the envelope sender
2388 # we got not the one we are using in this smtp transport
2389 headers_add = "Return-path: $sender_address"
2390 .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
2391 hosts_avoid_tls = REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
2393 .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS
2394 hosts_require_tls = REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS
2396 .ifdef REMOTE_SMTP_SMARTHOST_TLS_VERIFY_CERTIFICATES
2397 tls_verify_certificates = REMOTE_SMTP_SMARTHOST_TLS_VERIFY_CERTIFICATES
2399 .ifdef REMOTE_SMTP_SMARTHOST_TLS_VERIFY_HOSTS
2400 tls_verify_hosts = REMOTE_SMTP_SMARTHOST_TLS_VERIFY_HOST
2402 .ifdef REMOTE_SMTP_HEADERS_REWRITE
2403 headers_rewrite = REMOTE_SMTP_HEADERS_REWRITE
2405 .ifdef REMOTE_SMTP_HELO_DATA
2406 helo_data=REMOTE_SMTP_HELO_DATA
2408 .ifdef TLS_DH_MIN_BITS
2409 tls_dh_min_bits = TLS_DH_MIN_BITS
2411 .ifdef REMOTE_SMTP_SMARTHOST_TLS_CERTIFICATE
2412 tls_certificate = REMOTE_SMTP_SMARTHOST_TLS_CERTIFICATE
2414 .ifdef REMOTE_SMTP_SMARTHOST_PRIVATEKEY
2415 tls_privatekey = REMOTE_SMTP_SMARTHOST_PRIVATEKEY
2417 .ifdef REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
2418 headers_remove = REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
2423 # this avoids some error. i cant remember what. todo:
2424 # test it out and document why/if its needed.
2425 i
/etc
/exim
4/host_local_deny_exceptions
<<'EOF'
2430 # cron email from smarthost hosts will automatically be to
2431 # USER@FQDN. I redirect that to alerts@, on the smarthosts, but in
2432 # case that doesn't work, we still want to accept that mail, but not
2433 # from any host except the smarthosts. local_hostnames and this rule
2434 # is for that purpose.
2435 i
/etc
/exim
4/conf.d
/rcpt_local_acl
<<'EOF'
2438 domains = +local_hostnames
2441 echo|i
/etc
/exim
4/conf.d
/router
/880_universal_forward
2443 # for iank@fsf.org, i have mail.fsf.org forward it to fsf@iankelling.org.
2444 # and also have mail.iankelling.org whitelisted as a relay domain.
2445 # I could avoid that if I changed this to submit to 587 with a
2446 # password like a standard mua.
2447 i
/etc
/exim
4/conf.d
/router
/188_exim4-config_smarthost
<<'EOF'
2448 # ian: copied from /etc/exim4/conf.d/router/200_exim4-config_primary, and added senders = and
2449 # replaced DCsmarthost with hostname
2451 debug_print = "R: smarthost for $local_part@$domain"
2452 driver = manualroute
2453 domains = ! +local_domains
2455 transport = remote_smtp_smarthost
2456 route_list = * mail.fsf.org::587 byname
2457 host_find_failed = ignore
2458 same_domain_copy_routing = yes
2462 debug_print = "R: smarthost for $local_part@$domain"
2463 driver = manualroute
2464 domains = ! +local_domains
2465 senders = *@posteo.net
2466 transport = remote_smtp_smarthost
2467 route_list = * posteo.de::587 byname
2468 host_find_failed = ignore
2469 same_domain_copy_routing = yes
2474 # Greping /etc/exim4, unqualified mails this would end up as
2475 # a return path, so it should go somewhere we will see.
2476 # The debconf output about mailname is as follows:
2477 # The 'mail name' is the domain name used to 'qualify' mail addresses without a domain
2479 # This name will also be used by other programs. It should be the single, fully
2480 # qualified domain name (FQDN).
2481 # Thus, if a mail address on the local host is foo@example.org, the correct value for
2482 # this option would be example.org.
2483 # This name won\'t appear on From: lines of outgoing messages if rewriting is enabled.
2484 echo iankelling.org
> /etc
/mailname
2487 # mail.iankelling.org so local imap clients can connect with tls and
2488 # when they happen to not be local.
2489 # todo: this should be 10.8.0.4
2491 /a
/exe
/cedit nn
/etc
/hosts
<<'EOF' || [[ $? == 1 ]]
2492 # note: i put nn.b8.nz into bind for good measure
2493 10.173.8.2 nn.b8.nz mx.iankelling.org
2496 # note: systemd-resolved will consult /etc/hosts, dnsmasq wont. this assumes
2497 # weve configured this file in dnsmasq if we are using it.
2498 /a
/exe
/cedit
mail /etc
/dnsmasq-servers.conf
<<'EOF' || [[ $? == 1 ]]
2499 server=/mx.iankelling.org/127.0.1.1
2501 # I used to use debconf-set-selections + dpkg-reconfigure,
2502 # which then updates this file
2503 # but the process is slower than updating it directly and then I want to set other things in
2504 # update-exim4.conf.conf, so there's no point.
2505 # The file is documented in man update-exim4.conf,
2506 # except the man page is not perfect, read the bash script to be sure about things.
2508 # The debconf questions output is additional documentation that is not
2509 # easily accessible, but super long, along with the initial default comment in this
2510 # file, so I've saved that into ./mail-notes.conf.
2511 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2512 # man page: is used to build the local_domains list, together with "localhost"
2513 # this is duplicated in a later router.
2514 dc_other_hostnames='iankelling.org;zroe.org;r2e.iankelling.org;!je.b8.nz;!bk.b8.nz;*.b8.nz;b8.nz'
2518 # dmarc. not used currently
2519 f
=/etc
/cron.daily
/refresh-dmarc-tld-file
2523 wget -q -N https://publicsuffix.org/list/public_suffix_list.dat
2529 ## we use this host to monitor MAIL_HOST and host a mail server for someone
2532 echo|i
/etc
/exim
4/conf.d
/rcpt_local_acl
2533 echo|i
/etc
/exim
4/conf.d
/router
/880_universal_forward
2535 echo amnimal.ninja
> /etc
/mailname
2537 /a
/exe
/cedit nn
/etc
/hosts
<<'EOF' || [[ $? == 1 ]]
2541 sed -r -f - /etc
/init.d
/exim4
<<'EOF' | i /etc/init.d/exim4in
2542 s,/etc/default/exim4,/etc/default/exim4in,g
2543 s,/run/exim4/exim.pid,/run/exim4/eximin.pid,g
2544 s,(^[ #]*Provides:).*,\1 exim4in,
2545 s,(^[ #]*NAME=).*,\1"exim4in",
2547 chmod +x
/etc
/init.d
/exim4in
2548 i
/etc
/systemd
/system
/exim4in.service.d
/alwaysrestart.conf
<<'EOF'
2550 # needed to continually restart
2551 StartLimitIntervalSec=0
2555 # time to sleep before restarting a service
2559 i
/etc
/default
/exim4in
<<'EOF'
2560 # defaults but no queue runner and alternate config dir
2562 COMMONOPTIONS='-oP /run/exim4/eximin.pid'
2563 UPEX4OPTS='-d /etc/myexim4'
2566 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2567 # man page: is used to build the local_domains list, together with "localhost"
2568 dc_other_hostnames='amnimal.ninja;expertpathologyreview.com'
2574 echo je.b8.nz
> /etc
/mailname
2575 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2576 dc_other_hostnames='je.b8.nz'
2578 echo|i
/etc
/exim
4/conf.d
/router
/188_exim4-config_smarthost
2579 echo|i
/etc
/exim
4/conf.d
/router
/190_exim4-config_fsfsmarthost
2580 echo|i
/etc
/exim
4/conf.d
/rcpt_local_acl
2581 echo|i
/etc
/exim
4/conf.d
/router
/880_universal_forward
2583 # ** not MAIL_HOST|bk|je
2585 # this one should be removed for all non mail hosts, but
2586 # bk and je never become mail_host
2587 echo|i
/etc
/exim
4/conf.d
/router
/195_dnslookup_vpn
2589 echo|i
/etc
/exim
4/conf.d
/router
/188_exim4-config_smarthost
2590 echo|i
/etc
/exim
4/conf.d
/router
/190_exim4-config_fsfsmarthost
2591 echo|i
/etc
/exim
4/conf.d
/rcpt_local_acl
2592 echo|i
/etc
/exim
4/conf.d
/router
/890_backup_copy
2593 echo|i
/etc
/exim
4/conf.d
/main
/000_local-nn
2597 cat >>/etc
/exim
4/conf.d
/main
/000_local
<<EOF
2598 MAIN_TLS_CERTIFICATE = /etc/exim4/certs/$wghost/fullchain.pem
2599 MAIN_TLS_PRIVATEKEY = /etc/exim4/certs/$wghost/privkey.pem
2600 # so we can maintiain the originals of the backups.
2601 # we wouldnt want this if we were dealing with any other
2602 # local deliveries, but we sent all others to the smarthost
2603 # which then strips the headers.
2604 envelope_to_remove = false
2605 return_path_remove = false
2609 # catches things like cronjob email
2610 i
/etc
/exim
4/conf.d
/router
/880_universal_forward
<<'EOF'
2613 domains = +local_domains
2614 data = alerts@iankelling.org
2618 for unit
in ${nn_progs[@]}; do
2619 f
=/etc
/systemd
/system
/$unit.service.d
/nn.conf
2623 # dont i dont care if defaultnn section gets left, it wont
2625 echo |
/a
/exe
/cedit nn
/etc
/hosts ||
[[ $?
== 1 ]]
2626 echo |
/a
/exe
/cedit
mail /etc
/dnsmasq-servers.conf ||
[[ $?
== 1 ]]
2629 i
/etc
/exim
4/conf.d
/transport
/30_backup_maildir
<<EOF
2630 # modified debian maildir transport
2635 # note, no return path or envelope added
2637 directory_mode = 0700
2639 mode_fail_narrower = false
2643 i
/etc
/exim
4/conf.d
/router
/870_backup_local
<<EOF
2644 ### router/900_exim4-config_local_user
2645 #################################
2648 debug_print = "R: local_user for \$local_part@\$domain"
2650 domains = eximbackup.b8.nz
2651 transport = backup_maildir
2654 wgholeip
=$
(sed -rn 's/^ *Address *= *([^/]+).*/\1/p' /etc
/wireguard
/wghole.conf
)
2655 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2656 dc_other_hostnames='eximbackup.b8.nz'
2657 dc_local_interfaces='127.0.0.1;::1;$wgholeip'
2661 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2662 # Note: If theres like a temporary problem where mail gets sent to
2663 # one of these hosts, if exim isnt listening, it will be a temporary error
2664 # instead of a permanent 5xx.
2665 dc_local_interfaces='127.0.0.1;::1'
2668 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2669 dc_eximconfig_configtype='smarthost'
2670 dc_smarthost='$smarthost'
2673 hostname
-f |i
/etc
/mailname
2674 cat >>/etc
/exim
4/update-exim4.conf.conf
<<EOF
2675 # The manpage incorrectly states this will do header rewriting, but
2676 # that only happens if we have dc_hide_mailname is set.
2677 dc_readhost='iankelling.org'
2678 # Only used in case of bounces.
2679 dc_localdelivery='maildir_home'
2687 # ** $MAILHOST|bk, things that belong at the end
2690 # config for the non-nn exim
2691 m rsync
-ra --delete /etc
/exim
4/ /etc
/myexim4
2692 cat >>/etc
/myexim
4/update-exim4.conf.conf
<<'EOF'
2693 dc_eximconfig_configtype='smarthost'
2694 dc_smarthost='nn.b8.nz'
2699 # config for the non-nn exim
2700 cat >/etc
/myexim
4/conf.d
/main
/000_local-nn
<<'EOF'
2701 MAIN_HARDCODE_PRIMARY_HOSTNAME = mail2.iankelling.org
2705 # for bk, we have a exim4in.service that will do this for us.
2706 m update-exim4.conf
-d /etc
/myexim4
2712 # ** bind mount setup
2713 # put spool dir in directory that spans multiple distros.
2714 # based on http://www.postfix.org/qmgr.8.html and my notes in gnus
2717 sdir
=/var
/spool
/exim4
2718 # we only do this if our system has $dir
2720 # this used to do a symlink, but, in the boot logs, /nocow would get mounted succesfully,
2721 # about 2 seconds later, exim starts, and immediately puts into paniclog:
2722 # honVi-0000u3-82 Failed to create directory "/var/spool/exim4/input": No such file or directory
2723 # so, im trying a bind mount to get rid of that.
2724 if [[ -e /nocow
]]; then
2725 if ! grep -Fx "/nocow/exim4 /var/spool/exim4 none bind 0 0" /etc
/fstab
; then
2726 echo "/nocow/exim4 /var/spool/exim4 none bind 0 0" >>/etc
/fstab
2728 i
/etc
/systemd
/system
/exim4.service.d
/override.conf
<<'EOF'
2730 # without local-fs on exim, we get these kind of errors in paniclog on shutdown:
2731 # Failed to create spool file /var/spool/exim4//input//1jCLxz-0008V4-V9-D: Permission denied
2732 After=local-fs.target
2734 if ! mountpoint
-q $sdir; then
2735 stopifactive exim4 exim4in
2736 if [[ -L $sdir ]]; then
2739 if [[ ! -e $dir && -d $sdir ]]; then
2742 if [[ ! -d $sdir ]]; then
2744 m
chmod 000 $sdir # only want it to be used when its mounted
2752 # ** exim/spool uid setup
2753 # i have the spool directory be common to distro multi-boot, so
2754 # we need the uid to be the same. 608 cuz it's kind of in the middle
2755 # of the free system uids.
2756 IFS
=:; read -r _ _ uid _
< <(getent passwd Debian-exim ||
:) ||
:; unset IFS
2757 IFS
=:; read -r _ _ gid _
< <(getent group Debian-exim ||
:) ||
:; unset IFS
2758 if [[ ! $uid ]]; then
2759 # from /var/lib/dpkg/info/exim4-base.postinst, plus uid and gid options
2760 m adduser
--uid 608 --system --group --quiet --home /var
/spool
/exim4 \
2761 --no-create-home --disabled-login --force-badname Debian-exim
2762 elif [[ $uid != 608 ]]; then
2763 stopifactive exim4 exim4in
2764 m usermod
-u 608 Debian-exim
2765 m groupmod
-g 608 Debian-exim
2766 m usermod
-g 608 Debian-exim
2767 m
find / /nocow
-path .
/var
/tmp
-prune -o -xdev -uid $uid -execdir chown
-h 608 {} +
2768 m
find / /nocow
-path .
/var
/tmp
-prune -o -xdev -gid $gid -execdir chgrp
-h 608 {} +
2771 # * start / stop services
2773 reifactive dnsmasq nscd
2776 m systemctl daemon-reload
2779 m systemctl
--now enable epanicclean.timer
2783 /a
/exe
/web-conf apache2 je.b8.nz
2786 /a
/exe
/web-conf apache2 mail2.iankelling.org
2790 m
/a
/bin
/ds
/mail-cert-cron
-1
2795 # todo, this should be done in distro-begin
2796 soff systemd-resolved
2797 ln -sf 127.0.0.1-resolv/stub-resolv.conf
/etc
/resolv.conf
2800 m systemctl
--now enable mailnn mailnnroute
2803 # we use dns to start wg
2807 m systemctl
--now enable unbound
2811 # If these have changes, id rather manually restart it, id rather
2812 # not restart and cause temporary errors
2816 m systemctl
--now enable $vpnser
2818 if ! systemctl is-active clamav-daemon
>/dev
/null
; then
2819 m systemctl
--now enable clamav-daemon
2820 out
=$
(rsync
-aiSAX --chown=root
:root
--chmod=g-s
/a
/bin
/ds
/filesystem
/etc
/systemd
/system
/epanicclean.
{timer
,service
} /etc
/systemd
/system
)
2825 # note, this will cause paniclog entries because it takes like 45
2826 # seconds for clamav to start, i use ./epanic-clean to remove
2831 # start spamassassin/dovecot before exim.
2832 sre dovecot spamassassin
2833 # need to wait a bit before restarting exim, else I
2834 # get a paniclog entry like: spam acl condition: all spamd servers failed
2836 m systemctl
--now enable mailclean.timer
2839 # < 2.1 (eg: in t9), uses a different data format which required manual
2840 # migration. dont start if we are running an old version.
2841 if dpkg
--compare-versions $
(dpkg
-s radicale |
awk '$1 == "Version:" { print $2 }') ge
2.1; then
2842 m systemctl
--now enable radicale
2847 # last use of $reload happens in previous block
2848 rm -f /var
/local
/mail-setup-reload
2852 $MAIL_HOST|bk|je
) : ;;
2854 soff radicale mailclean.timer dovecot spamassassin
$vpnser mailnn clamav-daemon
2862 m systemctl
--now enable mailbindwatchdog
2865 soff mailbindwatchdog
2874 # * mail monitoring / testing
2876 # note, to test clamav, send an email with body that only contains
2877 # https://en.wikipedia.org/wiki/EICAR_test_file
2878 # which set malware_name to Eicar-Signature
2881 # note: cronjob "ian" also does some important monitoring
2882 # todo: this will sometimes cause an alert because mailtest-check will run
2883 # before we have setup network namespace and spamassassin
2884 cat >/etc
/cron.d
/mailtest
<<EOF
2886 PATH=/usr/bin:/bin:/usr/local/bin
2887 MAILTO=alerts@iankelling.org
2888 */5 * * * * $u send-test-forward |& log-once send-test-forward
2889 */10 * * * * root chmod -R g+rw /m/md/bounces |& log-once -1 bounces-chmod
2890 # im seeing some intermittent failures on the slow check, do it all the time
2891 # for now. It looks like a dns failure.
2892 #5-59/5 * * * * root mailtest-check |& log-once -1 mailtest-check
2893 #0 * * * * root mailtest-check slow |& log-once -1 mailtest-slow
2894 */5 * * * * root timeout 290 mailtest-check slow |& log-once -12 mailtest-check
2896 m sudo rsync
-ahhi --chown=root
:root
--chmod=0755 \
2897 /b
/ds
/mailtest-check
/b
/ds
/check-remote-mailqs
/usr
/local
/bin
/
2900 test_froms
=(ian@iankelling.org z@zroe.org iank@gnu.org
)
2901 test_to
="testignore@expertpathologyreview.com, testignore@je.b8.nz, testignore@amnimal.ninja, jtuttle@gnu.org"
2903 cat >>/etc
/cron.d
/mailtest
<<EOF
2904 2 * * * * $u check-remote-mailqs |& log-once check-remote-mailqs
2908 test_froms
=(testignore@expertpathologyreview.com testignore@amnimal.ninja
)
2909 test_to
="testignore@iankelling.org, testignore@zroe.org, testignore@je.b8.nz"
2912 test_froms
=(testignore@je.b8.nz
)
2913 test_to
="testignore@iankelling.org, testignore@zroe.org, testignore@expertpathologyreview.com, testignore@amnimal.ninja"
2916 cat >/usr
/local
/bin
/send-test-forward
<<'EOF'
2919 $(/sbin/exiqgrep -o 260 -i -r '^(testignore@(iankelling\.org|zroe\.org|expertpathologyreview\.com|amnimal\.ninja|je\.b8\.nz)|jtuttle@gnu\.org)$')
2921 if (( ${#olds[@]} )); then
2922 /sbin/exim -Mrm "${olds[@]}" >/dev/null
2925 for test_from
in ${test_froms[@]}; do
2926 cat >>/usr
/local
/bin
/send-test-forward
<<EOFOUTER
2927 /usr/sbin/exim -f $test_from -t <<EOF
2930 Subject: test \$(date +%Y-%m-%dT%H:%M:%S%z) \$(date +%s)
2932 /usr/local/bin/send-test-forward
2936 m
chmod +x
/usr
/local
/bin
/send-test-forward
2939 rm -fv /etc
/cron.d
/mailtest
2946 m sudo
-u $u mkdir
-p /home
/$u/.cache
2947 set -- /m
/mucache
/home
/$u/.cache
/mu
/m
/.mu
/home
/$u/.mu
2952 if [[ ! -L $f ]]; then
2953 if [[ -e $f ]]; then
2956 m sudo
-u $u ln -sf -T $target $f
2961 # /etc/alias setup is debian specific, and exim postinst script sets up
2962 # an /etc/alias from root to the postmaster, based on the question
2963 # exim4-config exim4/dc_postmaster, as long as there exists an entry for
2964 # root, or there was no preexisting aliases file. postfix won\'t set up
2965 # a root to $postmaster alias if it\'s already installed. Easiest to
2966 # just set it ourselves.
2968 # debconf question for postmaster:
2969 # Mail for the 'postmaster', 'root', and other system accounts needs to be redirected
2970 # to the user account of the actual system administrator.
2971 # If this value is left empty, such mail will be saved in /var/mail/mail, which is not
2973 # Note that postmaster\'s mail should be read on the system to which it is directed,
2974 # rather than being forwarded elsewhere, so (at least one of) the users listed here
2975 # should not redirect their mail off this machine. A 'real-' prefix can be used to
2976 # force local delivery.
2977 # Multiple user names need to be separated by spaces.
2978 # Root and postmaster mail recipient:
2984 # eval: (outline-minor-mode)
2985 # outline-regexp: "\\( *\\)# [*]\\{1,8\\} "
2987 # this is combined with defining outline-level in init.el