aboutsummaryrefslogtreecommitdiff
path: root/utils/owfs/files/owfs.init
blob: 83c8913a0383b68fc73e622ab03c1327f1235a63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh /etc/rc.common
# Copyright (C) 2009-2015 OpenWrt.org

START=95
USE_PROCD=1

PROG=/usr/bin/owfs

append_arg() {
	local cfg="$1"
	local var="$2"
	local opt="$3"
	local def="$4"
	local val

	config_get val "$cfg" "$var"
	[ -n "$val" -o -n "$def" ] && procd_append_param command $opt "${val:-$def}"
}

append_bool() {
	local cfg="$1"
	local var="$2"
	local opt="$3"
	local def="$4"
	local val

	config_get_bool val "$cfg" "$var" "$def"
	[ "$val" = 1 ] && procd_append_param command "$opt"
}

append_plain() {
	procd_append_param command "$1"
}

append_param() {
	local cfg="$1"
	local var="$2"
	local opt="$3"
	local def="$4"
	local val

	config_get val "$cfg" "$var"
	[ -n "$val" -o -n "$def" ] && procd_append_param "$opt" "${val:-$def}"
}

start_instance() {
	local cfg="$1"
	local enabled

	config_get_bool enabled "$cfg" 'enabled' '0'
	[ "$enabled" = 0 ] && return 1

	procd_open_instance

	procd_set_param command "$PROG" --foreground --error_print=1

	# common parameters
	append_bool "$cfg" readonly "--readonly"
	append_arg "$cfg" error_level "--error_level"
	config_list_foreach "$cfg" options append_plain
	config_list_foreach "$cfg" devices append_plain
	append_param "$cfg" user user

	# owfs-specific
	append_arg "$cfg" mountpoint "--mountpoint" /mnt/owfs
	append_bool "$cfg" fuse_allow_other "--allow_other"
	append_arg "$cfg" fuse_open_opt "--fuse_open_opt"

	# don't respawn fuse

	procd_close_instance

}

service_triggers() {
	procd_add_reload_trigger owfs
}

start_service() {
	config_load owfs
	config_foreach start_instance owfs
}