host info updates
[distro-setup] / prof-tail
1 #!/bin/bash
2 # I, Ian Kelling, follow the GNU license recommendations at
3 # https://www.gnu.org/licenses/license-recommendations.en.html. They
4 # recommend that small programs, < 300 lines, be licensed under the
5 # Apache License 2.0. This file contains or is part of one or more small
6 # programs. If a small program grows beyond 300 lines, I plan to switch
7 # its license to GPL.
8
9 # Copyright 2024 Ian Kelling
10
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
14
15 # http://www.apache.org/licenses/LICENSE-2.0
16
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
22
23 # hacky way to kill off old leftover processes
24 pkill -O 1 -x 'prof-tail'
25
26 set -e; . /usr/local/lib/bash-bear; set +e
27
28 # kill 0 doesn't seem to be documented in man bash, but it kills the
29 # background processes.
30 # https://unix.stackexchange.com/questions/67532/what-does-kill-0-do-actually/67552
31 # commented out because the way I exit prof-tail is from an ssh disconnect from
32 # the connection dying or killing konsole, and this has no effect on either.
33 #trap "kill 0" EXIT
34
35
36 xmpp_users=(
37 anoukr
38 craigt
39 dawnbp
40 devinu
41 gregf
42 johnh
43 jrasata
44 ksiewicz
45 michael
46 miriam
47 ruben
48 zoe
49 jtuttle
50 )
51
52 # start emacs daemon for profanity if it doesnt exist.
53 if ! pgrep -f '^emacs --daemon=profanity$' &>/dev/null; then
54 emacs --daemon=profanity &>/dev/null
55 fi
56
57
58 while true; do
59 midnight=$(date -d '00:00:00 tomorrow' +%s)
60 secs_till_midnight=$(( midnight - EPOCHSECONDS ))
61 log_today=$(date '+%Y_%m_%d').log
62 logdir=/home/iank/.local/share/profanity/chatlogs/iank_at_fsf.org
63
64 # when this fails, it has PIPESTATUS: 124 0 1 0 0, which seems to end up with 1 as the overall code, which is not what
65 # i expected. todo: investigate if and why that is, and narrow the ||:
66 # shellcheck disable=SC2046 # intentional
67 timeout --foreground $secs_till_midnight tail -n0 -qF \
68 $(for u in ${xmpp_users[@]}; do echo $logdir/${u}_at_fsf.org/$log_today; done) 2>/dev/null \
69 | awk '$3 != "me:" {print $3; fflush()}' | sed -u 's/^/pm /;s/@.*//' ||: &
70
71 timeout --foreground $secs_till_midnight tail -n0 -qF \
72 $logdir/rooms/*/$log_today 2>/dev/null \
73 | awk '$3 != "iank:"' | grep -i '\biank\b' | awk '{print $3; fflush()}' | sed 's/^/room /;s/@.*//' ||:
74
75 kill %
76 sleep 1
77 done