2021-02-24 11:43:45 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
grepzt() {
|
2022-03-18 07:08:23 +00:00
|
|
|
[ -f /var/lib/zerotier-one/zerotier-one.pid -a -n "$(cat /var/lib/zerotier-one/zerotier-one.pid)" -a -d "/proc/$(cat /var/lib/zerotier-one/zerotier-one.pid)" ]
|
2021-02-24 11:43:45 +00:00
|
|
|
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-06-01 16:27:05 +00:00
|
|
|
mkztfile zerotier-one.port 0600 "9993"
|
|
|
|
|
|
|
|
killzerotier() {
|
|
|
|
echo "Killing zerotier"
|
|
|
|
kill $(cat /var/lib/zerotier-one/zerotier-one.pid)
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
trap killzerotier INT TERM
|
|
|
|
|
2021-02-24 11:43:45 +00:00
|
|
|
echo "starting zerotier"
|
2021-06-01 19:30:01 +00:00
|
|
|
nohup /usr/sbin/zerotier-one &
|
2021-02-24 11:43:45 +00:00
|
|
|
|
|
|
|
while ! grepzt
|
|
|
|
do
|
|
|
|
echo "zerotier hasn't started, waiting a second"
|
2022-03-18 07:08:23 +00:00
|
|
|
tail -n 10 nohup.out
|
2021-02-24 11:43:45 +00:00
|
|
|
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"
|
|
|
|
|
2022-03-18 07:08:23 +00:00
|
|
|
zerotier-cli join "$i"
|
|
|
|
|
2022-03-18 07:22:03 +00:00
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
|
|
|
echo >&2 "ZeroTier could not be started; did you pass the right arguments to \`docker run\`?"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-03-18 07:08:23 +00:00
|
|
|
while [ "$(zerotier-cli get $i status)" != "OK" ]
|
2021-02-24 11:43:45 +00:00
|
|
|
do
|
2022-03-18 07:08:23 +00:00
|
|
|
echo "joining $i failed (are they added in central?); trying again in 1s"
|
2021-02-24 11:43:45 +00:00
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
sleep infinity
|