summaryrefslogtreecommitdiffstats
path: root/net/iodine/files/iodined.init
blob: 8d7e0b94271498bc897329811e7c6dfad808ff32 (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
#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2011 OpenWrt.org

START=50
PROG=/usr/sbin/iodined
USE_PROCD=1
NAME=iodined

validate_section_iodined()
{
	uci_load_validate iodined iodined "$1" "$2" \
		'enable:bool:1' \
		'address:cidr4' \
		'password:string' \
		'tunnelip:cidr4' \
		'tld:string' \
		'port:range(0,65535)' \
		'debuglevel:range(0,6):0' \
		'client_ip_check:bool:1'
}

iodined_instance()
{
	[ "$2" = 0 ] || {
		echo "validation failed"
		return 1
	}

	[ "$enable" = "0" ] && return 1

	procd_open_instance
	procd_set_param command "$PROG" -f
	[ -n "$address" ] && procd_append_param command -l "$address"
	[ -n "$password" ] && procd_append_param command -P "$password"
	[ -n "$port" ] && procd_append_param command -p "$port"
	[ "$debuglevel" -gt 0 ] && procd_append_param command -$(printf 'D%.0s' $(seq $debuglevel))
	[ "$client_ip_check" -eq 0 ] && procd_append_param command -c
	procd_append_param command "$tunnelip" "$tld"
	procd_set_param stdout 1
	procd_set_param stderr 1
	procd_close_instance
}

start_service () {
	config_load "$NAME"
	config_foreach validate_section_iodined iodined iodined_instance
}

service_triggers() {
	procd_add_reload_trigger "$NAME"
	procd_add_validation validate_section_iodined
}