entrypoint.sh.release 966 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/sh
  2. grepzt() {
  3. (find /proc -name exe | xargs -I{} readlink {}) 2>/dev/null | grep -q zerotier-one
  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. echo "starting zerotier"
  27. setsid /usr/sbin/zerotier-one &
  28. while ! grepzt
  29. do
  30. echo "zerotier hasn't started, waiting a second"
  31. sleep 1
  32. done
  33. echo "joining networks: $@"
  34. for i in "$@"
  35. do
  36. echo "joining $i"
  37. while ! zerotier-cli join "$i"
  38. do
  39. echo "joining $i failed; trying again in 1s"
  40. sleep 1
  41. done
  42. done
  43. sleep infinity