summaryrefslogtreecommitdiff
path: root/package/base-files
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2015-11-25 15:43:28 +0000
committerJo-Philipp Wich <jow@openwrt.org>2015-11-25 15:43:28 +0000
commit04b8b97fffd205a9c4a7f156b99378adc206e0ae (patch)
tree75dae3c6cacf44c3e1a699a37e06d2c53f222b16 /package/base-files
parent2f69fefc37a90ed129aeb136ed64396da54df8ca (diff)
downloadmtk-20170518-04b8b97fffd205a9c4a7f156b99378adc206e0ae.zip
mtk-20170518-04b8b97fffd205a9c4a7f156b99378adc206e0ae.tar.gz
mtk-20170518-04b8b97fffd205a9c4a7f156b99378adc206e0ae.tar.bz2
base-files: uci-defaults-new: add ucidef_add_switch_port_attr() helper
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org> SVN-Revision: 47645
Diffstat (limited to 'package/base-files')
-rwxr-xr-xpackage/base-files/files/lib/functions/uci-defaults-new.sh36
1 files changed, 36 insertions, 0 deletions
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 9d1ecb6..120f35a 100755
--- a/package/base-files/files/lib/functions/uci-defaults-new.sh
+++ b/package/base-files/files/lib/functions/uci-defaults-new.sh
@@ -144,6 +144,42 @@ ucidef_add_switch_ports() {
json_select ..
}
+ucidef_add_switch_port_attr() {
+ local name=$1
+ local port=$2
+ local key=$3
+ local val=$4
+ local ports i num
+
+ json_select_object switch
+ json_select_object $name
+
+ json_get_keys ports ports
+ json_select_array ports
+
+ for i in $ports; do
+ json_select $i
+ json_get_var num num
+
+ if [ -n "$num" ] && [ $num -eq $port ]; then
+ json_select_object attr
+
+ case "$val" in
+ [0-9]) json_add_int "$key" "$val" ;;
+ *) json_add_string "$key" "$val" ;;
+ esac
+
+ json_select ..
+ fi
+
+ json_select ..
+ done
+
+ json_select ..
+ json_select ..
+ json_select ..
+}
+
ucidef_add_switch_vlan() {
local name=$1
local vlan=$2