e70820feed35996713a101e900ab528749608228
[feed/packages.git] / utils / owfs / files / owfs.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2009-2012 OpenWrt.org
3
4 START=99
5
6 SERVICE_WRITE_PID=1
7 SERVICE_DAEMONIZE=1
8
9 # Workaround insufficient /dev/fuse permissions and the lack of /etc/fuse.conf
10 DEFAULT_SERVICE_UID=0
11 DEFAULT_SERVICE_GID=0
12
13 append_device() {
14 append devices "$1"
15 }
16
17
18 start_owfs_daemon() {
19 local program="$1"
20 local config="$1"
21 local args="--foreground --error_print=1 $2"
22
23
24 local enabled
25 config_get_bool enabled "$config" enabled 0
26 [ "${enabled}" -eq 0 ] && return 1
27
28 local readonly
29 config_get_bool readonly "$config" readonly 0
30 [ "${readonly}" -eq 1 ] && append args "--readonly"
31
32 local error_level
33 config_get error_level "$config" error_level
34 [ -n "${error_level}" ] && append args "--error_level=${error_level}"
35
36 local options
37 config_get options "$config" options
38
39 devices=""
40 config_list_foreach "$config" devices append_device
41
42 config_get SERVICE_UID "$config" uid "$DEFAULT_SERVICE_UID"
43 config_get SERVICE_GID "$config" gid "$DEFAULT_SERVICE_GID"
44
45 service_start "/usr/bin/$program" $args $options $devices
46 }
47
48 start_owfs() {
49 local config="owfs"
50 local args=""
51
52 config_load "$config"
53
54 local mountpoint
55 config_get mountpoint "$config" mountpoint /mnt/owfs
56 append args "--mountpoint=${mountpoint}"
57
58 local fuse_allow_other
59 config_get_bool fuse_allow_other "$config" fuse_allow_other 0
60 [ "${fuse_allow_other}" -eq 1 ] && append args "--allow_other"
61
62 local fuse_open_opt
63 config_get fuse_open_opt "$config" fuse_open_opt
64 [ -n "${fuse_open_opt}" ] && append args "--fuse_open_opt=\"${fuse_open_opt}\""
65
66 start_owfs_daemon "$config" "$args"
67 }
68
69 start() {
70 start_owfs
71 }
72
73 stop() {
74 service_stop /usr/bin/owfs
75 }