]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/functions/functions.zone
Cleanup code that deletes ports/zones
[people/ms/network.git] / src / functions / functions.zone
index f724f503bd182e44869ba9cc82df91cbc654e83d..b9d475f71745e7cbadd97bbff92bef3eb19a4228 100644 (file)
@@ -322,15 +322,19 @@ zone_destroy() {
                return ${EXIT_ERROR}
        fi
 
-       log INFO "Destroying zone ${zone}"
-
        # Force the zone down.
        zone_is_active "${zone}" && zone_stop "${zone}"
 
        # Disable zone auto-start
        zone_disable "${zone}"
 
-       rm -rf "${NETWORK_ZONES_DIR}/${zone}"
+       if ! rm -rf "${NETWORK_ZONES_DIR}/${zone}"; then
+               log ERROR "Could not destroy zone ${zone}"
+               return ${EXIT_ERROR}
+       fi
+
+       log INFO "Destroyed zone ${zone}"
+       return ${EXIT_OK}
 }
 
 zone_up() {
@@ -696,22 +700,6 @@ zone_config_convert_hid_to_id() {
        return ${EXIT_FALSE}
 }
 
-zone_show() {
-       local zone=${1}
-
-       echo "${zone}"
-       echo "  Type: $(zone_get_hook ${zone})"
-       echo
-}
-
-zones_show() {
-       local zone
-
-       for zone in $(zones_get "$@"); do
-               zone_show ${zone}
-       done
-}
-
 zones_get_all() {
        local zone
        for zone in $(list_directory "${NETWORK_ZONES_DIR}"); do
@@ -1097,22 +1085,29 @@ zone_config_check_same_setting() {
        # with the same setting is already configured for this zone.
        # Returns True when yes and False when no.
 
-       assert [ $# -eq 4 ]
+       assert [ $# -eq 5 ]
 
        local zone=${1}
        local hook=${2}
-       local key=${3}
-       local value=${4}
+       local id=${3}
+       local key=${4}
+       local value=${5}
 
        # The key should be local for this function
        local ${key}
        local config
 
        for config in $(zone_configs_list ${zone}); do
+               # Check if the config is eqal with the config we want to edit, when continue
+               if [[ "${config}" = "${hook}.${id}" ]]; then
+                       continue
+               fi
+
                # Check if the config is from the given hook, when not continue
                if  [[ $(zone_config_get_hook "${zone}" "${config}") != ${hook} ]]; then
                        continue
                fi
+
                # Get the value of the key for a given function
                zone_config_settings_read "${zone}" "${config}" \
                 --ignore-superfluous-settings "${key}"
@@ -1343,10 +1338,7 @@ zone_config_settings_write() {
        local hook="${2}"
        local id=${3}
 
-       if ! isset id; then
-               id=$(zone_config_get_new_id ${zone})
-               log DEBUG "ID for the config is: ${id}"
-       fi
+       assert isset id
 
        local args
        if function_exists "hook_check_config_settings"; then
@@ -1376,6 +1368,39 @@ zone_config_settings_destroy() {
        rm -f "${path}"
 
 }
+
+zone_config_find_by_hook() {
+       local zone="${1}"
+       assert isset zone
+
+       local hook="${2}"
+       assert isset hook
+
+       local config
+       for config in $(zone_configs_list "${zone}"); do
+               local h="$(zone_config_get_hook "${zone}" "${config}")"
+
+               [[ "${hook}" = "${h}" ]] && echo "${config}"
+       done
+
+       return ${EXIT_OK}
+}
+
+zone_config_settings_read_by_hook() {
+       local zone="${1}"
+       assert isset zone
+
+       local hook="${2}"
+       assert isset hook
+
+       local config
+       for config in $(zone_config_find_by_hook "${zone}" "${hook}"); do
+               zone_config_settings_read "${zone}" "${config}"
+       done
+
+       return ${EXIT_OK}
+}
+
 zone_port_settings_read() {
        assert [ $# -ge 2 ]