]> git.ipfire.org Git - people/ms/network.git/commitdiff
zone: add function to avoid multiple configs which are senseless
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Tue, 4 Jul 2017 15:46:07 +0000 (17:46 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 4 Jul 2017 21:16:53 +0000 (23:16 +0200)
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.zone

index fd13875feaf751efd5af9e7f42afe38de35f54b5..f321c2d3d03e04b625ee001844b5a7602547e60f 100644 (file)
@@ -1008,6 +1008,28 @@ zone_config_get_hook() {
        print "${HOOK}"
 }
 
+zone_config_hook_is_configured() {
+       # Checks if a zone has already at least one config with the given hook.
+       # Returns True when yes and False when no
+
+       assert [ $# -eq 2 ]
+       local zone=${1}
+       local hook=${2}
+
+       local config
+       for config in $(zone_configs_list "${zone}"); do
+               local config_hook="$(zone_config_get_hook "${zone}" "${config}")"
+               assert isset config_hook
+               if [[ ${hook} == ${config_hook} ]]; then
+                       return ${EXIT_TRUE}
+               fi
+
+       done
+
+       # If we get here the zone has no config with the given hook
+       return ${EXIT_FALSE}
+}
+
 zone_has_ip() {
        device_has_ip $@
 }