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