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
39 if ! make -q ~
/.local
/distro-begin ||
[[ $
(<~
/.local
/distro-begin
) != 0 ]]; then
40 chars
+=("DISTRO-BEGIN!")
43 if ! make -q ~
/.local
/distro-end ||
[[ $
(<~
/.local
/distro-end
) != 0 ]]; then
44 chars
+=("DISTRO-END!")
52 fmin
=$
(( (fsec
- now
) / 60 + 1 ))
53 fminplus
=$
(( fmin
+ 60*24 ))
54 # Filesystem files get copied, so find any newer than the last run.
55 # The rest are hueristics:
56 # Given the last time we added a file in git, is that newer than the last conflink run.
57 # Given new files not added to git, were they modified more recently than the last conflink? but,
58 # push their modification time back by a day so we can develop them before needing to add them to git.
59 if (( $
(date -d "$(git log --diff-filter=ACR --format=%aD -1)" +%s
) > fsec
)) || \
60 [[ $
(find {/a
/bin
/ds
,/p
/c
}{/filesystem
,/machine_specific
/$HOSTNAME/filesystem
} -mmin $fmin -type f
-print -quit 2>/dev
/null
) ]] \
61 ||
[[ $
(find $
(git ls-files
-o --exclude-standard) -mmin $fminplus -type f
-print -quit) ]]; then
66 if [[ ! -e $f || $
(<$f) != 0 ]]; then
71 ## Clean the paniclog, but only up to 4 times per day, or else we
72 ## should investigate.
73 loglog
=/tmp
/panicloglog-$
(date --rfc-3339=date)
74 if [[ -s $loglog ]]; then
75 spamcount
=$
(stat
-c%s
$loglog)
79 if (( spamcount
<= 4 )); then
80 if grep -q 'spam acl condition' /var
/log
/exim
4/paniclog
; then
83 /a
/bin
/distro-setup
/epanic-clean
86 if [[ -s /var
/log
/exim
4/paniclog
]]; then
88 tail -n 20 /var
/log
/exim
4/paniclog | lo
-1 paniclog
93 source /a
/bin
/bash_unpublished
/source-state
94 if [[ $MAIL_HOST == "$HOSTNAME" ]]; then
95 if [[ $
(systemctl is-active btrbk.timer
) != active
]]; then
96 chars
+=("BTRBK.TIMER!")
97 bbkmsg
="btrbk.timer not enabled"
99 lo
-60 btrbk.timer
$bbkmsg
101 ## check if last snapshot was within an hour
103 snaps
=(/mnt
/root
/btrbk
/$vol.20*)
106 for s
in ${snaps[@]}; do
108 t
=$
(date -d $
(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${file#$vol.}) +%s
)
109 if (( t
> maxtime
)); then
113 if (( maxtime
< now
- 60*60 )); then
114 chars
+=("OLD-SNAPSHOT!")
115 snapshotmsg
="/o snapshot older than 1 hour"
117 lo
-1 old-snapshot
$snapshotmsg
120 cat /a
/bin
/bash_unpublished
/source-state
>$status_file
122 if [[ ${chars[*]} ]]; then
123 echo "ps_char=\"${chars[*]} \$ps_char\"" >>$status_file
132 for ((i
=1; i
<=3; i
++)); do