From: Michael Tremer Date: Sun, 6 Aug 2017 09:22:09 +0000 (+0000) Subject: wireless-ap: Improve command line parsing X-Git-Tag: 009~27 X-Git-Url: http://git.ipfire.org/?p=people%2Fms%2Fnetwork.git;a=commitdiff_plain;h=270aab39b6aae48c0add6de041aad67e18db4f38 wireless-ap: Improve command line parsing Signed-off-by: Michael Tremer --- diff --git a/src/functions/functions.ports b/src/functions/functions.ports index d2e8fd09..3f873c99 100644 --- a/src/functions/functions.ports +++ b/src/functions/functions.ports @@ -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 $@ } diff --git a/src/hooks/ports/wireless-ap b/src/hooks/ports/wireless-ap index dffae405..9c77bb13 100644 --- a/src/hooks/ports/wireless-ap +++ b/src/hooks/ports/wireless-ap @@ -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() {