summaryrefslogtreecommitdiffstats
path: root/krebs/5pkgs/simple/Reaktor/scripts/tell-on_join.sh
diff options
context:
space:
mode:
authorlassulus <lassulus@lassul.us>2021-09-14 19:10:16 +0200
committerlassulus <lassulus@lassul.us>2021-09-14 20:32:51 +0200
commite7d5d990837981496fd8883c85391132200a5319 (patch)
tree6fa8b03b3bfdff44cd48c4c70a542e4fddbb77c2 /krebs/5pkgs/simple/Reaktor/scripts/tell-on_join.sh
parent04ba40838dc4d3b644bf8af2d4da7c0ea417e7c4 (diff)
rip Reaktor
Diffstat (limited to 'krebs/5pkgs/simple/Reaktor/scripts/tell-on_join.sh')
-rwxr-xr-xkrebs/5pkgs/simple/Reaktor/scripts/tell-on_join.sh25
1 files changed, 25 insertions, 0 deletions
diff --git a/krebs/5pkgs/simple/Reaktor/scripts/tell-on_join.sh b/krebs/5pkgs/simple/Reaktor/scripts/tell-on_join.sh
new file mode 100755
index 000000000..c21dc8776
--- /dev/null
+++ b/krebs/5pkgs/simple/Reaktor/scripts/tell-on_join.sh
@@ -0,0 +1,25 @@
+#! /bin/sh
+set -euf
+
+# require flock from util-linux (pkgs.utillinux)
+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"