History

[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).

Randy.Dunlap committed 21 years ago

Commit 19221631 parent 64f562c1 file · +101 −30Browse files

Showing the changes to scripts/patch-kernel (1 of 1 file). Show all

Unified · Split

scripts/patch-kernel+101−30
@@ -46,6 +46,19 @@ · 45 unmodified lines
4646 # fix some whitespace damage;
4747 # be smarter about stopping when current version is larger than requested;
4848 # 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
4962
5063 # Set directories from arguments, or use defaults.
5164 sourcedir=${1-/usr/src/linux}
@@ -54,7 +67,7 @@ stopvers=${3-default} · 2 unmodified lines
5467
5568 if [ "$1" == -h -o "$1" == --help -o ! -r "$sourcedir/Makefile" ]; then
5669 cat << USAGE
57−usage: patch-kernel [-h] [ sourcedir [ patchdir [ stopversion ] [ -acxx ] ] ]
70+usage: $PNAME [-h] [ sourcedir [ patchdir [ stopversion ] [ -acxx ] ] ]
5871 source directory defaults to /usr/src/linux,
5972 patch directory defaults to the current directory,
6073 stopversion defaults to <all in patchdir>.
@@ -72,6 +85,19 @@ do · 11 unmodified lines
7285 esac;
7386 done
7487
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+
75101 # ---------------------------------------------------------------------------
76102 # Find a file, first parameter is basename of file
77103 # it tries many compression mechanisms and sets variables to say how to get it
@@ -133,6 +159,28 @@ applyPatch () { · 55 unmodified lines
133159 return 0;
134160 }
135161
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+
136184 # set current VERSION, PATCHLEVEL, SUBLEVEL, EXTRAVERSION
137185 TMPFILE=`mktemp .tmpver.XXXXXX` || { echo "cannot make temp file" ; exit 1; }
138186 grep -E "^(VERSION|PATCHLEVEL|SUBLEVEL|EXTRAVERSION)" $sourcedir/Makefile > $TMPFILE
@@ -160,53 +208,57 @@ then · 21 unmodified lines
160208 EXTRAVER=$EXTRAVERSION
161209 fi
162210 EXTRAVER=${EXTRAVER%%[[:punct:]]*}
163− #echo "patch-kernel: changing EXTRAVERSION from $EXTRAVERSION to $EXTRAVER"
211+ #echo "$PNAME: changing EXTRAVERSION from $EXTRAVERSION to $EXTRAVER"
164212 fi
165213
166214 #echo "stopvers=$stopvers"
167215 if [ $stopvers != "default" ]; then
168216 STOPSUBLEVEL=`echo $stopvers | cut -d. -f3`
169217 STOPEXTRA=`echo $stopvers | cut -d. -f4`
170− #echo "STOPSUBLEVEL=$STOPSUBLEVEL, STOPEXTRA=$STOPEXTRA"
218+ #echo "#___STOPSUBLEVEL=/$STOPSUBLEVEL/, STOPEXTRA=/$STOPEXTRA/"
171219 else
172220 STOPSUBLEVEL=9999
173221 STOPEXTRA=9999
174222 fi
175223
176−while : # incrementing SUBLEVEL (s in v.p.s)
177−do
178− if [ x$EXTRAVER != "x" ]; then
224+# This all assumes a 2.6.x[.y] kernel tree.
225+# Don't allow backwards/reverse patching.
226+if [ $STOPSUBLEVEL -lt $SUBLEVEL ]; then
227+ backwards
228+fi
229+
230+if [ x$EXTRAVER != "x" ]; then
179231 CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL.$EXTRAVER"
180− else
232+else
181233 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
183242
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=
184254 if [ $stopvers == $CURRENTFULLVERSION ]; then
185255 echo "Stopping at $CURRENTFULLVERSION base as requested."
186256 break
187257 fi
188258
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=
207259 SUBLEVEL=$((SUBLEVEL + 1))
208260 FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL"
209− #echo "___ trying $FULLVERSION ___"
261+ #echo "#___ trying $FULLVERSION ___"
210262
211263 if [ $((SUBLEVEL)) -gt $((STOPSUBLEVEL)) ]; then
212264 echo "Stopping since sublevel ($SUBLEVEL) is beyond stop-sublevel ($STOPSUBLEVEL)"
@@ -214,14 +266,33 @@ do · 1 unmodified line
214266 fi
215267
216268 patch=patch-$FULLVERSION
217−
218269 # See if the file exists and find extension
219− findFile $patchdir/${patch} || break
270+ findFile $patchdir/${patch} || noFile ${patch}
220271
221272 # Apply the patch and check all is OK
222273 applyPatch $patch || break
223274 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
225296
226297 if [ x$gotac != x ]; then
227298 # Out great user wants the -ac patches