Branch oldpackages for 14.07
[14.07/packages.git] / multimedia / ushare / files / ushare.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008 OpenWrt.org
3 START=50
4
5 SERVICE_DAEMONIZE=1
6 SERVICE_WRITE_PID=1
7
8 append_bool() {
9         local section="$1"
10         local option="$2"
11         local value="$3"
12         local _val
13         config_get_bool _val "$section" "$option" '0'
14         [ "$_val" -gt 0 ] && append args "$3"
15 }
16
17 append_string() {
18         local section="$1"
19         local option="$2"
20         local value="$3"
21         local _val
22         config_get _val "$section" "$option"
23         [ -n "$_val" ] && append args "$3 $_val"
24 }
25
26 section_enabled() {
27         config_get_bool enabled "$1" 'enabled' 0
28         [ $enabled -gt 0 ]
29 }
30
31 start_instance() {
32         local section="$1"
33
34         section_enabled "$section" || return 1
35
36         args=""
37         config_get uid "$section" 'user'
38         config_get servername "$section" 'servername'
39         config_get interface "$section" 'interface'
40         config_get options "$section" 'options'
41         config_get content_directories "$section" 'content_directories'
42         append_bool "$section" 'disable_webif' '-w'
43         append_bool "$section" 'disable_telnet' '-t'
44
45         SERVICE_UID="$uid" \
46         service_start /usr/bin/ushare -n "${servername:-OpenWrt}" -i "${interface:-br-lan}" -c "${content_directories:-/tmp}" $args ${options}
47 }
48
49 stop_instance() {
50         local section="$1"
51
52         section_enabled "$section" || return 1
53
54         config_get uid "$section" "user"
55
56         SERVICE_UID="$uid" \
57         service_stop /usr/bin/ushare
58 }
59
60 start() {
61         config_load 'ushare'
62         config_foreach start_instance 'ushare'
63 }
64
65 stop() {
66         config_load 'ushare'
67         config_foreach stop_instance 'ushare'
68 }