diff mbox series

[kteam-tools] sort-config: sort a kernel config file as splitconfig does

Message ID 1508434506-22360-1-git-send-email-kamal@canonical.com
State New
Headers show
Series [kteam-tools] sort-config: sort a kernel config file as splitconfig does | expand

Commit Message

Kamal Mostafa Oct. 19, 2017, 5:35 p.m. UTC
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
---
 misc/sort-config | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100755 misc/sort-config

Comments

Marcelo Henrique Cerri Oct. 20, 2017, 12:37 p.m. UTC | #1
Hi, Kamal.

(Now replying to the correct email)

The script looks perfectly fine for me. But is there a particular use or
motivation for it?

Acked-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
Kamal Mostafa Oct. 20, 2017, 2:19 p.m. UTC | #2
On Fri, Oct 20, 2017 at 10:37:43AM -0200, Marcelo Henrique Cerri wrote:
> Hi, Kamal.
> 
> (Now replying to the correct email)
> 
> The script looks perfectly fine for me. But is there a particular use or
> motivation for it?
> 
> Acked-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>

I frequently find myself wanting to "import" a group of configs from one
repo to another...  E.g. after enabling some feature in a config, now
there will be a whole bunch of new config options for that feature that
need to be set (which weren't in the config at all before).  I might
decide to just import all of those options from some other repo, by just
appending all the new ones to the bottom of my
debian.something/config/config.common.ubuntu (or any other .config-ish
file really).  That works fine, but then that config file won't be
sorted properly, which will make later rebase-merges difficult.

The config file is difficult to just "sort manually" (because it wants
to be sorted by the config name itself, regardless of "# ... is not present").
Hence this script.  After you make my sloppy changes to
debian.something/config/config.common.ubuntu, I can use this script to
"fix it" before I check it in.

 -Kamal
Kleber Sacilotto de Souza Oct. 23, 2017, 10:41 a.m. UTC | #3
On 10/19/17 19:35, Kamal Mostafa wrote:
> Signed-off-by: Kamal Mostafa <kamal@canonical.com>

Applied to kteam-tools/master branch.

Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>

> ---
>  misc/sort-config | 42 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 42 insertions(+)
>  create mode 100755 misc/sort-config
> 
> diff --git a/misc/sort-config b/misc/sort-config
> new file mode 100755
> index 0000000..49f6194
> --- /dev/null
> +++ b/misc/sort-config
> @@ -0,0 +1,42 @@
> +#!/bin/bash
> +#
> +# sort-config - sort a kernel config file as splitconfig does
> +# Kamal Mostafa <kamal@canonical.com>
> +#
> +
> +[ "$1" = "-i" ] && { iflag=1; shift; }	### inplace: write to the config file
> +
> +config="$1"				### a kernel .config file
> +
> +[ -f "$config" ] || {
> +    echo "usage: sort-config [-i] configfile" 1>&2
> +    exit 1
> +}
> +
> +set -e
> +
> +header="$(sed -n '/CONFIG/q;p' $config)"
> +
> +TMPOUT=$(mktemp)
> +trap "rm -f $TMPOUT" 0
> +
> +### Method:
> +### 0. Pass the header (comment block) through.
> +### 1. Homogenize the config lines for sorting (strip '=' and leading '#').
> +### 2. Sort by the first column.
> +### 3. Put back the stripped '=' and '#' markers.
> +
> +{
> +echo "$header"
> +cat "$config" \
> +| sed -e '/^CONFIG/s/=/ /' -e 's/^# CONFIG/CONFIG/' -e '/^#/d' \
> +| LC_ALL=C sort -k1,1 \
> +| sed -e '/is not set/s/^/# /' -e '/^CONFIG/s/ /=/'
> +} > "$TMPOUT"
> +
> +if [ "$iflag" = "1" ]
> +then
> +	mv "$TMPOUT" "$config"
> +else
> +	cat "$TMPOUT"
> +fi
>
diff mbox series

Patch

diff --git a/misc/sort-config b/misc/sort-config
new file mode 100755
index 0000000..49f6194
--- /dev/null
+++ b/misc/sort-config
@@ -0,0 +1,42 @@ 
+#!/bin/bash
+#
+# sort-config - sort a kernel config file as splitconfig does
+# Kamal Mostafa <kamal@canonical.com>
+#
+
+[ "$1" = "-i" ] && { iflag=1; shift; }	### inplace: write to the config file
+
+config="$1"				### a kernel .config file
+
+[ -f "$config" ] || {
+    echo "usage: sort-config [-i] configfile" 1>&2
+    exit 1
+}
+
+set -e
+
+header="$(sed -n '/CONFIG/q;p' $config)"
+
+TMPOUT=$(mktemp)
+trap "rm -f $TMPOUT" 0
+
+### Method:
+### 0. Pass the header (comment block) through.
+### 1. Homogenize the config lines for sorting (strip '=' and leading '#').
+### 2. Sort by the first column.
+### 3. Put back the stripped '=' and '#' markers.
+
+{
+echo "$header"
+cat "$config" \
+| sed -e '/^CONFIG/s/=/ /' -e 's/^# CONFIG/CONFIG/' -e '/^#/d' \
+| LC_ALL=C sort -k1,1 \
+| sed -e '/is not set/s/^/# /' -e '/^CONFIG/s/ /=/'
+} > "$TMPOUT"
+
+if [ "$iflag" = "1" ]
+then
+	mv "$TMPOUT" "$config"
+else
+	cat "$TMPOUT"
+fi