59a122af106ed8aa5ca04c278eaae1a2720a6675
[distro-setup] / mail-setup
1 #!/bin/bash
2 # * intro
3 # Copyright (C) 2019 Ian Kelling
4 # SPDX-License-Identifier: AGPL-3.0-or-later
5
6 # todo: backup 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.
9
10 # todo: emailing info@amnimal.ninja produces a bounce, user doesn't exist
11 # instead of a simple rejection like it should.
12
13 # todo: auto restart of je on checkrestart
14
15 # todo: run mailping test after running, or otherwise
16 # clear out terminal alert
17
18 # todo: reinstall bk with bigger filesystem
19
20 # todo: on bk, dont send email if mailvpn is not up
21
22 # todo: mailtest-check should check on bk too
23
24 # todo: disable postgrey
25
26 # todo: in testforward-check, we should also look
27
28 # todo: test that bounces dont help create valid mailtest-check
29
30 # todo: move mail stuff in distro-end into this file
31
32 # todo: consider rotating dkim & publishing key so every past email I sent
33 # isnt necessarily signed
34
35 # todo: consider how to get clamav out of Debian-exim group
36 # so it cant read/write the whole mail spool, for better
37 # security.
38
39 # todo: create a cronjob to update or warn on expiring dnssec keys
40
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.
48
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.
52 #
53
54 # todo: mailtest-check failure on remote hosts is not going to alert me.
55 # sort that out.
56 # todo: test mail failure as well as success.
57 #
58 # todo: validate that mailtest-check is doing dnsbl checks.
59
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.
75 # That implementation
76 # is below here:
77 #
78 # sudoers:
79 # user ALL=(ALL) /usr/sbin/exim4
80 #
81 # move exim4 to eximian, use this script for exim4:
82 #
83 # #!/bin/bash
84 # if ip a show veth1-mail &>/dev/null; then
85 # /usr/sbin/eximian "$@"
86 # exit
87 # fi
88 # dosudo=false
89 # if [[ $USER && $USER != root ]]; then
90 # dosudo=true
91 # fi
92 # pid=$(pgrep -f "/usr/sbin/openvpn .* --config /etc/openvpn/.*mail.conf")
93 # if $dosudo; then
94 # sudo nsenter -t $pid -n -m sudo -u $USER /usr/sbin/eximian "$@"
95 # else
96 # nsenter -t $pid -n -m /usr/sbin/eximian "$@"
97 # fi
98 # ## end script
99 #
100 # an alternate solution: there is a small setguid program for
101 # network namespaces in my bookmarks.
102 #
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.
108 #
109 # I have a bash function, enn to invoke exim like the daemon is running.
110 # and mailbash to just enter its network namespace.
111
112 if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
113
114 shopt -s nullglob
115
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
120 else
121 err "no err tracing script found"
122 fi
123 source /a/bin/distro-functions/src/identify-distros
124 source /a/bin/distro-functions/src/package-manager-abstractions
125
126 # has nextcloud_admin_pass in it
127 f=/p/c/machine_specific/$HOSTNAME/mail
128 if [[ -e $f ]]; then
129 # shellcheck source=/p/c/machine_specific/bk/mail
130 source $f
131 fi
132
133
134 [[ $EUID == 0 ]] || exec sudo -E "${BASH_SOURCE[0]}" "$@"
135
136
137 u=$(id -nu 1000)
138
139
140 usage() {
141 cat <<EOF
142 Usage: ${0##*/} anything_here_to_debug
143 Setup exim4 & dovecot & related things
144
145 -h|--help Print help and exit.
146 EOF
147 exit $1
148 }
149
150 # debug output if we pass any arg
151 if (( $# )); then
152 set -x
153 fi
154
155
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
160 #
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
164 #
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
168 #######
169
170
171 # * perstent password instructions
172 # Note: for cert cron, we need to manually run first to accept known_hosts
173
174 # # exim passwords:
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:
178 # f=$(mktemp)
179 # host=tp
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
185 # mkdir -p $dir
186 # echo "mail.iankelling.org:$host:$(<$f)" > $dir/passwd.client
187 # # then run this script
188
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
192
193 ####### end perstent password instructions ######
194
195
196 # * dkim dns
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
199 # # into dns.
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
204
205 # openssl genrsa -out $domain-private.pem 2048
206 # # Then, to get the public key strings to put in bind:
207
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"
217 # cat <<EOF
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')" )
220 # EOF
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.
226
227 # # selector was also put into /etc/exim4/conf.d/main/000_local,
228
229 # * dmarc dns
230
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.
238 #
239 # echo "dmarc dns, name: _dmarc value: v=DMARC1; p=none; rua=mailto:mailauth-reports@$domain"
240
241 # * other dns
242
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.
249
250 # # to check if dns has updated, you do
251 # host -a mesmtp._domainkey.$domain
252
253 # # mx records,
254 # # setting it to iankelling.org would work the same, but this
255 # # is more flexible, I could change where mail.iankelling.org pointed.
256 # cat <<'EOF'
257 # mx records, 2 records each, for * and empty domain
258 # pri 10 mail.iankelling.org
259 # EOF
260
261 # # dnssec
262 # from brc2, run dnsecgen then dsign, update named.local.conf, publish keys to registrar
263
264 # * functions & constants
265
266 pre="${0##*/}:"
267 m() { printf "$pre %s\n" "$*"; "$@"; }
268 e() { printf "$pre %s\n" "$*"; }
269 err() { printf "$pre %s\n" "$*" >&2; exit 1; }
270
271 reload=false
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
274 reload=true
275 fi
276 i() { # install file
277 local tmp tmpdir dest="$1"
278 local base="${dest##*/}"
279 mkdir -p ${dest%/*}
280 ir=false # i result
281 tmpdir=$(mktemp -d)
282 cat >$tmpdir/"$base"
283 tmp=$(rsync -ic $tmpdir/"$base" "$dest")
284 if [[ $tmp ]]; then
285 printf "%s\n" "$tmp"
286 ir=true
287 if [[ $dest == /etc/systemd/system/* ]]; then
288 touch /var/local/mail-setup-reload
289 reload=true
290 fi
291 fi
292 rm -rf $tmpdir
293 }
294 setini() {
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"
298 }
299 soff () {
300 for service; do
301 # ignore services that dont exist
302 if systemctl cat $service &>/dev/null; then
303 m systemctl stop $service;
304 m systemctl disable $service
305 fi
306 done
307 }
308 sre () {
309 for service; do
310 m systemctl restart $service
311 m systemctl enable $service;
312 done
313 }
314 sstart() {
315 for service; do
316 m systemctl enable --now $service;
317 done
318 }
319 mailhost() {
320 [[ $HOSTNAME == "$MAIL_HOST" ]]
321 }
322 e() { printf "%s\n" "$*"; }
323 reifactive() {
324 for service; do
325 if systemctl is-active $service >/dev/null; then
326 m systemctl restart $service
327 fi
328 done
329 }
330 stopifactive() {
331 for service; do
332 if systemctl is-active $service >/dev/null; then
333 m systemctl stop $service
334 fi
335 done
336 }
337
338 mxhost=mx.iankelling.org
339 mxport=587
340 forward=$u@$mxhost
341
342 # old setup. left as comment for example
343 # mxhost=mail.messagingengine.com
344 # mxport=587
345 # forward=ian@iankelling.org
346
347 smarthost="$mxhost::$mxport"
348 uhome=$(eval echo ~$u)
349
350 # Somehow on one machine, a file got written with 664 perms.
351 # just being defensive here.
352 umask 0022
353
354 source /a/bin/bash_unpublished/source-state
355 if [[ ! $MAIL_HOST ]]; then
356 err "\$MAIL_HOST not set"
357 fi
358
359 bhost_t=false
360 case $HOSTNAME in
361 $MAIL_HOST) : ;;
362 kd|frodo|x2|x3|kw|sy)
363 bhost_t=true
364 ;;
365 esac
366
367
368 # * Install universal packages
369
370 if [[ $(debian-codename-compat) == bionic ]]; then
371 cat >/etc/apt/preferences.d/spamassassin <<'EOF'
372 Package: spamassassin sa-compile spamc
373 Pin: release n=focal,o=Ubuntu
374 Pin-Priority: 500
375 EOF
376 fi
377
378 # light version of exim does not have sasl auth support.
379 pi-nostart exim4 exim4-daemon-heavy spamassassin openvpn unbound clamav-daemon wireguard
380
381 # note: pyzor debian readme says you need to run some initialization command
382 # but its outdated.
383 pi spf-tools-perl p0f postgrey pyzor razor jq moreutils certbot
384 # bad packages that sometimes get automatically installed
385 pu openresolv resolvconf
386
387 soff openvpn
388
389
390 if [[ $(debian-codename) == etiona ]]; then
391 # ip6tables stopped loading on boot. openvpn has reduced capability set,
392 # so running iptables as part of openvpn startup wont work. This should do it.
393 pi iptables-persistent
394 cat >/etc/iptables/rules.v6 <<'EOF'
395 *mangle
396 COMMIT
397 *nat
398 COMMIT
399 EOF
400 # load it now.
401 m ip6tables -S >/dev/null
402 fi
403
404 # our nostart pi fails to avoid enabling
405
406
407 # * user forward file
408 case $HOSTNAME in
409 $MAIL_HOST)
410 # afaik, these will get ignored on MAIL_HOST because they are routing to my own
411 # machine, but rm them is safer
412 rm -fv $uhome/.forward /root/.forward
413 ;;
414 *)
415 # this can\'t be a symlink and has permission restrictions
416 # it might work in /etc/aliases, but this seems more proper.
417 e setting $uhome/.forward to $forward
418 install -m 644 {-o,-g}$u <(e $forward) $uhome/.forward
419 ;;
420 esac
421
422 # * Mail clean cronjob
423
424 i /etc/systemd/system/mailclean.timer <<'EOF'
425 [Unit]
426 Description=Run mailclean daily
427
428 [Timer]
429 OnCalendar=monthly
430
431 [Install]
432 WantedBy=timers.target
433 EOF
434
435 i /etc/systemd/system/mailclean.service <<EOF
436 [Unit]
437 Description=Delete and archive old mail files
438 After=multi-user.target
439
440 [Service]
441 User=$u
442 Type=oneshot
443 ExecStart=/usr/local/bin/sysd-mail-once mailclean /a/bin/distro-setup/mailclean
444 EOF
445
446 # * postgrey
447
448
449 i /etc/default/postgrey <<'EOF'
450 POSTGREY_OPTS="--exim --unix=/var/run/postgrey/postgrey.sock --retry-window=4 --max-age=60"
451 EOF
452
453 # * clamav
454
455 m usermod -a -G Debian-exim clamav
456
457 i /etc/systemd/system/clamav-daemon.service.d/fix.conf <<EOF
458 [Service]
459 ExecStartPre=-/bin/mkdir /var/run/clamav
460 ExecStartPre=/bin/chown clamav /var/run/clamav
461 EOF
462
463 # * mail vpn config
464
465 vpnser=mailvpn.service
466 vpnser=wg-quick@wgmail.service
467
468 case $HOSTNAME in
469 $MAIL_HOST)
470 bindpaths="/etc/127.0.0.1-resolv:/run/systemd/resolve /etc/basic-nsswitch:/etc/resolved-nsswitch:norbind"
471 ;;&
472 bk)
473 bindpaths="/etc/10.173.8.1-resolv:/etc/127.0.0.1-resolv"
474 ;;&
475 esac
476
477 i /etc/systemd/system/wg-quick@wgmail.service.d/override.conf <<EOF
478 [Unit]
479 Requires=mailnn.service
480 After=network.target mailnn.service
481 JoinsNamespaceOf=mailnn.service
482 BindsTo=mailnn.service
483
484 [Service]
485 PrivateNetwork=true
486 # i dont think we need any of these, but it doesnt hurt to stay consistent
487 BindPaths=$bindpaths
488 EOF
489
490 # https://selivan.github.io/2017/12/30/systemd-serice-always-restart.html
491 i /etc/systemd/system/mailvpn.service <<EOF
492 [Unit]
493 Description=OpenVPN tunnel for mail
494 After=syslog.target network-online.target mailnn.service
495 Wants=network-online.target
496 Documentation=man:openvpn(8)
497 Documentation=https://community.openvpn.net/openvpn/wiki/Openvpn24ManPage
498 Documentation=https://community.openvpn.net/openvpn/wiki/HOWTO
499 # needed to continually restatr
500 JoinsNamespaceOf=mailnn.service
501 BindsTo=mailnn.service
502 StartLimitIntervalSec=0
503
504 [Service]
505 Type=notify
506 RuntimeDirectory=openvpn-client
507 RuntimeDirectoryMode=0710
508 WorkingDirectory=/etc/openvpn/client
509 ExecStart=/usr/sbin/openvpn --suppress-timestamps --nobind --config /etc/openvpn/client/mail.conf
510 #CapabilityBoundingSet=CAP_IPC_LOCK CAP_NET_ADMIN CAP_NET_RAW CAP_SETGID CAP_SETUID CAP_SYS_CHROOT CAP_DAC_OVERRIDE
511 LimitNPROC=10
512 # DeviceAllow=/dev/null rw
513 # DeviceAllow=/dev/net/tun rw
514 PrivateNetwork=true
515 # in the network namespace, we cant connect to systemd-resolved on 127.0.0.53,
516 # because of
517 # https://unix.stackexchange.com/questions/445782/how-to-allow-systemd-resolved-to-listen-to-an-interface-other-than-loopback
518 # there is a workaround there, but i dont think its really worth it,
519 # the mail server is fine with a static dns anyways.
520 # This thread is also interesting,
521 # https://github.com/slingamn/namespaced-openvpn/issues/7
522 # todo: the iptables rule at the bottom could be useful to prevent
523 # dns from leaking in my network namespaced vpn.
524 # I also like the idea of patching systemd-resolved so it
525 # will listen on other interfaces, but its not worth my time.
526 BindPaths=$bindpaths
527 Restart=always
528 # time to sleep before restarting a service
529 RestartSec=1
530
531 [Install]
532 WantedBy=multi-user.target
533 EOF
534
535 i /etc/systemd/system/mailnnroute.service <<'EOF'
536 [Unit]
537 Description=Network routing for mailnn
538 After=syslog.target network-online.target mailnn.service
539 Wants=network-online.target
540 JoinsNamespaceOf=mailnn.service
541 BindsTo=mailnn.service
542 StartLimitIntervalSec=0
543
544 [Service]
545 Type=simple
546 RemainAfterExit=true
547 PrivateNetwork=true
548 ExecStart=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns -n 10.173.8 start mail
549 ExecStop=/usr/bin/flock -w 20 /tmp/newns.flock /a/bin/newns/newns stop mail
550 Restart=always
551 RestartSec=10
552
553
554 [Install]
555 WantedBy=multi-user.target
556 EOF
557
558 #
559 i /etc/systemd/system/mailnn.service <<'EOF'
560 [Unit]
561 Description=Network Namespace for mail vpn service that will live forever and cant fail
562 After=syslog.target network-online.target
563 Wants=network-online.target
564
565 [Service]
566 Type=simple
567 PrivateNetwork=true
568 ExecStart=/bin/sleep infinity
569
570 [Install]
571 WantedBy=multi-user.target
572 EOF
573
574
575
576 # old service name
577 rm -fv /etc/systemd/system/openvpn-client-mail@.service
578
579 # We use a local unbound because systemd-resolved wont accept our
580 # request, it will only listen to 127.0.0.53 in the main network
581 # namespace, and rejected feature requests to change that (although I
582 # could change the code and recompile), but anyways, that could answer
583 # with things specific to the lan that aren't applicable in this
584 # namespace, and since unbound is a recursive resolver, it means we just
585 # use our own ip against dnsbl rate limits.
586 #
587 # If we ever notice this change, chattr +i on it
588 # trust-ad is used in t10+, glibc 2.31
589
590 i /etc/127.0.0.1-resolv/stub-resolv.conf <<'EOF'
591 nameserver 127.0.0.1
592 options edns0 trust-ad
593 EOF
594
595 i /etc/127.0.0.53-resolv/stub-resolv.conf <<'EOF'
596 nameserver 127.0.0.53
597 options edns0 trust-ad
598 EOF
599
600
601 i /etc/10.173.8.1-resolv/stub-resolv.conf <<'EOF'
602 nameserver 10.173.8.1
603 options edns0 trust-ad
604 EOF
605
606 # this is just a bug fix for trisquel.
607 f=/etc/apparmor.d/usr.sbin.unbound
608 line="/usr/sbin/unbound flags=(attach_disconnected) {"
609 if ! grep -qFx "$line" $f; then
610 badline="/usr/sbin/unbound {"
611 if ! grep -qFx "$badline" $f; then
612 err expected line in $f not found
613 fi
614 sed -i "s,^$badline$,$line," $f
615 if systemctl is-active apparmor &>/dev/null; then
616 m systemctl reload apparmor
617 fi
618 fi
619
620 # note: anything added to nn_progs needs corresponding rm
621 # down below in the host switch
622 nn_progs=(exim4)
623 if mailhost; then
624 # Note dovecots lmtp doesnt need to be in the same nn to accept delivery.
625 # Its in the nn so remote clients can connect to it.
626 nn_progs+=(spamassassin dovecot)
627 fi
628
629 case $HOSTNAME in
630 $MAIL_HOST)
631 i /etc/systemd/system/unbound.service.d/nn.conf <<EOF
632 [Unit]
633 After=mailnn.service
634 JoinsNamespaceOf=mailnn.service
635 BindsTo=mailnn.service
636 StartLimitIntervalSec=0
637
638 [Service]
639 PrivateNetwork=true
640 # note the nsswitch bind is actually not needed for bk, but
641 # its the same file so it does no harm.
642 BindPaths=$bindpaths
643
644 Restart=always
645 RestartSec=1
646 EOF
647
648 # sooo, there are a few ways to get traffic from the mail network
649 # namespace to go over the wghole.
650 #
651 #1: unify the mail vpn and wghole
652 # into 1 network. this seems simple and logical, so I'm doing it.
653 # One general downside is tying things together, if I need to mess
654 # with one thing, it breaks the other. Oh well for now.
655 #
656 # 2. We can route 10.5.3.0/24 out of the mail nn and nat it into wghole.
657 #
658 # 3. We can setup the routing to happen on li, which seemed like I
659 # just needed to add 10.8.0.4/24 to AllowedIPs in at least the
660 # wghole clients, but I think that is kind of hacky and breaks ipv4
661 # routing within the mailvpn, it happened to work just because exim
662 # prefers ipv6 and that was also available in the mailvpn.
663 #
664 # 4. Put the hole interface into the mail network namespace. This
665 # doesn't work if the mail vpn is wg. For openvpn, it bypasses the
666 # vpn routing and establishes a direct connection. I only use the
667 # hole vpn for randomish things, it should be fine to join the mail
668 # nn for that. There should be some way to fix the routing issue
669 # by doing manual routing, but that doesn't seem like a good use of time.
670 # relevant:
671 # https://www.wireguard.com/netns/#
672 #
673 # for wireguard debugging
674 # echo module wireguard +p > /sys/kernel/debug/dynamic_debug/control
675 # dmesg -w
676
677 ;;&
678 $MAIL_HOST|bk)
679 for unit in ${nn_progs[@]}; do
680 i /etc/systemd/system/$unit.service.d/nn.conf <<EOF
681 [Unit]
682 # commented for old openvpn
683 Requires=$vpnser
684 After=network.target mailnn.service $vpnser
685 JoinsNamespaceOf=mailnn.service
686 BindsTo=mailnn.service
687 StartLimitIntervalSec=0
688
689 [Service]
690 PrivateNetwork=true
691 # note the nsswitch bind is actually not needed for bk, but
692 # its the same file so it does no harm.
693 BindPaths=$bindpaths
694
695 Restart=always
696 RestartSec=1
697 EOF
698 done
699 ;;
700 *)
701 for unit in exim4 spamassassin dovecot unbound; do
702 f=/etc/systemd/system/$unit.service.d/nn.conf
703 if [[ -s $f ]]; then
704 rm -fv $f
705 reload=true
706 fi
707 done
708 ;;
709 esac
710
711 # * spamassassin config
712 i /etc/sysctl.d/80-iank-mail.conf <<'EOF'
713 # see exim spec
714 net.netfilter.nf_conntrack_tcp_timeout_close_wait = 120
715 EOF
716 if $ir; then
717 m sysctl -p
718 fi
719
720 i /etc/spamassassin/mylocal.cf <<'EOF'
721 # this is mylocal.cf because the normal local.cf has a bunch of upstream stuff i dont want to mess with
722
723 # /usr/share/doc/exim4-base/README.Debian.gz:
724 # SpamAssassin's default report should not be used in a add_header
725 # statement since it contains empty lines. (This triggers e.g. Amavis'
726 # warning "BAD HEADER SECTION, Improper folded header field made up
727 # entirely of whitespace".) This is a safe, terse alternative:
728 clear_report_template
729 report (_SCORE_ / _REQD_ requ) _TESTSSCORES(,)_ autolearn=_AUTOLEARN
730 uridnsbl_skip_domain iankelling.org
731 uridnsbl_skip_domain amnimal.ninja
732 uridnsbl_skip_domain expertpathologyreview.com
733 uridnsbl_skip_domain zroe.org
734 EOF
735
736 # 2020-10-19 remove old file. remove this when all hosts updated
737 rm -fv /etc/systemd/system/spamddnsfix.{timer,service}
738
739 i /etc/default/spamassassin <<'EOF'
740 # defaults plus debugging flags for an issue im having
741 OPTIONS="--create-prefs --max-children 5 --helper-home-dir"
742 PIDFILE="/var/run/spamd.pid"
743 # my additions
744 NICE="--nicelevel 15"
745 CRON=1
746 EOF
747 ##### end spamassassin config
748
749
750 # * Update mail cert
751 if [[ -e /p/c/filesystem ]]; then
752 # note, man openvpn implies we could just call mail-route on vpn startup/shutdown with
753 # systemd, buuut it can remake the tun device unexpectedly, i got this in the log
754 # after my internet was down for a bit:
755 # NOTE: Pulled options changed on restart, will need to close and reopen TUN/TAP device.
756 m /a/exe/vpn-mk-client-cert -b mailclient -n mail li.iankelling.org
757 fi
758 case $HOSTNAME in
759 bk)
760 if [[ ! -e /etc/openvpn/client/mail.conf ]]; then
761 echo "$0: error: first, on a system with /p/c/filesystem, run mail-setup, or the vpn-mk-client-cert line above this err" 2>&2
762 exit 1
763 fi
764 ;;
765 esac
766
767 m rsync -aiSAX --chown=root:root --chmod=g-s /a/bin/ds/mail-cert-cron /usr/local/bin
768
769 i /etc/systemd/system/mailcert.service <<'EOF'
770 [Unit]
771 Description=Mail cert rsync
772 After=multi-user.target
773
774 [Service]
775 Type=oneshot
776 ExecStart=/usr/local/bin/sysd-mail-once mailcert /usr/local/bin/mail-cert-cron
777 EOF
778 i /etc/systemd/system/mailcert.timer <<'EOF'
779 [Unit]
780 Description=Run mail-cert once a day
781
782 [Timer]
783 OnCalendar=daily
784
785 [Install]
786 WantedBy=timers.target
787 EOF
788
789
790 wghost=${HOSTNAME}wg.b8.nz
791 if $bhost_t && [[ ! -e /etc/exim4/certs/$wghost/privkey.pem ]]; then
792 certbot -n --manual-public-ip-logging-ok --eff-email --agree-tos -m letsencrypt@iankelling.org \
793 certonly --manual --preferred-challenges=dns \
794 --manual-auth-hook /a/bin/ds/le-dns-challenge \
795 --manual-cleanup-hook /a/bin/ds/le-dns-challenge-cleanup \
796 --deploy-hook /a/bin/ds/le-exim-deploy -d $wghost
797 fi
798
799 # * common exim4 config
800
801
802 # Make all system users be aliases. preventative
803 # measure for things like cron mail for user without alias
804 awk 'BEGIN { FS = ":" } ; $6 !~ /^\/home/ { print $1 }' /etc/passwd| while read -r user; do
805 if [[ ! $user ]]; then
806 continue
807 fi
808 if ! grep -q "^$user:" /etc/aliases; then
809 echo "$user: root" |m tee -a /etc/aliases
810 fi
811 done
812
813 if ! grep -q "^ncsoft:" /etc/aliases; then
814 echo "ncsoft: graceq2323@gmail.com" |m tee -a /etc/aliases
815 fi
816
817
818
819 m gpasswd -a iank adm #needed for reading logs
820
821 ### make local bounces go to normal maildir
822 # local mail that bounces goes to /Maildir or /root/Maildir
823 dirs=(/m/md/bounces/{cur,tmp,new})
824 m mkdir -p ${dirs[@]}
825 m chown iank:iank /m /m/md
826 m ln -sfT /m/md /m/iank
827 m chmod 771 /m /m/md
828 m chown -R $u:Debian-exim /m/md/bounces
829 m chmod 775 ${dirs[@]}
830 m usermod -a -G Debian-exim $u
831 for d in /Maildir /root/Maildir; do
832 if [[ ! -L $d ]]; then
833 m rm -rf $d
834 fi
835 m ln -sf -T /m/md/bounces $d
836 done
837
838 # dkim, client passwd file
839 files=(/p/c/machine_specific/$HOSTNAME/filesystem/etc/exim4/*)
840 f=/p/c/filesystem/etc/exim4/passwd.client
841 if [[ -e $f ]]; then
842 files+=($f)
843 fi
844 if (( ${#files[@]} )); then
845 m rsync -ahhi --chown=root:Debian-exim --chmod=0640 \
846 ${files[@]} /etc/exim4
847 fi
848
849 # by default, only 10 days of logs are kept. increase that.
850 m sed -ri 's/^(\s*rotate\s).*/\11000/' /etc/logrotate.d/exim4-base
851
852
853 ## https://blog.dhampir.no/content/make-exim4-on-debian-respect-forward-and-etcaliases-when-using-a-smarthost
854 # i only need .forwards, so just doing that one.
855 cd /etc/exim4/conf.d/router
856 b=userforward_higher_priority
857 # replace the router name so it is unique
858 sed -r s/^\\S+:/$b:/ 600_exim4-config_userforward >175_$b
859
860 # todo, consider 'separate' in etc/exim4.conf, could it help on busy systems?
861
862 # alerts is basically the postmaster address
863 m sed -i --follow-symlinks -f - /etc/aliases <<EOF
864 \$a root: alerts@iankelling.org
865 /^root:/d
866 EOF
867
868 cat >/etc/exim4/conf.d/rewrite/34_iank_rewriting <<'EOF'
869 ncsoft@zroe.org graceq2323@gmail.com hE
870 EOF
871
872 # old name
873 rm -fv /etc/exim4/conf.d/retry/37_retry
874
875 cat >/etc/exim4/conf.d/retry/17_retry <<'EOF'
876 # Retry faster than usual for sending to domains that I send with send-test-forward.
877 iankelling.org * F,2d,15m;F,14d,2h
878 amnimal.ninja * F,2d,15m;F,14d,2h
879 expertpathologyreview.com * F,2d,15m;F,14d,2h
880 je.b8.nz * F,2d,15m;F,14d,2h
881 zroe.org * F,2d,15m;F,14d,2h
882 EOF
883
884
885 rm -vf /etc/exim4/conf.d/main/000_localmacros # old filename
886 cat >/etc/exim4/conf.d/main/000_local <<EOF
887 MAIN_TLS_ENABLE = true
888
889 # require tls connections for all smarthosts
890 REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS = *
891
892 # debian exim config added this in 2016 or so?
893 # it's part of the smtp spec, to limit lines to 998 chars
894 # but a fair amount of legit mail does not adhere to it. I don't think
895 # this should be default, like it says in
896 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=828801
897 # todo: the bug for introducing this was about headers, but
898 # the fix maybe is for all lines? one says gmail rejects, the
899 # other says gmail does not reject. figure out and open a new bug.
900 IGNORE_SMTP_LINE_LENGTH_LIMIT = true
901
902 # more verbose logs
903 MAIN_LOG_SELECTOR = +all
904
905 # Based on spec, seems like a good idea to be nice.
906 smtp_return_error_details = true
907
908 # normally empty, I set this so I can set the envelope address
909 # when doing mail redelivery to invoke filters. Also allows
910 # me exiqgrep and stuff.
911 MAIN_TRUSTED_GROUPS = $u
912
913 # default is 10. when exim has been down for a bit, fsf mailserver
914 # will do a big send in one connection, then exim decides to put
915 # the messages in the queue instead of delivering them, to avoid
916 # spawning too many delivery processes. Pretty sure my system
917 # can handle a lot more, but lets go with this.
918 smtp_accept_queue_per_connection = 100
919
920
921 DKIM_CANON = relaxed
922 DKIM_SELECTOR = li
923
924 # from comments in
925 # https://debian-administration.org/article/718/DKIM-signing_outgoing_mail_with_exim4
926 # and its best for this to align https://tools.ietf.org/html/rfc7489#page-8
927 # There could be some circumstance when the
928 # from: isnt our domain, but the envelope sender is
929 # and so still want to sign, but I cant think of any case.
930 DKIM_DOMAIN = \${lc:\${domain:\$rh_from:}}
931 # The file is based on the outgoing domain-name in the from-header.
932 # sign if key exists
933 DKIM_PRIVATE_KEY = \${if exists{/etc/exim4/\${dkim_domain}-private.pem} {/etc/exim4/\${dkim_domain}-private.pem}}
934
935 # most of the ones that gmail seems to use.
936 # Exim has horrible default of signing unincluded
937 # list- headers since they got mentioned in an
938 # rfc, but this messes up mailing lists, like gnu/debian which want to
939 # keep your dkim signature intact but add list- headers.
940 DKIM_SIGN_HEADERS = mime-version:in-reply-to:references:from:date:subject:to
941
942 domainlist local_hostnames = ! je.b8.nz : ! bk.b8.nz : *.b8.nz : b8.nz
943
944 hostlist iank_trusted = <; \\
945 # veth0
946 10.173.8.1 ; \\
947 # li li_ip6
948 72.14.176.105 ; 2600:3c00::f03c:91ff:fe6d:baf8 ; \\
949 # li_vpn_net li_vpn_net_ip6s
950 10.8.0.0/24; 2600:3c00:e000:280::/64 ; 2600:3c00:e002:3800::/56 ; \\
951 # bk bk_ip6
952 85.119.83.50 ; 2001:ba8:1f1:f0c9::2 ; \\
953 # je je_ipv6
954 85.119.82.128 ; 2001:ba8:1f1:f09d::2 ; \\
955 # fsf_mit_net fsf_mit_net_ip6 fsf_net fsf_net_ip6 fsf_office_net
956 18.4.89.0/24 ; 2603:3005:71a:2e00::/64 ; 209.51.188.0/24 ; 2001:470:142::/48 ; 74.94.156.208/28
957 EOF
958
959 rm -fv /etc/exim4/rcpt_local_acl # old path
960
961 i /etc/exim4/conf.d/local_deny_exceptions_acl <<'EOF'
962 # This acl already exists in rcpt, this just makes it more widespread.
963 # See the comment there for its rationale. The reason it needs to be
964 # more widespread is that I've turned on sender verification, but cron
965 # emails can fail sender verification since I may be in a network that
966 # doesn't have my local dns.
967 accept
968 authenticated = *
969
970 # i setup a local programs smtp to mail.iankelling.org, this
971 # skips sender verification for it.
972 accept
973 hosts = 10.173.8.1
974 EOF
975
976 rm -fv /etc/exim4/data_local_acl # old path
977 i /etc/exim4/conf.d/data_local_acl <<'EOF'
978 # Except for the "condition =", this was
979 # a comment in the check_data acl. The comment about this not
980 # being suitable has been changed in newer exim versions. The only thing
981 # related I found was to
982 # add the condition =, cuz spamassassin has problems with big
983 # messages and spammers don't bother with big messages,
984 # but I've increased the size from 10k
985 # suggested in official docs, and 100k in the wiki example because
986 # those docs are rather old and I see a 110k spam message
987 # pretty quickly looking through my spam folder.
988
989 warn
990 !hosts = +iank_trusted
991 remove_header = X-Spam_score: X-Spam_score_int : X-Spam_bar : X-Spam_report
992
993 warn
994 !hosts = +iank_trusted
995 condition = ${if < {$message_size}{5000K}}
996 spam = Debian-exim:true
997 add_header = X-Spam_score_int: $spam_score_int
998 add_header = X-Spam_score: $spam_score
999 add_header = X-Spam_bar: $spam_bar
1000 add_header = X-Spam_report: $spam_report
1001 add_header = X-Spam_action: $spam_action
1002
1003 warn
1004 condition = ${if def:malware_name}
1005 remove_header = Subject:
1006 add_header = Subject: [Clamav warning: $malware_name] $h_subject
1007 log_message = heuristic malware warning: $malware_name
1008
1009 #accept
1010 # spf = pass:fail:softfail:none:neutral:permerror:temperror
1011 # dmarc_status = reject:quarantine
1012 # add_header = Reply-to: dmarctest@iankelling.org
1013
1014 EOF
1015
1016 i /etc/exim4/conf.d/router/900_exim4-config_local_user <<EOF
1017 ### router/900_exim4-config_local_user
1018 #################################
1019
1020 # This router matches local user mailboxes. If the router fails, the error
1021 # message is "Unknown user".
1022 local_user:
1023 debug_print = "R: local_user for \$local_part@\$domain"
1024 driver = accept
1025 domains = +local_domains
1026 # ian: default file except where mentioned.
1027 # ian: commented this. I get all local parts. for bk, an rcpt
1028 # check handles checking with dovecot, and the only router
1029 # after this is root.
1030 # local_parts = ! root
1031 transport = LOCAL_DELIVERY
1032 cannot_route_message = Unknown user
1033 # ian: added for + addressing.
1034 local_part_suffix = +*
1035 local_part_suffix_optional
1036 EOF
1037 i /etc/exim4/conf.d/transport/30_exim4-config_dovecot_lmtp <<'EOF'
1038 dovecot_lmtp:
1039 driver = lmtp
1040 socket = /var/run/dovecot/lmtp
1041 #maximum number of deliveries per batch, default 1
1042 batch_max = 200
1043 envelope_to_add
1044 EOF
1045
1046 i /etc/exim4/conf.d/transport/30_remote_smtp_vpn <<'EOF'
1047 # same as debians 30_exim4-config_remote_smtp, but
1048 # with interface added at the end.
1049
1050 remote_smtp_vpn:
1051 debug_print = "T: remote_smtp_vpn for $local_part@$domain"
1052 driver = smtp
1053 .ifndef IGNORE_SMTP_LINE_LENGTH_LIMIT
1054 message_size_limit = ${if > {$max_received_linelength}{998} {1}{0}}
1055 .endif
1056 .ifdef REMOTE_SMTP_HOSTS_AVOID_TLS
1057 hosts_avoid_tls = REMOTE_SMTP_HOSTS_AVOID_TLS
1058 .endif
1059 .ifdef REMOTE_SMTP_HEADERS_REWRITE
1060 headers_rewrite = REMOTE_SMTP_HEADERS_REWRITE
1061 .endif
1062 .ifdef REMOTE_SMTP_RETURN_PATH
1063 return_path = REMOTE_SMTP_RETURN_PATH
1064 .endif
1065 .ifdef REMOTE_SMTP_HELO_DATA
1066 helo_data=REMOTE_SMTP_HELO_DATA
1067 .endif
1068 .ifdef DKIM_DOMAIN
1069 dkim_domain = DKIM_DOMAIN
1070 .endif
1071 .ifdef DKIM_SELECTOR
1072 dkim_selector = DKIM_SELECTOR
1073 .endif
1074 .ifdef DKIM_PRIVATE_KEY
1075 dkim_private_key = DKIM_PRIVATE_KEY
1076 .endif
1077 .ifdef DKIM_CANON
1078 dkim_canon = DKIM_CANON
1079 .endif
1080 .ifdef DKIM_STRICT
1081 dkim_strict = DKIM_STRICT
1082 .endif
1083 .ifdef DKIM_SIGN_HEADERS
1084 dkim_sign_headers = DKIM_SIGN_HEADERS
1085 .endif
1086 .ifdef TLS_DH_MIN_BITS
1087 tls_dh_min_bits = TLS_DH_MIN_BITS
1088 .endif
1089 .ifdef REMOTE_SMTP_TLS_CERTIFICATE
1090 tls_certificate = REMOTE_SMTP_TLS_CERTIFICATE
1091 .endif
1092 .ifdef REMOTE_SMTP_PRIVATEKEY
1093 tls_privatekey = REMOTE_SMTP_PRIVATEKEY
1094 .endif
1095 .ifdef REMOTE_SMTP_HOSTS_REQUIRE_TLS
1096 hosts_require_tls = REMOTE_SMTP_HOSTS_REQUIRE_TLS
1097 .endif
1098 .ifdef REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
1099 headers_remove = REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
1100 .endif
1101 interface = <; 10.8.0.4 ; 2600:3c00:e002:3800::4
1102 EOF
1103
1104 i /etc/exim4/conf.d/transport/30_smarthost_dkim <<'EOF'
1105 # ian: this is remote_smtp_smarthost plus the dkim parts from remote_smtp
1106
1107 smarthost_dkim:
1108 debug_print = "T: remote_smtp_smarthost for $local_part@$domain"
1109 driver = smtp
1110 multi_domain
1111 .ifndef IGNORE_SMTP_LINE_LENGTH_LIMIT
1112 message_size_limit = ${if > {$max_received_linelength}{998} {1}{0}}
1113 .endif
1114 hosts_try_auth = <; ${if exists{CONFDIR/passwd.client} \
1115 {\
1116 ${lookup{$host}nwildlsearch{CONFDIR/passwd.client}{$host_address}}\
1117 }\
1118 {} \
1119 }
1120 .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
1121 hosts_avoid_tls = REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
1122 .endif
1123 .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS
1124 hosts_require_tls = REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS
1125 .endif
1126 .ifdef REMOTE_SMTP_SMARTHOST_TLS_VERIFY_CERTIFICATES
1127 tls_verify_certificates = REMOTE_SMTP_SMARTHOST_TLS_VERIFY_CERTIFICATES
1128 .endif
1129 .ifdef REMOTE_SMTP_SMARTHOST_TLS_VERIFY_HOSTS
1130 tls_verify_hosts = REMOTE_SMTP_SMARTHOST_TLS_VERIFY_HOST
1131 .endif
1132 .ifdef REMOTE_SMTP_HEADERS_REWRITE
1133 headers_rewrite = REMOTE_SMTP_HEADERS_REWRITE
1134 .endif
1135 .ifdef REMOTE_SMTP_RETURN_PATH
1136 return_path = REMOTE_SMTP_RETURN_PATH
1137 .endif
1138 .ifdef REMOTE_SMTP_HELO_DATA
1139 helo_data=REMOTE_SMTP_HELO_DATA
1140 .endif
1141 .ifdef TLS_DH_MIN_BITS
1142 tls_dh_min_bits = TLS_DH_MIN_BITS
1143 .endif
1144 .ifdef REMOTE_SMTP_SMARTHOST_TLS_CERTIFICATE
1145 tls_certificate = REMOTE_SMTP_SMARTHOST_TLS_CERTIFICATE
1146 .endif
1147 .ifdef REMOTE_SMTP_SMARTHOST_PRIVATEKEY
1148 tls_privatekey = REMOTE_SMTP_SMARTHOST_PRIVATEKEY
1149 .endif
1150 .ifdef REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
1151 headers_remove = REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
1152 .endif
1153 .ifdef DKIM_DOMAIN
1154 dkim_domain = DKIM_DOMAIN
1155 .endif
1156 .ifdef DKIM_SELECTOR
1157 dkim_selector = DKIM_SELECTOR
1158 .endif
1159 .ifdef DKIM_PRIVATE_KEY
1160 dkim_private_key = DKIM_PRIVATE_KEY
1161 .endif
1162 .ifdef DKIM_CANON
1163 dkim_canon = DKIM_CANON
1164 .endif
1165 .ifdef DKIM_STRICT
1166 dkim_strict = DKIM_STRICT
1167 .endif
1168 .ifdef DKIM_SIGN_HEADERS
1169 dkim_sign_headers = DKIM_SIGN_HEADERS
1170 .endif
1171 EOF
1172
1173
1174 cat >/etc/exim4/update-exim4.conf.conf <<'EOF'
1175 # default stuff, i havent checked if its needed
1176 dc_minimaldns='false'
1177 dc_relay_nets=''
1178 CFILEMODE='644'
1179 dc_use_split_config='true'
1180 dc_mailname_in_oh='true'
1181 EOF
1182
1183
1184 # * radicale
1185 if mailhost; then
1186 if ! mountpoint /o; then
1187 echo "error /o is not a mountpoint" >&2
1188 exit 1
1189 fi
1190
1191 # davx/davdroid setup instructions at the bottom
1192
1193 # main docs:
1194 # http://radicale.org/user_documentation/
1195 # https://davdroid.bitfire.at/configuration/
1196
1197 # note on debugging: if radicale can't bind to the address,
1198 # in the log it just says "Starting Radicale". If you run
1199 # it in the foreground, it will give more info. Background
1200 # plus debug does not help.
1201 # sudo -u radicale radicale -D -f
1202
1203 # created password file with:
1204 # htpasswd -c /p/c/machine_specific/li/filesystem/etc/caldav-htpasswd
1205 # chmod 640 /p/c/machine_specific/li/filesystem/etc/caldav-htpasswd
1206 # # setup chgrp www-data in ./conflink
1207
1208 pi-nostart radicale
1209
1210 i /etc/systemd/system/radicale.service.d/override.conf <<EOF
1211 [Unit]
1212 # this unit is configured to start and stop whenever
1213 # $vpnser does
1214
1215 After=network.target network-online.target mailnn.service $vpnser
1216 BindsTo=$vpnser
1217
1218 Wants=network-online.target
1219 JoinsNamespaceOf=mailnn.service
1220 StartLimitIntervalSec=0
1221
1222 [Service]
1223 PrivateNetwork=true
1224 BindPaths=$bindpaths
1225 Restart=always
1226 # time to sleep before restarting a service
1227 RestartSec=1000
1228
1229 [Install]
1230 # for openvpn
1231 RequiredBy=$vpnser
1232 EOF
1233
1234
1235 # use persistent uid/gid
1236 IFS=:; read -r _ _ uid _ < <(getent passwd radicale ); unset IFS
1237 IFS=:; read -r _ _ gid _ < <(getent group radicale ); unset IFS
1238 if [[ $uid != 609 ]]; then
1239 m systemctl stop radicale ||:
1240 m usermod -u 609 radicale
1241 m groupmod -g 609 radicale
1242 m usermod -g 609 radicale
1243 fi
1244 m find /o/radicale -xdev -exec chown -h 609 {} +
1245 m find /o/radicale -xdev -exec chgrp -h 609 {} +
1246
1247
1248 # I moved /var/lib/radicale after it's initialization.
1249 # I did a sudo -u radicale git init in the collections subfolder
1250 # after it gets created, per the git docs.
1251 m /a/exe/lnf -T /o/radicale /var/lib/radicale
1252
1253 # from https://www.williamjbowman.com/blog/2015/07/24/setting-up-webdav-caldav-and-carddav-servers/
1254
1255 # more config is for li in distro-end
1256
1257 # coment in this file says this is needed for it to run on startup
1258 sed -ri 's/^\s*#+\s*(ENABLE_RADICALE\s*=\s*yes\s*)/\1/' /etc/default/radicale
1259
1260 # comments say default is 0.0.0.0:5232
1261 m setini hosts 10.8.0.4:5232 server
1262 # https://radicale.org/2.1.html
1263 m setini type http_x_remote_user auth
1264
1265
1266 # disable power management feature, set to 240 min sync interval,
1267 # so it shouldn't be bad.
1268
1269 # davdroid from f-druid.
1270 # login with url and user name
1271 # url https://cal.iankelling.org/ian
1272 # username ian
1273 # pass, see password manager for radicale
1274 #
1275 # add account dialog:
1276 #
1277 # set account name as ian@iankelling.org, per help text below the
1278 # field.
1279 #
1280 # switch to groups are per-contact categories,
1281 # per https://davdroid.bitfire.at/configuration/radicale/
1282 #
1283 #
1284 # After setting up account, I added one address book, named
1285 # ianaddr. calender was already created, named ian. checked boxes under
1286 # both. synced.
1287 #
1288 # To restore from old phone to new phone, I wiped all data out, then copied over the newly created files. I think
1289 #
1290 # ignorable background info:
1291 #
1292 # opentasks uses the calendar file.
1293 #
1294 # The address book I created got a uuid as a name for the file. Note
1295 # the .props file says if it's a calendar or addressbook.
1296 #
1297 # When debugging, tailed /var/log/radicale/radicale.log and apache log,
1298 # both show the requests happening. Without creating the address book,
1299 # after creating a contact, a sync would delete it.
1300 #
1301 # Address books correspond to .props files in the radicale dir.
1302 #
1303 # Some background is here,
1304 # https://davdroid.bitfire.at/faq/entry/cant-manage-groups-on-device/
1305 # which shows separate vcard option is from rfc 6350, the other is 2426,
1306 # radicale page says it implements the former not the latter,
1307 # which conflicts with the documentation of which to select, but whatever.
1308 # http://radicale.org/technical_choices/
1309 # https://davdroid.bitfire.at/faq/entry/cant-manage-groups-on-device/
1310 #
1311 # Note, url above says only cayanogenmod 13+ and omnirom can manage groups.
1312
1313 # Note, radicale had built-in git support to track changes, but they
1314 # removed it in 2.0.
1315
1316 fi
1317
1318 # * dovecot
1319
1320 # ** $MAIL_HOST|bk|je)
1321 case $HOSTNAME in
1322 $MAIL_HOST|bk|je)
1323 # based on a little google and package search, just the dovecot
1324 # packages we need instead of dovecot-common.
1325 #
1326 # dovecot-lmtpd is for exim to deliver to dovecot instead of maildir
1327 # directly. The reason to do this is to use dovecot\'s sieve, which
1328 # can generally do more than exims filters (a few things less) and
1329 # sieve has the benefit of being supported in postfix and
1330 # proprietary/weird environments, so there is more examples on the
1331 # internet.
1332 pi dovecot-core dovecot-imapd dovecot-sieve dovecot-lmtpd dovecot-sqlite sqlite3
1333
1334 for f in /p/c{/machine_specific/$HOSTNAME,}/filesystem/etc/dovecot/users; do
1335 if [[ -e $f ]]; then
1336 m rsync -ahhi --chown=root:dovecot --chmod=0640 $f /etc/dovecot/
1337 break
1338 fi
1339 done
1340 for f in /p/c/subdir_files/sieve/*sieve /a/c/subdir_files/sieve/*sieve; do
1341 m sudo -u $u /a/exe/lnf -T $f $uhome/sieve/${f##*/}
1342 done
1343
1344 # https://wiki.dovecot.org/SSL/DovecotConfiguration
1345 i /etc/dovecot/dhparam <<'EOF'
1346 -----BEGIN DH PARAMETERS-----
1347 MIIBCAKCAQEAoleil6SBxGqQKk7j0y2vV3Oklv6XupZKn7PkPv485QuFeFagifeS
1348 A+Jz6Wquqk5zhGyCu63Hp4wzGs4TyQqoLjkaWL6Ra/Bw3g3ofPEzMGEsV1Qdqde4
1349 jorwiwtr2i9E6TXQp0noT/7VFeHulIkayTeW8JulINdMHs+oLylv16McGCIrxbkM
1350 8D1PuO0TP/CNDs2QbRvJ1RjY3CeGpxMhrSHVgBCUMwnA2cvz3bYjI7UMYMMDPNrE
1351 PLrwsYzXGGCdJsO2vsmmqqgLsZiapYJlUNjfiyWLt7E2H6WzkNB3VIhIPfLqFDPK
1352 xioE3sYKdjOt+p6mlg3l8+OLtODEFPHDqwIBAg==
1353 -----END DH PARAMETERS-----
1354 EOF
1355 {
1356 if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
1357 cat <<'EOF'
1358 ssl_cert = </etc/exim4/fullchain.pem
1359 ssl_key = </etc/exim4/privkey.pem
1360 EOF
1361 else
1362 cat <<'EOF'
1363 ssl_cert = </etc/exim4/exim.crt
1364 ssl_key = </etc/exim4/exim.key
1365 EOF
1366 fi
1367 cat <<EOF
1368 # https://ssl-config.mozilla.org
1369 ssl = required
1370 # this is the same as the certbot list, in my cert cronjob, I check if that has changed upstream.
1371 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
1372 ssl_protocols = TLSv1.2
1373 ssl_prefer_server_ciphers = no
1374 ssl_dh_parameters_length = 2048
1375
1376 protocol lmtp {
1377 #per https://wiki2.dovecot.org/Pigeonhole/Sieve/Configuration
1378 # default is just \$mail_plugins
1379 mail_plugins = \$mail_plugins sieve
1380 }
1381 EOF
1382 if dpkg --compare-versions $(dpkg-query -f='${Version}\n' --show dovecot-core) ge 1:2.3; then
1383 cat <<EOF
1384 ssl_dh = </etc/dovecot/dhparam
1385 EOF
1386 fi
1387 } >/etc/dovecot/local.conf
1388
1389 ;;&
1390
1391 # ** $MAIL_HOST)
1392 $MAIL_HOST)
1393 # If we changed 90-sieve.conf and removed the active part of the
1394 # sieve option, we wouldn\'t need this, but I\'d rather not modify a
1395 # default config if not needed. This won\'t work as a symlink in /a/c
1396 # unfortunately.
1397 m sudo -u $u /a/exe/lnf -T sieve/main.sieve $uhome/.dovecot.sieve
1398
1399 if [[ ! -e $uhome/sieve/personal.sieve ]]; then
1400 m touch $uhome/sieve/personal{,end}{,test}.sieve
1401 fi
1402
1403 rm -fv /etc/dovecot/conf.d/20-lmtp.conf # file from prev version
1404 cat >>/etc/dovecot/local.conf <<EOF
1405 # simple password file based login
1406 !include conf.d/auth-passwdfile.conf.ext
1407
1408 # ian: %u is used for alerts user vs iank
1409 mail_location = maildir:/m/%u:LAYOUT=fs:INBOX=/m/%u/INBOX
1410 mail_uid = $u
1411 mail_gid = $u
1412
1413 protocol lmtp {
1414 # For a normal setup with exim, we need something like this, which
1415 # removes the domain part
1416 # auth_username_format = %Ln
1417 #
1418 # or else # Exim says something like
1419 # "LMTP error after RCPT ... 550 ... User doesn't exist someuser@somedomain"
1420 # Dovecot verbose log says something like
1421 # "auth-worker(9048): passwd(someuser@somedomain): unknown user"
1422 # reference: http://wiki.dovecot.org/LMTP/Exim
1423 #
1424 # However, I use this to direct all mail to the same inbox.
1425 # A normal way to do this, which I did at first is to have
1426 # a router in exim almost at the end, eg 950,
1427 #local_catchall:
1428 # debug_print = "R: catchall for \$local_part@\$domain"
1429 # driver = redirect
1430 # domains = +local_domains
1431 # data = $u
1432 # based on
1433 # http://blog.alteholz.eu/2015/04/exim4-and-catchall-email-address/
1434 # with superflous options removed.
1435 # However, this causes the envelope to be rewritten,
1436 # which makes filtering into mailboxes a little less robust or more complicated,
1437 # so I've done it this way instead. it also requires
1438 # modifying the local router in exim.
1439 auth_username_format = $u
1440 }
1441 EOF
1442 ;;&
1443 # ** bk|je)
1444 bk|je)
1445 chown -R mail.mail /m/md
1446
1447 f=/etc/dovecot/conf.d/10-auth.conf
1448 if [[ -e $f ]]; then
1449 mv $f $f-iank-disabled
1450 fi
1451
1452 cat >>/etc/dovecot/local.conf <<EOF
1453 !include /etc/dovecot/local.conf.ext
1454
1455 # for debugging info, uncomment these.
1456 # logs go to syslog and to /var/log/mail.log
1457 #auth_verbose=yes
1458 #mail_debug=yes
1459
1460
1461 protocol lmtp {
1462 # This downcases the localpart. default is case sensitive.
1463 # case sensitive local part will miss out on valid email when some person or system
1464 # mistakenly capitalizes things.
1465 auth_username_format = %Lu
1466 }
1467
1468 # make 147 only listen on localhost, plan to use for nextcloud.
1469 # copied from mailinabox
1470 service imap-login {
1471 inet_listener imap {
1472 address = 127.0.0.1
1473 }
1474 }
1475 # https://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_dovecot_authenticator.html
1476 service auth {
1477 unix_listener auth-client {
1478 user = Debian-exim
1479 group = Debian-exim
1480 }
1481 }
1482
1483
1484 plugin {
1485 sieve_before = /etc/dovecot/sieve-spam.sieve
1486 # from mailinabox
1487 sieve = /m/sieve/%d/%n.sieve
1488 sieve_dir = /m/sieve/%d/%n
1489 }
1490
1491
1492 # all taken from mailinabox.
1493 mail_location = maildir:/m/md/%d/%n
1494 # meh, ok.
1495 mail_privileged_group = mail
1496 # By default Dovecot allows users to log in only with UID numbers 500 and above. mail is 8
1497 first_valid_uid = 1
1498
1499 # todo: test these changes in the universal config
1500 # mailboxes taken from mailinabox but removed
1501 # settings duplicate to defaults
1502 namespace inbox {
1503 mailbox INBOX {
1504 auto = subscribe
1505 }
1506 mailbox Spam {
1507 special_use = \Junk
1508 auto = subscribe
1509 }
1510 mailbox Drafts {
1511 auto = subscribe
1512 }
1513 mailbox Sent {
1514 auto = subscribe
1515 }
1516 mailbox Trash {
1517 auto = subscribe
1518 }
1519 mailbox Archive {
1520 special_use = \Archive
1521 auto = subscribe
1522 }
1523 }
1524 auth_mechanisms = plain login
1525 EOF
1526
1527 i /etc/dovecot/sieve-spam.sieve <<'EOF'
1528 require ["regex", "fileinto", "imap4flags"];
1529
1530 if allof (header :regex "X-Spam-Status" "^Yes") {
1531 fileinto "Spam";
1532 stop;
1533 }
1534 EOF
1535
1536 i /etc/dovecot/local.conf.ext <<'EOF'
1537 passdb {
1538 driver = sql
1539 args = /etc/dovecot/dovecot-sql.conf.ext
1540 }
1541 userdb {
1542 driver = sql
1543 args = /etc/dovecot/dovecot-sql.conf.ext
1544 }
1545
1546 EOF
1547
1548 i /etc/dovecot/dovecot-sql.conf.ext <<'EOF'
1549 # from mailinabox
1550 driver = sqlite
1551 connect = /m/rc/users.sqlite
1552 default_pass_scheme = SHA512-CRYPT
1553 password_query = SELECT email as user, password FROM users WHERE email='%u';
1554 user_query = SELECT email AS user, "mail" as uid, "mail" as gid, "/m/md/%d/%n" as home FROM users WHERE email='%u';
1555 iterate_query = SELECT email AS user FROM users;
1556 EOF
1557 m chmod 0600 /etc/dovecot/dovecot-sql.conf.ext # per Dovecot instructions
1558
1559 # db needs to be in a www-data writable directory
1560 db=/m/rc/users.sqlite
1561 if [[ ! -s $db ]]; then
1562 m mkdir -p /m/rc
1563 m sqlite3 $db <<'EOF'
1564 CREATE TABLE users (
1565 id INTEGER PRIMARY KEY AUTOINCREMENT,
1566 email TEXT NOT NULL UNIQUE,
1567 password TEXT NOT NULL,
1568 extra,
1569 privileges TEXT NOT NULL DEFAULT '');
1570 EOF
1571 fi
1572 # example of adding a user:
1573 # hash: doveadm pw -s SHA512-CRYPT -p passhere
1574 # sqlite3 /m/rc/users.sqlite <<'EOF'
1575 #insert into users (email, password) values ('testignore@bk.b8.nz', 'hash');
1576 #EOF
1577 # update users set password = 'hash' where email = 'testignore@bk.b8.nz';
1578
1579 # this should be at the end since it requires a valid dovecot config
1580 m sievec /etc/dovecot/sieve-spam.sieve
1581 ;;&
1582 # ** bk)
1583 bk)
1584 # roundcube uses this
1585 mkdir -p /m/sieve
1586 chown mail.mail /m/sieve
1587 m pi dovecot-managesieved
1588 ;;
1589 esac
1590
1591 # * thunderbird autoconfig setup
1592
1593 bkdomains=(expertpathologyreview.com amnimal.ninja)
1594 if [[ $HOSTNAME == bk ]]; then
1595 for domain in ${bkdomains[@]}; do
1596 m /a/exe/web-conf apache2 autoconfig.$domain
1597 dir=/var/www/autoconfig.$domain/html/mail
1598 m mkdir -p $dir
1599 # taken from mailinabox
1600 i $dir/config-v1.1.xml <<EOF
1601 <?xml version="1.0" encoding="UTF-8"?>
1602 <clientConfig version="1.1">
1603 <emailProvider id="$domain">
1604 <domain>$domain</domain>
1605
1606 <displayName>$domain Mail</displayName>
1607 <displayShortName>$domain</displayShortName>
1608
1609 <incomingServer type="imap">
1610 <hostname>mail2.iankelling.org</hostname>
1611 <port>993</port>
1612 <socketType>SSL</socketType>
1613 <username>%EMAILADDRESS%</username>
1614 <authentication>password-cleartext</authentication>
1615 </incomingServer>
1616
1617 <outgoingServer type="smtp">
1618 <hostname>mail2.iankelling.org</hostname>
1619 <port>587</port>
1620 <socketType>STARTTLS</socketType>
1621 <username>%EMAILADDRESS%</username>
1622 <authentication>password-cleartext</authentication>
1623 <addThisServer>true</addThisServer>
1624 <useGlobalPreferredServer>false</useGlobalPreferredServer>
1625 </outgoingServer>
1626
1627 <documentation url="https://$domain/">
1628 <descr lang="en">$domain website.</descr>
1629 </documentation>
1630 </emailProvider>
1631
1632 <webMail>
1633 <loginPage url="https://$domain/roundcube" />
1634 <loginPageInfo url="https://$domain/roundcube" >
1635 <username>%EMAILADDRESS%</username>
1636 <usernameField id="rcmloginuser" name="_user" />
1637 <passwordField id="rcmloginpwd" name="_pass" />
1638 <loginButton id="rcmloginsubmit" />
1639 </loginPageInfo>
1640 </webMail>
1641 <clientConfigUpdate url="https://autoconfig.$domain/mail/config-v1.1.xml" />
1642 </clientConfig>
1643 EOF
1644 done
1645 fi
1646
1647 # * roundcube setup
1648
1649 if [[ $HOSTNAME == bk ]]; then
1650
1651 # zip according to /installer
1652 # which requires adding a line to /usr/local/lib/roundcubemail/config/config.inc.php
1653 # $config['enable_installer'] = true;
1654 pi roundcube roundcube-sqlite3 php-zip apache2 php-fpm
1655
1656 ### begin composer install
1657 # https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md
1658 # cd $(mktemp -d)
1659 # sum="$(wget -q -O - https://composer.github.io/installer.sig)"
1660 # m php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
1661 # if [[ $sum != $(php -r "echo hash_file('sha384', 'composer-setup.php');") ]]; then
1662 # echo 'ERROR: Invalid composer installer checksum' >&2
1663 # rm -fv composer-setup.php
1664 # exit 1
1665 # fi
1666 # m php composer-setup.php --quiet
1667 # rm -fv composer-setup.php
1668 # m mv composer.phar /usr/local/bin
1669
1670 # the above method gets composer2, carddav plugin at least doesnt work with that
1671 # yet, it was just released 10-24-2020.
1672 m cd /usr/local/bin
1673 m wget -nv -N https://getcomposer.org/composer-1.phar
1674 chmod +x composer-1.phar
1675 ### end composer install
1676
1677 rcdirs=(/usr/local/lib/rcexpertpath /usr/local/lib/rcninja)
1678 ncdirs=(/var/www/ncexpertpath /var/www/ncninja)
1679 # point debian cronjob to our local install, preventing daily cron error
1680
1681 # debian's cronjob will fail, remove both paths it uses just to be sure
1682 rm -fv /usr/share/roundcube/bin/cleandb.sh /etc/cron.d/roundcube-core
1683
1684 #### begin dl roundcube
1685 # note, im r2e subbed to https://github.com/roundcube/roundcubemail/releases.atom
1686 v=1.4.11; f=roundcubemail-$v-complete.tar.gz
1687 cd /a/opt
1688 if [[ -e $f ]]; then
1689 timestamp=$(stat -c %Y $f)
1690 else
1691 timestamp=0
1692 fi
1693 m wget -nv -N https://github.com/roundcube/roundcubemail/releases/download/$v/$f
1694 new_timestamp=$(stat -c %Y $f)
1695 for rcdir in ${rcdirs[@]}; do
1696 if [[ $timestamp != "$new_timestamp" || ! -e "$rcdir/config/secret" ]]; then
1697 m tar -C /usr/local/lib --no-same-owner -zxf $f
1698 m rm -rf $rcdir
1699 m mv /usr/local/lib/roundcubemail-$v $rcdir
1700 fi
1701 done
1702 #### end dl roundcube
1703
1704 for ((i=0; i < ${#bkdomains[@]}; i++)); do
1705 domain=${bkdomains[i]}
1706 rcdir=${rcdirs[i]}
1707 rcbase=${rcdir##*/}
1708 ncdir=${ncdirs[i]}
1709
1710 # copied from debians cronjob
1711 i /etc/cron.d/$rcbase <<EOF
1712 # Roundcube database cleaning: finally removes all records that are
1713 # marked as deleted.
1714 0 5 * * * www-data $rcdir/bin/cleandb.sh >/dev/null
1715 EOF
1716
1717 m /a/exe/web-conf - apache2 $domain <<EOF
1718 Alias /roundcube $rcdir
1719 ### begin roundcube settings
1720 # taken from /etc/apache2/conf-available/roundcube.conf version 1.4.8+dfsg.1-1~bpo10+1
1721 <Directory $rcdir/>
1722 Options +FollowSymLinks
1723 # This is needed to parse $rcdir/.htaccess.
1724 AllowOverride All
1725 Require all granted
1726 </Directory>
1727 # Protecting basic directories:
1728 <Directory $rcdir/config>
1729 Options -FollowSymLinks
1730 AllowOverride None
1731 </Directory>
1732 ### end roundcube settings
1733
1734
1735 ### begin nextcloud settings
1736 Alias /nextcloud "$ncdir/"
1737 <Directory $ncdir/>
1738 Require all granted
1739 AllowOverride All
1740 Options FollowSymLinks MultiViews
1741
1742 <IfModule mod_dav.c>
1743 Dav off
1744 </IfModule>
1745
1746 </Directory>
1747
1748 # based on install checker, links to
1749 # https://docs.nextcloud.com/server/19/admin_manual/issues/general_troubleshooting.html#service-discovery
1750 # their example was a bit wrong, I figured it out by adding
1751 # LogLevel warn rewrite:trace5
1752 # then watching the apache logs
1753
1754 RewriteEngine on
1755 RewriteRule ^/\.well-known/host-meta /nextcloud/public.php?service=host-meta [QSA,L]
1756 RewriteRule ^/\.well-known/host-meta\.json /nextcloud/public.php?service=host-meta-json [QSA,L]
1757 RewriteRule ^/\.well-known/webfinger /nextcloud/public.php?service=webfinger [QSA,L]
1758 RewriteRule ^/\.well-known/carddav /nextcloud/remote.php/dav/ [R=301,L]
1759 RewriteRule ^/\.well-known/caldav /nextcloud/remote.php/dav/ [R=301,L]
1760 ### end nextcloud settings
1761 EOF
1762 if [[ ! -e $rcdir/config/secret ]]; then
1763 base64 </dev/urandom | head -c24 >$rcdir/config/secret || [[ $? == 141 || ${PIPESTATUS[0]} == 32 ]]
1764 fi
1765 secret=$(cat $rcdir/config/secret)
1766
1767 rclogdir=/var/log/$rcbase
1768 rctmpdir=/var/tmp/$rcbase
1769 rcdb=/m/rc/$rcbase.sqlite
1770 # config from mailinabox
1771 i $rcdir/config/config.inc.php <<EOF
1772 <?php
1773 \$config = array();
1774 # debian creates this for us
1775 \$config['log_dir'] = '$rclogdir/';
1776 # debian also creates a temp dir, but it is under its install dir,
1777 # seems better to have our own.
1778 \$config['temp_dir'] = '$rctmpdir/';
1779 \$config['db_dsnw'] = 'sqlite:///$rcdb?mode=0640';
1780 \$config['default_host'] = 'ssl://localhost';
1781 \$config['default_port'] = 993;
1782 \$config['imap_conn_options'] = array(
1783 'ssl' => array(
1784 'verify_peer' => false,
1785 'verify_peer_name' => false,
1786 ),
1787 );
1788 \$config['imap_timeout'] = 15;
1789 \$config['smtp_server'] = 'tls://127.0.0.1';
1790 \$config['smtp_conn_options'] = array(
1791 'ssl' => array(
1792 'verify_peer' => false,
1793 'verify_peer_name' => false,
1794 ),
1795 );
1796 \$config['product_name'] = 'webmail';
1797 \$config['des_key'] = '$secret';
1798 \$config['plugins'] = array('archive', 'zipdownload', 'password', 'managesieve', 'jqueryui', 'carddav', 'html5_notifier');
1799 \$config['skin'] = 'elastic';
1800 \$config['login_autocomplete'] = 2;
1801 \$config['password_charset'] = 'UTF-8';
1802 \$config['junk_mbox'] = 'Spam';
1803 # disable builtin addressbook
1804 \$config['address_book_type'] = '';
1805 ?>
1806 EOF
1807
1808 m mkdir -p $rclogdir
1809 m chmod 750 $rclogdir
1810 m chown www-data:adm $rclogdir
1811 # note: subscribed to updates:
1812 # r2e add rcmcarddav https://github.com/blind-coder/rcmcarddav/commits/master.atom ian@iankelling.org
1813 # r2e add roundcube https://github.com/roundcube/roundcubemail/releases.atom ian@iankelling.org
1814 m mkdir -p $rctmpdir /m/rc
1815 m chown -R www-data.www-data $rctmpdir /m/rc
1816 m chmod 750 $rctmpdir
1817 # Ensure the log file monitored by fail2ban exists, or else fail2ban can't start.
1818 # todo: setup fail2ban
1819 # todo: check for other mailinabox things
1820 m sudo -u www-data touch $rclogdir/errors.log
1821
1822 #### begin carddav install
1823 # This is the official roundcube carddav repo.
1824 # Install doc suggests downloading with composer, but that
1825 # didnt work, it said some ldap package for roundcube was missing,
1826 # but I dont want to download some extra ldap thing.
1827 # https://github.com/blind-coder/rcmcarddav/blob/master/doc/INSTALL.md
1828 verf=$rcdir/plugins/carddav/myversion
1829 upgrade=false
1830 install=false
1831 v=4.0.0
1832 if [[ -e $verf ]]; then
1833 if [[ $(cat $verf) != "$v" ]]; then
1834 install=true
1835 upgrade=true
1836 fi
1837 else
1838 install=true
1839 fi
1840 if $install; then
1841 m rm -rf $rcdir/plugins/carddav
1842 tmpd=$(mktemp -d)
1843 m wget -nv -O $tmpd/t.tgz https://github.com/blind-coder/rcmcarddav/releases/download/v$v/carddav-v$v.tgz
1844 cd $rcdir/plugins
1845 tar xzf $tmpd/t.tgz
1846 rm -rf $tmpd
1847 m chown -R www-data:www-data $rcdir/plugins/carddav
1848 m cd $rcdir/plugins/carddav
1849 if $upgrade; then
1850 m sudo -u www-data composer-1.phar update --no-dev
1851 else
1852 m sudo -u www-data composer-1.phar install --no-dev
1853 fi
1854 m chown -R root:root $rcdir/plugins/carddav
1855 echo $v >$verf
1856 fi
1857
1858 # So, strangely, this worked in initial testing, but then
1859 # on first run it wouldn't show the existing contacts until
1860 # I went into the carddav settings and did "force immediate sync",
1861 # which seemed to fix things. Note, some of these settings
1862 # get initalized per/addressbook in the db, then need changing
1863 # there or through the settings menu.
1864
1865 # About categories, see https://www.davx5.com/tested-with/nextcloud
1866 # https://github.com/blind-coder/rcmcarddav/blob/master/doc/GROUPS.md
1867 i $rcdir/plugins/carddav/config.inc.php <<EOF;
1868 <?php
1869 \$prefs['_GLOBAL']['hide_preferences'] = false;
1870 \$prefs['davserver'] = array(
1871 # name in the UI is kind of dumb. This is just something short that seems to fit ok.
1872 'name' => 'Main',
1873 'username' => '%u', // login username
1874 'password' => '%p', // login password
1875 'url' => 'https://$domain/nextcloud/remote.php/dav/addressbooks/users/%u/contacts',
1876 'active' => true,
1877 'readonly' => false,
1878 'refresh_time' => '00:10:00',
1879 'fixed' => array('username','password'),
1880 'use_categories' => false,
1881 'hide' => false,
1882 );
1883 ?>
1884 EOF
1885 #### end carddav install
1886
1887 cd $rcdir/plugins
1888 if [[ ! -d html5_notifier ]]; then
1889 m git clone https://github.com/stremlau/html5_notifier
1890 fi
1891 cd $rcdir/plugins/html5_notifier
1892 m git pull --rebase
1893
1894 # todo: try out roundcube plugins: thunderbird labels
1895
1896 # Password changing plugin settings
1897 cat $rcdir/plugins/password/config.inc.php.dist - >$rcdir/plugins/password/config.inc.php <<'EOF'
1898 # following are from mailinabox
1899 $config['password_minimum_length'] = 8;
1900 $config['password_db_dsn'] = 'sqlite:////m/rc/users.sqlite';
1901 $config['password_query'] = 'UPDATE users SET password=%D WHERE email=%u';
1902 $config['password_dovecotpw'] = '/usr/bin/doveadm pw';
1903 $config['password_dovecotpw_method'] = 'SHA512-CRYPT';
1904 $config['password_dovecotpw_with_method'] = true;
1905 EOF
1906 # so PHP can use doveadm, for the password changing plugin
1907 m usermod -a -G dovecot www-data
1908 m usermod -a -G mail $u
1909
1910 # so php can update passwords
1911 m chown www-data:dovecot /m/rc/users.sqlite
1912 m chmod 664 /m/rc/users.sqlite
1913
1914 # Run Roundcube database migration script (database is created if it does not exist)
1915 m $rcdir/bin/updatedb.sh --dir $rcdir/SQL --package roundcube
1916 m chown www-data:www-data $rcdb
1917 m chmod 664 $rcdb
1918 done # end loop over domains and rcdirs
1919
1920 ### begin php setup for rc ###
1921 # Enable PHP modules.
1922 m phpenmod -v php mcrypt imap
1923 # dpkg says this is required
1924 m a2enmod proxy_fcgi setenvif
1925 fpm=$(dpkg-query -s php-fpm | sed -nr 's/^Depends:.* (php[^ ]*-fpm)( .*|$)/\1/p') # eg: php7.3-fpm
1926 phpver=$(dpkg-query -s php-fpm | sed -nr 's/^Depends:.* php([^ ]*)-fpm( .*|$)/\1/p')
1927 m a2enconf $fpm
1928 # 3 useless guides on php fpm fcgi debian 10 later, i figure out from reading
1929 # /etc/apache2/conf-enabled/php7.3-fpm.conf
1930 m a2dismod php$phpver
1931 # according to /install, we should set date.timezone,
1932 # but that is dumb, the system already has the right zone in
1933 # $rclogdir/errors.log
1934 # todo: consider other settings in
1935 # /a/opt/mailinabox/setup/nextcloud.sh
1936 i /etc/php/$phpver/cli/conf.d/30-local.ini <<'EOF'
1937 apc.enable_cli = 1
1938 EOF
1939
1940 i /etc/php/$phpver/fpm/conf.d/30-local.ini <<'EOF'
1941 date.timezone = "America/New_York"
1942 # for nextcloud
1943 upload_max_filesize = 2000M
1944 post_max_size = 2000M
1945 # install checker, nextcloud/settings/admin/overview
1946 memory_limit = 512M
1947 EOF
1948 m systemctl restart $fpm
1949 # dunno if reload/restart is needed
1950 m systemctl reload apache2
1951 # note bk backups are defined in crontab outside this file
1952 ### end php setup for rc ###
1953
1954 fi # end roundcube setup
1955
1956 # * nextcloud setup
1957
1958 if [[ $HOSTNAME == bk ]]; then
1959 # from install checker, nextcloud/settings/admin/overview and
1960 # https://docs.nextcloud.com/server/19/admin_manual/installation/source_installation.html
1961 # curl from the web installer requirement, but i switched to cli
1962 # it recommends php-file info, but that is part of php7.3-common, already got installed
1963 # with roundcube.
1964 m pi php-curl php-bz2 php-gmp php-bcmath php-imagick php-apcu
1965
1966 # https://docs.nextcloud.com/server/19/admin_manual/installation/source_installation.html
1967 cat >/etc/php/$phpver/fpm/pool.d/localwww.conf <<'EOF'
1968 [www]
1969 clear_env = no
1970 EOF
1971
1972 for ((i=0; i < ${#bkdomains[@]}; i++)); do
1973 domain=${bkdomains[i]}
1974 ncdir=${ncdirs[i]}
1975 ncbase=${ncdir##*/}
1976 m cd /var/www
1977 if [[ ! -e $ncdir/index.php ]]; then
1978 # if we wanted to only install a specific version, use something like
1979 # file=latest-22.zip
1980 file=latest.zip
1981 m wget -nv -N https://download.nextcloud.com/server/releases/$file
1982 m rm -rf nextcloud
1983 m unzip -q $file
1984 m rm -f $file
1985 m chown -R www-data.www-data nextcloud
1986 m mv nextcloud $ncdir
1987 m cd $ncdir
1988 m sudo -u www-data php occ maintenance:install --database sqlite --admin-user iank --admin-pass $nextcloud_admin_pass
1989 fi
1990 # note, strange this happend where updater did not increment the version var,
1991 # mine was stuck on 20. I manually updated it.
1992 m cd $ncdir/config
1993 if [[ ! -e config.php-orig ]]; then
1994 m cp -a config.php config.php-orig
1995 fi
1996 cat config.php-orig - >tmp.php <<EOF
1997 # https://docs.nextcloud.com/server/19/admin_manual/configuration_server/email_configuration.html
1998 \$CONFIG["mail_smtpmode"] = "sendmail";
1999 \$CONFIG["mail_smtphost"] = "127.0.0.1";
2000 \$CONFIG["mail_smtpport"] = 25;
2001 \$CONFIG["mail_smtptimeout"] = 10;
2002 \$CONFIG["mail_smtpsecure"] = "";
2003 \$CONFIG["mail_smtpauth"] = false;
2004 \$CONFIG["mail_smtpauthtype"] = "LOGIN";
2005 \$CONFIG["mail_smtpname"] = "";
2006 \$CONFIG["mail_smtppassword"] = "";
2007 \$CONFIG["mail_domain"] = "$domain";
2008
2009 # https://github.com/nextcloud/user_external#readme
2010 # plus mailinabox example
2011 \$CONFIG['user_backends'] = array(array('class' => 'OC_User_IMAP','arguments' => array('127.0.0.1', 143, null),),);
2012
2013
2014 # based on installer check
2015 # https://docs.nextcloud.com/server/19/admin_manual/configuration_server/caching_configuration.html
2016 \$CONFIG['memcache.local'] = '\OC\Memcache\APCu';
2017
2018 \$CONFIG['overwrite.cli.url'] = 'https://$domain/nextcloud';
2019 \$CONFIG['htaccess.RewriteBase'] = '/nextcloud';
2020 \$CONFIG['trusted_domains'] = array (
2021 0 => '$domain',
2022 );
2023 #\$CONFIG[''] = '';
2024 fwrite(STDOUT, "<?php\n\\\$CONFIG = ");
2025 var_export(\$CONFIG);
2026 fwrite(STDOUT, ";\n");
2027 EOF
2028 m php tmp.php >config.php
2029 m rm tmp.php
2030 m sudo -u www-data php $ncdir/occ maintenance:update:htaccess
2031 list=$(sudo -u www-data php $ncdir/occ --output=json_pretty app:list)
2032 # user_external not compaible with nc 23
2033 for app in contacts calendar; do
2034 if [[ $(printf "%s\n" "$list"| jq ".enabled.$app") == null ]]; then
2035 m sudo -u www-data php $ncdir/occ app:install $app
2036 fi
2037 done
2038 i /etc/systemd/system/$ncbase.service <<EOF
2039 [Unit]
2040 Description=ncup $ncbase
2041 After=multi-user.target
2042
2043 [Service]
2044 Type=oneshot
2045 ExecStart=/usr/local/bin/ncup $ncbase
2046 User=www-data
2047 IOSchedulingClass=idle
2048 CPUSchedulingPolicy=idle
2049 EOF
2050 i /etc/systemd/system/$ncbase.timer <<EOF
2051 [Unit]
2052 Description=ncup $ncbase timer
2053
2054 [Timer]
2055 OnCalendar=Daily
2056
2057 [Install]
2058 WantedBy=timers.target
2059 EOF
2060 systemctl enable --now $ncbase.timer
2061 i /usr/local/bin/ncup <<'EOFOUTER'
2062 #!/bin/bash
2063 if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
2064 shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4
2065 set -eE -o pipefail
2066 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR
2067
2068 ncbase=$1
2069 if ! php /var/www/$ncbase/updater/updater.phar -n; then
2070 echo failed nextcloud update for $ncbase >&2
2071 /sbin/exim -t <<EOF
2072 To: alerts@iankelling.org
2073 From: root@$(hostname -f)
2074 Subject: failed nextcloud update for $ncbase
2075
2076 For logs, run: jr -u $ncbase
2077 EOF
2078 fi
2079 EOFOUTER
2080
2081 mkdir -p /var/www/cron-errors
2082 chown www-data.www-data /var/www/cron-errors
2083 i /etc/cron.d/$ncbase <<EOF
2084 PATH=/sbin:/usr/sbin:/usr/bin:/bin:/usr/local/bin
2085 SHELL=/bin/bash
2086 # https://docs.nextcloud.com/server/20/admin_manual/configuration_server/background_jobs_configuration.html
2087 */5 * * * * www-data php -f $ncdir/cron.php --define apc.enable_cli=1 |& log-once nccron
2088 EOF
2089
2090 done
2091 fi
2092
2093
2094 # * exim host conditional config
2095
2096 # ** exim certs
2097
2098 all_dirs=(/p/c/filesystem)
2099 for x in /p/c/machine_specific/*.hosts /a/bin/ds/machine_specific/*.hosts; do
2100 if grep -qxF $HOSTNAME $x; then all_dirs+=( ${x%.hosts} ); fi
2101 done
2102 files=()
2103 for d in ${all_dirs[@]}; do
2104 f=$d/etc/exim4/passwd
2105 if [[ -e $f ]]; then
2106 files+=($f)
2107 fi
2108 tmp=($d/etc/exim4/*.pem)
2109 if (( ${#tmp[@]} )); then
2110 files+=(${tmp[@]})
2111 fi
2112 done
2113
2114 if (( ${#files[@]} )); then
2115 sudo rsync -ahhi --chown=root:Debian-exim --chmod=0640 ${files[@]} /etc/exim4/
2116 fi
2117
2118
2119 # ** auth
2120
2121 case $HOSTNAME in
2122 bk|je)
2123 # avoid accepting mail for invalid users
2124 # https://wiki.dovecot.org/LMTP/Exim
2125 cat >>/etc/exim4/conf.d/rcpt_local_acl <<'EOF'
2126 deny
2127 message = invalid recipient
2128 domains = +local_domains
2129 !verify = recipient/callout=no_cache
2130 EOF
2131 i /etc/exim4/conf.d/auth/29_exim4-config_auth <<'EOF'
2132 dovecot_plain:
2133 driver = dovecot
2134 public_name = PLAIN
2135 server_socket = /var/run/dovecot/auth-client
2136 server_set_id = $auth1
2137 EOF
2138 ;;
2139 esac
2140 if $bhost_t; then
2141 i /etc/exim4/conf.d/auth/29_exim4-config_auth <<'EOF'
2142 # from 30_exim4-config_examples
2143 plain_server:
2144 driver = plaintext
2145 public_name = PLAIN
2146 server_condition = "${if crypteq{$auth3}{${extract{1}{:}{${lookup{$auth2}lsearch{CONFDIR/passwd}{$value}{*:*}}}}}{1}{0}}"
2147 server_set_id = $auth2
2148 server_prompts = :
2149 .ifndef AUTH_SERVER_ALLOW_NOTLS_PASSWORDS
2150 server_advertise_condition = ${if eq{$tls_in_cipher}{}{}{*}}
2151 .endif
2152 EOF
2153 fi
2154
2155 # ** main daemon use non-default config file
2156 case $HOSTNAME in
2157 bk|$MAIL_HOST)
2158 # to see the default comments in /etc/default/exim4:
2159 # s update-exim4defaults --force --init
2160 # which will overwrite any existing file
2161 i /etc/default/exim4 <<'EOF'
2162 QUEUERUNNER='combined'
2163 QUEUEINTERVAL='30m'
2164 COMMONOPTIONS='-C /etc/exim4/my.conf'
2165 UPEX4OPTS='-o /etc/exim4/my.conf'
2166 #E4BCD_PANICLOG_NOISE='malware acl condition: clamd /var/run/clamav/clamd\.ctl : unable to connect to UNIX socket'
2167 EOF
2168 i /etc/exim4/trusted_configs <<'EOF'
2169 /etc/exim4/my.conf
2170 EOF
2171 ;;
2172 *)
2173 # default file
2174 i /etc/default/exim4 <<'EOF'
2175 QUEUERUNNER='combined'
2176 QUEUEINTERVAL='30m'
2177 EOF
2178 ;;
2179 esac
2180
2181 case $HOSTNAME in
2182 # ** $MAIL_HOST|bk|je)
2183 $MAIL_HOST|bk|je)
2184
2185 echo|i /etc/exim4/conf.d/router/870_backup_local
2186
2187 cat >>/etc/exim4/update-exim4.conf.conf <<EOF
2188 # note: some things we don't set that are here by default because they are unused.
2189 dc_local_interfaces=''
2190 dc_eximconfig_configtype='internet'
2191 dc_localdelivery='dovecot_lmtp'
2192 EOF
2193 cat >>/etc/exim4/conf.d/main/000_local <<EOF
2194 # recommended if dns is expected to work
2195 CHECK_RCPT_VERIFY_SENDER = true
2196 # default config comment says: If you enable this, you might reject legitimate mail,
2197 # but eggs has had this a long time, so that seems unlikely.
2198 CHECK_DATA_VERIFY_HEADER_SYNTAX = true
2199 CHECK_RCPT_SPF = true
2200 CHECK_RCPT_REVERSE_DNS = true
2201 CHECK_MAIL_HELO_ISSUED = true
2202
2203 # enable 587 in addition to the default 25, so that
2204 # i can send mail where port 25 is firewalled by isp
2205 daemon_smtp_ports = 25 : 587
2206 # default of 25, can get stuck when catching up on mail
2207 smtp_accept_max = 400
2208 smtp_accept_reserve = 100
2209 smtp_reserve_hosts = +iank_trusted
2210
2211 # options exim has to avoid having to alter the default config files
2212 CHECK_RCPT_LOCAL_ACL_FILE = /etc/exim4/conf.d/rcpt_local_acl
2213 CHECK_DATA_LOCAL_ACL_FILE = /etc/exim4/conf.d/data_local_acl
2214 LOCAL_DENY_EXCEPTIONS_LOCAL_ACL_FILE = /etc/exim4/conf.d/local_deny_exceptions_acl
2215 # testing dmarc
2216 #dmarc_tld_file = /etc/public_suffix_list.dat
2217 EOF
2218 ;;&
2219
2220 # ** $MAIL_HOST|bk)
2221 $MAIL_HOST|bk)
2222
2223 cat >>/etc/exim4/conf.d/main/000_local <<EOF
2224 # je.b8.nz will run out of memory with freshclam
2225 av_scanner = clamd:/var/run/clamav/clamd.ctl
2226 EOF
2227
2228 cat >> /etc/exim4/conf.d/data_local_acl <<'EOF'
2229 deny
2230 malware = */defer_ok
2231 !condition = ${if match {$malware_name}{\N^Heuristic\N}}
2232 message = This message was detected as possible malware ($malware_name).
2233 EOF
2234
2235 cat >/etc/exim4/conf.d/main/000_local-nn <<EOF
2236 # MAIN_HARDCODE_PRIMARY_HOSTNAME might mess up the
2237 # smarthost config type, not sure.
2238 # failing message on mail-tester.com:
2239 # We check if there is a server (A Record) behind your hostname kd.
2240 # You may want to publish a DNS record (A type) for the hostname kd or use a different hostname in your mail software
2241 # https://serverfault.com/questions/46545/how-do-i-change-exim4s-primary-hostname-on-a-debian-box
2242 # and this one seemed appropriate from grepping config.
2243 # I originally set this to li.iankelling.org, but then ended up with errors when li tried to send
2244 # mail to kd, so this should basically be a name that no host has as their
2245 # canonical hostname since the actual host sits behind a nat and changes.
2246 MAIN_HARDCODE_PRIMARY_HOSTNAME = mail.iankelling.org
2247 # I used this to avoid sender verification, didnt work but it still
2248 # makes sense based on the spec.
2249 hosts_treat_as_local = defaultnn.b8.nz
2250
2251 # Outside nn, we get the default cert location from a debian macro,
2252 # and the cert file is put in place by a certbot hook.
2253 MAIN_TLS_CERTIFICATE = /etc/exim4/fullchain.pem
2254 MAIN_TLS_PRIVATEKEY = /etc/exim4/privkey.pem
2255 EOF
2256
2257 i /etc/exim4/conf.d/router/190_exim4-config_fsfsmarthost <<'EOF'
2258 gnusmarthost:
2259 debug_print = "R: smarthost for $local_part@$domain"
2260 driver = manualroute
2261 domains = ! +local_domains
2262 # send most mail through eggs, helps fsfs sender reputation.
2263 # uncomment and optionally move to 188 file to send through my own servers again
2264 senders = *@gnu.org
2265 transport = smarthost_dkim
2266 route_list = * fencepost.gnu.org::587 byname
2267 host_find_failed = ignore
2268 same_domain_copy_routing = yes
2269 no_more
2270 EOF
2271
2272 /a/exe/cedit defaultnn /etc/hosts <<'EOF' || [[ $? == 1 ]]
2273 10.173.8.1 defaultnn.b8.nz
2274 EOF
2275 ;;&
2276 # ** $MAIL_HOST)
2277 $MAIL_HOST)
2278
2279 i /etc/exim4/conf.d/router/195_dnslookup_vpn <<'EOF'
2280 # copied from /etc/exim4/conf.d/router/200_exim4-config_primary, but
2281 # use vpn transport. lower priority so it overrides the default route.
2282 # Use this in case our vpn fails, we dont send anything without it.
2283 .ifdef DCconfig_internet
2284 dnslookup_vpn:
2285 debug_print = "R: dnslookup for $local_part@$domain"
2286 driver = dnslookup
2287 domains = ! +local_domains
2288 transport = remote_smtp_vpn
2289 same_domain_copy_routing = yes
2290 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
2291 no_more
2292 .endif
2293 EOF
2294
2295
2296 # note on backups: I used to do an automatic sshfs and restricted
2297 # permissions to a specific directory on the remote server, /bu/mnt,
2298 # which required using a dedicated user, but realized smtp will be
2299 # more reliable and less fuss. If I ever need that again, see the
2300 # history of this file, and bum in brc2.
2301
2302 i /etc/exim4/conf.d/router/890_backup_copy <<EOF
2303 ### router/900_exim4-config_local_user
2304 #################################
2305
2306 # todo, it would be nice to save sent email too,
2307 # but its not so important, they still exist in my head
2308
2309 backup_redir:
2310 driver = redirect
2311 domains = +local_domains
2312 # b is just an arbirary short string
2313 data = b@eximbackup.b8.nz
2314 # note, to test this, i could temporarily allow testignore.
2315 # alerts avoids potential mail loop. root is already
2316 # redirected earlier, so that is just being overly cautious.
2317 local_parts = ! root : ! testignore : ! alerts
2318 unseen
2319
2320 backup_copy:
2321 driver = manualroute
2322 domains = eximbackup.b8.nz
2323 transport = backup_remote
2324 ignore_target_hosts = ${HOSTNAME}wg.b8.nz
2325 # note changes here also require change in passwd.client
2326 route_list = * eximbackup.b8.nz
2327 same_domain_copy_routing = yes
2328 no_more
2329 EOF
2330
2331
2332 i /etc/exim4/conf.d/transport/30_backup_remote <<'EOF'
2333 backup_remote:
2334 driver = smtp
2335 multi_domain
2336 .ifndef IGNORE_SMTP_LINE_LENGTH_LIMIT
2337 message_size_limit = ${if > {$max_received_linelength}{998} {1}{0}}
2338 .endif
2339 hosts_require_auth = *
2340 hosts_try_auth = *
2341 return_path = alerts@iankelling.org
2342 envelope_to_add
2343 # manual return path because we dont want it to be the envelope sender
2344 # we got not the one we are using in this smtp transport
2345 headers_add = "Return-path: $sender_address"
2346 .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
2347 hosts_avoid_tls = REMOTE_SMTP_SMARTHOST_HOSTS_AVOID_TLS
2348 .endif
2349 .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS
2350 hosts_require_tls = REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS
2351 .endif
2352 .ifdef REMOTE_SMTP_SMARTHOST_TLS_VERIFY_CERTIFICATES
2353 tls_verify_certificates = REMOTE_SMTP_SMARTHOST_TLS_VERIFY_CERTIFICATES
2354 .endif
2355 .ifdef REMOTE_SMTP_SMARTHOST_TLS_VERIFY_HOSTS
2356 tls_verify_hosts = REMOTE_SMTP_SMARTHOST_TLS_VERIFY_HOST
2357 .endif
2358 .ifdef REMOTE_SMTP_HEADERS_REWRITE
2359 headers_rewrite = REMOTE_SMTP_HEADERS_REWRITE
2360 .endif
2361 .ifdef REMOTE_SMTP_HELO_DATA
2362 helo_data=REMOTE_SMTP_HELO_DATA
2363 .endif
2364 .ifdef TLS_DH_MIN_BITS
2365 tls_dh_min_bits = TLS_DH_MIN_BITS
2366 .endif
2367 .ifdef REMOTE_SMTP_SMARTHOST_TLS_CERTIFICATE
2368 tls_certificate = REMOTE_SMTP_SMARTHOST_TLS_CERTIFICATE
2369 .endif
2370 .ifdef REMOTE_SMTP_SMARTHOST_PRIVATEKEY
2371 tls_privatekey = REMOTE_SMTP_SMARTHOST_PRIVATEKEY
2372 .endif
2373 .ifdef REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
2374 headers_remove = REMOTE_SMTP_TRANSPORTS_HEADERS_REMOVE
2375 .endif
2376 EOF
2377
2378
2379 # this avoids some error. i cant remember what. todo:
2380 # test it out and document why/if its needed.
2381 i /etc/exim4/host_local_deny_exceptions <<'EOF'
2382 mail.fsf.org
2383 *.posteo.de
2384 EOF
2385
2386 # cron email from smarthost hosts will automatically be to
2387 # USER@FQDN. I redirect that to alerts@, on the smarthosts, but in
2388 # case that doesn't work, we still want to accept that mail, but not
2389 # from any host except the smarthosts. local_hostnames and this rule
2390 # is for that purpose.
2391 i /etc/exim4/conf.d/rcpt_local_acl <<'EOF'
2392 deny
2393 !authenticated = *
2394 domains = +local_hostnames
2395 message = no relay
2396 EOF
2397 echo|i /etc/exim4/conf.d/router/880_universal_forward
2398
2399 # for iank@fsf.org, i have mail.fsf.org forward it to fsf@iankelling.org.
2400 # and also have mail.iankelling.org whitelisted as a relay domain.
2401 # I could avoid that if I changed this to submit to 587 with a
2402 # password like a standard mua.
2403 i /etc/exim4/conf.d/router/188_exim4-config_smarthost <<'EOF'
2404 # ian: copied from /etc/exim4/conf.d/router/200_exim4-config_primary, and added senders = and
2405 # replaced DCsmarthost with hostname
2406 fsfsmarthost:
2407 debug_print = "R: smarthost for $local_part@$domain"
2408 driver = manualroute
2409 domains = ! +local_domains
2410 senders = *@fsf.org
2411 transport = remote_smtp_smarthost
2412 route_list = * mail.fsf.org::587 byname
2413 host_find_failed = ignore
2414 same_domain_copy_routing = yes
2415 no_more
2416
2417 posteosmarthost:
2418 debug_print = "R: smarthost for $local_part@$domain"
2419 driver = manualroute
2420 domains = ! +local_domains
2421 senders = *@posteo.net
2422 transport = remote_smtp_smarthost
2423 route_list = * posteo.de::587 byname
2424 host_find_failed = ignore
2425 same_domain_copy_routing = yes
2426 no_more
2427
2428 EOF
2429
2430 # Greping /etc/exim4, unqualified mails this would end up as
2431 # a return path, so it should go somewhere we will see.
2432 # The debconf output about mailname is as follows:
2433 # The 'mail name' is the domain name used to 'qualify' mail addresses without a domain
2434 # name.
2435 # This name will also be used by other programs. It should be the single, fully
2436 # qualified domain name (FQDN).
2437 # Thus, if a mail address on the local host is foo@example.org, the correct value for
2438 # this option would be example.org.
2439 # This name won\'t appear on From: lines of outgoing messages if rewriting is enabled.
2440 echo iankelling.org > /etc/mailname
2441
2442
2443 # mail.iankelling.org so local imap clients can connect with tls and
2444 # when they happen to not be local.
2445 # todo: this should be 10.8.0.4
2446
2447 /a/exe/cedit nn /etc/hosts <<'EOF' || [[ $? == 1 ]]
2448 # note: i put nn.b8.nz into bind for good measure
2449 10.173.8.2 nn.b8.nz mail.iankelling.org
2450 EOF
2451
2452 # note: systemd-resolved will consult /etc/hosts, dnsmasq wont. this assumes
2453 # weve configured this file in dnsmasq if we are using it.
2454 /a/exe/cedit mail /etc/dnsmasq-servers.conf <<'EOF' || [[ $? == 1 ]]
2455 server=/mail.iankelling.org/127.0.1.1
2456 EOF
2457 # I used to use debconf-set-selections + dpkg-reconfigure,
2458 # which then updates this file
2459 # but the process is slower than updating it directly and then I want to set other things in
2460 # update-exim4.conf.conf, so there's no point.
2461 # The file is documented in man update-exim4.conf,
2462 # except the man page is not perfect, read the bash script to be sure about things.
2463
2464 # The debconf questions output is additional documentation that is not
2465 # easily accessible, but super long, along with the initial default comment in this
2466 # file, so I've saved that into ./mail-notes.conf.
2467 cat >>/etc/exim4/update-exim4.conf.conf <<EOF
2468 # man page: is used to build the local_domains list, together with "localhost"
2469 # this is duplicated in a later router.
2470 dc_other_hostnames='iankelling.org;zroe.org;r2e.iankelling.org;!je.b8.nz;!bk.b8.nz;*.b8.nz;b8.nz'
2471 EOF
2472
2473
2474 # dmarc. not used currently
2475 f=/etc/cron.daily/refresh-dmarc-tld-file
2476 cat >$f <<'EOF'
2477 #!/bin/bash
2478 cd /etc
2479 wget -q -N https://publicsuffix.org/list/public_suffix_list.dat
2480 EOF
2481 m chmod 755 $f
2482
2483 ;;
2484 # ** bk
2485 ## we use this host to monitor MAIL_HOST and host a mail server for someone
2486 bk)
2487
2488 echo|i /etc/exim4/conf.d/rcpt_local_acl
2489 echo|i /etc/exim4/conf.d/router/880_universal_forward
2490
2491 echo amnimal.ninja > /etc/mailname
2492
2493 /a/exe/cedit nn /etc/hosts <<'EOF' || [[ $? == 1 ]]
2494 10.173.8.2 nn.b8.nz
2495 EOF
2496
2497 sed -r -f - /etc/init.d/exim4 <<'EOF' | i /etc/init.d/exim4in
2498 s,/etc/default/exim4,/etc/default/exim4in,g
2499 s,/run/exim4/exim.pid,/run/exim4/eximin.pid,g
2500 s,(^[ #]*Provides:).*,\1 exim4in,
2501 s,(^[ #]*NAME=).*,\1"exim4in",
2502 EOF
2503 chmod +x /etc/init.d/exim4in
2504 i /etc/systemd/system/exim4in.service.d/alwaysrestart.conf <<'EOF'
2505 [Unit]
2506 # needed to continually restart
2507 StartLimitIntervalSec=0
2508
2509 [Service]
2510 Restart=always
2511 # time to sleep before restarting a service
2512 RestartSec=1
2513 EOF
2514
2515 i /etc/default/exim4in <<'EOF'
2516 # defaults but no queue runner and alternate config dir
2517 QUEUERUNNER='no'
2518 COMMONOPTIONS='-oP /run/exim4/eximin.pid'
2519 UPEX4OPTS='-d /etc/myexim4'
2520 EOF
2521
2522 cat >>/etc/exim4/update-exim4.conf.conf <<EOF
2523 # man page: is used to build the local_domains list, together with "localhost"
2524 dc_other_hostnames='amnimal.ninja;expertpathologyreview.com'
2525 EOF
2526
2527 ;;
2528 # ** je
2529 je)
2530 echo je.b8.nz > /etc/mailname
2531 cat >>/etc/exim4/update-exim4.conf.conf <<EOF
2532 dc_other_hostnames='je.b8.nz'
2533 EOF
2534 echo|i /etc/exim4/conf.d/router/188_exim4-config_smarthost
2535 echo|i /etc/exim4/conf.d/router/190_exim4-config_fsfsmarthost
2536 echo|i /etc/exim4/conf.d/rcpt_local_acl
2537 echo|i /etc/exim4/conf.d/router/880_universal_forward
2538 ;;
2539 # ** not MAIL_HOST|bk|je
2540 *)
2541 # this one should be removed for all non mail hosts, but
2542 # bk and je never become mail_host
2543 echo|i /etc/exim4/conf.d/router/195_dnslookup_vpn
2544
2545 echo|i /etc/exim4/conf.d/router/188_exim4-config_smarthost
2546 echo|i /etc/exim4/conf.d/router/190_exim4-config_fsfsmarthost
2547 echo|i /etc/exim4/conf.d/rcpt_local_acl
2548 echo|i /etc/exim4/conf.d/router/890_backup_copy
2549
2550
2551 if $bhost_t; then
2552 cat >>/etc/exim4/conf.d/main/000_local <<EOF
2553 MAIN_TLS_CERTIFICATE = /etc/exim4/certs/$wghost/fullchain.pem
2554 MAIN_TLS_PRIVATEKEY = /etc/exim4/certs/$wghost/privkey.pem
2555 # so we can maintiain the originals of the backups.
2556 # we wouldnt want this if we were dealing with any other
2557 # local deliveries, but we sent all others to the smarthost
2558 # which then strips the headers.
2559 envelope_to_remove = false
2560 return_path_remove = false
2561 EOF
2562 fi
2563
2564 # catches things like cronjob email
2565 i /etc/exim4/conf.d/router/880_universal_forward <<'EOF'
2566 universal_forward:
2567 driver = redirect
2568 domains = +local_domains
2569 data = alerts@iankelling.org
2570 EOF
2571
2572
2573 for unit in ${nn_progs[@]}; do
2574 f=/etc/systemd/system/$unit.service.d/nn.conf
2575 rm -fv $f
2576 done
2577
2578 # dont i dont care if defaultnn section gets left, it wont
2579 # get used.
2580 echo | /a/exe/cedit nn /etc/hosts || [[ $? == 1 ]]
2581 echo | /a/exe/cedit mail /etc/dnsmasq-servers.conf || [[ $? == 1 ]]
2582
2583 if $bhost_t; then
2584 i /etc/exim4/conf.d/transport/30_backup_maildir <<EOF
2585 # modified debian maildir transport
2586 backup_maildir:
2587 driver = appendfile
2588 directory = /bu/md
2589 delivery_date_add
2590 # note, no return path or envelope added
2591 maildir_format
2592 directory_mode = 0700
2593 mode = 0644
2594 mode_fail_narrower = false
2595 user = $u
2596 EOF
2597
2598 i /etc/exim4/conf.d/router/870_backup_local <<EOF
2599 ### router/900_exim4-config_local_user
2600 #################################
2601
2602 backup_local:
2603 debug_print = "R: local_user for \$local_part@\$domain"
2604 driver = accept
2605 domains = eximbackup.b8.nz
2606 transport = backup_maildir
2607 EOF
2608
2609
2610 wgholeip=$(sed -rn 's/^ *Address *= *([^/]+).*/\1/p' /etc/wireguard/wghole.conf)
2611 cat >>/etc/exim4/update-exim4.conf.conf <<EOF
2612 dc_other_hostnames='eximbackup.b8.nz'
2613 dc_local_interfaces='127.0.0.1;::1;$wgholeip'
2614 EOF
2615 else
2616 cat >>/etc/exim4/update-exim4.conf.conf <<EOF
2617 # Note: If theres like a temporary problem where mail gets sent to
2618 # one of these hosts, if exim isnt listening, it will be a temporary error
2619 # instead of a permanent 5xx.
2620 dc_local_interfaces='127.0.0.1;::1'
2621 EOF
2622 fi
2623 cat >>/etc/exim4/update-exim4.conf.conf <<EOF
2624 dc_eximconfig_configtype='smarthost'
2625 dc_smarthost='$smarthost'
2626 EOF
2627
2628 hostname -f |i /etc/mailname
2629 cat >>/etc/exim4/update-exim4.conf.conf <<EOF
2630 # The manpage incorrectly states this will do header rewriting, but
2631 # that only happens if we have dc_hide_mailname is set.
2632 dc_readhost='iankelling.org'
2633 # Only used in case of bounces.
2634 dc_localdelivery='maildir_home'
2635 EOF
2636 ;;
2637 esac
2638
2639
2640
2641
2642 # ** $MAILHOST|bk, things that belong at the end
2643 case $HOSTNAME in
2644 $MAIL_HOST|bk)
2645 # config for the non-nn exim
2646 m rsync -ra --delete /etc/exim4/ /etc/myexim4
2647 cat >>/etc/myexim4/update-exim4.conf.conf <<'EOF'
2648 dc_eximconfig_configtype='smarthost'
2649 dc_smarthost='nn.b8.nz'
2650 EOF
2651 ;;&
2652 bk)
2653
2654 # config for the non-nn exim
2655 cat >/etc/myexim4/conf.d/main/000_local-nn <<'EOF'
2656 MAIN_HARDCODE_PRIMARY_HOSTNAME = mail2.iankelling.org
2657 EOF
2658 ;;
2659 $MAIL_HOST)
2660 # for bk, we have a exim4in.service that will do this for us.
2661 m update-exim4.conf -d /etc/myexim4
2662 ;;
2663 esac
2664
2665 # * spool dir setup
2666
2667 # ** bind mount setup
2668 # put spool dir in directory that spans multiple distros.
2669 # based on http://www.postfix.org/qmgr.8.html and my notes in gnus
2670 #
2671 dir=/nocow/exim4
2672 sdir=/var/spool/exim4
2673 # we only do this if our system has $dir
2674
2675 # this used to do a symlink, but, in the boot logs, /nocow would get mounted succesfully,
2676 # about 2 seconds later, exim starts, and immediately puts into paniclog:
2677 # honVi-0000u3-82 Failed to create directory "/var/spool/exim4/input": No such file or directory
2678 # so, im trying a bind mount to get rid of that.
2679 if [[ -e /nocow ]]; then
2680 if ! grep -Fx "/nocow/exim4 /var/spool/exim4 none bind 0 0" /etc/fstab; then
2681 echo "/nocow/exim4 /var/spool/exim4 none bind 0 0" >>/etc/fstab
2682 fi
2683 i /etc/systemd/system/exim4.service.d/override.conf <<'EOF'
2684 [Unit]
2685 # without local-fs on exim, we get these kind of errors in paniclog on shutdown:
2686 # Failed to create spool file /var/spool/exim4//input//1jCLxz-0008V4-V9-D: Permission denied
2687 After=local-fs.target
2688 EOF
2689 if ! mountpoint -q $sdir; then
2690 stopifactive exim4 exim4in
2691 if [[ -L $sdir ]]; then
2692 m rm $sdir
2693 fi
2694 if [[ ! -e $dir && -d $sdir ]]; then
2695 m mv $sdir $dir
2696 fi
2697 if [[ ! -d $sdir ]]; then
2698 m mkdir $sdir
2699 m chmod 000 $sdir # only want it to be used when its mounted
2700 fi
2701 m mount $sdir
2702 fi
2703 fi
2704
2705
2706
2707 # ** exim/spool uid setup
2708 # i have the spool directory be common to distro multi-boot, so
2709 # we need the uid to be the same. 608 cuz it's kind of in the middle
2710 # of the free system uids.
2711 IFS=:; read -r _ _ uid _ < <(getent passwd Debian-exim ||:) ||:; unset IFS
2712 IFS=:; read -r _ _ gid _ < <(getent group Debian-exim ||:) ||:; unset IFS
2713 if [[ ! $uid ]]; then
2714 # from /var/lib/dpkg/info/exim4-base.postinst, plus uid and gid options
2715 m adduser --uid 608 --system --group --quiet --home /var/spool/exim4 \
2716 --no-create-home --disabled-login --force-badname Debian-exim
2717 elif [[ $uid != 608 ]]; then
2718 stopifactive exim4 exim4in
2719 m usermod -u 608 Debian-exim
2720 m groupmod -g 608 Debian-exim
2721 m usermod -g 608 Debian-exim
2722 m find / /nocow -path ./var/tmp -prune -o -xdev -uid $uid -execdir chown -h 608 {} +
2723 m find / /nocow -path ./var/tmp -prune -o -xdev -gid $gid -execdir chgrp -h 608 {} +
2724 fi
2725
2726 # * start / stop services
2727
2728 reifactive dnsmasq nscd
2729
2730 if $reload; then
2731 m systemctl daemon-reload
2732 fi
2733
2734 case $HOSTNAME in
2735 je)
2736 /a/exe/web-conf apache2 je.b8.nz
2737 ;;
2738 bk)
2739 /a/exe/web-conf apache2 mail2.iankelling.org
2740 ;;
2741 esac
2742
2743 m /a/bin/ds/mail-cert-cron -1
2744 sre mailcert.timer
2745
2746 case $HOSTNAME in
2747 bk)
2748 # todo, this should be done in distro-begin
2749 soff systemd-resolved
2750 ln -sf 127.0.0.1-resolv/stub-resolv.conf /etc/resolv.conf
2751 ;;&
2752 $MAIL_HOST|bk)
2753 sstart mailnn mailnnroute
2754 # If these have changes, id rather manually restart it, id rather
2755 # not restart and cause temporary errors
2756 if $reload; then
2757 sre $vpnser
2758 else
2759 sstart $vpnser
2760 fi
2761 ;;&
2762 $MAIL_HOST)
2763 if $reload; then
2764 sre unbound
2765 else
2766 sstart unbound
2767 fi
2768 ;;&
2769 $MAIL_HOST|bk)
2770 if ! systemctl is-active clamav-daemon >/dev/null; then
2771 sstart clamav-daemon
2772 # note, this will cause paniclog entries because it takes like 45
2773 # seconds for clamav to start, i use ./epanic-clean to remove
2774 # them.
2775 fi
2776 ;;&
2777 $MAIL_HOST|bk|je)
2778 # start spamassassin/dovecot before exim.
2779 sre dovecot spamassassin
2780 # need to wait a bit before restarting exim, else I
2781 # get a paniclog entry like: spam acl condition: all spamd servers failed
2782 sleep 3
2783 sstart mailclean.timer
2784 ;;&
2785 $MAIL_HOST)
2786 # < 2.1 (eg: in t9), uses a different data format which required manual
2787 # migration. dont start if we are running an old version.
2788 if dpkg --compare-versions $(dpkg -s radicale | awk '$1 == "Version:" { print $2 }') ge 2.1; then
2789 sstart radicale
2790 fi
2791 ;;&
2792 esac
2793
2794 # last use of $reload happens in previous block
2795 rm -f /var/local/mail-setup-reload
2796
2797
2798 case $HOSTNAME in
2799 $MAIL_HOST|bk|je) : ;;
2800 *)
2801 soff radicale mailclean.timer dovecot spamassassin $vpnser mailnn clamav-daemon
2802 ;;
2803 esac
2804
2805 sre exim4
2806
2807 case $HOSTNAME in
2808 bk) sre exim4in ;;
2809 esac
2810
2811 # * mail monitoring / testing
2812
2813 # note, to test clamav, send an email with body that only contains
2814 # https://en.wikipedia.org/wiki/EICAR_test_file
2815 # which set malware_name to Eicar-Signature
2816 case $HOSTNAME in
2817 $MAIL_HOST|bk|je)
2818 # note: cronjob "ian" also does some important monitoring
2819 # todo: this will sometimes cause an alert because mailtest-check will run
2820 # before we have setup network namespace and spamassassin
2821 cat >/etc/cron.d/mailtest <<EOF
2822 SHELL=/bin/bash
2823 PATH=/usr/bin:/bin:/usr/local/bin
2824 MAILTO=alerts@iankelling.org
2825 */5 * * * * $u send-test-forward |& log-once send-test-forward
2826 */10 * * * * root chmod -R g+rw /m/md/bounces |& log-once -1 bounces-chmod
2827 # im seeing some intermittent failures on the slow check, do it all the time
2828 # for now. It looks like a dns failure.
2829 #5-59/5 * * * * root mailtest-check |& log-once -1 mailtest-check
2830 #0 * * * * root mailtest-check slow |& log-once -1 mailtest-slow
2831 */5 * * * * root timeout 290 mailtest-check slow |& log-once -12 mailtest-check
2832 EOF
2833 m sudo rsync -ahhi --chown=root:root --chmod=0755 \
2834 /b/ds/mailtest-check /b/ds/check-remote-mailqs /usr/local/bin/
2835 ;;&
2836 $MAIL_HOST)
2837 test_froms=(ian@iankelling.org z@zroe.org iank@gnu.org)
2838 test_to="testignore@expertpathologyreview.com, testignore@je.b8.nz, testignore@amnimal.ninja, jtuttle@gnu.org"
2839
2840 cat >>/etc/cron.d/mailtest <<EOF
2841 2 * * * * $u check-remote-mailqs |& log-once check-remote-mailqs
2842 EOF
2843 ;;&
2844 bk)
2845 test_froms=(testignore@expertpathologyreview.com testignore@amnimal.ninja)
2846 test_to="testignore@iankelling.org, testignore@zroe.org, testignore@je.b8.nz"
2847 ;;&
2848 je)
2849 test_froms=(testignore@je.b8.nz)
2850 test_to="testignore@iankelling.org, testignore@zroe.org, testignore@expertpathologyreview.com, testignore@amnimal.ninja"
2851 ;;&
2852 $MAIL_HOST|bk|je)
2853 echo '#!/bin/bash' >/usr/local/bin/send-test-forward
2854 for test_from in ${test_froms[@]}; do
2855 cat >>/usr/local/bin/send-test-forward <<EOFOUTER
2856 /usr/sbin/exim -f $test_from -t <<EOF
2857 From: $test_from
2858 To: $test_to
2859 Subject: test \$(date +%Y-%m-%dT%H:%M:%S%z) \$(date +%s)
2860
2861 /usr/local/bin/send-test-forward
2862 EOF
2863 EOFOUTER
2864 done
2865 m chmod +x /usr/local/bin/send-test-forward
2866 ;;
2867 *)
2868 rm -fv /etc/cron.d/mailtest
2869 ;;
2870 esac
2871
2872
2873
2874 # * misc
2875 m sudo -u $u mkdir -p /home/$u/.cache
2876 set -- /m/mucache /home/$u/.cache/mu /m/.mu /home/$u/.mu
2877 while (($#)); do
2878 target=$1
2879 f=$2
2880 shift 2
2881 if [[ ! -L $f ]]; then
2882 if [[ -e $f ]]; then
2883 rm -rf $f
2884 fi
2885 m sudo -u $u ln -sf -T $target $f
2886 fi
2887 done
2888
2889
2890 # /etc/alias setup is debian specific, and exim postinst script sets up
2891 # an /etc/alias from root to the postmaster, based on the question
2892 # exim4-config exim4/dc_postmaster, as long as there exists an entry for
2893 # root, or there was no preexisting aliases file. postfix won\'t set up
2894 # a root to $postmaster alias if it\'s already installed. Easiest to
2895 # just set it ourselves.
2896
2897 # debconf question for postmaster:
2898 # Mail for the 'postmaster', 'root', and other system accounts needs to be redirected
2899 # to the user account of the actual system administrator.
2900 # If this value is left empty, such mail will be saved in /var/mail/mail, which is not
2901 # recommended.
2902 # Note that postmaster\'s mail should be read on the system to which it is directed,
2903 # rather than being forwarded elsewhere, so (at least one of) the users listed here
2904 # should not redirect their mail off this machine. A 'real-' prefix can be used to
2905 # force local delivery.
2906 # Multiple user names need to be separated by spaces.
2907 # Root and postmaster mail recipient:
2908
2909 # duplicated in brc2
2910 bum() {
2911 local cur host
2912 host=$1
2913 (( $# == 1 )) || return 1
2914 cur="$(awk '$2 == "/bu/mnt" {print $1}' /proc/mounts)"
2915 if [[ $cur ]]; then
2916 if [[ $cur == "$host:/bu/md" ]]; then
2917 return 0
2918 else
2919 fusermount -u /bu/mnt
2920 fi
2921 fi
2922 m sshfs bu@$host:/bu/home/md /bu/mnt -o reconnect,ServerAliveInterval=20,ServerAliveCountMax=30 -o allow_other
2923 }
2924 bu() {
2925 if mountpoint -q /bu/mnt; then
2926 if ! timeout -s 9 10 fusermount -u /bu/mnt; then
2927 fusermount -zu /bu/mnt
2928 fi
2929 fi
2930 }
2931
2932 case $HOSTNAME in
2933 $MAIL_HOST)
2934 case $HOSTNAME in
2935 kw) bum x3 ;;
2936 x3) bum kw ;;
2937 kd|sy) bum x2 ;;
2938 x2) bum kd ;;
2939 esac
2940 ;;
2941 *)
2942 bu
2943 ;;
2944 esac
2945
2946
2947 m exit 0
2948 :
2949
2950 # Local Variables:
2951 # eval: (outline-minor-mode)
2952 # outline-regexp: "\\( *\\)# [*]\\{1,8\\} "
2953 # End:
2954 # this is combined with defining outline-level in init.el