]> git.ipfire.org Git - people/ms/network.git/commitdiff
wireless-ap: Improve command line parsing
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 6 Aug 2017 09:22:09 +0000 (09:22 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 6 Aug 2017 09:22:09 +0000 (09:22 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.ports
src/hooks/ports/wireless-ap

index d2e8fd09b957ecbd48987b6bef927436c44eed28..3f873c9971798861663e3a09393b79c0ec1505d5 100644 (file)
@@ -219,6 +219,11 @@ port_remove() {
        local port="${1}"
        assert isset port
 
+       if ! port_exists "${port}"; then
+               log ERROR "Port ${port} does not exist"
+               return ${EXIT_ERROR}
+       fi
+
        # If the device is still up, we need to bring it down first.
        if device_is_up "${port}"; then
                port_down "${port}"
@@ -227,6 +232,16 @@ port_remove() {
        port_cmd "remove" "${port}"
 }
 
+# Restarts the port by removing it and then re-creating it
+port_restart() {
+       local port="${1}"
+       assert isset port
+
+       port_remove "${port}"
+
+       port_create "${port}"
+}
+
 port_edit() {
        port_cmd edit $@
 }
index dffae405e0875d7c6a1868b79be4f1401491d7d1..9c77bb13f3779a204451721bce2c6dceb95140f0 100644 (file)
@@ -53,7 +53,7 @@ hook_check_settings() {
        fi
 }
 
-hook_new() {
+hook_parse_cmdline() {
        while [ $# -gt 0 ]; do
                case "${1}" in
                        --broadcast-ssid=*)
@@ -90,6 +90,12 @@ hook_new() {
        # Save address of phy do identify it again
        PHY=$(phy_get ${PHY})
        PHY=$(phy_get_address ${PHY})
+}
+
+hook_new() {
+       if ! hook_parse_cmdline $@; then
+               return ${EXIT_ERROR}
+       fi
 
        local port=$(port_find_free ${PORT_PATTERN_ACCESSPOINT})
        assert isset port
@@ -101,42 +107,14 @@ hook_new() {
 
 hook_edit() {
        local port=${1}
-       shift
-
        assert isset port
 
-       port_settings_read "${port}" ${HOOK_SETTINGS}
-
-       while [ $# -gt 0 ]; do
-               case "${1}" in
-                       --broadcast-ssid=*)
-                               BROADCAST_SSID=$(cli_get_val ${1})
-                               ;;
-                       --channel=*)
-                               CHANNEL=$(cli_get_val ${1})
-                               ;;
-                       --encryption=*)
-                               ENCRYPTION=$(cli_get_val ${1})
-                               ;;
-                       --key=*)
-                               KEY=$(cli_get_val ${1})
-                               ;;
-                       --ssid=*)
-                               SSID=$(cli_get_val ${1})
-                               ;;
-                       --mode=*)
-                               MODE=$(cli_get_val ${1})
-                               ;;
-                       *)
-                               warning "Unknown argument '${1}'"
-                               ;;
-               esac
-               shift
-       done
-
-       port_settings_write "${port}" ${HOOK_SETTINGS}
+       if ! hook_default_edit $@; then
+               return ${EXIT_ERROR}
+       fi
 
-       exit ${EXIT_OK} 
+       # To apply all changes, we need to restart the port
+       port_restart "${port}"
 }
 
 hook_create() {