From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54CEF13D530 for ; Thu, 12 Sep 2024 19:55:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726170919; cv=none; b=G/vvqRud9/GF63iRrzU/bZxinbGvV0uUe6IQKg55FYYHWn6rmpWsCAJ9NaGfgFfSEP80o8uSAiDPEFWaNY0Y1Kr55cmySco/OU/JzXZsA061E1EPvh1znVe3zyYzhLpdKclrDGJJSkbwYej0VG7yrIFQI78FjAYdNJgQvucVACo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726170919; c=relaxed/simple; bh=jsjh82FQ2mGnX2yB0wZyFX/sbyK48CHGP7YPq8SDSSI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=jhjP4S62FPE0HFj/Icq5VVnamSj3J5pupQ4RnWOFwX2QqnB6ki+LkkMtzs2SdfeWNNgzCHLL2p4u747aE6lmOHK3hbfCMifnY0D+qn9SlgKqJ0Sgr818BuOK80Q/p+q46V3jG6YENrdhKHs45SoaV1a6d++M8V2c8qL0W1EU6i4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=o5BBD4ob; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="o5BBD4ob" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9AF48C4CEC3; Thu, 12 Sep 2024 19:55:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1726170918; bh=jsjh82FQ2mGnX2yB0wZyFX/sbyK48CHGP7YPq8SDSSI=; h=From:To:Cc:Subject:Date:From; b=o5BBD4obRRz0Wv3Pnkp+Lt+8GYqG05E0IpQ19LSmQlGdJTR5m7nPVRt20RCt+FHBS LHP+WyXDIfphVHXwdowuJzG/rZsE1Xlrk1Iuwyxi9+/ZFuUOHV/JeB+4GAPV1ZO+6T UWL/W0OcWSoFZ249g54PH4jbHq4wK1WOCdvAYOrxROIEkdSa/U1M9/3O7e1CFB9imk adeCv1YVtd+cKmfXqYEEG9r1ArjjCB9buyIgM/A1uuLB1rG96j+w+TNKSJaHfubSPD 6ieVWrXvsNB6XOU3s/vTHPMo38kC3CCFty4XIr+d3pga1xVXSMAWaxIbGek4YyHW43 oKEZy+wdQY7Rw== From: cel@kernel.org To: Cc: Chuck Lever Subject: [RFC PATCH] scripts: Copy scripts/config from the Linux kernel repo Date: Thu, 12 Sep 2024 15:55:12 -0400 Message-ID: <20240912195512.354585-1-cel@kernel.org> X-Mailer: git-send-email 2.46.0 Precedence: bulk X-Mailing-List: kdevops@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Chuck Lever scripts/config is a scriptable way to modify .config files. I find this script useful for making the same small change repeatedly to a number of kdevops or kernel .config files, or for having a set-up script that can poke a bunch of settings into a .config automatically. Signed-off-by: Chuck Lever --- scripts/config | 230 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 230 insertions(+) create mode 100755 scripts/config diff --git a/scripts/config b/scripts/config new file mode 100755 index 000000000000..ff88e2faefd3 --- /dev/null +++ b/scripts/config @@ -0,0 +1,230 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0 +# Manipulate options in a .config file from the command line + +myname=${0##*/} + +# If no prefix forced, use the default CONFIG_ +CONFIG_="${CONFIG_-CONFIG_}" + +# We use an uncommon delimiter for sed substitutions +SED_DELIM=$(echo -en "\001") + +usage() { + cat >&2 <"$tmpfile" + # replace original file with the edited one + mv "$tmpfile" "$infile" +} + +txt_subst() { + local before="$1" + local after="$2" + local infile="$3" + local tmpfile="$infile.swp" + + sed -e "s$SED_DELIM$before$SED_DELIM$after$SED_DELIM" "$infile" >"$tmpfile" + # replace original file with the edited one + mv "$tmpfile" "$infile" +} + +txt_delete() { + local text="$1" + local infile="$2" + local tmpfile="$infile.swp" + + sed -e "/$text/d" "$infile" >"$tmpfile" + # replace original file with the edited one + mv "$tmpfile" "$infile" +} + +set_var() { + local name=$1 new=$2 before=$3 + + name_re="^($name=|# $name is not set)" + before_re="^($before=|# $before is not set)" + if test -n "$before" && grep -Eq "$before_re" "$FN"; then + txt_append "^$before=" "$new" "$FN" + txt_append "^# $before is not set" "$new" "$FN" + elif grep -Eq "$name_re" "$FN"; then + txt_subst "^$name=.*" "$new" "$FN" + txt_subst "^# $name is not set" "$new" "$FN" + else + echo "$new" >>"$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 + ;; + --refresh) + ;; + --*-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 "${CONFIG_}$ARG" "${CONFIG_}$ARG=y" + ;; + + --disable|-d) + set_var "${CONFIG_}$ARG" "# ${CONFIG_}$ARG is not set" + ;; + + --module|-m) + set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=m" + ;; + + --set-str) + # sed swallows one level of escaping, so we need double-escaping + set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=\"${1//\"/\\\\\"}\"" + shift + ;; + + --set-val) + set_var "${CONFIG_}$ARG" "${CONFIG_}$ARG=$1" + shift + ;; + --undefine|-u) + undef_var "${CONFIG_}$ARG" + ;; + + --state|-s) + if grep -q "# ${CONFIG_}$ARG is not set" $FN ; then + echo n + else + V="$(grep "^${CONFIG_}$ARG=" $FN)" + if [ $? != 0 ] ; then + echo undef + else + V="${V/#${CONFIG_}$ARG=/}" + V="${V/#\"/}" + V="${V/%\"/}" + V="${V//\\\"/\"}" + echo "${V}" + fi + fi + ;; + + --enable-after|-E) + set_var "${CONFIG_}$B" "${CONFIG_}$B=y" "${CONFIG_}$A" + ;; + + --disable-after|-D) + set_var "${CONFIG_}$B" "# ${CONFIG_}$B is not set" "${CONFIG_}$A" + ;; + + --module-after|-M) + set_var "${CONFIG_}$B" "${CONFIG_}$B=m" "${CONFIG_}$A" + ;; + + # undocumented because it ignores --file (fixme) + --refresh) + yes "" | make oldconfig + ;; + + *) + echo "bad command: $CMD" >&2 + usage + ;; + esac +done -- 2.46.0