3 # kinstall.sh -- install updated kernel PPP driver in Linux kernel source
4 # Michael Callahan callahan@maths.ox.ac.uk 17 May 1995
6 # This script is complicated because we want to avoid installing a driver
7 # in a kernel if it won't work in that kernel. This means two things:
8 # 1) we check the version of the kernel and refuse to install if the
10 # 2) we check that the files already in the kernel aren't more recent
11 # than the one we're about to install.
12 # If either 1) or 2) occurs then we exit with an error message and don't
15 # In addition, we have to edit the Makefile in the drivers/net
16 # directory to add support for the ppp-comp compression option.
18 # Finally, we have to check that certain include file stubs in
19 # /usr/include/net exist, or else pppd won't compile. Phew!
21 LINUXSRC=/usr/src/linux
24 echo usage: $0 [linux-source-directory]
33 # Make sure we can find the kernel source
35 LINUXMK=$LINUXSRC/Makefile
37 if [ ! -r $LINUXMK -o ! -d $LINUXSRC/drivers ]; then
38 echo There appears to be no kernel source distribution in $LINUXSRC.
39 echo Give the top-level kernel source directory as the argument to
41 echo usage: $0 [linux-source-directory]
46 # Check that the kernel source Makefile includes the
47 # VERSION, PATCHLEVEL, SUBLEVEL version-numbering scheme
49 if [ `egrep '^VERSION|^PATCHLEVEL|^SUBLEVEL' $LINUXMK | wc -l` -ne 3 ]; then
50 echo You appear to have a very old kernel. You must upgrade.
51 echo It is recommended that you upgrade to the most recent 1.2.X kernel.
56 # Set the VERSION, PATCHLEVEL, SUBLEVEL variables
57 VERSION=`egrep '^VERSION' $LINUXMK | sed 's/[^0-9]//g'`
58 PATCHLEVEL=`egrep '^PATCHLEVEL' $LINUXMK | sed 's/[^0-9]//g'`
59 SUBLEVEL=`egrep '^SUBLEVEL' $LINUXMK | sed 's/[^0-9]//g'`
61 KERNEL=$VERSION.$PATCHLEVEL.$SUBLEVEL
64 # Pass judgement on the kernel version
65 if [ $VERSION -lt 2 ]; then
66 echo You appear to be running $KERNEL. There is no support for
67 echo kernels predating 2.0.0. It is recommended that you upgrade
68 echo to the most recent 2.0.x kernel.
73 echo Installing into kernel version $KERNEL in $LINUXSRC
76 echo "Notice to the user:"
78 echo "It is perfectly legal for this script to run without making any changes"
79 echo "to your system. This only means that the system currently contains the"
80 echo "necessary changes to support this package. Please do not attempt to"
81 echo "force this script to replace any file or make any patch. If you do so"
82 echo "then it is probable that you are actually putting older, buggier, code"
83 echo "over newer, fixed, code. Thank you."
85 echo Installing into kernel version $KERNEL in $LINUXSRC
89 # convenience function to exit if the last command failed
93 if [ $STATUS -ne 0 ]; then
94 echo "=== kinstall.sh exiting with failure status $STATUS"
100 # convenience function to compare two files marked with ==FILEVERSION
101 # version numbers; returns success if $1 is newer than $2
106 pat='==FILEVERSION[ \t]+[0-9]+[ \t]*=='
108 # Find the revision in the kernel
110 if [ -r $file1 ]; then
111 f1rev=`egrep "$pat" $file1 | head -1 | sed 's/[^0-9]//g'`
114 # Find the revision of the local file
116 if [ -r $file2 ]; then
117 f2rev=`egrep "$pat" $file2 | head -1 | sed 's/[^0-9]//g'`
120 # Make the strings the same length to avoid comparison problems
121 f1rev=`echo "0000000000"$f1rev | tail -c 10`
122 f2rev=`echo "0000000000"$f2rev | tail -c 10`
124 # Test the order of the two revisions
125 if [ $f1rev -ge $f2rev ]; then
137 if newer $1 $BASE; then
138 echo $1 is newer than $BASE, skipping
141 BACKUP=`echo $1 | sed 's/.c$/.old.c/;s/.h$/.old.h/'`
142 if [ -f $1 -a $BACKUP != $1 ]; then
143 echo Saving old $1 as `basename $BACKUP`
147 echo Installing new $1
155 # Patch the bad copies of the sys/types.h file
158 echo -n "Ensuring that sys/types.h includes sys/bitypes.h"
159 fgrep "<sys/bitypes.h>" /usr/include/sys/types.h >/dev/null
160 if [ ! "$?" = "0" ]; then
162 rm -f /usr/include/sys/types.h.rej
163 (cd /usr/include/sys; patch -p0 -f -F30 -s) <patch-include
164 if [ ! "$?" = "0" ]; then
165 touch /usr/include/sys/types.h.rej
167 if [ -f /usr/include/sys/types.h.rej ]; then
168 echo " --- FAILED!!!! You must fix this yourself!"
169 echo "The /usr/include/sys/types.h file must include the file"
170 echo "<sys/bitypes.h> after it includes the <linux/types.h> file."
171 echo -n "Please change it so that it does."
172 rm -f /usr/include/sys/types.h.rej
174 echo -n " -- completed"
177 echo -n " -- skipping"
183 # Check for the root user
187 if [ $my_uid -ne 0 ]; then
189 echo "********************************************************************"
190 echo "Hello, $my_name. Since you are not running as the root user, it"
191 echo "is possible that this script will fail to install the needed files."
192 echo "If this happens then please use the root account and re-execute the"
193 echo "'make kernel' command. (This script is paused for 10 seconds.)"
194 echo "********************************************************************"
203 echo "Notice to the user:"
205 echo "It is perfectly legal for this script to run without making any changes"
206 echo "to your system. This means that the system currently contains the"
207 echo "necessary changes to support this package. Please do not attempt to"
208 echo "force this script to replace any file nor make any patch. If you do so"
209 echo "then it is probable that you are actually putting older, buggier, code"
210 echo "over the newer, fixed, code. Thank you."
212 echo Installing into kernel version $KERNEL in $LINUXSRC
215 if [ -f $LINUXSRC/drivers/net/ppp.h ]; then
216 echo Moving old $LINUXSRC/drivers/net/ppp.h file out of the way
217 mv $LINUXSRC/drivers/net/ppp.h $LINUXSRC/drivers/net/ppp.old.h
221 for FILE in $LINUXSRC/drivers/net/bsd_comp.c \
222 $LINUXSRC/drivers/net/ppp_deflate.c \
223 $LINUXSRC/drivers/net/zlib.c \
224 $LINUXSRC/drivers/net/zlib.h \
225 $LINUXSRC/include/linux/if_ppp.h \
226 $LINUXSRC/include/linux/if_pppvar.h \
227 $LINUXSRC/include/linux/ppp-comp.h \
228 $LINUXSRC/include/linux/ppp_defs.h
233 installfile $LINUXSRC/drivers/net/ppp.c yes
235 for FILE in if.h if_arp.h route.h
237 if [ ! -f $LINUXSRC/include/linux/$FILE ]; then
238 echo Installing new $1
239 cp $FILE $LINUXSRC/include/linux/$FILE
241 touch $LINUXSRC/include/linux/$FILE
246 echo -n 'Adding BSD compression module to drivers makefile...'
247 NETMK=$LINUXSRC/drivers/net/Makefile
248 fgrep bsd_comp.o $NETMK >/dev/null
249 if [ ! "$?" = "0" ]; then
250 if [ -f $NETMK.orig ]; then
251 mv $NETMK.orig $NETMK
253 sed 's/ppp.o$/ppp.o bsd_comp.o/g' <$NETMK >$NETMK.temp
256 mv $NETMK $NETMK.orig
259 mv $NETMK.temp $NETMK
262 echo -n '(already there--skipping)'
265 echo -n 'Adding Deflate compression module to drivers makefile...'
266 NETMK=$LINUXSRC/drivers/net/Makefile
267 fgrep ppp_deflate.o $NETMK >/dev/null
268 if [ ! "$?" = "0" ]; then
270 sed 's/bsd_comp.o$/bsd_comp.o ppp_deflate.o/g' <$NETMK >$NETMK.temp
273 mv $NETMK $NETMK.orig
276 mv $NETMK.temp $NETMK
279 echo -n '(already there--skipping)'
284 # install header stub files in /usr/include/net
286 for FILE in if_ppp.h \
294 if [ ! -f /usr/include/net/$FILE ]; then
295 echo Installing stub include file in /usr/include/net/$FILE
296 echo "#include <linux/$FILE>" > /usr/include/net/$FILE
298 chown 0:0 /usr/include/net/$FILE
300 chmod 444 /usr/include/net/$FILE
302 touch /usr/include/net/$FILE
310 if [ ! -f /usr/include/netinet/$FILE ]; then
311 echo Installing stub include file in /usr/include/netinet/$FILE
312 if [ ! -f $LINUXSRC/include/linux/$FILE ]; then
313 echo "#include \"$LINUXSRC/net/inet/$FILE\"" >/usr/include/netinet/$FILE
315 echo "#include <linux/$FILE>" > /usr/include/netinet/$FILE
317 chown 0:0 /usr/include/netinet/$FILE
319 chmod 444 /usr/include/netinet/$FILE
321 touch /usr/include/netinet/$FILE
328 echo "Kernel driver files installation done."