2021-02-24 11:43:45 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
grepzt() {
|
|
|
|
(find /proc -name exe | xargs -I{} readlink {}) 2>/dev/null | grep -q zerotier-one
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
2021-04-13 20:18:21 +00:00
|
|
|
mkztfile() {
|
|
|
|
file=$1
|
|
|
|
mode=$2
|
|
|
|
content=$3
|
|
|
|
|
|
|
|
mkdir -p /var/lib/zerotier-one
|
|
|
|
echo "$content" > "/var/lib/zerotier-one/$file"
|
|
|
|
chmod "$mode" "/var/lib/zerotier-one/$file"
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ "x$ZEROTIER_API_SECRET" != "x" ]
|
|
|
|
then
|
|
|
|
mkztfile authtoken.secret 0600 "$ZEROTIER_API_SECRET"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "x$ZEROTIER_IDENTITY_PUBLIC" != "x" ]
|
|
|
|
then
|
|
|
|
mkztfile identity.public 0644 "$ZEROTIER_IDENTITY_PUBLIC"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "x$ZEROTIER_IDENTITY_SECRET" != "x" ]
|
|
|
|
then
|
|
|
|
mkztfile identity.secret 0600 "$ZEROTIER_IDENTITY_SECRET"
|
|
|
|
fi
|
|
|
|
|
2021-02-24 11:43:45 +00:00
|
|
|
echo "starting zerotier"
|
|
|
|
setsid /usr/sbin/zerotier-one &
|
|
|
|
|
|
|
|
while ! grepzt
|
|
|
|
do
|
|
|
|
echo "zerotier hasn't started, waiting a second"
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
2021-04-13 20:18:21 +00:00
|
|
|
echo "joining networks: $@"
|
2021-02-24 11:43:45 +00:00
|
|
|
|
|
|
|
for i in "$@"
|
|
|
|
do
|
|
|
|
echo "joining $i"
|
|
|
|
|
|
|
|
while ! zerotier-cli join "$i"
|
|
|
|
do
|
|
|
|
echo "joining $i failed; trying again in 1s"
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
sleep infinity
|