1 |
1275 |
phoenix |
#! /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
|
20 |
|
|
#
|
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.
|
26 |
|
|
#
|
27 |
|
|
# Nick Holloway , 2nd January 1995.
|
28 |
|
|
#
|
29 |
|
|
# Added support for handling multiple types of compression. What includes
|
30 |
|
|
# gzip, bzip, bzip2, zip, compress, and plaintext.
|
31 |
|
|
#
|
32 |
|
|
# Adam Sulmicki , 1st January 1997.
|
33 |
|
|
#
|
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 , 11th December 1999.
|
37 |
|
|
|
38 |
|
|
# Fixed previous patch so that if we are already at the correct version
|
39 |
|
|
# not to patch up.
|
40 |
|
|
#
|
41 |
|
|
# Added -ac option, use -ac or -ac9 (say) to stop at a particular version
|
42 |
|
|
# Dave Gilbert , 29th September 2001.
|
43 |
|
|
|
44 |
|
|
# Set directories from arguments, or use defaults.
|
45 |
|
|
sourcedir=${1-/usr/src/linux}
|
46 |
|
|
patchdir=${2-.}
|
47 |
|
|
stopvers=${3-imnotaversion}
|
48 |
|
|
|
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
|
56 |
|
|
fi
|
57 |
|
|
|
58 |
|
|
# See if we have any -ac options
|
59 |
|
|
for PARM in $*
|
60 |
|
|
do
|
61 |
|
|
case $PARM in
|
62 |
|
|
-ac*)
|
63 |
|
|
gotac=$PARM;
|
64 |
|
|
|
65 |
|
|
esac;
|
66 |
|
|
done
|
67 |
|
|
|
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;
|
73 |
|
|
|
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;
|
100 |
|
|
fi
|
101 |
|
|
|
102 |
|
|
return 0;
|
103 |
|
|
}
|
104 |
|
|
|
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
|
108 |
|
|
|
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;
|
117 |
|
|
fi
|
118 |
|
|
if [ "`find $sourcedir/ '(' -name '*.rej' -o -name '.*.rej' ')' -print`" ]
|
119 |
|
|
then
|
120 |
|
|
echo "Aborting. Reject files found."
|
121 |
|
|
return 1;
|
122 |
|
|
fi
|
123 |
|
|
# Remove backup files
|
124 |
|
|
find $sourcedir/ '(' -name '*.orig' -o -name '.*.orig' ')' -exec rm -f {} \;
|
125 |
|
|
|
126 |
|
|
return 0;
|
127 |
|
|
}
|
128 |
|
|
|
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
|
135 |
|
|
fi
|
136 |
|
|
|
137 |
|
|
echo "Current kernel version is $VERSION.$PATCHLEVEL.$SUBLEVEL${EXTRAVERSION}"
|
138 |
|
|
|
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;
|
143 |
|
|
fi
|
144 |
|
|
|
145 |
|
|
while :
|
146 |
|
|
do
|
147 |
|
|
CURRENTFULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL"
|
148 |
|
|
if [ $stopvers = $CURRENTFULLVERSION ]
|
149 |
|
|
then
|
150 |
|
|
echo "Stoping at $CURRENTFULLVERSION base as requested."
|
151 |
|
|
break
|
152 |
|
|
fi
|
153 |
|
|
|
154 |
|
|
SUBLEVEL=`expr $SUBLEVEL + 1`
|
155 |
|
|
FULLVERSION="$VERSION.$PATCHLEVEL.$SUBLEVEL"
|
156 |
|
|
|
157 |
|
|
patch=patch-$FULLVERSION
|
158 |
|
|
|
159 |
|
|
# See if the file exists and find extension
|
160 |
|
|
findFile $patchdir/${patch} || break
|
161 |
|
|
|
162 |
|
|
# Apply the patch and check all is OK
|
163 |
|
|
applyPatch $patch || break
|
164 |
|
|
done
|
165 |
|
|
|
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*\.*
|
174 |
|
|
do
|
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
|
178 |
|
|
|
179 |
|
|
if [ $ACVALUE -gt $HIGHESTPATCH ]
|
180 |
|
|
then
|
181 |
|
|
HIGHESTPATCH=$ACVALUE
|
182 |
|
|
fi
|
183 |
|
|
done
|
184 |
|
|
|
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"
|
191 |
|
|
fi
|
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
|
197 |
|
|
}
|
198 |
|
|
applyPatch patch-${CURRENTFULLVERSION}${gotac}
|
199 |
|
|
fi
|
200 |
|
|
fi
|
201 |
|
|
|
202 |
|
|
|