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.

61 lines
1.1 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2008-2014 OpenWrt.org
  3. START=99
  4. STOP=99
  5. USE_PROCD=1
  6. PROG=/usr/bin/socat
  7. NAME=socat
  8. validate_section_socat()
  9. {
  10. uci_load_validate socat socat "$1" "$2" \
  11. 'enable:bool:1' \
  12. 'SocatOptions:or(string, list(string))' \
  13. 'user:string:root'
  14. }
  15. append_param_command()
  16. {
  17. procd_append_param command "$1"
  18. }
  19. socat_instance()
  20. {
  21. local is_list
  22. local user
  23. [ "$2" = 0 ] || {
  24. echo "validation failed"
  25. return 1
  26. }
  27. [ "$enable" = "0" ] && return 1
  28. procd_open_instance
  29. procd_set_param command "$PROG"
  30. config_get is_list "$1" SocatOptions_LENGTH
  31. if [ -z "$is_list" ]; then
  32. procd_append_param command $SocatOptions
  33. else
  34. config_list_foreach "$1" SocatOptions append_param_command
  35. fi
  36. config_get user "$1" user
  37. if [ -n "$user" ]; then
  38. procd_set_param user $user
  39. fi
  40. procd_set_param stdout 1
  41. procd_set_param stderr 1
  42. procd_close_instance
  43. }
  44. start_service () {
  45. config_load "$NAME"
  46. config_foreach validate_section_socat socat socat_instance
  47. }
  48. service_triggers() {
  49. procd_add_reload_trigger "$NAME"
  50. procd_add_validation validate_section_socat
  51. }