summaryrefslogtreecommitdiffstats
path: root/net/u2pnpd/files/u2pnpd.init
blob: 01437fd51e28705053829bc2f05908bd4dec29ab (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
#!/bin/sh /etc/rc.common
# Copyright (C) 2015 OpenWrt.org

START=50
STOP=20

SERVICE_DAEMONIZE=1
SERVICE_PID_FILE=/var/run/u2pnpd.pid
SERVICE_USE_PID=1
SERVICE_WRITE_PID=1

start_instance() {
	local section="$1"
	local enabled
	local interface manufacturer manufacturerURL modelDescription
	local modelName modelNumber modelURL serialNumber friendlyName
	local uuid httpsURL
	local i

	config_get_bool enabled "$section" 'enabled' 1
	[ "$enabled" -gt 0 ] || return 0

	for i in interface httpsURL manufacturer manufacturerURL modelDescription \
	         modelName modelNumber modelURL serialNumber friendlyName uuid; do
		config_get "$i" "$section" "$i"
	done

	[ -n "$interface" ] && SERVICE_PID_FILE="/var/run/u2pnpd.$interface.pid"

	service_start /usr/bin/u2pnpd ${httpsURL:+-s} \
	    ${interface:+--interface="$interface"} \
	    ${manufacturer:+--manufacturer="$manufacturer"} \
	    ${manufacturerURL:+--manufacturerURL="$manufacturerURL"} \
	    ${modelDescription:+--modelDescription="$modelDescription"} \
	    ${modelName:+--modelName="$modelName"} \
	    ${modelNumber:+--modelNumber="$modelNumber"} \
	    ${modelURL:+--modelURL="$modelURL"} \
	    ${serialNumber:+--serialNumber="$serialNumber"} \
	    ${friendlyName:+--friendlyName="$friendlyName"} \
	    ${uuid:+--uuid="$uuid"}
}

stop_instance() {
	local section="$1"
	local interface

	config_get interface "$section" 'interface'
	[ -n "$interface" ] && SERVICE_PID_FILE="/var/run/u2pnpd.$interface.pid"

	service_stop /usr/bin/u2pnpd
	rm -f "$SERVICE_PID_FILE"
}

start() {
	config_load 'u2pnpd'
	config_foreach start_instance 'u2pnpd'
}

stop() {
	config_load 'u2pnpd'
	config_foreach stop_instance 'u2pnpd'
}