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
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} · 2 unmodified lines
54 67
55if [ "$1" == -h -o "$1" == --help -o ! -r "$sourcedir/Makefile" ]; then68if [ "$1" == -h -o "$1" == --help -o ! -r "$sourcedir/Makefile" ]; then
56cat << USAGE69cat << 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>.
@@ -72,6 +85,19 @@ do · 11 unmodified lines
72 esac;85 esac;
73done86done
74 87
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
75# ---------------------------------------------------------------------------101# ---------------------------------------------------------------------------
76# Find a file, first parameter is basename of file102# Find a file, first parameter is basename of file
77# it tries many compression mechanisms and sets variables to say how to get it103# it tries many compression mechanisms and sets variables to say how to get it
@@ -133,6 +159,28 @@ applyPatch () { · 55 unmodified lines
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, EXTRAVERSION184# 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 > $TMPFILE186grep -E "^(VERSION|PATCHLEVEL|SUBLEVEL|EXTRAVERSION)" $sourcedir/Makefile > $TMPFILE
@@ -160,53 +208,57 @@ then · 21 unmodified lines
160 EXTRAVER=$EXTRAVERSION208 EXTRAVER=$EXTRAVERSION
161 fi209 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"
164fi212fi
165 213
166#echo "stopvers=$stopvers"214#echo "stopvers=$stopvers"
167if [ $stopvers != "default" ]; then215if [ $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/"
171else219else
172 STOPSUBLEVEL=9999220 STOPSUBLEVEL=9999
173 STOPEXTRA=9999221 STOPEXTRA=9999
174fi222fi
175 223
176while : # incrementing SUBLEVEL (s in v.p.s)224# This all assumes a 2.6.x[.y] kernel tree.
177do225# Don't allow backwards/reverse patching.
178 if [ x$EXTRAVER != "x" ]; then226if [ $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 else232else
181 CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL"233 CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL"
182 fi234fi
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 ]; then254 if [ $stopvers == $CURRENTFULLVERSION ]; then
185 echo "Stopping at $CURRENTFULLVERSION base as requested."255 echo "Stopping at $CURRENTFULLVERSION base as requested."
186 break256 break
187 fi257 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)) ]; then263 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 · 1 unmodified line
214 fi266 fi
215 267
216 patch=patch-$FULLVERSION268 patch=patch-$FULLVERSION
217
218 # See if the file exists and find extension269 # See if the file exists and find extension
219 findFile $patchdir/${patch} || break270 findFile $patchdir/${patch} || noFile ${patch}
220 271
221 # Apply the patch and check all is OK272 # Apply the patch and check all is OK
222 applyPatch $patch || break273 applyPatch $patch || break
223done274done
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 ]; then297if [ x$gotac != x ]; then
227 # Out great user wants the -ac patches298 # Out great user wants the -ac patches