From: Marcus Folkesson Date: Tue, 26 Sep 2017 21:15:02 +0000 (+0200) Subject: utils/config: new script to manipulate .config files on the command line X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f2c5c7a263d9d61faba80544e0f6ac6da03716ee;p=buildroot.git utils/config: new script to manipulate .config files on the command line Default prefix is set to `BR2_` but may be overidden by setting BR2_PREFIX. Example usage: Enable `BR2_PACKAGE_GNUPG`: ./utils/config --package --enable GNUPG Check state of config option `BR2_PACKAGE_GNUPG`: ./utils/config --package --state GNUPG y Enable `BR2_PACKAGE_GNUPG`: ./utils/config --package --disable GNUPG Set `BR2_TARGET_GENERIC_ISSUE` to "Welcome": ./utils/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 [Arnout: merge the two tr invications] Signed-off-by: Arnout Vandecappelle (Essensium/Mind) --- diff --git a/utils/config b/utils/config new file mode 100755 index 0000000000..c5e2d723ea --- /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