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