2021-02-24 11:43:45 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
grepzt() {
|
2022-04-13 06:56:16 +00:00
|
|
|
[ -f /var/lib/zerotier-one/zerotier-one.pid -a -n "$(cat /var/lib/zerotier-one/zerotier-one.pid 2>/dev/null)" -a -d "/proc/$(cat /var/lib/zerotier-one/zerotier-one.pid 2>/dev/null)" ]
|
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"
|
2022-04-13 06:56:16 +00:00
|
|
|
kill $(cat /var/lib/zerotier-one/zerotier-one.pid 2>/dev/null)
|
2021-06-01 16:27:05 +00:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
trap killzerotier INT TERM
|
|
|
|
|
2022-03-24 00:56:09 +00:00
|
|
|
echo "Configuring networks to join"
|
|
|
|
mkdir -p /var/lib/zerotier-one/networks.d
|
|
|
|
|
|
|
|
echo "joining networks: $@"
|
|
|
|
for i in "$@"
|
|
|
|
do
|
|
|
|
echo "Configuring join for $i"
|
|
|
|
touch "/var/lib/zerotier-one/networks.d/${i}.conf"
|
|
|
|
done
|
|
|
|
|
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-24 00:56:09 +00:00
|
|
|
|
|
|
|
if [ -f nohup.out ]
|
|
|
|
then
|
|
|
|
tail -n 10 nohup.out
|
|
|
|
fi
|
|
|
|
|
2021-02-24 11:43:45 +00:00
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
2022-03-24 01:08:46 +00:00
|
|
|
echo "Writing healthcheck for networks: $@"
|
2021-02-24 11:43:45 +00:00
|
|
|
|
2022-03-24 01:08:46 +00:00
|
|
|
cat >/healthcheck.sh <<EOF
|
|
|
|
#!/bin/bash
|
|
|
|
for i in $@
|
2021-02-24 11:43:45 +00:00
|
|
|
do
|
2022-03-24 01:08:46 +00:00
|
|
|
[ "\$(zerotier-cli get \$i status)" = "OK" ] || exit 1
|
2021-02-24 11:43:45 +00:00
|
|
|
done
|
2022-03-24 01:08:46 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
chmod +x /healthcheck.sh
|
2021-02-24 11:43:45 +00:00
|
|
|
|
2022-04-09 04:03:54 +00:00
|
|
|
echo "zerotier-cli info: $(zerotier-cli info)"
|
|
|
|
|
2022-03-24 01:09:04 +00:00
|
|
|
echo "Sleeping infinitely"
|
|
|
|
while true
|
|
|
|
do
|
|
|
|
sleep 1
|
|
|
|
done
|