Skip to content

Instantly share code, notes, and snippets.

@trawor
Last active December 16, 2023 01:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trawor/46f8bb592a2b5c58b04d34d91dfd8f0a to your computer and use it in GitHub Desktop.
Save trawor/46f8bb592a2b5c58b04d34d91dfd8f0a to your computer and use it in GitHub Desktop.
Auto setup for zerotier
#!/bin/sh
NIC=
iptables -I FORWARD -i zt+ -j ACCEPT
iptables -I FORWARD -o zt+ -j ACCEPT
iptables -t nat -I POSTROUTING -o zt+ -j MASQUERADE
iptables -t nat -A POSTROUTING -o ${NIC} -j MASQUERADE
#!/bin/sh
NW_ID=
NW_TOKEN=
if [ -n "$NW_ID" ]; then
sleep 1; zerotier-cli join "${NW_ID}";
MYID=$(zerotier-cli info|cut -d " " -f 3);
echo "Join to ${NW_ID}, my ID: ${MYID}"
while [ -z "$(zerotier-cli listnetworks | grep $NW_ID | grep ACCESS_DENIED)" ]; do echo "wait for connect"; sleep 1 ; done
if [ -n "$NW_TOKEN" ]; then
echo "Found ENV: NW_TOKEN, will auto auth myself ..."
MYURL=https://my.zerotier.com/api/network/${NW_ID}/member/$MYID
wget --header "Authorization: Bearer ${NW_TOKEN}" "${MYURL}" -q -O /tmp/ztinfo.txt
sed \'s/"authorized":false/"authorized":true/\' /tmp/ztinfo.txt > /tmp/ztright.txt
wget --header "Authorization: Bearer ${NW_TOKEN}" --post-data="$(cat /tmp/ztright.txt)" -q -O- "${MYURL}"
rm /tmp/ztinfo.txt && rm /tmp/ztright.txt
while [ -z "$(zerotier-cli listnetworks | grep $NW_ID | grep OK)" ]; do echo "wait for auth";sleep 1 ; done
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment