diff options
author | Randy.Dunlap <rddunlap@osdl.org> | 2005-05-05 19:15:43 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-05-05 19:36:40 -0400 |
commit | 1922163c8dfe717c089bdcc18ade4a65350a09c8 (patch) | |
tree | be95a8f0df16e71f41dce26e8e530a900a4173a2 /scripts | |
parent | 64f562c6df3cfc5d1b2b4bdbcb7951457df9c237 (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')
-rwxr-xr-x | scripts/patch-kernel | 131 |
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 | |||
61 | PNAME=patch-kernel | ||
49 | 62 | ||
50 | # Set directories from arguments, or use defaults. | 63 | # Set directories from arguments, or use defaults. |
51 | sourcedir=${1-/usr/src/linux} | 64 | sourcedir=${1-/usr/src/linux} |
@@ -54,7 +67,7 @@ stopvers=${3-default} | |||
54 | 67 | ||
55 | if [ "$1" == -h -o "$1" == --help -o ! -r "$sourcedir/Makefile" ]; then | 68 | if [ "$1" == -h -o "$1" == --help -o ! -r "$sourcedir/Makefile" ]; then |
56 | cat << USAGE | 69 | cat << USAGE |
57 | usage: patch-kernel [-h] [ sourcedir [ patchdir [ stopversion ] [ -acxx ] ] ] | 70 | usage: $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 | |||
73 | done | 86 | done |
74 | 87 | ||
75 | # --------------------------------------------------------------------------- | 88 | # --------------------------------------------------------------------------- |
89 | # arg1 is filename | ||
90 | noFile () { | ||
91 | echo "cannot find patch file: ${patch}" | ||
92 | exit 1 | ||
93 | } | ||
94 | |||
95 | # --------------------------------------------------------------------------- | ||
96 | backwards () { | ||
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 |
78 | findFile () { | 104 | findFile () { |
@@ -133,6 +159,28 @@ applyPatch () { | |||
133 | return 0; | 159 | return 0; |
134 | } | 160 | } |
135 | 161 | ||
162 | # --------------------------------------------------------------------------- | ||
163 | # arg1 is patch filename | ||
164 | reversePatch () { | ||
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 |
137 | TMPFILE=`mktemp .tmpver.XXXXXX` || { echo "cannot make temp file" ; exit 1; } | 185 | TMPFILE=`mktemp .tmpver.XXXXXX` || { echo "cannot make temp file" ; exit 1; } |
138 | grep -E "^(VERSION|PATCHLEVEL|SUBLEVEL|EXTRAVERSION)" $sourcedir/Makefile > $TMPFILE | 186 | grep -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" |
164 | fi | 212 | fi |
165 | 213 | ||
166 | #echo "stopvers=$stopvers" | 214 | #echo "stopvers=$stopvers" |
167 | if [ $stopvers != "default" ]; then | 215 | if [ $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/" |
171 | else | 219 | else |
172 | STOPSUBLEVEL=9999 | 220 | STOPSUBLEVEL=9999 |
173 | STOPEXTRA=9999 | 221 | STOPEXTRA=9999 |
174 | fi | 222 | fi |
175 | 223 | ||
176 | while : # incrementing SUBLEVEL (s in v.p.s) | 224 | # This all assumes a 2.6.x[.y] kernel tree. |
177 | do | 225 | # Don't allow backwards/reverse patching. |
178 | if [ x$EXTRAVER != "x" ]; then | 226 | if [ $STOPSUBLEVEL -lt $SUBLEVEL ]; then |
227 | backwards | ||
228 | fi | ||
229 | |||
230 | if [ x$EXTRAVER != "x" ]; then | ||
179 | CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL.$EXTRAVER" | 231 | CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL.$EXTRAVER" |
180 | else | 232 | else |
181 | CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" | 233 | CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL" |
182 | fi | 234 | fi |
235 | |||
236 | if [ 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 | ||
241 | fi | ||
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 | |||
249 | if [ $STOPSUBLEVEL -gt $SUBLEVEL ]; then | ||
250 | while : # incrementing SUBLEVEL (s in v.p.s) | ||
251 | do | ||
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 |
223 | done | 274 | done |
224 | #echo "base all done" | 275 | #echo "#___sublevel all done" |
276 | fi | ||
277 | |||
278 | # There is no incremental searching for extraversion... | ||
279 | if [ "$STOPEXTRA" != "" ]; then | ||
280 | while : # just to allow break | ||
281 | do | ||
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 | ||
294 | done | ||
295 | fi | ||
225 | 296 | ||
226 | if [ x$gotac != x ]; then | 297 | if [ x$gotac != x ]; then |
227 | # Out great user wants the -ac patches | 298 | # Out great user wants the -ac patches |