add some zerotier scripts

This commit is contained in:
Ingolf Wagner 2024-06-26 01:09:51 +02:00
parent 0a6221d6aa
commit f5fbd372a2
Signed by: palo
GPG key ID: 76BF5F1928B9618B

View file

@ -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
'')
];
}