From b2269ecbf779b712db8ef40203ef1bcaaf4175ce Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Wed, 20 Dec 2023 09:59:13 +0100 Subject: [PATCH] openvpn: move path instances call to sub function Move the start of the OpenVPN configurations in '/etc/openvpn' in a function. Signed-off-by: Florian Eckert --- net/openvpn/files/openvpn.init | 44 ++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/net/openvpn/files/openvpn.init b/net/openvpn/files/openvpn.init index af59098afb..c282021ae9 100644 --- a/net/openvpn/files/openvpn.init +++ b/net/openvpn/files/openvpn.init @@ -206,6 +206,29 @@ start_uci_instance() { openvpn_add_instance "$s" "/var/etc" "openvpn-$s.conf" "$script_security" "$up" "$down" } +start_path_instances() { + local path name up down + + for path in /etc/openvpn/*.conf; do + if [ -f "$path" ]; then + name="${path##*/}"; name="${name%.conf}" + + # don't start configs again that are already started by uci + if echo "$UCI_STARTED" | grep -qxF "$path"; then + continue + # don't start configs which are set to disabled in uci + elif echo "$UCI_DISABLED" | grep -qxF "$path"; then + logger -t openvpn "$name.conf is disabled in /etc/config/openvpn" + continue + fi + + get_openvpn_option "$path" up up || up="" + get_openvpn_option "$path" down down || down="" + openvpn_add_instance "$name" "${path%/*}" "$path" "" "$up" "$down" + fi + done +} + start_service() { local instance="$1" local instance_found=0 @@ -230,26 +253,7 @@ start_service() { else config_foreach start_uci_instance 'openvpn' - local path name up down - for path in /etc/openvpn/*.conf; do - if [ -f "$path" ]; then - name="${path##*/}"; name="${name%.conf}" - - # don't start configs again that are already started by uci - if echo "$UCI_STARTED" | grep -qxF "$path"; then - continue - - # don't start configs which are set to disabled in uci - elif echo "$UCI_DISABLED" | grep -qxF "$path"; then - logger -t openvpn "$name.conf is disabled in /etc/config/openvpn" - continue - fi - - get_openvpn_option "$path" up up || up="" - get_openvpn_option "$path" down down || down="" - openvpn_add_instance "$name" "${path%/*}" "$path" "" "$up" "$down" - fi - done + start_path_instances fi }