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.

58 lines
1.3 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=98
  3. STOP=1
  4. USE_PROCD=1
  5. PROG=/usr/bin/bcg
  6. CONF=/tmp/etc/bigclown-gateway.conf
  7. append() {
  8. local cfg="$1"
  9. local uci_name="$2"
  10. local out_name="$3"
  11. local default="$4"
  12. config_get val $cfg $uci_name $default
  13. if [ -n "$val" ]; then
  14. echo "$out_name $val" >> $CONF
  15. fi
  16. }
  17. start_service() {
  18. config_load bigclown-gateway
  19. local enabled
  20. config_get_bool enabled gateway enabled "0"
  21. [ "$enabled" = "1" ] || {
  22. echo "Bigclown gateway service disabled"
  23. exit 1
  24. }
  25. rm -rf $CONF
  26. echo "Generating bigclown-gateway config file in $CONF"
  27. append gateway name 'name:' usb-dongle
  28. # TODO add hotplug script and use different default here
  29. append gateway device 'device:' /dev/ttyUSB0
  30. append gateway automatic_rename_kit_nodes 'automatic_rename_kit_nodes:' 1
  31. append gateway base_topic_prefix 'base_topic_prefix:'
  32. echo "mqtt:" >> $CONF
  33. append mqtt host ' host:' localhost
  34. append mqtt port ' port:' 1883
  35. append mqtt cafile ' cafile:'
  36. append mqtt certfile ' certfile:'
  37. append mqtt keyfile ' keyfile:'
  38. procd_open_instance
  39. procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
  40. procd_set_param command "$PROG" -c "$CONF"
  41. procd_set_param stdout 1
  42. procd_set_param stderr 1
  43. procd_close_instance
  44. }
  45. service_triggers() {
  46. procd_add_reload_trigger 'bigclown-gateway'
  47. }