entrypoint.sh.release 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/sh
  2. grepzt() {
  3. [ ! -n "$(cat /var/lib/zerotier-one/zerotier-one.pid)" -a -d "/proc/$(cat /var/lib/zerotier-one/zerotier-one.pid)" ]
  4. return $?
  5. }
  6. mkztfile() {
  7. file=$1
  8. mode=$2
  9. content=$3
  10. mkdir -p /var/lib/zerotier-one
  11. echo "$content" > "/var/lib/zerotier-one/$file"
  12. chmod "$mode" "/var/lib/zerotier-one/$file"
  13. }
  14. if [ "x$ZEROTIER_API_SECRET" != "x" ]
  15. then
  16. mkztfile authtoken.secret 0600 "$ZEROTIER_API_SECRET"
  17. fi
  18. if [ "x$ZEROTIER_IDENTITY_PUBLIC" != "x" ]
  19. then
  20. mkztfile identity.public 0644 "$ZEROTIER_IDENTITY_PUBLIC"
  21. fi
  22. if [ "x$ZEROTIER_IDENTITY_SECRET" != "x" ]
  23. then
  24. mkztfile identity.secret 0600 "$ZEROTIER_IDENTITY_SECRET"
  25. fi
  26. mkztfile zerotier-one.port 0600 "9993"
  27. killzerotier() {
  28. echo "Killing zerotier"
  29. kill $(cat /var/lib/zerotier-one/zerotier-one.pid)
  30. exit 0
  31. }
  32. trap killzerotier INT TERM
  33. echo "starting zerotier"
  34. nohup /usr/sbin/zerotier-one &
  35. while ! grepzt
  36. do
  37. echo "zerotier hasn't started, waiting a second"
  38. sleep 1
  39. done
  40. echo "joining networks: $@"
  41. for i in "$@"
  42. do
  43. echo "joining $i"
  44. while ! zerotier-cli join "$i"
  45. do
  46. echo "joining $i failed; trying again in 1s"
  47. sleep 1
  48. done
  49. done
  50. sleep infinity