]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/functions/functions.ports
Cleanup code that deletes ports/zones
[people/ms/network.git] / src / functions / functions.ports
index af3f5f06dcb375ceb68e799d8d588ffff3042d1c..f70adf638f24732697c9180224298c662a169fa0 100644 (file)
 #                                                                             #
 ###############################################################################
 
-port_dir() {
-       local port="${1}"
-       echo "${NETWORK_CONFIG_DIR}/ports/${port}"
-}
-
-port_list() {
+ports_get_all() {
        local port
-       for port in $(port_dir)/*; do
-               port="$(basename "${port}")"
+       for port in $(list_directory "${NETWORK_PORTS_DIR}"); do
                if port_exists "${port}"; then
                        print "${port}"
                fi
        done
 }
 
+# XXX TO BE REMOVED
+port_list() {
+       ports_get_all "$@"
+}
+
 port_list_in_use() {
        local ports_in_use
 
@@ -101,20 +100,16 @@ port_settings_write() {
        if function_exists "hook_check_settings"; then
                list_append args "--check=\"hook_check_settings\""
        fi
-       list_append args ${HOOK_SETTINGS}
+       list_append args HOOK ${HOOK_SETTINGS}
 
        settings_write "$(port_file "${port}")" ${args}
 }
 
-ports_get_all() {
-       port_list
-}
-
 port_file() {
        local port="${1}"
        assert isset port
 
-       echo "$(port_dir ${port})/settings"
+       echo "${NETWORK_PORTS_DIR}/${port}/settings"
 }
 
 port_exists() {
@@ -149,7 +144,7 @@ port_is_attached() {
 }
 
 port_is_up() {
-       device_is_up $@
+       device_is_up "$@"
 }
 
 port_new() {
@@ -161,7 +156,7 @@ port_new() {
                return ${EXIT_ERROR}
        fi
 
-       hook_exec port "${hook}" new $@
+       hook_exec port "${hook}" new "$@"
 }
 
 port_destroy() {
@@ -199,11 +194,17 @@ port_destroy() {
                return ${EXIT_ERROR}
        fi
 
-       rm -rf $(port_dir ${port})
+       if ! rm -rf "${NETWORK_PORTS_DIR}/${port}"; then
+               log ERROR "Could not destroy port ${port}"
+               return ${EXIT_ERROR}
+       fi
+
+       log INFO "Destroyed port ${port}"
+       return ${EXIT_OK}
 }
 
 port_create() {
-       port_cmd "create" $@
+       port_cmd "create" "$@"
 }
 
 port_remove() {
@@ -234,19 +235,29 @@ port_restart() {
 }
 
 port_edit() {
-       port_cmd edit $@
+       port_cmd edit "$@"
 }
 
 port_up() {
-       port_cmd up $@
+       assert [ $# -eq 1 ]
+
+       local port="${1}"
+
+       # Check if the port exists
+       if ! device_exists "${port}"; then
+               log ERROR "Could not bring up port ${port} which has not been created"
+               return ${EXIT_ERROR}
+       fi
+
+       port_cmd up "${port}"
 }
 
 port_down() {
-       port_cmd down $@
+       port_cmd down "$@"
 }
 
 port_status() {
-       port_cmd status $@
+       port_cmd status "$@"
 }
 
 port_cmd() {
@@ -265,13 +276,12 @@ port_cmd() {
                return ${EXIT_ERROR}
        fi
 
-       hook_exec port ${hook} ${cmd} ${port} $@
+       hook_exec port ${hook} ${cmd} ${port} "$@"
 }
 
 ports_get() {
        local port
-       for port in $(port_dir)/*; do
-               port=$(basename ${port})
+       for port in $(list_directory "${NETWORK_PORTS_DIR}"); do
                if port_exists ${port}; then
                        echo "${port}"
                fi
@@ -404,7 +414,7 @@ ports_lowest_address() {
 }
 
 port_identify() {
-       device_identify $@
+       device_identify "$@"
 }
 
 port_get_color() {