From patchwork Fri May 3 16:05:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kristian Evensen X-Patchwork-Id: 1094961 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="HUCF4XD1"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="gqYNXZk5"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44wcSZ0MJLz9s9N for ; Sat, 4 May 2019 02:06:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:Message-Id:Date:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=A9EKMj2jgXY3XAv222cc2o5WW2lpG294zmauguak6co=; b=HUCF4XD1AZZJLz zL6eB3aJUiOgJRlsCElgS1/bjPlrCN0AJn3hGrkp/01wE068dVCX6eQj8eejfpMcD4n6mCecQBK4m Z2XL15KL1it6yV57sjOCZV/H8MkAOdtnWKxrAxsTydfajvEYv8wNtZ3sgX+Dm57PrKqfWAFk18ilG lbCh0nSoD06n7aBfkSLaZfHfaDzieZV0ZKupfEw0SfjxQJfNe2Y4jhh68ubzcH1g+ydNeDK25hsxY VXZsArccyjqsm5mv1ZiyoLoQcYImh8014iGCWKJNQBqv5zHDM5j8klCQZVa8VvJthLO3X4gAID4jQ vFZQH09yP7IuGeKYZbfA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMagv-00036p-5d; Fri, 03 May 2019 16:05:41 +0000 Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hMagr-000363-OU for openwrt-devel@lists.openwrt.org; Fri, 03 May 2019 16:05:39 +0000 Received: by mail-lj1-x243.google.com with SMTP id b12so5673421lji.4 for ; Fri, 03 May 2019 09:05:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rBYGrjwk3HGOKNilbgcBmPVqAfiL75tvO0k42iiWyeM=; b=gqYNXZk5+304JMCdFqmQfqv9neYAKskawNkJVAvvq1IUZ4JOqfHgc6oc37cobwxOzF 8dFFSgEVAWb9LaY1MAVSjWWA5npiBVbKDt/Sw1QETM9K+NMfnaozSKIAyI4qlVbbhXfN WS1wfpQFP654wIfyZP8cdJPqpQzapMekfOEK3eUmZRmujkSp+Fmk5fgOnGACpKF1G6ku jQYwdd7wnXeaP5ob5cPJD5jHq32U7+U6c0SWhCKD8W9yqsmIrd6ivrt187j9g2Ox6s8v WJaOArVXrxb68GLMjx7T/mTcl1wA51LmD0lA2YeY0mxTOYfYMGmP8aKs4rbQiHJ7j8Au bsVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rBYGrjwk3HGOKNilbgcBmPVqAfiL75tvO0k42iiWyeM=; b=Ciy7mq9vl2t34do0CTLJayrM8gvnh4XBt9QODciAsWUNoMlqy6ZVj6XCvHY+GrlH48 dE8Ilw/sJSajYNPNUoFUgEln+bIvGSMkrZB+IGhRuehlzt1F8XZoCs24GBrv/MhoGtog oWNpIYy7ncKzngwEaPcyJPPZc62rNL2OSLbaUIAewDF6OMB2fBhtu4PzWopLnJv+hjsv oRWKszApFKwTsLgunlRSPSyUuNCzWQdTZXjhqz4WMImTl0Ri/C+WrwjYZ1cE5nejV3on zr4N6yQJNNeoS2sQ4rvykv9Dlk1iM6hZQXts1Tg5f8k/yuclMTbEELtp3e8zPHTrkZMc 28PQ== X-Gm-Message-State: APjAAAWoOEoTzc+c0Mr0jTjbrdK2suAub5mEUVSP8IOCq0N45vVbXweh RlawK8l0DEYeywy5IWhLKiSKDmdd X-Google-Smtp-Source: APXvYqzp7xoTgiGZPChptzt2Pqfys44uOo3a17bzbCHtoztSGsiDVsp2LkVlPC/Z1lq1K8GxTb/KgA== X-Received: by 2002:a2e:824b:: with SMTP id j11mr5324678ljh.197.1556899535257; Fri, 03 May 2019 09:05:35 -0700 (PDT) Received: from kristrev-XPS-15-9570.lan ([193.213.155.210]) by smtp.gmail.com with ESMTPSA id q15sm495728lfh.59.2019.05.03.09.05.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 May 2019 09:05:34 -0700 (PDT) From: Kristian Evensen To: openwrt-devel@lists.openwrt.org Date: Fri, 3 May 2019 18:05:32 +0200 Message-Id: <20190503160532.2214-1-kristian.evensen@gmail.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190503_090537_822589_73CEBD10 X-CRM114-Status: GOOD ( 10.08 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:243 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (kristian.evensen[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Subject: [OpenWrt-Devel] [PATCH] system: uci: Use config dir on uci_add and support add_/del_list X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kristian Evensen Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org This commit makes three changes to the uci shell library: * A check for UCI_CONFIG_DIR has been added to the command line when adding anonymous sections. Without this change, adding anonymous sections to configs not stored in /etc/config is not possible. * Support for adding/removing items from lists were missing, so I have added the functions uci_add_list() and uci_del_list() to simplify working with uci lists from scripts. Signed-off-by; Kristian Evensen --- package/system/uci/files/lib/config/uci.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/package/system/uci/files/lib/config/uci.sh b/package/system/uci/files/lib/config/uci.sh index 78ec277669..803adf9d97 100644 --- a/package/system/uci/files/lib/config/uci.sh +++ b/package/system/uci/files/lib/config/uci.sh @@ -85,6 +85,15 @@ uci_set() { /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set "$PACKAGE.$CONFIG.$OPTION=$VALUE" } +uci_add_list() { + local PACKAGE="$1" + local CONFIG="$2" + local OPTION="$3" + local VALUE="$4" + + /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} add_list "$PACKAGE.$CONFIG.$OPTION=$VALUE" +} + uci_get_state() { uci_get "$1" "$2" "$3" "$4" "/var/state" } @@ -108,7 +117,7 @@ uci_add() { local CONFIG="$3" if [ -z "$CONFIG" ]; then - export ${NO_EXPORT:+-n} CONFIG_SECTION="$(/sbin/uci add "$PACKAGE" "$TYPE")" + export ${NO_EXPORT:+-n} CONFIG_SECTION="$(/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} add "$PACKAGE" "$TYPE")" else /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set "$PACKAGE.$CONFIG=$TYPE" export ${NO_EXPORT:+-n} CONFIG_SECTION="$CONFIG" @@ -132,6 +141,15 @@ uci_remove() { /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} del "$PACKAGE.$CONFIG${OPTION:+.$OPTION}" } +uci_del_list() { + local PACKAGE="$1" + local CONFIG="$2" + local OPTION="$3" + local VALUE="$4" + + /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} del_list "$PACKAGE.$CONFIG.$OPTION=$VALUE" +} + uci_commit() { local PACKAGE="$1" /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} commit $PACKAGE