+ services=( epanicclean )
+ case $HOSTNAME in
+ bk|je|li) : ;;
+ *)
+ services+=(
+ systemstatus
+ btrfsmaintstop
+ dynamicipupdate
+ )
+ bads=()
+ if systemctl show -p SubState --value ${services[@]} | egrep -v '^(running|)$' &>/dev/null; then
+ for s in ${services[@]}; do
+ if [[ $(systemctl show -p SubState --value $s 2>&1) != running ]]; then
+ bads+=($s)
+ fi
+ done
+ chars+=(MYSERS)
+ fi
+ p ${bads[*]} | lo -240 mysers
+ ;;
+ esac
+
+ case $HOSTNAME in
+ kd)
+ services=(
+ prometheus-node-exporter
+ prometheus-alertmanager
+ prometheus
+ )
+ bads=()
+ if systemctl show -p SubState --value ${services[@]} | egrep -v '^(running|)$' &>/dev/null; then
+ for s in ${services[@]}; do
+ if [[ $(systemctl show -p SubState --value $s 2>&1) != running ]]; then
+ bads+=($s)
+ fi
+ done
+ chars+=(PROM)
+ fi
+ p ${bads[*]} | lo -240 prom
+ ;;
+ esac
+
+
+ # this section copied from servicepid()
+ unit=exim4
+ pid=$(systemctl show --property MainPID --value $unit ||:)
+ case $pid in
+ [1-9]*) : ;;
+ *)
+ dir=/sys/fs/cgroup/system.slice
+ if [[ ! -d $dir ]]; then
+ dir=/sys/fs/cgroup/systemd/system.slice
+ fi;
+ pid=$(head -n1 $dir/${unit%.service}.service/cgroup.procs ||:)
+ ;;
+ esac
+ if [[ ! $pid ]]; then
+ chars+=(EXIM)
+ fi
+
+
+ if [[ -e /a/bin/bash_unpublished/source-state ]]; then
+ # /a gets remounted due to btrbk, ignore error code for file doesnt exist
+ source /a/bin/bash_unpublished/source-state || [[ $? == 1 ]]
+ fi
+ if [[ $MAIL_HOST == "$HOSTNAME" ]]; then
+
+ bouncemsg=
+ glob=(/m/md/bounces/new/*)
+ if [[ -e ${glob[0]} ]]; then
+ chars+=(BOUNCE)
+ bouncemsg="message in /m/md/bounces/new"
+ fi
+ p $bouncemsg | loday -1 bounce
+ # emails without the S (seen) flag. this only checks the last flag,
+ # but its good enough for me.
+ glob=(/m/md/alerts/{new,cur}/!(*,S))
+ if [[ -e ${glob[0]} ]]; then
+ chars+=(A)
+ fi
+
+ glob=(/m/md/daylert/{new,cur}/!(*,S))
+ if [[ -e ${glob[0]} ]]; then
+ chars+=(DAY)
+ fi
+
+ bbkmsg=
+ if [[ $(systemctl is-active btrbk.timer) != active ]]; then
+ chars+=(BTRBK.TIMER)
+ bbkmsg="not enabled"
+ fi
+ p "$bbkmsg" | lo -480 btrbk.timer
+
+ ## check if last snapshot was within an hour
+ vol=o
+ # this section generally copied from btrbk scripts, but
+ # this part modified to speed things up by about half a second.
+ # I'm not sure if its quite as reliable, but it looks pretty safe.
+ # Profiled it using time and also adding to the top of the file:
+ # set -x
+ # PS4='+ $(date "+%2N") '
+ # allow failure in case there are no snapshots yet.
+ # shellcheck disable=SC2012
+ shopt -u nullglob
+ files=(/mnt/o/btrbk/$vol.20*)
+ shopt -s nullglob
+ snaps=()
+ if (( ${#files[@]} )); then
+ snaps=($(ls -1avdr "${files[@]}" 2>/dev/null |head -n1 || : ))
+ fi
+ now=$EPOCHSECONDS
+ maxtime=0
+ for s in ${snaps[@]}; do
+ file=${s##*/}
+ t=$(date -d $(sed -r 's/(.{4})(..)(.{5})(..)(.*)/\1-\2-\3:\4:\5/' <<<${file#$vol.}) +%s)
+ if (( t > maxtime )); then
+ maxtime=$t
+ fi
+ done
+ snapshotmsg=
+ if (( maxtime < now - 4*60*60 )); then
+ chars+=(OLD-SNAP)
+ snapshotmsg="/o snapshot older than 4 hours"
+ fi
+ p "$snapshotmsg" | lo -1 old-snapshot
+
+
+ # commented out, only using timetrap retrospectively.
+ # # clock us out in timetrap if are idle too long
+ # if [[ -e /p/.timetrap.db ]]; then
+ # export DISPLAY=:0
+ # if type -p xprintidle &>/dev/null && xidle=$(xprintidle 2>/dev/null); then
+ # if [[ $xidle == [0-9]* ]]; then
+ # sheet=$(sqlite3 /p/.timetrap.db "select sheet from entries where end is NULL;")
+ # idle=300000
+ # if [[ $sheet == w ]]; then
+ # idle=900000
+ # fi
+ # if [[ $sheet && $xidle -gt $idle ]]; then
+ # timetrap out
+ # fi
+ # fi
+ # fi
+ # fi
+ else # end if $MAIL_HOST
+ rmg /home/iank/cron-errors/bounce* \
+ /home/iank/cron-errors/btrbk.timer* \
+ /home/iank/cron-errors/old-snapshot*
+ fi
+
+ if ip l show tunfsf &>/dev/null; then
+ # this is for tracking dns over tls issue, which
+ # fixvpndns() in brc2 fixes.
+ stat=$(resolvectl dnsovertls tunfsf 2>/dev/null ||: )
+ read _ _ _ istls <<<"$stat"
+ case $istls in
+ no) : ;;
+ *)
+ printf "%s\n" "$istls" | ts >> /tmp/istls.log
+ chars+=("T:$istls")
+ ;;
+ esac
+ fi
+
+ # We do this once every 5 minutes, since this is not a grave problem.
+ # For formatted elisp, see /b/ds/unsaved-buffers.el
+ elisp='(format "%s" (-reduce-from (lambda (acc buf) (let ((bpath (buffer-file-name buf))) (if (and bpath (buffer-modified-p buf)) (cons bpath acc ) acc))) nil (buffer-list)))'
+ if [[ ! $last_emacs_check || $emacsfiles ]] || (( last_emacs_check < EPOCHSECONDS - 300 )); then
+ if pgrep -G iank -u iank -f 'emacs --daemon' &>/dev/null; then
+ # i dun care if this fails
+ emacsfiles="$(timeout 1 emacsclient -a /usr/bin/true --eval "$elisp" 2>/dev/null | sed '/^"nil"$/d;s/^"(/E: /;s/)"$//' ||:)"
+ if [[ $emacsfiles ]]; then
+ chars+=("$emacsfiles")