aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/patch-kernel
diff options
context:
space:
mode:
authorRandy.Dunlap <rddunlap@osdl.org>2005-05-05 19:15:43 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-05-05 19:36:40 -0400
commit1922163c8dfe717c089bdcc18ade4a65350a09c8 (patch)
treebe95a8f0df16e71f41dce26e8e530a900a4173a2 /scripts/patch-kernel
parent64f562c6df3cfc5d1b2b4bdbcb7951457df9c237 (diff)
[PATCH] patch-kernel: support non-incremental 2.6.x.y 'stable' patches
Add better support for (non-incremental) 2.6.x.y patches; If an ending version number if not specified, the script automatically increments the SUBLEVEL (x in 2.6.x.y) until no more patch files are found; however, EXTRAVERSION (y in 2.6.x.y) is never automatically incremented but must be specified fully. patch-kernel does not normally support reverse patching, but does so when applying EXTRAVERSION (x.y) patches, so that moving from 2.6.11.y to 2.6.11.z is easy and handled by the script (reverse 2.6.11.y and apply 2.6.11.z). Signed-off-by: Randy Dunlap <rddunlap@osdl.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'scripts/patch-kernel')
-rwxr-xr-xscripts/patch-kernel131
1 files changed, 101 insertions, 30 deletions
diff --git a/scripts/patch-kernel b/scripts/patch-kernel
index 43af01075612..f2d47ca9c8fa 100755
--- a/scripts/patch-kernel
+++ b/scripts/patch-kernel
@@ -46,6 +46,19 @@
46# fix some whitespace damage; 46# fix some whitespace damage;
47# be smarter about stopping when current version is larger than requested; 47# be smarter about stopping when current version is larger than requested;
48# Randy Dunlap <rddunlap@osdl.org>, 2004-AUG-18. 48# Randy Dunlap <rddunlap@osdl.org>, 2004-AUG-18.
49#
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.
55#
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 <rddunlap@osdl.org>, 2005-APR-08.
60
61PNAME=patch-kernel
49 62
50# Set directories from arguments, or use defaults. 63# Set directories from arguments, or use defaults.
51sourcedir=${1-/usr/src/linux} 64sourcedir=${1-/usr/src/linux}
@@ -54,7 +67,7 @@ stopvers=${3-default}
54 67
55if [ "$1" == -h -o "$1" == --help -o ! -r "$sourcedir/Makefile" ]; then 68if [ "$1" == -h -o "$1" == --help -o ! -r "$sourcedir/Makefile" ]; then
56cat << USAGE 69cat << USAGE
57usage: patch-kernel [-h] [ sourcedir [ patchdir [ stopversion ] [ -acxx ] ] ] 70usage: $PNAME [-h] [ sourcedir [ patchdir [ stopversion ] [ -acxx ] ] ]
58 source directory defaults to /usr/src/linux, 71 source directory defaults to /usr/src/linux,
59 patch directory defaults to the current directory, 72 patch directory defaults to the current directory,
60 stopversion defaults to <all in patchdir>. 73 stopversion defaults to <all in patchdir>.
@@ -73,6 +86,19 @@ do
73done 86done
74 87
75# --------------------------------------------------------------------------- 88# ---------------------------------------------------------------------------
89# arg1 is filename
90noFile () {
91 echo "cannot find patch file: ${patch}"
92 exit 1
93}
94
95# ---------------------------------------------------------------------------
96backwards () {
97 echo "$PNAME does not support reverse patching"
98 exit 1
99}
100
101# ---------------------------------------------------------------------------
76# Find a file, first parameter is basename of file 102# Find a file, first parameter is basename of file
77# it tries many compression mechanisms and sets variables to say how to get it 103# it tries many compression mechanisms and sets variables to say how to get it
78findFile () { 104findFile () {
@@ -133,6 +159,28 @@ applyPatch () {
133 return 0; 159 return 0;
134} 160}
135 161
162# ---------------------------------------------------------------------------
163# arg1 is patch filename
164reversePatch () {
165 echo -n "Reversing $1 (${name}) ... "
166 if $uncomp ${patchdir}/"$1"${ext} | patch -p1 -Rs -N -E -d $sourcedir
167 then
168 echo "done."
169 else
170 echo "failed. Clean it up."
171 exit 1
172 fi
173 if [ "`find $sourcedir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ]
174 then
175 echo "Aborting. Reject files found."
176 return 1
177 fi
178 # Remove backup files
179 find $sourcedir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
180
181 return 0
182}
183
136# set current VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION 184# set current VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION
137TMPFILE=`mktemp .tmpver.XXXXXX` || { echo "cannot make temp file" ; exit 1; } 185TMPFILE=`mktemp .tmpver.XXXXXX` || { echo "cannot make temp file" ; exit 1; }
138grep -E "^(VERSION|PATCHLEVEL|SUBLEVEL|EXTRAVERSION)" $sourcedir/Makefile > $TMPFILE 186grep -E "^(VERSION|PATCHLEVEL|SUBLEVEL|EXTRAVERSION)" $sourcedir/Makefile > $TMPFILE
@@ -160,53 +208,57 @@ then
160 EXTRAVER=$EXTRAVERSION 208 EXTRAVER=$EXTRAVERSION
161 fi 209 fi
162 EXTRAVER=${EXTRAVER%%[[:punct:]]*} 210 EXTRAVER=${EXTRAVER%%[[:punct:]]*}
163 #echo "patch-kernel: changing EXTRAVERSION from $EXTRAVERSION to $EXTRAVER" 211 #echo "$PNAME: changing EXTRAVERSION from $EXTRAVERSION to $EXTRAVER"
164fi 212fi
165 213
166#echo "stopvers=$stopvers" 214#echo "stopvers=$stopvers"
167if [ $stopvers != "default" ]; then 215if [ $stopvers != "default" ]; then
168 STOPSUBLEVEL=`echo $stopvers | cut -d. -f3` 216 STOPSUBLEVEL=`echo $stopvers | cut -d. -f3`
169 STOPEXTRA=`echo $stopvers | cut -d. -f4` 217 STOPEXTRA=`echo $stopvers | cut -d. -f4`
170 #echo "STOPSUBLEVEL=$STOPSUBLEVEL, STOPEXTRA=$STOPEXTRA" 218 #echo "#___STOPSUBLEVEL=/$STOPSUBLEVEL/, STOPEXTRA=/$STOPEXTRA/"
171else 219else
172 STOPSUBLEVEL=9999 220 STOPSUBLEVEL=9999
173 STOPEXTRA=9999 221 STOPEXTRA=9999
174fi 222fi
175 223
176while : # incrementing SUBLEVEL (s in v.p.s) 224# This all assumes a 2.6.x[.y] kernel tree.
177do 225# Don't allow backwards/reverse patching.
178 if [ x$EXTRAVER != "x" ]; then 226if [ $STOPSUBLEVEL -lt $SUBLEVEL ]; then
227 backwards
228fi
229
230if [ x$EXTRAVER != "x" ]; then
179 CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL.$EXTRAVER" 231 CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL.$EXTRAVER"
180 else 232else
181 CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" 233 CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL"
182 fi 234fi
235
236if [ x$EXTRAVER != "x" ]; then
237 echo "backing up to: $VERSION.$PATCHLEVEL.$SUBLEVEL"
238 patch="patch-${CURRENTFULLVERSION}"
239 findFile $patchdir/${patch} || noFile ${patch}
240 reversePatch ${patch} || exit 1
241fi
183 242
243# now current is 2.6.x, with no EXTRA applied,
244# so update to target SUBLEVEL (2.6.SUBLEVEL)
245# and then to target EXTRAVER (2.6.SUB.EXTRAVER) if requested.
246# If not ending sublevel is specified, it is incremented until
247# no further sublevels are found.
248
249if [ $STOPSUBLEVEL -gt $SUBLEVEL ]; then
250while : # incrementing SUBLEVEL (s in v.p.s)
251do
252 CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL"
253 EXTRAVER=
184 if [ $stopvers == $CURRENTFULLVERSION ]; then 254 if [ $stopvers == $CURRENTFULLVERSION ]; then
185 echo "Stopping at $CURRENTFULLVERSION base as requested." 255 echo "Stopping at $CURRENTFULLVERSION base as requested."
186 break 256 break
187 fi 257 fi
188 258
189 while : # incrementing EXTRAVER (x in v.p.s.x)
190 do
191 EXTRAVER=$((EXTRAVER + 1))
192 FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL.$EXTRAVER"
193 #echo "... trying $FULLVERSION ..."
194
195 patch=patch-$FULLVERSION
196
197 # See if the file exists and find extension
198 findFile $patchdir/${patch} || break
199
200 # Apply the patch and check all is OK
201 applyPatch $patch || break
202
203 continue 2
204 done
205
206 EXTRAVER=
207 SUBLEVEL=$((SUBLEVEL + 1)) 259 SUBLEVEL=$((SUBLEVEL + 1))
208 FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" 260 FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL"
209 #echo "___ trying $FULLVERSION ___" 261 #echo "#___ trying $FULLVERSION ___"
210 262
211 if [ $((SUBLEVEL)) -gt $((STOPSUBLEVEL)) ]; then 263 if [ $((SUBLEVEL)) -gt $((STOPSUBLEVEL)) ]; then
212 echo "Stopping since sublevel ($SUBLEVEL) is beyond stop-sublevel ($STOPSUBLEVEL)" 264 echo "Stopping since sublevel ($SUBLEVEL) is beyond stop-sublevel ($STOPSUBLEVEL)"
@@ -214,14 +266,33 @@ do
214 fi 266 fi
215 267
216 patch=patch-$FULLVERSION 268 patch=patch-$FULLVERSION
217
218 # See if the file exists and find extension 269 # See if the file exists and find extension
219 findFile $patchdir/${patch} || break 270 findFile $patchdir/${patch} || noFile ${patch}
220 271
221 # Apply the patch and check all is OK 272 # Apply the patch and check all is OK
222 applyPatch $patch || break 273 applyPatch $patch || break
223done 274done
224#echo "base all done" 275#echo "#___sublevel all done"
276fi
277
278# There is no incremental searching for extraversion...
279if [ "$STOPEXTRA" != "" ]; then
280while : # just to allow break
281do
282# apply STOPEXTRA directly (not incrementally) (x in v.p.s.x)
283 FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL.$STOPEXTRA"
284 #echo "#... trying $FULLVERSION ..."
285 patch=patch-$FULLVERSION
286
287 # See if the file exists and find extension
288 findFile $patchdir/${patch} || noFile ${patch}
289
290 # Apply the patch and check all is OK
291 applyPatch $patch || break
292 #echo "#___extraver all done"
293 break
294done
295fi
225 296
226if [ x$gotac != x ]; then 297if [ x$gotac != x ]; then
227 # Out great user wants the -ac patches 298 # Out great user wants the -ac patches