rpms/kernel/devel/scripts sort-config,1.1,1.2
Chuck Ebbert
cebbert at fedoraproject.org
Sun Aug 16 03:08:21 UTC 2009
Author: cebbert
Update of /cvs/pkgs/rpms/kernel/devel/scripts
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv27043/scripts
Modified Files:
sort-config
Log Message:
sort-config: fix option matching, add force option
Index: sort-config
===================================================================
RCS file: /cvs/pkgs/rpms/kernel/devel/scripts/sort-config,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -p -r1.1 -r1.2
--- sort-config 16 Aug 2009 00:52:13 -0000 1.1
+++ sort-config 16 Aug 2009 03:08:19 -0000 1.2
@@ -1,26 +1,40 @@
#!/bin/bash
SRC=($(ls config-* 2>/dev/null))
-TGT=($(ls kernel-*/linux-*.noarch/configs/kernel-2.6.*-*.config kernel-*/linux-*.noarch/configs/kernel-2.6.*-*-debug.config 2>/dev/null))
+TGT=($(ls kernel-*/linux-*.noarch/configs/kernel-2.6.*-*.config \
+ kernel-*/linux-*.noarch/configs/kernel-2.6.*-*-debug.config 2>/dev/null))
TGT1=(${TGT[*]#kernel-*/linux-*.noarch/configs/kernel-2.6.*-})
if [ $# -lt 2 ] ; then
- echo -e "Usage: $(basename $0) [-d] input target"
- echo -e "Sort input config file into the same order as the target"
- echo -e " -d: show raw unsorted output with extra debug text"
- echo -e " input: source config file" ' [' "${SRC[*]#config-}" ']'
- echo -e " target: output arch name" ' [' "${TGT1[*]%.config}" ']'
- exit 1
+ echo -e "Usage:\n $(basename $0) [-df] input target\n"
+ echo -e " Sort input config file into the same order as the target\n"
+ echo -e " -d: show raw unsorted output with extra debug text"
+ echo -e " -f: force output to match what is in the target config\n"
+ echo -e " input: source config file" ' [' "${SRC[*]#config-}" ']\n'
+ echo -e " target: output arch name" ' [' "${TGT1[*]%.config}" ']\n'
+ exit 1
fi
-if [ "$1" = "-d" ] ; then
- DEBUG=1
- shift
-fi
+while getopts "df" OPTION ; do
+case $OPTION in
+d)
+ DEBUG=1
+;;
+f)
+ FORCE=1
+;;
+\?)
+ exit 2
+;;
+esac
+done
+
+shift $((OPTIND-1))
if [ -f xx00 -o -f xx01 -o -f xx99 ] ; then
- echo "WARNING! Output files named xx?? already exist."
- read -p "Press <Enter> to erase files, or Ctrl-C to exit..."
+ echo "WARNING! Output files named xx?? already exist." >&2
+ read -p "Press <Enter> to erase files, or Ctrl-C to exit..."
+ echo >&2
fi
rm -f xx00 xx01 xx99
@@ -35,75 +49,89 @@ declare -a SAVECOMMENT
cat ${SRCFILE} | while read TEXT ; do
- LINE=
- COMMENT=
- [ -z "$TEXT" ] && TEXT='#'
-
- if [ "${TEXT:0:7}" = "CONFIG_" -o "${TEXT:0:9}" = "# CONFIG_" ] ; then
- LINE=$(grep -n "^$TEXT" $TGTFILE | head -1 | grep "$TEXT" | cut -f 1 -d ':')
- if [ -z "$LINE" ] ; then
- [ "$DEBUG" ] && echo "nofind ->" "$TEXT"
-
- # see if option changed in output file
- OPTNAME=
- if [ "${TEXT:0:7}" = "CONFIG_" ] ; then
- OPTNAME=${TEXT%%=*}
- elif [ "${TEXT:0:9}" = "# CONFIG_" ] ; then
- OPTNAME=${TEXT%"is not set"}
- OPTNAME=${OPTNAME#\# }
- fi
- if [ "$OPTNAME" ] ; then
- [ "$DEBUG" ] && echo "looking for ->" "$OPTNAME"
- LINE=$(grep -n "$OPTNAME" $TGTFILE | head -1 | grep "$OPTNAME" | cut -f 1 -d ':')
- [ "$LINE" ] && COMMENT="# -- Next line was changed by config rules in output at line $LINE"
- fi
- fi
- else
- COMMENT="$TEXT"
- TEXT=
- fi
-
- [ "$DEBUG" -a "$COMMENT" ] && echo "comment ->" "$LINE" "$COMMENT"
- [ "$DEBUG" -a "$TEXT" ] && echo "text ->" "$LINE" "$TEXT"
-
- if [ "$TEXT" ] ; then
- # we have output, make sure it has a line number
- [ -z "$LINE" ] && LINE=999999
-
- # print saved comments first
- if [ $IX -gt 0 ] ; then
- [ "$DEBUG" ] && echo " ->" $IX "comments were saved"
- (( IX-- ))
- for IX in $(seq 0 $IX) ; do
- echo "$LINE":"${SAVECOMMENT[$IX]}"
- done
- unset SAVECOMMENT
- IX=0
- fi
- [ "$COMMENT" ] && echo "$LINE":"$COMMENT"
- echo "$LINE":"$TEXT"
- else
- # no output yet, save the comment
- SAVECOMMENT[$IX]="$COMMENT"
- [ "$DEBUG" ] && echo "savecomment ->" "$LINE" "${SAVECOMMENT[$IX]}"
- (( IX++ ))
- fi
+ LINE=
+ COMMENT=
+ [ -z "$TEXT" ] && TEXT='#'
+
+ if [ "${TEXT:0:7}" = "CONFIG_" -o "${TEXT:0:9}" = "# CONFIG_" ] ; then
+
+ LINE=$(grep -n "^$TEXT" $TGTFILE | head -1 | cut -f 1 -d ':')
+ if [ -z "$LINE" ] ; then
+ [ "$DEBUG" ] && echo "nofind ->" "$TEXT"
+
+ # see if option changed in output file
+ OPTNAME=
+ if [ "${TEXT:0:7}" = "CONFIG_" ] ; then
+ OPTNAME=${TEXT%%=*}
+ elif [ "${TEXT:0:9}" = "# CONFIG_" ] ; then
+ OPTNAME=${TEXT%"is not set"}
+ OPTNAME=${OPTNAME#\# }
+ fi
+ if [ "$OPTNAME" ] ; then
+ for FINDTEXT in "^${OPTNAME}=" "^# ${OPTNAME} is not set" ; do
+ if [ -z "$LINE" ] ; then
+ [ "$DEBUG" ] && echo "looking for ->" "$FINDTEXT"
+ LINE=$(grep -n "$FINDTEXT" $TGTFILE | head -1 | cut -f 1 -d ':')
+ if [ "$LINE" ] ; then
+ if [ "$FORCE" ] ; then
+ TEXT=$(grep "$FINDTEXT" $TGTFILE | head -1)
+ [ "$DEBUG" ] && echo 'forced ->' "$TEXT"
+ else
+ COMMENT="# -- Next option was changed in target line $LINE --"
+ fi
+ fi
+ fi
+ done
+ fi
+
+ fi
+
+ else
+ COMMENT="$TEXT"
+ TEXT=
+ fi
+
+ [ "$DEBUG" -a "$COMMENT" ] && echo "comment ->" "$LINE" "$COMMENT"
+ [ "$DEBUG" -a "$TEXT" ] && echo "text ->" "$LINE" "$TEXT"
+
+ if [ "$TEXT" ] ; then
+ # we have output, make sure it has a line number
+ [ -z "$LINE" ] && LINE=999999
+
+ # print saved comments first
+ if [ $IX -gt 0 ] ; then
+ [ "$DEBUG" ] && echo " ->" $IX "comments were saved"
+ (( IX-- ))
+ for IX in $(seq 0 $IX) ; do
+ echo "$LINE":"${SAVECOMMENT[$IX]}"
+ done
+ unset SAVECOMMENT
+ IX=0
+ fi
+ [ "$COMMENT" ] && echo "$LINE":"$COMMENT"
+ echo "$LINE":"$TEXT"
+ else
+ # no output yet, save the comment
+ SAVECOMMENT[$IX]="$COMMENT"
+ [ "$DEBUG" ] && echo "savecomment ->" "$LINE" "${SAVECOMMENT[$IX]}"
+ (( IX++ ))
+ fi
done > xx99
if [ "$DEBUG" ] ; then
- cat xx99
+ cat xx99
else
- cat xx99 | sort -s -t ":" -k 1g | csplit -k -s - /^999999/ 2>/dev/null
+ cat xx99 | sort -s -t ":" -k 1g | csplit -k -s - /^999999/ 2>/dev/null
- cat xx00 | cut -f 2- -d ':'
- if [ -s xx01 ] ; then
- echo
- echo '# ------------ UNMATCHED OPTIONS ------------'
- echo
- cat xx01 | cut -f 2- -d ':'
- fi
+ cat xx00 | cut -f 2- -d ':'
+ if [ -s xx01 ] ; then
+ echo
+ echo '# ------------ UNMATCHED OPTIONS ------------'
+ echo
+ cat xx01 | cut -f 2- -d ':'
+ fi
fi
More information about the scm-commits
mailing list