From 2bed435f6774c6160f1e8e8bd46a748ca4efc3fb Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 3 Dec 2015 17:30:24 +0000 Subject: board.d: merge ucidef_add_switch() and ucidef_add_switch_ports() This changes uci-defaults-new.sh, config_generate and all relevant board.d files in order combine ucidef_add_switch() and ucidef_add_switch_ports() into a single function. Also removes now superfluous enable and reset arguments. Signed-off-by: Jo-Philipp Wich git-svn-id: svn://svn.openwrt.org/openwrt/trunk@47721 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- .../files/lib/functions/uci-defaults-new.sh | 110 ++++++++++----------- 1 file changed, 50 insertions(+), 60 deletions(-) (limited to 'package/base-files/files/lib/functions/uci-defaults-new.sh') diff --git a/package/base-files/files/lib/functions/uci-defaults-new.sh b/package/base-files/files/lib/functions/uci-defaults-new.sh index e652a8b521..f025cb696e 100755 --- a/package/base-files/files/lib/functions/uci-defaults-new.sh +++ b/package/base-files/files/lib/functions/uci-defaults-new.sh @@ -82,35 +82,6 @@ ucidef_set_interfaces_lan_wan() { json_select .. } -ucidef_add_switch() { - local name="$1" - - json_select_object switch - json_select_object "$name" - json_add_boolean enable 1 - json_add_boolean reset 1 - json_select .. - json_select .. -} - -ucidef_add_switch_attr() { - local name="$1" - local key="$2" - local val="$3" - - json_select_object switch - json_select_object "$name" - - case "$val" in - true|false) [ "$val" != "true" ]; json_add_boolean "$key" $? ;; - [0-9]) json_add_int "$key" "$val" ;; - *) json_add_string "$key" "$val" ;; - esac - - json_select .. - json_select .. -} - _ucidef_add_switch_port() { # inherited: $num $device $need_tag $role $index $prev_role # inherited: $n_cpu $n_ports $n_vlan $cpu0 $cpu1 $cpu2 $cpu3 $cpu4 $cpu5 @@ -205,50 +176,69 @@ _ucidef_finish_switch_roles() { done } -ucidef_add_switch_ports() { +ucidef_add_switch() { local name="$1"; shift local port num role device index need_tag prev_role local cpu0 cpu1 cpu2 cpu3 cpu4 cpu5 local n_cpu=0 n_vlan=0 n_ports=0 json_select_object switch - json_select_object "$name" - - for port in "$@"; do - case "$port" in - [0-9]*@*) - num="${port%%@*}" - device="${port##*@}" - need_tag=0 - [ "${num%t}" != "$num" ] && { - num="${num%t}" - need_tag=1 - } - ;; - [0-9]*:*:[0-9]*) - num="${port%%:*}" - index="${port##*:}" - role="${port#[0-9]*:}"; role="${role%:*}" - ;; - [0-9]*:*) - num="${port%%:*}" - role="${port##*:}" - ;; - esac - - if [ -n "$num" ] && [ -n "$device$role" ]; then - _ucidef_add_switch_port - fi + json_select_object "$name" + json_add_boolean enable 1 + json_add_boolean reset 1 - unset num device role index need_tag - done + for port in "$@"; do + case "$port" in + [0-9]*@*) + num="${port%%@*}" + device="${port##*@}" + need_tag=0 + [ "${num%t}" != "$num" ] && { + num="${num%t}" + need_tag=1 + } + ;; + [0-9]*:*:[0-9]*) + num="${port%%:*}" + index="${port##*:}" + role="${port#[0-9]*:}"; role="${role%:*}" + ;; + [0-9]*:*) + num="${port%%:*}" + role="${port##*:}" + ;; + esac + + if [ -n "$num" ] && [ -n "$device$role" ]; then + _ucidef_add_switch_port + fi - json_select .. + unset num device role index need_tag + done + json_select .. json_select .. _ucidef_finish_switch_roles } +ucidef_add_switch_attr() { + local name="$1" + local key="$2" + local val="$3" + + json_select_object switch + json_select_object "$name" + + case "$val" in + true|false) [ "$val" != "true" ]; json_add_boolean "$key" $? ;; + [0-9]) json_add_int "$key" "$val" ;; + *) json_add_string "$key" "$val" ;; + esac + + json_select .. + json_select .. +} + ucidef_add_switch_port_attr() { local name="$1" local port="$2" -- cgit v1.2.3