Last active
December 16, 2023 01:32
-
-
Save trawor/46f8bb592a2b5c58b04d34d91dfd8f0a to your computer and use it in GitHub Desktop.
Auto setup for zerotier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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