From: Jonatan Schlag Date: Tue, 30 May 2017 08:46:20 +0000 (+0200) Subject: route: Allow deleting multiple routes at once X-Git-Tag: 009~258 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e618256e690d143d34747cb2a40be302c8fb7c1d;p=network.git route: Allow deleting multiple routes at once Signed-off-by: Jonatan Schlag Signed-off-by: Michael Tremer --- diff --git a/src/functions/functions.route b/src/functions/functions.route index c82f86eb..303415ac 100644 --- a/src/functions/functions.route +++ b/src/functions/functions.route @@ -150,40 +150,43 @@ route_add() { } route_remove() { - local _network=${1} - - # Validate input - if ! ip_is_network ${_network} && ! ip_is_valid ${_network}; then - error "Invalid IP address or network: ${_network}" - return ${EXIT_ERROR} - fi + local _network + local error=${EXIT_OK} + + for _network in $@; do + # Validate input + if ! ip_is_network ${_network} && ! ip_is_valid ${_network}; then + error "Invalid IP address or network: ${_network}" + error=${EXIT_ERROR} + fi - local found="false" + local found="false" - local ${NETWORK_CONFIG_ROUTES_PARAMS} - local line - while read line; do - route_parse_line ${line} - [ $? -eq ${EXIT_OK} ] || continue + local ${NETWORK_CONFIG_ROUTES_PARAMS} + local line + while read line; do + route_parse_line ${line} + [ $? -eq ${EXIT_OK} ] || continue - # Skip the rule, we want to delete. - if [ "${network}" = "${_network}" ]; then - found="true" - continue - fi + # Skip the rule, we want to delete. + if [ "${network}" = "${_network}" ]; then + found="true" + continue + fi - print "${line}" - done < ${NETWORK_CONFIG_ROUTES} > ${NETWORK_CONFIG_ROUTES}.tmp - mv ${NETWORK_CONFIG_ROUTES}{.tmp,} + print "${line}" + done < ${NETWORK_CONFIG_ROUTES} > ${NETWORK_CONFIG_ROUTES}.tmp + mv ${NETWORK_CONFIG_ROUTES}{.tmp,} - if enabled found; then - log INFO "Route to network '${_network}' has been removed." - else - error "No route to network '${_network}' was found." - return ${EXIT_ERROR} - fi + if enabled found; then + log INFO "Route to network '${_network}' has been removed." + else + error "No route to network '${_network}' was found." + error=${EXIT_ERROR} + fi + done - return ${EXIT_OK} + return ${error} } route_list() {