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.

90 lines
2.0 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2009-2014 OpenWrt.org
  3. START=90
  4. STOP=10
  5. USE_PROCD=1
  6. PROG=/usr/bin/mjpg_streamer
  7. error() {
  8. echo "${initscript}:" "$@" 1>&2
  9. }
  10. start_instance() {
  11. local s="$1"
  12. config_get_bool enabled "$1" 'enabled' 0
  13. [ $enabled -eq 0 ] && return
  14. config_get input "$s" 'input'
  15. if [ -z "$input" ]; then
  16. error "in section '$s' option input is missing"
  17. return 1
  18. fi
  19. config_get output "$s" 'output'
  20. if [ -z "$output" ]; then
  21. error "in section '$s' option output is missing"
  22. return 1
  23. fi
  24. local input_arg
  25. if [ "x$input" = 'xuvc' ]; then
  26. input_arg="input_uvc.so"
  27. config_get device "$s" 'device'
  28. if [ ! -c "$device" ]; then
  29. error "device '$device' does not exist"
  30. return 1
  31. fi
  32. input_arg="${input_arg} --device $device"
  33. config_get fps "$s" 'fps'
  34. [ -n "$fps" ] && input_arg="${input_arg} --fps $fps"
  35. config_get resolution "$s" 'resolution'
  36. [ -n "$resolution" ] && input_arg="${input_arg} --resolution $resolution"
  37. config_get led "$s" 'led'
  38. [ -n "$led" ] && input_arg="${input_arg} --led $led"
  39. fi
  40. if [ -z "$input_arg" ]; then
  41. error "unsuported input option '$input' in section '$s'"
  42. return 1
  43. fi
  44. local output_arg
  45. if [ "x$output" = 'xhttp' ]; then
  46. output_arg="output_http.so"
  47. config_get port "$s" 'port'
  48. [ -n "$port" ] && output_arg="${output_arg} --port $port"
  49. config_get www "$s" 'www'
  50. [ -n "$www" ] && output_arg="${output_arg} --www $www"
  51. config_get username "$s" 'username'
  52. config_get password "$s" 'password'
  53. [ -n "$username" ] && [ -n "$password" ] && output_arg="${output_arg} --credentials $username:$password"
  54. fi
  55. if [ -z "$output_arg" ]; then
  56. error "unsuported output option '$output' in section '$s'"
  57. return 1
  58. fi
  59. procd_open_instance
  60. procd_set_param command "$PROG" --input "$input_arg" --output "$output_arg"
  61. procd_close_instance
  62. }
  63. start_service() {
  64. config_load 'mjpg-streamer'
  65. config_foreach start_instance 'mjpg-streamer'
  66. }
  67. service_triggers() {
  68. procd_add_reload_trigger 'mjpg-streamer'
  69. }