]> git.ipfire.org Git - people/ms/network.git/commitdiff
zone: new function zone_config_get_hook_from_id
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Wed, 5 Jul 2017 14:19:48 +0000 (16:19 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 5 Jul 2017 15:10:38 +0000 (17:10 +0200)
This function is needed to implement the id feature
described in #11405

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.zone

index fcc7bfa31e6c261f13fa465998dc15df3efeccab..90d7e115275e99b318e530440111a6fc63a5c4f8 100644 (file)
@@ -1061,6 +1061,26 @@ zone_config_id_is_valid() {
        [ -f ${zone_path}/configs/*.${id} ];
 }
 
+zone_config_get_hook_from_id() {
+       # Returns the hook for a given id
+       assert [ $# -eq 2 ]
+       local zone=${1}
+       local id=${2}
+
+       local config
+       for config in $(zone_configs_list "${zone}"); do
+               if [[ ${config} == *.${id} ]]; then
+                       local config_hook="$(zone_config_get_hook "${zone}" "${config}")"
+                       assert isset config_hook
+                       print "${config_hook}"
+                       return "${EXIT_OK}"
+               fi
+       done
+
+       # If we get here the zone has no config with the given id
+       return ${EXIT_ERROR}
+}
+
 zone_has_ip() {
        device_has_ip $@
 }