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 # Add support for (use of) EXTRAVERSION (to support 2.6.8.x, e.g.);
45 # update usage message;
46 # fix some whitespace damage;
47 # be smarter about stopping when current version is larger than requested;
48 # Randy Dunlap <rdunlap@xenotime.net>, 2004-AUG-18.
50 # Add better support for (non-incremental) 2.6.x.y patches;
51 # If an ending version number if not specified, the script automatically
52 # increments the SUBLEVEL (x in 2.6.x.y) until no more patch files are found;
53 # however, EXTRAVERSION (y in 2.6.x.y) is never automatically incremented
54 # but must be specified fully.
56 # patch-kernel does not normally support reverse patching, but does so when
57 # applying EXTRAVERSION (x.y) patches, so that moving from 2.6.11.y to 2.6.11.z
58 # is easy and handled by the script (reverse 2.6.11.y and apply 2.6.11.z).
59 # Randy Dunlap <rdunlap@xenotime.net>, 2005-APR-08.
63 # Set directories from arguments, or use defaults.
64 sourcedir
=${1-/usr/src/linux}
68 if [ "$1" = -h -o "$1" = --help -o ! -r "$sourcedir/Makefile" ]; then
70 usage: $PNAME [-h] [ sourcedir [ patchdir [ stopversion ] [ -acxx ] ] ]
71 source directory defaults to /usr/src/linux,
72 patch directory defaults to the current directory,
73 stopversion defaults to <all in patchdir>.
78 # See if we have any -ac options
88 # ---------------------------------------------------------------------------
91 echo "cannot find patch file: ${patch}"
95 # ---------------------------------------------------------------------------
97 echo "$PNAME does not support reverse patching"
101 # ---------------------------------------------------------------------------
102 # Find a file, first parameter is basename of file
103 # it tries many compression mechanisms and sets variables to say how to get it
107 if [ -r ${filebase}.gz
]; then
111 elif [ -r ${filebase}.bz
]; then
115 elif [ -r ${filebase}.bz2
]; then
119 elif [ -r ${filebase}.
zip ]; then
123 elif [ -r ${filebase}.Z
]; then
126 uncomp
="uncompress -c"
127 elif [ -r ${filebase} ]; then
138 # ---------------------------------------------------------------------------
139 # Apply a patch and check it goes in cleanly
140 # First param is patch name (e.g. patch-2.4.9-ac5) - without path or extension
143 echo -n "Applying $1 (${name})... "
144 if $uncomp ${patchdir}/$1${ext} |
patch -p1 -s -N -E -d $sourcedir
148 echo "failed. Clean up yourself."
151 if [ "`find $sourcedir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ]
153 echo "Aborting. Reject files found."
156 # Remove backup files
157 find $sourcedir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \
;
162 # ---------------------------------------------------------------------------
163 # arg1 is patch filename
165 echo -n "Reversing $1 (${name}) ... "
166 if $uncomp ${patchdir}/"$1"${ext} |
patch -p1 -Rs -N -E -d $sourcedir
170 echo "failed. Clean it up."
173 if [ "`find $sourcedir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ]
175 echo "Aborting. Reject files found."
178 # Remove backup files
179 find $sourcedir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \
;
184 # set current VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION
185 # force $TMPFILEs below to be in local directory: a slash character prevents
186 # the dot command from using the search path.
187 TMPFILE
=`mktemp ./.tmpver.XXXXXX` ||
{ echo "cannot make temp file" ; exit 1; }
188 grep -E "^(VERSION|PATCHLEVEL|SUBLEVEL|EXTRAVERSION)" $sourcedir/Makefile
> $TMPFILE
189 tr -d [:blank
:] < $TMPFILE > $TMPFILE.1
192 if [ -z "$VERSION" -o -z "$PATCHLEVEL" -o -z "$SUBLEVEL" ]
194 echo "unable to determine current kernel version" >&2
198 NAME
=`grep ^NAME $sourcedir/Makefile`
201 echo "Current kernel version is $VERSION.$PATCHLEVEL.$SUBLEVEL${EXTRAVERSION} ($NAME)"
203 # strip EXTRAVERSION to just a number (drop leading '.' and trailing additions)
205 if [ x
$EXTRAVERSION != "x" ]
207 EXTRAVER
=${EXTRAVERSION#.}
208 EXTRAVER
=${EXTRAVER%%[[:punct:]]*}
209 #echo "$PNAME: changing EXTRAVERSION from $EXTRAVERSION to $EXTRAVER"
212 #echo "stopvers=$stopvers"
213 if [ $stopvers != "default" ]; then
214 STOPSUBLEVEL
=`echo $stopvers | cut -d. -f3`
215 STOPEXTRA
=`echo $stopvers | cut -d. -f4`
216 STOPFULLVERSION
=${stopvers%%.$STOPEXTRA}
217 #echo "#___STOPSUBLEVEL=/$STOPSUBLEVEL/, STOPEXTRA=/$STOPEXTRA/"
223 # This all assumes a 2.6.x[.y] kernel tree.
224 # Don't allow backwards/reverse patching.
225 if [ $STOPSUBLEVEL -lt $SUBLEVEL ]; then
229 if [ x
$EXTRAVER != "x" ]; then
230 CURRENTFULLVERSION
="$VERSION.$PATCHLEVEL.$SUBLEVEL.$EXTRAVER"
232 CURRENTFULLVERSION
="$VERSION.$PATCHLEVEL.$SUBLEVEL"
235 if [ x
$EXTRAVER != "x" ]; then
236 echo "backing up to: $VERSION.$PATCHLEVEL.$SUBLEVEL"
237 patch="patch-${CURRENTFULLVERSION}"
238 findFile
$patchdir/${patch} || noFile
${patch}
239 reversePatch
${patch} ||
exit 1
242 # now current is 2.6.x, with no EXTRA applied,
243 # so update to target SUBLEVEL (2.6.SUBLEVEL)
244 # and then to target EXTRAVER (2.6.SUB.EXTRAVER) if requested.
245 # If not ending sublevel is specified, it is incremented until
246 # no further sublevels are found.
248 if [ $STOPSUBLEVEL -gt $SUBLEVEL ]; then
249 while : # incrementing SUBLEVEL (s in v.p.s)
251 CURRENTFULLVERSION
="$VERSION.$PATCHLEVEL.$SUBLEVEL"
253 if [ $STOPFULLVERSION = $CURRENTFULLVERSION ]; then
254 echo "Stopping at $CURRENTFULLVERSION base as requested."
258 SUBLEVEL
=$
(($SUBLEVEL + 1))
259 FULLVERSION
="$VERSION.$PATCHLEVEL.$SUBLEVEL"
260 #echo "#___ trying $FULLVERSION ___"
262 if [ $
(($SUBLEVEL)) -gt $
(($STOPSUBLEVEL)) ]; then
263 echo "Stopping since sublevel ($SUBLEVEL) is beyond stop-sublevel ($STOPSUBLEVEL)"
267 patch=patch-
$FULLVERSION
268 # See if the file exists and find extension
269 findFile
$patchdir/${patch} || noFile
${patch}
271 # Apply the patch and check all is OK
272 applyPatch
$patch ||
break
274 #echo "#___sublevel all done"
277 # There is no incremental searching for extraversion...
278 if [ "$STOPEXTRA" != "" ]; then
279 while : # just to allow break
281 # apply STOPEXTRA directly (not incrementally) (x in v.p.s.x)
282 FULLVERSION
="$VERSION.$PATCHLEVEL.$SUBLEVEL.$STOPEXTRA"
283 #echo "#... trying $FULLVERSION ..."
284 patch=patch-
$FULLVERSION
286 # See if the file exists and find extension
287 findFile
$patchdir/${patch} || noFile
${patch}
289 # Apply the patch and check all is OK
290 applyPatch
$patch ||
break
291 #echo "#___extraver all done"
296 if [ x
$gotac != x
]; then
297 # Out great user wants the -ac patches
298 # They could have done -ac (get latest) or -acxx where xx=version they want
299 if [ $gotac = "-ac" ]; then
300 # They want the latest version
302 for PATCHNAMES
in $patchdir/patch-
${CURRENTFULLVERSION}-ac*\.
*
304 ACVALUE
=`echo $PATCHNAMES | sed -e 's/^.*patch-[0-9.]*-ac\([0-9]*\).*/\1/'`
305 # Check it is actually a recognised patch type
306 findFile
$patchdir/patch-
${CURRENTFULLVERSION}-ac${ACVALUE} ||
break
308 if [ $ACVALUE -gt $HIGHESTPATCH ]; then
309 HIGHESTPATCH
=$ACVALUE
313 if [ $HIGHESTPATCH -ne 0 ]; then
314 findFile
$patchdir/patch-
${CURRENTFULLVERSION}-ac${HIGHESTPATCH} ||
break
315 applyPatch patch-
${CURRENTFULLVERSION}-ac${HIGHESTPATCH}
317 echo "No -ac patches found"
320 # They want an exact version
321 findFile
$patchdir/patch-
${CURRENTFULLVERSION}${gotac} ||
{
322 echo "Sorry, I couldn't find the $gotac patch for $CURRENTFULLVERSION. Hohum."
325 applyPatch patch-
${CURRENTFULLVERSION}${gotac}
This page took 0.036608 seconds and 5 git commands to generate.