zerotier.init 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/sh /etc/rc.common
  2. START=90
  3. USE_PROCD=1
  4. LIST_SEP="
  5. "
  6. ZT_COMMAND=/usr/bin/zerotier-one
  7. section_enabled() {
  8. config_get_bool enabled "$1" 'enabled' 0
  9. [ $enabled -gt 0 ]
  10. }
  11. start_instance() {
  12. local cfg="$1"
  13. local port secret interface
  14. local ARGS=""
  15. section_enabled "$cfg" || return 1
  16. mkdir -p /var/lib/zerotier-one/networks.d/
  17. config_get_bool port $cfg 'port'
  18. config_get secret $cfg 'secret'
  19. config_get interface $cfg 'interface'
  20. if [ -n "$port" ]; then
  21. ARGS="$ARGS -p$port"
  22. fi
  23. if [ "$secret" = "generate" ]; then
  24. echo "Generate secret - please wait..."
  25. local tmp="/tmp/zt.$cfg.secret"
  26. zerotier-idtool generate "$tmp" > /dev/null
  27. secret="$(cat $tmp)"
  28. rm "$tmp"
  29. uci set zerotier.$cfg.secret="$secret"
  30. uci commit zerotier
  31. fi
  32. if [ -n "$secret" ]; then
  33. echo "$secret" > /var/lib/zerotier-one/identity.secret
  34. #make sure there is not previous dentity.public
  35. rm -f /var/lib/zerotier-one/identity.public
  36. fi
  37. add_join() {
  38. #an (empty) config file will cause ZT to join a network
  39. touch /var/lib/zerotier-one/networks.d/$1.conf
  40. }
  41. config_list_foreach $cfg 'join' add_join
  42. procd_open_instance
  43. procd_add_reload_interface_trigger "$interface"
  44. procd_set_param command $ZT_COMMAND $ARGS
  45. procd_set_param nice -10
  46. procd_close_instance
  47. }
  48. service_triggers() {
  49. procd_add_reload_trigger zerotier
  50. }
  51. start_service() {
  52. config_load 'zerotier'
  53. config_foreach start_instance 'zerotier'
  54. }