2 # Script to apply kernel patches.
3 # usage: patch-kernel [ sourcedir [ patchdir [ stopversion ] [ -acxx ] ] ]
4 # The source directory defaults to /usr/src/linux, and the patch
5 # directory defaults to the current directory.
7 # scripts/patch-kernel . ..
8 # Update the kernel tree in the current directory using patches in the
9 # directory above to the latest Linus kernel
10 # scripts/patch-kernel . .. -ac
11 # Get the latest Linux kernel and patch it with the latest ac patch
12 # scripts/patch-kernel . .. 2.4.9
13 # Gets standard kernel 2.4.9
14 # scripts/patch-kernel . .. 2.4.9 -ac
15 # Gets 2.4.9 with latest ac patches
16 # scripts/patch-kernel . .. 2.4.9 -ac11
17 # Gets 2.4.9 with ac patch ac11
18 # Note: It uses the patches relative to the Linus kernels, not the
19 # ac to ac relative patches
21 # It determines the current kernel version from the top-level Makefile.
22 # It then looks for patches for the next sublevel in the patch directory.
23 # This is applied using "patch -p1 -s" from within the kernel directory.
24 # A check is then made for "*.rej" files to see if the patch was
25 # successful. If it is, then all of the "*.orig" files are removed.
27 # Nick Holloway <Nick.Holloway@alfie.demon.co.uk>, 2nd January 1995.
29 # Added support for handling multiple types of compression. What includes
30 # gzip, bzip, bzip2, zip, compress, and plaintext.
32 # Adam Sulmicki <adam@cfar.umd.edu>, 1st January 1997.
34 # Added ability to stop at a given version number
35 # Put the full version number (i.e. 2.3.31) as the last parameter
36 # Dave Gilbert <linux@treblig.org>, 11th December 1999.
38 # Fixed previous patch so that if we are already at the correct version
41 # Added -ac option, use -ac or -ac9 (say) to stop at a particular version
42 # Dave Gilbert <linux@treblig.org>, 29th September 2001.
44 # Set directories from arguments, or use defaults.
45 sourcedir
=${1-/usr/src/linux}
47 stopvers
=${3-imnotaversion}
49 if [ "$1" = -h -o "$1" = --help -o ! -r "$sourcedir/Makefile" ]; then
51 usage: patch-kernel [-h] [ sourcedir [ patchdir [ stopversion ] [ -acxx ] ] ]
52 The source directory defaults to /usr/src/linux, and
53 the patch directory defaults to the current directory.
58 # See if we have any -ac options
68 # ---------------------------------------------------------------------------
69 # Find a file, first parameter is basename of file
70 # it tries many compression mechanisms and sets variables to say how to get it
74 if [ -r ${filebase}.gz
]; then
78 elif [ -r ${filebase}.bz
]; then
82 elif [ -r ${filebase}.bz2
]; then
86 elif [ -r ${filebase}.
zip ]; then
90 elif [ -r ${filebase}.Z
]; then
93 uncomp
="uncompress -c"
94 elif [ -r ${filebase} ]; then
105 # ---------------------------------------------------------------------------
106 # Apply a patch and check it goes in cleanly
107 # First param is patch name (e.g. patch-2.4.9-ac5) - without path or extension
110 echo -n "Applying $1 (${name})... "
111 if $uncomp ${patchdir}/$1${ext} |
patch -p1 -s -N -E -d $sourcedir
115 echo "failed. Clean up yourself."
118 if [ "`find $sourcedir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ]
120 echo "Aborting. Reject files found."
123 # Remove backup files
124 find $sourcedir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \
;
129 # set current VERSION, PATCHLEVEL, SUBLEVEL, EXTERVERSION
130 eval `sed -n -e 's/^\([A-Z]*\) = \([0-9]*\)$/\1=\2/p' -e 's/^\([A-Z]*\) = \(-[-a-z0-9]*\)$/\1=\2/p' $sourcedir/Makefile`
131 if [ -z "$VERSION" -o -z "$PATCHLEVEL" -o -z "$SUBLEVEL" ]
133 echo "unable to determine current kernel version" >&2
137 echo "Current kernel version is $VERSION.$PATCHLEVEL.$SUBLEVEL${EXTRAVERSION}"
139 if [ x
$EXTRAVERSION != "x" ]
141 echo "I'm sorry but patch-kernel can't work with a kernel source tree that is not a base version"
147 CURRENTFULLVERSION
="$VERSION.$PATCHLEVEL.$SUBLEVEL"
148 if [ $stopvers = $CURRENTFULLVERSION ]
150 echo "Stoping at $CURRENTFULLVERSION base as requested."
154 SUBLEVEL
=`expr $SUBLEVEL + 1`
155 FULLVERSION
="$VERSION.$PATCHLEVEL.$SUBLEVEL"
157 patch=patch-
$FULLVERSION
159 # See if the file exists and find extension
160 findFile
$patchdir/${patch} ||
break
162 # Apply the patch and check all is OK
163 applyPatch
$patch ||
break
166 if [ x
$gotac != x
]; then
167 # Out great user wants the -ac patches
168 # They could have done -ac (get latest) or -acxx where xx=version they want
169 if [ $gotac == "-ac" ]
171 # They want the latest version
173 for PATCHNAMES
in $patchdir/patch-
${CURRENTFULLVERSION}-ac*\.
*
175 ACVALUE
=`echo $PATCHNAMES | sed -e 's/^.*patch-[0-9.]*-ac\([0-9]*\).*/\1/'`
176 # Check it is actually a recognised patch type
177 findFile
$patchdir/patch-
${CURRENTFULLVERSION}-ac${ACVALUE} ||
break
179 if [ $ACVALUE -gt $HIGHESTPATCH ]
181 HIGHESTPATCH
=$ACVALUE
185 if [ $HIGHESTPATCH -ne 0 ]
187 findFile
$patchdir/patch-
${CURRENTFULLVERSION}-ac${HIGHESTPATCH} ||
break
188 applyPatch patch-
${CURRENTFULLVERSION}-ac${HIGHESTPATCH}
190 echo "No ac patches found"
193 # They want an exact version
194 findFile
$patchdir/patch-
${CURRENTFULLVERSION}${gotac} ||
{
195 echo "Sorry, I couldn't find the $gotac patch for $CURRENTFULLVERSION. Hohum."
198 applyPatch patch-
${CURRENTFULLVERSION}${gotac}