rtty: update to 8.0.0
[feed/packages.git] / utils / rtty / files / rtty.init
1 #!/bin/sh /etc/rc.common
2
3 USE_PROCD=1
4 START=99
5
6 BIN=/usr/sbin/rtty
7
8 validate_rtty_section() {
9 uci_load_validate rtty rtty "$1" "$2" \
10 'interface:uci("network", "@interface"):lan' \
11 'id:maxlength(63)' \
12 'description:maxlength(126)' \
13 'host:host' \
14 'port:port' \
15 'ssl:bool:0' \
16 'insecure:bool:0' \
17 'token:maxlength(32)' \
18 'username:string' \
19 'verbose:bool:0'
20 }
21
22 start_rtty() {
23 . /lib/functions/network.sh
24
25 local ifname
26
27 [ "$2" = 0 ] || {
28 echo "validation failed" >&2
29 return 1
30 }
31
32 [ -n "$interface" ] && network_get_device ifname "$interface"
33
34 [ -z "$ifname" -a -z "$id" ] && {
35 echo "You must specify an interface or ID" >&2
36 return 1
37 }
38
39 [ -z "$host" ] && {
40 echo "host required" >&2
41 return 1
42 }
43
44 [ -z "$id" ] && {
45 id=$(sed 's/://g' /sys/class/net/$ifname/address | tr 'a-z' 'A-Z')
46 }
47
48 procd_open_instance
49 procd_set_param command $BIN -h $host -I "$id" -a
50 [ -n "$port" ] && procd_append_param command -p "$port"
51 [ -n "$description" ] && procd_append_param command -d "$description"
52 [ "$ssl" = "1" ] && procd_append_param command -s
53 [ "$insecure" = "1" ] && procd_append_param command -x
54 [ -n "$token" ] && procd_append_param command -t "$token"
55 [ -n "$username" ] && procd_append_param command -f "$username"
56 [ "$verbose" = "1" ] && procd_append_param command -v
57 procd_set_param respawn
58 procd_close_instance
59 }
60
61 start_service() {
62 config_load rtty
63 config_foreach validate_rtty_section rtty start_rtty
64 }
65
66 service_triggers() {
67 procd_add_reload_trigger "rtty"
68 procd_add_validation validate_rtty_section
69 }