Files
wlan-ap/feeds/ucentral/udhcprelay/files/dhcprelay.init
John Crispin cf63cb94aa udhcprelay: add new package
Signed-off-by: John Crispin <john@phrozen.org>
2023-08-31 16:08:34 +02:00

82 lines
1.3 KiB
Bash

#!/bin/sh /etc/rc.common
# Copyright (c) 2021 OpenWrt.org
START=40
USE_PROCD=1
PROG=/usr/sbin/udhcprelay
add_device() {
local cfg="$1"
config_get_bool disabled "$cfg" disabled 0
[ "$disabled" -gt 0 ] && return
config_get name "$cfg" name
json_add_object "$name"
json_close_object
}
add_string() {
json_add_string "" "$@"
}
add_array() {
local cfg="$1"
local name="$2"
json_add_array "$name"
config_list_foreach "$cfg" "$name" add_string
json_close_array
}
add_bridge() {
local cfg="$1"
config_get_bool disabled "$cfg" disabled 0
[ "$disabled" -gt 0 ] && return
config_get name "$cfg" name
json_add_object "$name"
add_array "$cfg" vlans
add_array "$cfg" ignore
add_array "$cfg" upstream
json_close_object
}
reload_service() {
json_init
config_load dhcprelay
json_add_object devices
config_foreach add_device device
json_close_object
json_add_object bridges
config_foreach add_bridge bridge
json_close_object
ubus call dhcprelay config "$(json_dump)"
}
service_triggers() {
procd_add_reload_trigger dhcprelay
}
start_service() {
procd_open_instance
procd_set_param command "$PROG"
procd_set_param respawn
procd_set_param limits core="unlimited"
procd_close_instance
}
service_started() {
ubus -t 10 wait_for dhcprelay
[ $? = 0 ] && reload_service
}