From patchwork Mon May 2 03:28:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vittorio Gambaletta X-Patchwork-Id: 617341 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (caladan.dune.hu [78.24.191.180]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qyqWr0rg1z9t6j for ; Mon, 2 May 2016 13:28:24 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (4096-bit key; unprotected) header.d=vittgam.net header.i=@vittgam.net header.b=afkERqF3; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id A808AB91B9C; Mon, 2 May 2016 05:28:16 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP; Mon, 2 May 2016 05:28:16 +0200 (CEST) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id E5107B91B97 for ; Mon, 2 May 2016 05:28:14 +0200 (CEST) X-policyd-weight: using cached result; rate: -6.1 Received: from mail.vittgam.net (server1.vittgam.net [213.239.197.142]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Mon, 2 May 2016 05:28:13 +0200 (CEST) Delivered-To: X-DKIM: OpenDKIM Filter v2.4.2 mail.vittgam.net u423SCGZ184280 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=vittgam.net; s=20150519; t=1462159692; bh=0SExyi3QSf7PGzhOl2bldNivGTNyvm3g7JPhAb0oRkc=; h=From:To:Subject:Content-Type:Message-ID; b=afkERqF3dsDY2FLJd23jgzPf9GitSBeUKXGphzPDzaxtQ/xW2mP1FyNatDDikXc68 dxg9Yo1u+OzCx2LbWBdGK4qyonoZ0Owsws5+Y//eL6OYyc8x1JZP+rpwSpSTozrrpJ Xp0UgIyDAoD2ZPm3ZzDJWgsbfBFj/ykEeDU/w/n+0+IycZwkLK1cexhWNA6qCRBaqA nhDpqXQRBfdAR+7pYX20vUA7eJNGpnvibE/7DqFm1Gg/eTlM7/EaNnJ+Xb3Xg9b58h El859pC9A45mLXBcsV8rCsQRNJ0Pm9Eh07JWKPeVlfpyV69jtYyhnyMM5l8umTT552 jDgCPhGm3XqEr9g1X/OVBhqw71DEeozOwff56BJXVZtnnVjasieFkDOpvb6iAMtO14 LLAus3XySMcJes2ukQUfQP6oOJhg3UCFnaY/kmLkEnEloo4Pv2zg1cmGeloVEwsMzX cwRoKS1rOVUO5mcgln+YPkAIDKFlE+mja557uHCzRkX54XjGRRtFloMQGlb772b6u7 hHozGM40y9kPo9hMWWjSZi1tsf3MHBBme1zIjBDG5qat2vMa5PnZf0lja2qYMhFCc6 ElIRguhd7lsaCwpPQxXeo/3fmb+9CRkfxOIoDdWz7rQJo7a/m7kovyPR2DwDypwbnE kArQ727OStaHsyhHrclelgv4= Received: from vl3 (vl3.r12.network.mietitrebbia.rocks [10.48.6.117]) by mail.vittgam.net with SMTP id u423SCGZ184280 for ; Mon, 2 May 2016 05:28:12 +0200 Date: Mon, 2 May 2016 05:28:12 +0200 From: "Vittorio Gambaletta (VittGam)" To: Message-ID: Subject: [OpenWrt-Devel] [PATCH] base-files: Fix config_generate when there are no switch VLANs or ports configured in board.json. X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" 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 --- 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.@switch_vlan[-1].device='$switch' - set network.@switch_vlan[-1].vlan='$role' - set network.@switch_vlan[-1].ports='$ports' - EOF - done + uci -q batch <<-EOF + add network switch_vlan + set network.@switch_vlan[-1].device='$switch' + set network.@switch_vlan[-1].vlan='$role' + set network.@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.@switch_port[-1].device='$switch' + set network.@switch_port[-1].port=$num + EOF + + for attr in $attr; do + json_get_var val "$attr" + uci -q set network.@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.@switch_port[-1].device='$switch' - set network.@switch_port[-1].port=$num - EOF - - for attr in $attr; do - json_get_var val "$attr" - uci -q set network.@switch_port[-1].$attr="$val" - done - json_select .. - fi json_select .. - done - - json_select .. + fi } generate_switch() {