Commit a2c665b0 authored by Randy Dunlap's avatar Randy Dunlap Committed by Sam Ravnborg

scripts/patch-kernel: use EXTRAVERSION

Update 'scripts/patch-kernel' to support EXTRAVERSION.
Update usage message text.
Fix some whitespace.
Handle command line arg3 (stop-version) more carefully.
No changes to -ac patch updates.

EXTRAVERSION handling:
any leading '.' and any trailing modifier (beginning with any
punctuation, like "-ac" or "_kexec" or "+mm") are stripped,
trying to get down to just a number.
Then 'patch-kernel' increments EXTRAVERSION as long as it can
apply "patch-V.P.S.X*".  When that file isn't found, it resets
EXTRAVERSION to "" and increments SUBLEVEL (as before this patch).

Works for me.
Signed-off-by: default avatarRandy Dunlap <rddunlap@osdl.org>
Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
parent e63a83e0
...@@ -40,17 +40,24 @@ ...@@ -40,17 +40,24 @@
# #
# Added -ac option, use -ac or -ac9 (say) to stop at a particular version # Added -ac option, use -ac or -ac9 (say) to stop at a particular version
# Dave Gilbert <linux@treblig.org>, 29th September 2001. # Dave Gilbert <linux@treblig.org>, 29th September 2001.
#
# Add support for (use of) EXTRAVERSION (to support 2.6.8.x, e.g.);
# update usage message;
# fix some whitespace damage;
# be smarter about stopping when current version is larger than requested;
# Randy Dunlap <rddunlap@osdl.org>, 2004-AUG-18.
# Set directories from arguments, or use defaults. # Set directories from arguments, or use defaults.
sourcedir=${1-/usr/src/linux} sourcedir=${1-/usr/src/linux}
patchdir=${2-.} patchdir=${2-.}
stopvers=${3-imnotaversion} stopvers=${3-default}
if [ "$1" = -h -o "$1" = --help -o ! -r "$sourcedir/Makefile" ]; then if [ "$1" == -h -o "$1" == --help -o ! -r "$sourcedir/Makefile" ]; then
cat << USAGE cat << USAGE
usage: patch-kernel [-h] [ sourcedir [ patchdir [ stopversion ] [ -acxx ] ] ] usage: patch-kernel [-h] [ sourcedir [ patchdir [ stopversion ] [ -acxx ] ] ]
The source directory defaults to /usr/src/linux, and source directory defaults to /usr/src/linux,
the patch directory defaults to the current directory. patch directory defaults to the current directory,
stopversion defaults to <all in patchdir>.
USAGE USAGE
exit 1 exit 1
fi fi
...@@ -77,7 +84,7 @@ findFile () { ...@@ -77,7 +84,7 @@ findFile () {
uncomp="gunzip -dc" uncomp="gunzip -dc"
elif [ -r ${filebase}.bz ]; then elif [ -r ${filebase}.bz ]; then
ext=".bz" ext=".bz"
name="bzip" name="bzip"
uncomp="bunzip -dc" uncomp="bunzip -dc"
elif [ -r ${filebase}.bz2 ]; then elif [ -r ${filebase}.bz2 ]; then
ext=".bz2" ext=".bz2"
...@@ -96,8 +103,8 @@ findFile () { ...@@ -96,8 +103,8 @@ findFile () {
name="plaintext" name="plaintext"
uncomp="cat" uncomp="cat"
else else
return 1; return 1;
fi fi
return 0; return 0;
} }
...@@ -126,48 +133,100 @@ applyPatch () { ...@@ -126,48 +133,100 @@ applyPatch () {
return 0; return 0;
} }
# set current VERSION, PATCHLEVEL, SUBLEVEL, EXTERVERSION # set current VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION
eval `sed -n -e 's/^\([A-Z]*\) = \([0-9]*\)$/\1=\2/p' -e 's/^\([A-Z]*\) = \(-[-a-z0-9]*\)$/\1=\2/p' $sourcedir/Makefile` TMPFILE=`mktemp .tmpver.XXXXXX` || { echo "cannot make temp file" ; exit 1; }
grep -E "^(VERSION|PATCHLEVEL|SUBLEVEL|EXTRAVERSION)" $sourcedir/Makefile > $TMPFILE
tr -d [:blank:] < $TMPFILE > $TMPFILE.1
source $TMPFILE.1
rm -f $TMPFILE*
if [ -z "$VERSION" -o -z "$PATCHLEVEL" -o -z "$SUBLEVEL" ] if [ -z "$VERSION" -o -z "$PATCHLEVEL" -o -z "$SUBLEVEL" ]
then then
echo "unable to determine current kernel version" >&2 echo "unable to determine current kernel version" >&2
exit 1 exit 1
fi fi
echo "Current kernel version is $VERSION.$PATCHLEVEL.$SUBLEVEL${EXTRAVERSION}" NAME=`grep ^NAME $sourcedir/Makefile`
NAME=${NAME##*=}
echo "Current kernel version is $VERSION.$PATCHLEVEL.$SUBLEVEL${EXTRAVERSION} ($NAME)"
# strip EXTRAVERSION to just a number (drop leading '.' and trailing additions)
EXTRAVER=
if [ x$EXTRAVERSION != "x" ] if [ x$EXTRAVERSION != "x" ]
then then
echo "I'm sorry but patch-kernel can't work with a kernel source tree that is not a base version" if [ ${EXTRAVERSION:0:1} == "." ]; then
exit 1; EXTRAVER=${EXTRAVERSION:1}
else
EXTRAVER=$EXTRAVERSION
fi
EXTRAVER=${EXTRAVER%%[[:punct:]]*}
#echo "patch-kernel: changing EXTRAVERSION from $EXTRAVERSION to $EXTRAVER"
fi
#echo "stopvers=$stopvers"
if [ $stopvers != "default" ]; then
STOPSUBLEVEL=`echo $stopvers | cut -d. -f3`
STOPEXTRA=`echo $stopvers | cut -d. -f4`
#echo "STOPSUBLEVEL=$STOPSUBLEVEL, STOPEXTRA=$STOPEXTRA"
else
STOPSUBLEVEL=9999
STOPEXTRA=9999
fi fi
while : while : # incrementing SUBLEVEL (s in v.p.s)
do do
CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" if [ x$EXTRAVER != "x" ]; then
if [ $stopvers = $CURRENTFULLVERSION ] CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL.$EXTRAVER"
then else
echo "Stoping at $CURRENTFULLVERSION base as requested." CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL"
fi
if [ $stopvers == $CURRENTFULLVERSION ]; then
echo "Stopping at $CURRENTFULLVERSION base as requested."
break break
fi fi
SUBLEVEL=`expr $SUBLEVEL + 1` while : # incrementing EXTRAVER (x in v.p.s.x)
do
EXTRAVER=$((EXTRAVER + 1))
FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL.$EXTRAVER"
#echo "... trying $FULLVERSION ..."
patch=patch-$FULLVERSION
# See if the file exists and find extension
findFile $patchdir/${patch} || break
# Apply the patch and check all is OK
applyPatch $patch || break
continue 2
done
EXTRAVER=
SUBLEVEL=$((SUBLEVEL + 1))
FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL"
#echo "___ trying $FULLVERSION ___"
if [ $((SUBLEVEL)) -gt $((STOPSUBLEVEL)) ]; then
echo "Stopping since sublevel ($SUBLEVEL) is beyond stop-sublevel ($STOPSUBLEVEL)"
exit 1
fi
patch=patch-$FULLVERSION patch=patch-$FULLVERSION
# See if the file exists and find extension # See if the file exists and find extension
findFile $patchdir/${patch} || break findFile $patchdir/${patch} || break
# Apply the patch and check all is OK # Apply the patch and check all is OK
applyPatch $patch || break applyPatch $patch || break
done done
#echo "base all done"
if [ x$gotac != x ]; then if [ x$gotac != x ]; then
# Out great user wants the -ac patches # Out great user wants the -ac patches
# They could have done -ac (get latest) or -acxx where xx=version they want # They could have done -ac (get latest) or -acxx where xx=version they want
if [ $gotac == "-ac" ] if [ $gotac == "-ac" ]; then
then
# They want the latest version # They want the latest version
HIGHESTPATCH=0 HIGHESTPATCH=0
for PATCHNAMES in $patchdir/patch-${CURRENTFULLVERSION}-ac*\.* for PATCHNAMES in $patchdir/patch-${CURRENTFULLVERSION}-ac*\.*
...@@ -176,18 +235,16 @@ if [ x$gotac != x ]; then ...@@ -176,18 +235,16 @@ if [ x$gotac != x ]; then
# Check it is actually a recognised patch type # Check it is actually a recognised patch type
findFile $patchdir/patch-${CURRENTFULLVERSION}-ac${ACVALUE} || break findFile $patchdir/patch-${CURRENTFULLVERSION}-ac${ACVALUE} || break
if [ $ACVALUE -gt $HIGHESTPATCH ] if [ $ACVALUE -gt $HIGHESTPATCH ]; then
then
HIGHESTPATCH=$ACVALUE HIGHESTPATCH=$ACVALUE
fi fi
done done
if [ $HIGHESTPATCH -ne 0 ] if [ $HIGHESTPATCH -ne 0 ]; then
then
findFile $patchdir/patch-${CURRENTFULLVERSION}-ac${HIGHESTPATCH} || break findFile $patchdir/patch-${CURRENTFULLVERSION}-ac${HIGHESTPATCH} || break
applyPatch patch-${CURRENTFULLVERSION}-ac${HIGHESTPATCH} applyPatch patch-${CURRENTFULLVERSION}-ac${HIGHESTPATCH}
else else
echo "No ac patches found" echo "No -ac patches found"
fi fi
else else
# They want an exact version # They want an exact version
...@@ -198,5 +255,3 @@ if [ x$gotac != x ]; then ...@@ -198,5 +255,3 @@ if [ x$gotac != x ]; then
applyPatch patch-${CURRENTFULLVERSION}${gotac} applyPatch patch-${CURRENTFULLVERSION}${gotac}
fi fi
fi fi
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment