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.

96 lines
1.9 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=95
  3. USE_PROCD=1
  4. PROG=/usr/bin/kadnode
  5. OPTS=""
  6. boot()
  7. {
  8. # Wait for the loopback interface to be ready
  9. ubus -t 30 wait_for network.interface network.loopback 2>/dev/null
  10. rc_procd start_service
  11. }
  12. xappend() {
  13. local name="$2" value="$1"
  14. OPTS="$OPTS--${name//_/-} ${value//'/\\'}
  15. "
  16. }
  17. append_opts_list() {
  18. local name cfg="$1"; shift
  19. for name in $*; do
  20. config_list_foreach "$cfg" "$name" xappend "$name"
  21. done
  22. }
  23. append_opts() {
  24. local name value cfg="$1"; shift
  25. for name in $*; do
  26. config_get value "$cfg" "$name"
  27. [ -n "$value" ] && xappend "$value" "$name"
  28. done
  29. }
  30. append_opts_boolean() {
  31. local name value cfg="$1"; shift
  32. for name in $*; do
  33. config_get_bool value "$cfg" "$name" 0
  34. [ $value -gt 0 ] && xappend '' $name
  35. done
  36. }
  37. section_enabled() {
  38. config_get_bool enabled "$1" 'enabled' 0
  39. [ $enabled -gt 0 ]
  40. }
  41. start_instance() {
  42. local cfg="$1"
  43. local CONFIG_FILE=/tmp/kadnode.${cfg}.conf
  44. section_enabled "$cfg" || return
  45. OPTS=""
  46. append_opts "$cfg" lpd_addr dns_server dns_port verbosity peerfile config \
  47. query_tld user port ifname cmd_port
  48. append_opts_list "$cfg" announce peer tls_client_cert tls_server_cert bob_load_key
  49. append_opts_boolean "$cfg" dns_proxy_enable lpd_disable fwd_disable ipv4 ipv6
  50. # Close stdin when cmd feature is present
  51. if [ $($PROG --version | grep -c cmd) -eq 1 ]; then
  52. xappend "" "cmd_disable_stdin"
  53. fi
  54. echo "$OPTS" > $CONFIG_FILE
  55. procd_open_instance
  56. procd_set_param command $PROG
  57. procd_set_param file $CONFIG_FILE
  58. procd_set_param stderr 1
  59. procd_set_param stdout 1
  60. procd_append_param command --config $CONFIG_FILE
  61. procd_close_instance
  62. }
  63. stop_instance() {
  64. local cfg="$1"
  65. local CONFIG_FILE=/tmp/kadnode.${cfg}.conf
  66. rm -f $CONFIG_FILE
  67. }
  68. start_service() {
  69. config_load 'kadnode'
  70. config_foreach start_instance 'kadnode'
  71. }
  72. stop_service() {
  73. config_load 'kadnode'
  74. config_foreach stop_instance 'kadnode'
  75. }