Import 2.3.99pre10-1
[davej-history.git] / scripts / patch-kernel
blob328c01b080a0e4a2a702396b03f86f2d36ba5c56
1 #! /bin/sh
2 # Script to apply kernel patches.
3 # usage: patch-kernel [ sourcedir [ patchdir [ stopversion ] ] ]
4 # The source directory defaults to /usr/src/linux, and the patch
5 # directory defaults to the current directory.
7 # It determines the current kernel version from the top-level Makefile.
8 # It then looks for patches for the next sublevel in the patch directory.
9 # This is applied using "patch -p1 -s" from within the kernel directory.
10 # A check is then made for "*.rej" files to see if the patch was
11 # successful. If it is, then all of the "*.orig" files are removed.
13 # Nick Holloway <Nick.Holloway@alfie.demon.co.uk>, 2nd January 1995.
15 # Added support for handling multiple types of compression. What includes
16 # gzip, bzip, bzip2, zip, compress, and plaintext.
18 # Adam Sulmicki <adam@cfar.umd.edu>, 1st January 1997.
20 # Added ability to stop at a given version number
21 # Put the full version number (i.e. 2.3.31) as the last parameter
22 # Dave Gilbert <linux@treblig.org>, 11th December 1999.
24 # Set directories from arguments, or use defaults.
25 sourcedir=${1-/usr/src/linux}
26 patchdir=${2-.}
27 stopvers=${3-imnotaversion}
29 # set current VERSION, PATCHLEVEL, SUBLEVEL
30 eval `sed -n 's/^\([A-Z]*\) = \([0-9]*\)$/\1=\2/p' $sourcedir/Makefile`
31 if [ -z "$VERSION" -o -z "$PATCHLEVEL" -o -z "$SUBLEVEL" ]
32 then
33 echo "unable to determine current kernel version" >&2
34 exit 1
37 echo "Current kernel version is $VERSION.$PATCHLEVEL.$SUBLEVEL"
39 while :
41 SUBLEVEL=`expr $SUBLEVEL + 1`
42 FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL"
44 patch=patch-$FULLVERSION
45 if [ -r $patchdir/${patch}.gz ]; then
46 ext=".gz"
47 name="gzip"
48 uncomp="gunzip -dc"
49 elif [ -r $patchdir/${patch}.bz ]; then
50 ext=".bz"
51 name="bzip"
52 uncomp="bunzip -dc"
53 elif [ -r $patchdir/${patch}.bz2 ]; then
54 ext=".bz2"
55 name="bzip2"
56 uncomp="bunzip2 -dc"
57 elif [ -r $patchdir/${patch}.zip ]; then
58 ext=".zip"
59 name="zip"
60 uncomp="unzip -d"
61 elif [ -r $patchdir/${patch}.Z ]; then
62 ext=".Z"
63 name="uncompress"
64 uncomp="uncompress -c"
65 elif [ -r $patchdir/${patch} ]; then
66 ext=""
67 name="plaintext"
68 uncomp="cat"
69 else
70 break
73 echo -n "Applying ${patch} (${name})... "
74 if $uncomp ${patchdir}/${patch}${ext} | patch -p1 -s -N -E -d $sourcedir
75 then
76 echo "done."
77 else
78 echo "failed. Clean up yourself."
79 break
81 if [ "`find $sourcedir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ]
82 then
83 echo "Aborting. Reject files found."
84 break
86 # Remove backup files
87 find $sourcedir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
89 if [ $stopvers = $FULLVERSION ]
90 then
91 echo "Stoping at $FULLVERSION as requested. Enjoy."
92 break
94 done