[OpenWrt-Devel] [PATCH] base-files: Fix config_generate when there are no switch VLANs or ports configured in board.json.
Vittorio Gambaletta (VittGam)
openwrt at vittgam.net
Sun May 1 23:28:12 EDT 2016
The json_select call fails when there are no roles or ports objects
in board.json. "json_select .." must not be executed after failing.
This fixes for example LEDs not being set up in /etc/config/system.
Signed-off-by: Vittorio Gambaletta <openwrt at vittgam.net>
---
--- a/package/base-files/files/bin/config_generate
+++ b/package/base-files/files/bin/config_generate
@@ -144,22 +144,24 @@ generate_switch_vlans_ports() {
#
json_get_keys roles roles
- json_select roles
+ if [ -n "$roles" ]; then
+ json_select roles
- for role in $roles; do
- json_select "$role"
- json_get_vars ports
- json_select ..
+ for role in $roles; do
+ json_select "$role"
+ json_get_vars ports
+ json_select ..
- uci -q batch <<-EOF
- add network switch_vlan
- set network. at switch_vlan[-1].device='$switch'
- set network. at switch_vlan[-1].vlan='$role'
- set network. at switch_vlan[-1].ports='$ports'
- EOF
- done
+ uci -q batch <<-EOF
+ add network switch_vlan
+ set network. at switch_vlan[-1].device='$switch'
+ set network. at switch_vlan[-1].vlan='$role'
+ set network. at switch_vlan[-1].ports='$ports'
+ EOF
+ done
- json_select ..
+ json_select ..
+ fi
#
@@ -167,31 +169,33 @@ generate_switch_vlans_ports() {
#
json_get_keys ports ports
- json_select ports
+ if [ -n "$ports" ]; then
+ json_select ports
+
+ for port in $ports; do
+ json_select "$port"
+ json_get_vars num
+
+ if json_is_a attr object; then
+ json_get_keys attr attr
+ json_select attr
+ uci -q batch <<-EOF
+ add network switch_port
+ set network. at switch_port[-1].device='$switch'
+ set network. at switch_port[-1].port=$num
+ EOF
+
+ for attr in $attr; do
+ json_get_var val "$attr"
+ uci -q set network. at switch_port[-1].$attr="$val"
+ done
+ json_select ..
+ fi
+ json_select ..
+ done
- for port in $ports; do
- json_select "$port"
- json_get_vars num
-
- if json_is_a attr object; then
- json_get_keys attr attr
- json_select attr
- uci -q batch <<-EOF
- add network switch_port
- set network. at switch_port[-1].device='$switch'
- set network. at switch_port[-1].port=$num
- EOF
-
- for attr in $attr; do
- json_get_var val "$attr"
- uci -q set network. at switch_port[-1].$attr="$val"
- done
- json_select ..
- fi
json_select ..
- done
-
- json_select ..
+ fi
}
generate_switch() {
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list