stockholm/krebs/5pkgs/simple/Reaktor/scripts/tell-on_join.sh

26 lines
638 B
Bash
Raw Normal View History

2021-09-14 17:10:16 +00:00
#! /bin/sh
set -euf
2022-09-27 10:26:37 +00:00
# require flock from util-linux (pkgs.util-linux)
2021-09-14 17:10:16 +00:00
if test "${FLOCK-}" != "$state_file"; then
exec env FLOCK="$state_file" flock "$state_file" "$0" "$@"
fi
# TODO tell now, if already joined
jq -r <"$state_file" \
--arg to "$_from" \
--arg msgtarget "$_msgtarget" \
'
select(.to == $to and .msgtarget == $msgtarget) |
"\(.to): \(.text) \u00032-- \(.from)\u00032 \(.date)"
'
jq -c <"$state_file" >"$state_file.tmp" \
--arg to "$_from" \
--arg msgtarget "$_msgtarget" \
'
select((.to == $to and .msgtarget == $msgtarget) | not)
'
mv "$state_file.tmp" "$state_file"