]> git.ozlabs.org Git - ppp.git/blob - linux/kinstall.sh
23ae2d128db5de7083958841c5a6ba2dce3dcc79
[ppp.git] / linux / kinstall.sh
1 #!/bin/sh
2 #
3 #  kinstall.sh -- install updated kernel PPP driver in Linux kernel source
4 #     Michael Callahan callahan@maths.ox.ac.uk 17 May 1995
5 #
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
9 #       kernel is too old;
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
13 #  touch anything.
14 #
15 #  In addition, we have to edit the Makefile in the drivers/net
16 #  directory to add support for the ppp-comp compression option.
17 #
18 #  Finally, we have to check that certain include file stubs in
19 #  /usr/include/net exist, or else pppd won't compile.  Phew!
20
21 LINUXSRC=/usr/src/linux
22
23 if [ $# -gt 1 ]; then
24    echo usage: $0 [linux-source-directory]
25    exit 1
26 fi
27
28 if [ $# -eq 1 ]; then
29    LINUXSRC=$1
30 fi
31
32 #
33 #  Make sure we can find the kernel source
34
35 LINUXMK=$LINUXSRC/Makefile
36
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
40   echo this script.
41   echo usage: $0 [linux-source-directory]
42   exit 1
43 fi
44
45 #
46 #  Check that the kernel source Makefile includes the 
47 #    VERSION, PATCHLEVEL, SUBLEVEL version-numbering scheme
48 #    introduced in 1.0.1
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.
52   exit 1
53 fi
54
55 #
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'`
60
61 KERNEL=$VERSION.$PATCHLEVEL.$SUBLEVEL
62
63 #
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.
69     exit 1
70 fi
71
72 echo
73 echo Installing into kernel version $KERNEL in $LINUXSRC
74 echo
75
76 echo "Notice to the user:"
77 echo
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."
84 echo
85 echo Installing into kernel version $KERNEL in $LINUXSRC
86 echo
87
88 #
89 # convenience function to exit if the last command failed
90
91 bombiffailed () {
92   STATUS=$?
93   if [ $STATUS -ne 0 ]; then
94     echo "=== kinstall.sh exiting with failure status $STATUS"
95     exit $STATUS
96   fi
97 }
98
99 #
100 # convenience function to compare two files marked with ==FILEVERSION
101 # version numbers; returns success if $1 is newer than $2
102
103 newer () {
104   file1=$1
105   file2=$2
106   pat='==FILEVERSION[ \t]+[0-9]+[ \t]*=='
107
108   # Find the revision in the kernel
109   f1rev=""
110   if [ -r $file1 ]; then
111     f1rev=`egrep "$pat" $file1 | head -1 | sed 's/[^0-9]//g'`
112   fi
113
114   # Find the revision of the local file
115   f2rev=""
116   if [ -r $file2 ]; then
117     f2rev=`egrep "$pat" $file2 | head -1 | sed 's/[^0-9]//g'`
118   fi
119
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`
123
124   # Test the order of the two revisions
125   if [ $f1rev -ge $f2rev ]; then
126     true ; return
127   fi
128
129   false ; return
130 }
131
132 #
133 #  Change the USE_SKB_PROTOCOL for correct operation on 1.3.x
134 update_ppp () {
135   return
136 }
137
138 #
139 #  Install the files.
140
141 installfile () {
142   BASE=`basename $1`
143   if newer $1 $BASE; then
144     echo $1 is newer than $BASE, skipping
145     return 0
146   fi
147   BACKUP=`echo $1 | sed 's/.c$/.old.c/;s/.h$/.old.h/'`
148   if [ -f $1 -a $BACKUP != $1 ]; then
149     echo Saving old $1 as `basename $BACKUP`
150     mv $1 $BACKUP
151     bombiffailed
152   fi
153   echo Installing new $1
154   cp $BASE $1
155   bombiffailed
156   touch $1
157   bombiffailed
158   if [ "$2" = "yes" ]; then
159     update_ppp
160   fi
161 }
162
163 #
164 # Patch the bad copies of the sys/types.h file
165 #
166 patch_include () {
167   echo -n "Ensuring that sys/types.h includes sys/bitypes.h"
168   fgrep "<sys/bitypes.h>" /usr/include/sys/types.h >/dev/null
169   if [ ! "$?" = "0" ]; then
170     echo -n '.'
171     rm -f /usr/include/sys/types.h.rej
172     (cd /usr/include/sys; patch -p0 -f -F30 -s) <patch-include
173     if [ ! "$?" = "0" ]; then
174        touch /usr/include/sys/types.h.rej
175     fi
176     if [ -f /usr/include/sys/types.h.rej ]; then
177        echo " --- FAILED!!!! You must fix this yourself!"
178        echo "The /usr/include/sys/types.h file must include the file"
179        echo "<sys/bitypes.h> after it includes the <linux/types.h> file."
180        echo -n "Please change it so that it does."
181        rm -f /usr/include/sys/types.h.rej
182     else
183        echo -n " -- completed"
184     fi
185   else
186     echo -n " -- skipping"
187   fi
188   echo ""
189 }
190
191 #
192 # Check for the root user
193 test_root() {
194   my_uid=`id -u`
195   my_name=`id -u -n`
196   if [ $my_uid -ne 0 ]; then
197     echo
198     echo "********************************************************************"
199     echo "Hello, $my_name. Since you are not running as the root user, it"
200     echo "is possible that this script will fail to install the needed files."
201     echo "If this happens then please use the root account and re-execute the"
202     echo "'make kernel' command.  (This script is paused for 10 seconds.)"
203     echo "********************************************************************"
204     echo
205     sleep 10s
206   fi
207 }
208
209 test_root
210
211 echo
212 echo "Notice to the user:"
213 echo
214 echo "It is perfectly legal for this script to run without making any changes"
215 echo "to your system. This means that the system currently contains the"
216 echo "necessary changes to support this package. Please do not attempt to"
217 echo "force this script to replace any file nor make any patch. If you do so"
218 echo "then it is probable that you are actually putting older, buggier, code"
219 echo "over the newer, fixed, code. Thank you."
220 echo
221 echo Installing into kernel version $KERNEL in $LINUXSRC
222 echo
223
224 if [ -f $LINUXSRC/drivers/net/ppp.h ]; then
225   echo Moving old $LINUXSRC/drivers/net/ppp.h file out of the way
226   mv $LINUXSRC/drivers/net/ppp.h $LINUXSRC/drivers/net/ppp.old.h
227   bombiffailed
228 fi
229
230 for FILE in $LINUXSRC/drivers/net/bsd_comp.c \
231             $LINUXSRC/drivers/net/ppp_deflate.c \
232             $LINUXSRC/drivers/net/zlib.c \
233             $LINUXSRC/drivers/net/zlib.h \
234             $LINUXSRC/include/linux/if_ppp.h \
235             $LINUXSRC/include/linux/if_pppvar.h \
236             $LINUXSRC/include/linux/ppp-comp.h \
237             $LINUXSRC/include/linux/ppp_defs.h
238   do
239   installfile $FILE no
240 done
241
242 installfile $LINUXSRC/drivers/net/ppp.c yes
243
244 for FILE in if.h if_arp.h route.h
245   do
246   if [ ! -f $LINUXSRC/include/linux/$FILE ]; then
247     echo Installing new $1
248     cp $FILE $LINUXSRC/include/linux/$FILE
249     bombiffailed
250     touch $LINUXSRC/include/linux/$FILE
251     bombiffailed
252   fi
253 done
254
255 echo -n 'Adding BSD compression module to drivers makefile...'
256 NETMK=$LINUXSRC/drivers/net/Makefile
257 fgrep bsd_comp.o $NETMK >/dev/null
258 if [ ! "$?" = "0" ]; then
259    if [ -f $NETMK.orig ]; then
260       mv $NETMK.orig $NETMK
261    fi
262    sed 's/ppp.o$/ppp.o bsd_comp.o/g' <$NETMK >$NETMK.temp
263    bombiffailed
264    echo -n '.'
265    mv $NETMK $NETMK.orig
266    bombiffailed
267    echo -n '.'
268    mv $NETMK.temp $NETMK
269    bombiffailed
270 else
271    echo -n '(already there--skipping)'
272 fi
273 echo
274 echo -n 'Adding Deflate compression module to drivers makefile...'
275 NETMK=$LINUXSRC/drivers/net/Makefile
276 fgrep ppp_deflate.o $NETMK >/dev/null
277 if [ ! "$?" = "0" ]; then
278    echo -n '.'
279    sed 's/bsd_comp.o$/bsd_comp.o ppp_deflate.o/g' <$NETMK >$NETMK.temp
280    bombiffailed
281    echo -n '.'
282    mv $NETMK $NETMK.orig
283    bombiffailed
284    echo -n '.'
285    mv $NETMK.temp $NETMK
286    bombiffailed
287 else
288    echo -n '(already there--skipping)'
289 fi
290 echo
291
292 #
293 # install header stub files in /usr/include/net
294
295 for FILE in if_ppp.h \
296             if_pppvar.h \
297             ppp-comp.h \
298             if.h \
299             if_arp.h \
300             route.h \
301             ppp_defs.h
302   do
303   if [ ! -f /usr/include/net/$FILE ]; then
304     echo Installing stub include file in /usr/include/net/$FILE
305     echo "#include <linux/$FILE>" > /usr/include/net/$FILE
306     bombiffailed
307     chown 0:0 /usr/include/net/$FILE
308     bombiffailed
309     chmod 444 /usr/include/net/$FILE
310     bombiffailed
311     touch /usr/include/net/$FILE
312     bombiffailed
313   fi
314 done
315
316 for FILE in ip.h \
317             tcp.h
318   do
319   if [ ! -f /usr/include/netinet/$FILE ]; then
320     echo Installing stub include file in /usr/include/netinet/$FILE
321     if [ ! -f $LINUXSRC/include/linux/$FILE ]; then
322       echo "#include \"$LINUXSRC/net/inet/$FILE\"" >/usr/include/netinet/$FILE
323     else
324       echo "#include <linux/$FILE>" > /usr/include/netinet/$FILE
325     fi
326     chown 0:0 /usr/include/netinet/$FILE
327     bombiffailed
328     chmod 444 /usr/include/netinet/$FILE
329     bombiffailed
330     touch /usr/include/netinet/$FILE
331     bombiffailed
332   fi
333 done
334
335 patch_include
336
337 echo "Kernel driver files installation done."
338
339 exit 0