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.

87 lines
1.9 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2009-2013 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. fi
  38. if [ -z "$input_arg" ]; then
  39. error "unsuported input option '$input' in section '$s'"
  40. return 1
  41. fi
  42. local output_arg
  43. if [ "x$output" = 'xhttp' ]; then
  44. output_arg="output_http.so"
  45. config_get port "$s" 'port'
  46. [ -n "$port" ] && output_arg="${output_arg} --port $port"
  47. config_get www "$s" 'www'
  48. [ -n "$www" ] && output_arg="${output_arg} --www $www"
  49. config_get username "$s" 'username'
  50. config_get password "$s" 'password'
  51. [ -n "$username" ] && [ -n "$password" ] && output_arg="${output_arg} --credentials $username:$password"
  52. fi
  53. if [ -z "$output_arg" ]; then
  54. error "unsuported output option '$output' in section '$s'"
  55. return 1
  56. fi
  57. procd_open_instance
  58. procd_set_param command "$PROG" --input "$input_arg" --output "$output_arg"
  59. procd_close_instance
  60. }
  61. start_service() {
  62. config_load 'mjpg-streamer'
  63. config_foreach start_instance 'mjpg-streamer'
  64. }
  65. service_triggers() {
  66. procd_add_reload_trigger 'mjpg-streamer'
  67. }