From f5fbd372a23c883038b37e17c8c705098e3ee1b1 Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Wed, 26 Jun 2024 01:09:51 +0200 Subject: [PATCH] add some zerotier scripts --- machines/chungus/zerotier-controller.nix | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/machines/chungus/zerotier-controller.nix b/machines/chungus/zerotier-controller.nix index 460c055..a07c3c7 100644 --- a/machines/chungus/zerotier-controller.nix +++ b/machines/chungus/zerotier-controller.nix @@ -5,9 +5,11 @@ let export TOKEN=$(cat /var/lib/zerotier-one/authtoken.secret) ''; zerotierCommand = name: command: pkgs.writers.writeBashBin name '' - export PATH=${pkgs.curl}/bin:${pkgs.gojq}/bin:${pkgs.zerotierone}/bin:$PATH - ${zerotierSetup} - ${command} + set -e + set -o pipefail + export PATH=${pkgs.curl}/bin:${pkgs.gojq}/bin:${pkgs.zerotierone}/bin:$PATH + ${zerotierSetup} + ${command} ''; in { @@ -15,8 +17,16 @@ in (zerotierCommand "zerotier-script-members" '' curl "http://localhost:9993/controller/network/''${NWID}/member" -H "X-ZT1-AUTH: ''${TOKEN}" | gojq '') - (zerotierCommand "zerotier-script-nodeid" '' - zerotier-cli info | cut -d " " -f 3 + (zerotierCommand "zerotier-script-delete-member" '' + if [ "$#" -ne 1 ]; then + echo "Memid is missing." + exit 1 + fi + export MEMID=$1 + echo "deauthorized $MEMID" + curl -X POST "http://localhost:9993/controller/network/''${NWID}/member/''${MEMID}" -H "X-ZT1-AUTH: ''${TOKEN}" -d '{"authorized": false}' | gojq + echo "delete $MEMID" + curl -X DELETE "http://localhost:9993/controller/network/''${NWID}/member/''${MEMID}" -H "X-ZT1-AUTH: ''${TOKEN}" | gojq '') ]; }