summaryrefslogtreecommitdiffstats
path: root/krebs
diff options
context:
space:
mode:
authorlassulus <lassulus@lassul.us>2022-10-18 23:44:02 +0200
committerlassulus <lassulus@lassul.us>2022-10-18 23:44:02 +0200
commitfbec9a17fe6a012ce6f794e5a2d73c6dcec19463 (patch)
treec8db116535421cf443ed38663a07a974e7ead233 /krebs
parent29df9c532b8a6871a355514a3dc8e82c2f528715 (diff)
reaktor2 locations: init
Diffstat (limited to 'krebs')
-rw-r--r--krebs/2configs/reaktor2.nix82
1 files changed, 82 insertions, 0 deletions
diff --git a/krebs/2configs/reaktor2.nix b/krebs/2configs/reaktor2.nix
index a7dedf562..2ca84f568 100644
--- a/krebs/2configs/reaktor2.nix
+++ b/krebs/2configs/reaktor2.nix
@@ -38,6 +38,38 @@ let
};
};
+ locationsLib = pkgs.writeText "locations.sh" ''
+ ENDPOINT=http://c.r/poi.json
+ get_locations() {
+ curl -fsS "$ENDPOINT"
+ }
+
+ set_locations() {
+ curl -fSs --data-binary @- "$ENDPOINT"
+ }
+
+ set_location() {
+ [ $# -eq 3 ] || return 1
+ get_locations \
+ | jq \
+ --arg name "$1" \
+ --arg latitude "$2" \
+ --arg longitude "$3" \
+ '.[$name] = { $latitude, $longitude }' \
+ | set_locations
+ }
+
+ get_location() {
+ [ $# -eq 1 ] || return 1
+ get_locations | jq --arg name "$1" '.[$name]'
+ }
+
+ delete_location() {
+ [ $# -eq 1 ] || return 1
+ get_locations | jq --arg name "$1" 'del(.[$name])' | set_locations
+ }
+ '';
+
systemPlugin = {
plugin = "system";
config = {
@@ -76,6 +108,56 @@ let
};
}
{
+ pattern = "^list-locations";
+ activate = "match";
+ command = {
+ filename = pkgs.writeDash "list-locations" ''
+ export PATH=${makeBinPath [
+ pkgs.curl
+ pkgs.jq
+ ]}
+ set -efu
+ set -x
+ . ${locationsLib}
+ get_locations | jq -r 'to_entries[]|"\(.key) \(.value.latitude),\(.value.longitude)"'
+ '';
+ };
+ }
+ {
+ pattern = ''^add-location (\S+) ([0-9.]+),([0-9.]+)$'';
+ activate = "match";
+ arguments = [1 2 3];
+ command = {
+ filename = pkgs.writeDash "add-location" ''
+ export PATH=${makeBinPath [
+ pkgs.curl
+ pkgs.jq
+ ]}
+ set -efu
+ set -x
+ . ${locationsLib}
+ set_location "$1" $2 $3
+ '';
+ };
+ }
+ {
+ pattern = ''^delete-location (\S+)$'';
+ activate = "match";
+ arguments = [1];
+ command = {
+ filename = pkgs.writeDash "add-location" ''
+ export PATH=${makeBinPath [
+ pkgs.curl
+ pkgs.jq
+ ]}
+ set -efu
+ set -x
+ . ${locationsLib}
+ delete_location "$1"
+ '';
+ };
+ }
+ {
pattern = "18@p";
activate = "match";
command = {