2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
5 # usage: runs 4 times every 15 seconds unless any args are passed, then just runs once
7 if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
9 source /a
/bin
/errhandle
/err
10 status_file
=/dev
/shm
/iank-status
15 lo
() { /usr
/local
/bin
/log-once
"$@"; }
20 glob
=(/nocow
/btrfs-stale
/*)
21 if [[ -e ${glob[0]} ]]; then
24 glob
=(/m
/md
/bounces
/new
/*)
25 if [[ -e ${glob[0]} ]]; then
27 bouncemsg
="message in /m/md/bounces/new"
29 lo
-1 bounce
$bouncemsg
30 glob
=(/m
/md
/alerts
/new
/* /m
/md
/alerts
/cur
/*)
31 if [[ -e ${glob[0]} ]]; then
34 if [[ -e /nocow
/user
/mailtest-failure
]]; then
38 ## Clean the paniclog, but only up to 4 times per day, or else we
39 ## should investigate.
40 loglog
=/tmp
/panicloglog-$
(date --rfc-3339=date)
41 if [[ -s $loglog ]]; then
42 spamcount
=$
(stat
-c%s
$loglog)
46 if (( spamcount
<= 4 )); then
47 if grep -q 'spam acl condition' /var
/log
/exim
4/paniclog
; then
50 /a
/bin
/distro-setup
/epanic-clean
53 if [[ -s /var
/log
/exim
4/paniclog
]]; then
55 tail -n 20 /var
/log
/exim
4/paniclog | lo
-1 paniclog
60 source /a
/bin
/bash_unpublished
/source-state
61 if [[ $MAIL_HOST == "$HOSTNAME" ]]; then
62 if [[ $
(systemctl is-active btrbk.timer
) != active
]]; then
63 chars
+=("BTRBK.TIMER!")
64 bbkmsg
="btrbk.timer not enabled"
66 lo
-60 btrbk.timer
$bbkmsg
68 ## check if last snapshot was within an hour
70 snaps
=(/mnt
/root
/btrbk
/$vol.20*)
73 for s
in ${snaps[@]}; do
75 t
=$
(date -d $
(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${file#$vol.}) +%s
)
76 if (( t
> maxtime
)); then
80 if (( maxtime
< now
- 60*60 )); then
81 chars
+=("OLD-SNAPSHOT!")
82 snapshotmsg
="/o snapshot older than 1 hour"
84 lo
-1 old-snapshot
$snapshotmsg
87 cat /a
/bin
/bash_unpublished
/source-state
>$status_file
89 if [[ ${chars[*]} ]]; then
90 echo "ps_char=\"${chars[*]} \$ps_char\"" >>$status_file
99 for ((i
=1; i
<=3; i
++)); do