You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright 2021 Stan Grishin (stangri@melmac.ca)
  3. # shellcheck disable=SC2039,SC3043
  4. PKG_VERSION='dev-test'
  5. # shellcheck disable=SC2034
  6. START=80
  7. # shellcheck disable=SC2034
  8. USE_PROCD=1
  9. if type extra_command 1>/dev/null 2>&1; then
  10. extra_command 'version' 'Show version information'
  11. else
  12. # shellcheck disable=SC2034
  13. EXTRA_COMMANDS='version'
  14. fi
  15. readonly PROG=/usr/sbin/nebula
  16. version() { echo "Version: $PKG_VERSION"; }
  17. start_instance() {
  18. local cfg="$1" port name="${1##*/}"
  19. port="$(grep -A2 "^listen:" "$cfg" | grep "port: " | awk '{print $2}')"
  20. procd_open_instance
  21. procd_set_param command ${PROG} -config "${cfg}"
  22. procd_set_param stderr 1
  23. procd_set_param stdout 1
  24. procd_set_param respawn
  25. procd_open_data
  26. json_add_array firewall
  27. json_add_object ''
  28. json_add_string type 'rule'
  29. json_add_string name "Allow-$name"
  30. json_add_string src 'wan'
  31. json_add_string dest_port "$port"
  32. json_add_string proto 'udp'
  33. json_add_string target 'ACCEPT'
  34. json_close_object
  35. json_close_array
  36. procd_close_data
  37. procd_close_instance
  38. }
  39. start_service() {
  40. local f
  41. for f in /etc/nebula/*.yml; do
  42. [ -s "$f" ] && start_instance "$f"
  43. done
  44. }
  45. service_started() { procd_set_config_changed firewall; }
  46. service_stopped() { procd_set_config_changed firewall; }