b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 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 | 'token:maxlength(32)' \ |
| 17 | 'verbose:bool:0' |
| 18 | } |
| 19 | |
| 20 | start_rtty() { |
| 21 | . /lib/functions/network.sh |
| 22 | |
| 23 | local ifname |
| 24 | |
| 25 | [ "$2" = 0 ] || { |
| 26 | echo "validation failed" >&2 |
| 27 | return 1 |
| 28 | } |
| 29 | |
| 30 | [ -n "$interface" ] && network_get_device ifname "$interface" |
| 31 | |
| 32 | [ -z "$ifname" -a -z "$id" ] && { |
| 33 | echo "You must specify an interface or ID" >&2 |
| 34 | return 1 |
| 35 | } |
| 36 | |
| 37 | [ -z "$host" ] && { |
| 38 | echo "host required" >&2 |
| 39 | return 1 |
| 40 | } |
| 41 | |
| 42 | [ -z "$id" ] && { |
| 43 | id=$(sed 's/://g' /sys/class/net/$ifname/address | tr 'a-z' 'A-Z') |
| 44 | } |
| 45 | |
| 46 | procd_open_instance |
| 47 | procd_set_param command $BIN -h $host -I "$id" -a |
| 48 | [ -n "$port" ] && procd_append_param command -p "$port" |
| 49 | [ -n "$description" ] && procd_append_param command -d "$description" |
| 50 | [ "$ssl" = "1" ] && procd_append_param command -s |
| 51 | [ -n "$token" ] && procd_append_param command -t "$token" |
| 52 | [ "$verbose" = "1" ] && procd_append_param command -v |
| 53 | procd_set_param respawn |
| 54 | procd_close_instance |
| 55 | } |
| 56 | |
| 57 | start_service() { |
| 58 | config_load rtty |
| 59 | config_foreach validate_rtty_section rtty start_rtty |
| 60 | } |
| 61 | |
| 62 | service_triggers() { |
| 63 | procd_add_reload_trigger "rtty" |
| 64 | procd_add_validation validate_rtty_section |
| 65 | } |