From patchwork Tue Sep 26 21:15:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcus Folkesson X-Patchwork-Id: 818829 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=busybox.net (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="gQ3LfLnq"; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3y1tyt42lCz9s4q for ; Wed, 27 Sep 2017 07:15:33 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id F010D30758; Tue, 26 Sep 2017 21:15:31 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mL+v38CNxIFK; Tue, 26 Sep 2017 21:15:29 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id C4B6530317; Tue, 26 Sep 2017 21:15:28 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id 324EB1CEC54 for ; Tue, 26 Sep 2017 21:15:28 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 2968486A5A for ; Tue, 26 Sep 2017 21:15:28 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id r-GlgdHm9rMI for ; Tue, 26 Sep 2017 21:15:27 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-lf0-f66.google.com (mail-lf0-f66.google.com [209.85.215.66]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 43F8F86758 for ; Tue, 26 Sep 2017 21:15:27 +0000 (UTC) Received: by mail-lf0-f66.google.com with SMTP id m199so3342575lfe.5 for ; Tue, 26 Sep 2017 14:15:27 -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; bh=8PhhZu4fp7ayjiei9J55jRt10vG403P9ljseTDmyPy4=; b=gQ3LfLnq7FItUB73jRPa+5XLDV+dGgvc6D2lTbipWNN5lT6WeQYv1G/AI4V6pEJahL OsNyZIEUfGCd58s8FVbAmxwiCZmXs9Z4ZZH7eMIEs3uF9QNdv2eehxj8O3I8M0VO8KS+ tBRebMU3FCan39a9Eem+BEgPU28UvvbEhmZaZVapdt3CeFC+snYQTu6l/fZMAXV1TzXQ G0Cs8LXrqWOoEERYBDZ11e4GhZEEIXwP96DioqQTrPLqiVcxSJc3otSg9kdtofHrn8He eRKB+93vpaKG+HTslyLXF3nSUQ0AGt4jIsqC3Nj0xF8n4cSB5sHG3VOhkGDevMsZvMrS A3VA== 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; bh=8PhhZu4fp7ayjiei9J55jRt10vG403P9ljseTDmyPy4=; b=KyctexBh3O4N0zNQcx/HF0WmITIehOARdJLjuW85BeNfz9APyRn2WgkCkdY0hnjAWH Kz5DS6gUUGc8BxGElg2VOW4oL/4k7tjn9TNgpXySUQeOlyB4QRnfc1iEf3y4pYaH0gRt NJ8qWPXRClX/b9d121gbG2WaUoHgwzYZ+6P+yL1Xq7mvV5jOmhZN9AEJYcohin8LEw9E 8XLgoeALJx6jtqSFa5pT2uoQD9pH3CgM9bUSZeEyKGmMO2yv2Wbmh2Tcx2klXTPe9P9o pzFcs+6gQgxqilyWS7NIN8M1PHgKbu0T1nLys87VVuohHhqHDhbtbh2zBlEnsQP/342/ exfA== X-Gm-Message-State: AHPjjUiUmz4axCsnG0zhFjdxFFAZyxpcolORp4hRRWnNKljYisZ2gl9Y Yi/zGoajqbYiLHz67VDQ4cgLpg== X-Google-Smtp-Source: AOwi7QD1vvTZV3RnKlG37adtUOfacs8EdJVWQRPXzg4Nf9UtaVHgEB9k+07k/aKGUvFx509HAnI76g== X-Received: by 10.46.88.83 with SMTP id x19mr5044386ljd.80.1506460525332; Tue, 26 Sep 2017 14:15:25 -0700 (PDT) Received: from localhost.localdomain (c-2ec252b3-74736162.cust.telenor.se. [46.194.82.179]) by smtp.gmail.com with ESMTPSA id u78sm2053301lja.70.2017.09.26.14.15.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Sep 2017 14:15:24 -0700 (PDT) From: Marcus Folkesson To: Arnout Vandecappelle Date: Tue, 26 Sep 2017 23:15:02 +0200 Message-Id: <20170926211502.5248-1-marcus.folkesson@gmail.com> X-Mailer: git-send-email 2.13.1 Cc: Marcus Folkesson , buildroot@buildroot.org Subject: [Buildroot] [PATCH v2] kconfig: add script to manipulate .config files on the command line X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" Default prefix is set to `BR2_` but may be overidden by setting BR2_PREFIX. Example usage: Enable `BR2_PACKAGE_GNUPG`: ./support/scripts/config --package --enable GNUPG Check state of config option `BR2_PACKAGE_GNUPG`: ./support/scripts/config --package --state GNUPG y Enable `BR2_PACKAGE_GNUPG`: ./support/scripts/config --package --disable GNUPG Set `BR2_TARGET_GENERIC_ISSUE` to "Welcome": ./support/scripts/config --set-str TARGET_GENERIC_ISSUE "Welcome" Copied from the Linux kernel (4.13-rc6) source code and adapted to Buildroot. Thanks to Andi Kleen who is the original author of this script. Signed-off-by: Marcus Folkesson --- v2: - Rearrange examples in commit message - Move --package to options section of help text - Munge case before strip prefix - Convert - to _ when munge case - Use sed -i instead of creating temporary files - Remove unnecessary options and commands (--refresh, --module and --module-after) utils/config | 206 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100755 utils/config diff --git a/utils/config b/utils/config new file mode 100755 index 0000000000..b2e012aa2c --- /dev/null +++ b/utils/config @@ -0,0 +1,206 @@ +#!/bin/bash +# Manipulate options in a .config file from the command line + +myname=${0##*/} + +# If no prefix forced, use the default BR2_ +BR2_PREFIX="${BR2_PREFIX-BR2_}" + +usage() { + cat >&2 <>"$FN" + fi +} + +undef_var() { + local name=$1 + + txt_delete "^$name=" "$FN" + txt_delete "^# $name is not set" "$FN" +} + +if [ "$1" = "--file" ]; then + FN="$2" + if [ "$FN" = "" ] ; then + usage + fi + shift 2 +else + FN=.config +fi + +if [ "$1" = "" ] ; then + usage +fi + +MUNGE_CASE=yes +while [ "$1" != "" ] ; do + CMD="$1" + shift + case "$CMD" in + --keep-case|-k) + MUNGE_CASE=no + continue + ;; + --package|-p) + BR2_PREFIX="BR2_PACKAGE_" + continue + ;; + --*-after|-E|-D|-M) + checkarg "$1" + A=$ARG + checkarg "$2" + B=$ARG + shift 2 + ;; + -*) + checkarg "$1" + shift + ;; + esac + case "$CMD" in + --enable|-e) + set_var "${BR2_PREFIX}$ARG" "${BR2_PREFIX}$ARG=y" + ;; + + --disable|-d) + set_var "${BR2_PREFIX}$ARG" "# ${BR2_PREFIX}$ARG is not set" + ;; + + --set-str) + # sed swallows one level of escaping, so we need double-escaping + set_var "${BR2_PREFIX}$ARG" "${BR2_PREFIX}$ARG=\"${1//\"/\\\\\"}\"" + shift + ;; + + --set-val) + set_var "${BR2_PREFIX}$ARG" "${BR2_PREFIX}$ARG=$1" + shift + ;; + --undefine|-u) + undef_var "${BR2_PREFIX}$ARG" + ;; + + --state|-s) + if grep -q "# ${BR2_PREFIX}$ARG is not set" $FN ; then + echo n + else + V="$(grep "^${BR2_PREFIX}$ARG=" $FN)" + if [ $? != 0 ] ; then + echo undef + else + V="${V/#${BR2_PREFIX}$ARG=/}" + V="${V/#\"/}" + V="${V/%\"/}" + V="${V//\\\"/\"}" + echo "${V}" + fi + fi + ;; + + --enable-after|-E) + set_var "${BR2_PREFIX}$B" "${BR2_PREFIX}$B=y" "${BR2_PREFIX}$A" + ;; + + --disable-after|-D) + set_var "${BR2_PREFIX}$B" "# ${BR2_PREFIX}$B is not set" "${BR2_PREFIX}$A" + ;; + + *) + usage + ;; + esac +done