openvpn: move path instances call to sub function
authorFlorian Eckert <fe@dev.tdt.de>
Wed, 20 Dec 2023 08:59:13 +0000 (09:59 +0100)
committerFlorian Eckert <fe@dev.tdt.de>
Wed, 20 Dec 2023 14:01:24 +0000 (15:01 +0100)
Move the start of the OpenVPN configurations in '/etc/openvpn' in a function.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
net/openvpn/files/openvpn.init

index af59098afbae67dee197a1c61180f89e6d26b43b..c282021ae9a60f35426bcfd95c191e64160163e7 100644 (file)
@@ -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
 }