From 04c27fe9cdbd8a9f9d1a974d9ac169ef4fc91897 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 17 Aug 2017 20:02:42 +0000 Subject: [PATCH] Remove zone_dir and zone_file Signed-off-by: Michael Tremer --- src/functions/functions.colors | 2 +- src/functions/functions.constants | 2 +- src/functions/functions.description | 2 +- src/functions/functions.firewall-zones | 2 +- src/functions/functions.util | 9 +++- src/functions/functions.zone | 61 ++++++++++---------------- 6 files changed, 35 insertions(+), 43 deletions(-) diff --git a/src/functions/functions.colors b/src/functions/functions.colors index 9a6caff..669587b 100644 --- a/src/functions/functions.colors +++ b/src/functions/functions.colors @@ -155,7 +155,7 @@ color_format_filename() { echo "${NETWORK_IPSEC_CONNS_DIR}/${name}/color" ;; zone) - echo "$(zone_dir ${name})/color" + echo "${NETWORK_ZONES_DIR}/${name}/color" ;; port) echo "${NETWORK_PORTS_DIR}/${name}/color" diff --git a/src/functions/functions.constants b/src/functions/functions.constants index 0403478..5467801 100644 --- a/src/functions/functions.constants +++ b/src/functions/functions.constants @@ -32,11 +32,11 @@ PPP_SECRETS=/etc/ppp/secrets # Network directory configuration. NETWORK_CONFIG_DIR="/etc/network" NETWORK_DB_DIR="${RUN_DIR}/db" -NETWORK_ZONE_DIR="${NETWORK_CONFIG_DIR}" NETWORK_HOOKS_DIR=/usr/lib/network/hooks NETWORK_HELPERS_DIR=/usr/lib/network/helpers NETWORK_PORTS_DIR="${NETWORK_CONFIG_DIR}/ports" NETWORK_TRIGGERS_DIR=/usr/lib/network/triggers +NETWORK_ZONES_DIR="${NETWORK_CONFIG_DIR}/zones" NETWORK_SHARE_DIR=/usr/share/network NETWORK_CACHE_DIR=/var/cache/network diff --git a/src/functions/functions.description b/src/functions/functions.description index 6a0206d..857b389 100644 --- a/src/functions/functions.description +++ b/src/functions/functions.description @@ -29,7 +29,7 @@ description_format_filename() { echo "${NETWORK_IPSEC_CONNS_DIR}/${name}/description" ;; zone) - echo "$(zone_dir ${name})/description" + echo "${NETWORK_ZONES_DIR}/${name}/description" ;; port) echo "${NETWORK_PORTS_DIR}/${name}/description" diff --git a/src/functions/functions.firewall-zones b/src/functions/functions.firewall-zones index 6b06fdf..7440a85 100644 --- a/src/functions/functions.firewall-zones +++ b/src/functions/functions.firewall-zones @@ -39,7 +39,7 @@ firewall_zone_config() { local zone=${1} assert isset zone - print "$(zone_dir ${zone})/fwsettings" + print "${NETWORK_ZONES_DIR}/${zone}/fwsettings" return ${EXIT_OK} } diff --git a/src/functions/functions.util b/src/functions/functions.util index 24e3e66..2e76e53 100644 --- a/src/functions/functions.util +++ b/src/functions/functions.util @@ -248,11 +248,16 @@ file_get_age() { return ${EXIT_ERROR} } +make_directory() { + local path="${1}" + + mkdir -p "${path}" +} + make_parent_dir() { local path="${1}" - local dirname="$(dirname "${path}")" - mkdir -p "${dirname}" + make_directory "$(dirname "${path}")" } enabled() { diff --git a/src/functions/functions.zone b/src/functions/functions.zone index 0d9c29a..f724f50 100644 --- a/src/functions/functions.zone +++ b/src/functions/functions.zone @@ -19,17 +19,11 @@ # # ############################################################################### -zone_dir() { - local zone=${1} - - echo "${NETWORK_ZONE_DIR}/zones/${zone}" -} - zone_exists() { local zone=${1} assert isset zone - [ -d "$(zone_dir ${zone})" ] + [ -d "${NETWORK_ZONES_DIR}/${zone}" ] } zone_match() { @@ -68,7 +62,7 @@ zone_get_hook() { local zone=${1} assert isset zone - config_get_hook $(zone_dir ${zone})/settings + config_get_hook "${NETWORK_ZONES_DIR}/${zone}/settings" } zone_start() { @@ -233,10 +227,11 @@ zone_new() { return ${EXIT_ERROR} fi - mkdir -p $(zone_dir ${zone}) - # Create directories for configs and ports - mkdir -p $(zone_dir ${zone})/{configs,ports} + local what + for what in configs ports; do + make_directory "${NETWORK_ZONES_DIR}/${zone}/${what}" + done hook_zone_exec "${hook}" "new" "${zone}" "$@" local ret=$? @@ -305,7 +300,7 @@ zone_rename() { zone_disable "${zone}" # Rename the configuration files - mv -f "$(zone_dir "${zone}")" "$(zone_dir "${name}")" + mv -f "${NETWORK_ZONES_DIR}/${zone}" "${NETWORK_ZONES_DIR}/${name}" # Enable the zone if it was enabled before [ ${zone_was_enabled} -eq ${EXIT_TRUE} ] && zone_enable "${name}" @@ -335,7 +330,7 @@ zone_destroy() { # Disable zone auto-start zone_disable "${zone}" - rm -rf "$(zone_dir "${zone}")" + rm -rf "${NETWORK_ZONES_DIR}/${zone}" } zone_up() { @@ -457,7 +452,7 @@ zone_get_ports() { assert isset zone local port - for port in $(list_directory "$(zone_dir ${zone})/ports"); do + for port in $(list_directory "${NETWORK_ZONES_DIR}/${zone}/ports"); do if port_exists "${port}"; then echo "${port}" fi @@ -470,7 +465,7 @@ zone_get_ports_num() { local counter=0 local port - for port in $(list_directory "$(zone_dir "${zone}")/ports"); do + for port in $(list_directory "${NETWORK_ZONES_DIR}/${zone}/ports"); do if port_exists "${port}"; then counter=$(( ${counter} + 1 )) fi @@ -491,7 +486,7 @@ zone_has_port() { assert isset zone assert isset port - [ -e "$(zone_dir ${zone})/ports/${port}" ] + [ -e "${NETWORK_ZONES_DIR}/${zone}/ports/${port}" ] } zone_config() { @@ -719,7 +714,7 @@ zones_show() { zones_get_all() { local zone - for zone in $(list_directory "$(zone_dir)"); do + for zone in $(list_directory "${NETWORK_ZONES_DIR}"); do if zone_exists ${zone}; then echo "${zone}" fi @@ -811,7 +806,7 @@ zones_get() { zone_ports_list() { local zone=${1} - list_directory "$(zone_dir ${zone})/ports" + list_directory "${NETWORK_ZONES_DIR}/${zone}/ports" } zone_port_attach() { @@ -1076,7 +1071,7 @@ zone_configs_status() { zone_configs_list() { local zone=${1} - list_directory "$(zone_dir ${zone})/configs" + list_directory "${NETWORK_ZONES_DIR}/${zone}/configs" } zone_config_get_new_id() { @@ -1085,7 +1080,7 @@ zone_config_get_new_id() { assert [ $# -eq 1 ] local zone=${1} - local zone_path=$(zone_dir ${zone}) + local zone_path="${NETWORK_ZONES_DIR}/${zone}" local i=0 while true; do @@ -1176,7 +1171,7 @@ zone_config_id_is_valid() { local zone=${1} local id=${2} - local zone_path=$(zone_dir ${zone}) + local zone_path="${NETWORK_ZONES_DIR}/${zone}" [ -f ${zone_path}/configs/*.${id} ]; } @@ -1256,14 +1251,6 @@ zone_get_supported_config_hooks() { hook_config_get_all } -zone_file() { - local zone=${1} - - assert isset zone - - echo "$(zone_dir ${zone})/settings" -} - zone_settings_read() { local zone=${1} assert isset zone @@ -1279,7 +1266,7 @@ zone_settings_read() { # Save the HOOK variable. local hook="${HOOK}" - settings_read "$(zone_file "${zone}")" ${args} + settings_read "${NETWORK_ZONES_DIR}/${zone}/settings" ${args} # Restore hook. HOOK="${hook}" @@ -1295,7 +1282,7 @@ zone_settings_write() { fi list_append args ${HOOK_SETTINGS} - settings_write "$(zone_file ${zone})" ${args} + settings_write "${NETWORK_ZONES_DIR}/${zone}/settings" ${args} } zone_settings_set() { @@ -1345,7 +1332,7 @@ zone_config_settings_read() { list_append args "$@" fi - local path="$(zone_dir "${zone}")/configs/${config}" + local path="${NETWORK_ZONES_DIR}/${zone}/configs/${config}" settings_read "${path}" ${args} } @@ -1367,7 +1354,7 @@ zone_config_settings_write() { fi list_append args ${HOOK_CONFIG_SETTINGS} - local path="$(zone_dir "${zone}")/configs/${hook}.${id}" + local path="${NETWORK_ZONES_DIR}/${zone}/configs/${hook}.${id}" settings_write "${path}" ${args} } @@ -1377,7 +1364,7 @@ zone_config_settings_destroy() { local zone="${1}" local config="${2}" - local path="$(zone_dir "${zone}")/configs/${config}" + local path="${NETWORK_ZONES_DIR}/${zone}/configs/${config}" # Check if path is valid if [ ! -f ${path} ]; then @@ -1403,7 +1390,7 @@ zone_port_settings_read() { list_append args "$@" fi - local path="$(zone_dir "${zone}")/ports/${port}" + local path="${NETWORK_ZONES_DIR}/${zone}/ports/${port}" settings_read "${path}" ${args} } @@ -1420,7 +1407,7 @@ zone_port_settings_write() { fi list_append args ${HOOK_PORT_SETTINGS} - local path="$(zone_dir "${zone}")/ports/${port}" + local path="${NETWORK_ZONES_DIR}/${zone}/ports/${port}" settings_write "${path}" ${args} } @@ -1430,7 +1417,7 @@ zone_port_settings_remove() { local zone="${1}" local port="${2}" - local path="$(zone_dir "${zone}")/ports/${port}" + local path="${NETWORK_ZONES_DIR}/${zone}/ports/${port}" settings_remove "${path}" } -- 2.47.3