[PATCH] DVB: Update documentation and credits
[linux-2.6/history.git] / scripts / patch-kernel
blob3f316b6c4d9cd71ae3ec7080b226708cceb5b52d
1 #! /bin/sh
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.
6 # e.g.
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
39 # not to patch up.
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}
46 patchdir=${2-.}
47 stopvers=${3-imnotaversion}
49 if [ "$1" = -h -o "$1" = --help -o ! -r "$sourcedir/Makefile" ]; then
50 cat << USAGE
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.
54 USAGE
55 exit 1
58 # See if we have any -ac options
59 for PARM in $*
61 case $PARM in
62 -ac*)
63 gotac=$PARM;
65 esac;
66 done
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
71 findFile () {
72 filebase=$1;
74 if [ -r ${filebase}.gz ]; then
75 ext=".gz"
76 name="gzip"
77 uncomp="gunzip -dc"
78 elif [ -r ${filebase}.bz ]; then
79 ext=".bz"
80 name="bzip"
81 uncomp="bunzip -dc"
82 elif [ -r ${filebase}.bz2 ]; then
83 ext=".bz2"
84 name="bzip2"
85 uncomp="bunzip2 -dc"
86 elif [ -r ${filebase}.zip ]; then
87 ext=".zip"
88 name="zip"
89 uncomp="unzip -d"
90 elif [ -r ${filebase}.Z ]; then
91 ext=".Z"
92 name="uncompress"
93 uncomp="uncompress -c"
94 elif [ -r ${filebase} ]; then
95 ext=""
96 name="plaintext"
97 uncomp="cat"
98 else
99 return 1;
102 return 0;
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
109 applyPatch () {
110 echo -n "Applying $1 (${name})... "
111 if $uncomp ${patchdir}/$1${ext} | patch -p1 -s -N -E -d $sourcedir
112 then
113 echo "done."
114 else
115 echo "failed. Clean up yourself."
116 return 1;
118 if [ "`find $sourcedir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ]
119 then
120 echo "Aborting. Reject files found."
121 return 1;
123 # Remove backup files
124 find $sourcedir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
126 return 0;
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" ]
132 then
133 echo "unable to determine current kernel version" >&2
134 exit 1
137 echo "Current kernel version is $VERSION.$PATCHLEVEL.$SUBLEVEL${EXTRAVERSION}"
139 if [ x$EXTRAVERSION != "x" ]
140 then
141 echo "I'm sorry but patch-kernel can't work with a kernel source tree that is not a base version"
142 exit 1;
145 while :
147 CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL"
148 if [ $stopvers = $CURRENTFULLVERSION ]
149 then
150 echo "Stoping at $CURRENTFULLVERSION base as requested."
151 break
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
164 done
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" ]
170 then
171 # They want the latest version
172 HIGHESTPATCH=0
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 ]
180 then
181 HIGHESTPATCH=$ACVALUE
183 done
185 if [ $HIGHESTPATCH -ne 0 ]
186 then
187 findFile $patchdir/patch-${CURRENTFULLVERSION}-ac${HIGHESTPATCH} || break
188 applyPatch patch-${CURRENTFULLVERSION}-ac${HIGHESTPATCH}
189 else
190 echo "No ac patches found"
192 else
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."
196 exit 1
198 applyPatch patch-${CURRENTFULLVERSION}${gotac}