]> git.ozlabs.org Git - ppp.git/blob - linux/kinstall.sh
fixes for old C compilers and for Ultrix
[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 -eq 1 ]; then
66   if [ $PATCHLEVEL -eq 0 -o $PATCHLEVEL -eq 1 -a $SUBLEVEL -lt 14 ]; then
67     echo You appear to be running $KERNEL. There is no support for
68     echo kernels predating 1.1.14.  It is recommended that you upgrade
69     echo to the most recent 1.2.X kernel.
70     exit 1
71   fi
72   if [ $PATCHLEVEL -eq 1 ]; then
73     echo You appear to be running $KERNEL. It is recommended that you
74     echo upgrade to the most recent 1.2.X kernel.
75     echo However, installation will proceed.
76   fi
77 fi
78
79 echo
80 echo Installing into kernel version $KERNEL in $LINUXSRC
81 echo
82
83 echo "Notice to the user:"
84 echo
85 echo "It is perfectly legal for this script to run without making any changes"
86 echo "to your system. This only means that the system currently contains the"
87 echo "necessary changes to support this package. Please do not attempt to"
88 echo "force this script to replace any file or make any patch. If you do so"
89 echo "then it is probable that you are actually putting older, buggier, code"
90 echo "over newer, fixed, code. Thank you."
91 echo
92 echo Installing into kernel version $KERNEL in $LINUXSRC
93 echo
94
95 #
96 # convenience function to exit if the last command failed
97
98 bombiffailed () {
99   STATUS=$?
100   if [ $STATUS -ne 0 ]; then
101     echo "=== kinstall.sh exiting with failure status $STATUS"
102     exit $STATUS
103   fi
104 }
105
106 #
107 # convenience function to compare two files marked with ==FILEVERSION
108 # version numbers; returns success if $1 is newer than $2
109
110 newer () {
111   file1=$1
112   file2=$2
113   pat='==FILEVERSION[ \t]+[0-9]+[ \t]*=='
114
115   # Find the revision in the kernel
116   f1rev=""
117   if [ -r $file1 ]; then
118     f1rev=`egrep "$pat" $file1 | head -1 | sed 's/[^0-9]//g'`
119   fi
120
121   # Find the revision of the local file
122   f2rev=""
123   if [ -r $file2 ]; then
124     f2rev=`egrep "$pat" $file2 | head -1 | sed 's/[^0-9]//g'`
125   fi
126
127   # Make the strings the same length to avoid comparison problems
128   f1rev=`echo "0000000000"$f1rev | tail -c 10`
129   f2rev=`echo "0000000000"$f2rev | tail -c 10`
130
131   # Test the order of the two revisions
132   if [ $f1rev -ge $f2rev ]; then
133     true ; return
134   fi
135
136   false ; return
137 }
138
139 #
140 #  Change the USE_SKB_PROTOCOL for correct operation on 1.3.x
141 update_ppp () {
142   mv $LINUXSRC/drivers/net/ppp.c $LINUXSRC/drivers/net/ppp.c.in
143   if [ "$VERSION.$PATCHLEVEL" = "1.3" ]; then
144     sed 's/#define USE_SKB_PROTOCOL 0/#define USE_SKB_PROTOCOL 1/' <$LINUXSRC/drivers/net/ppp.c.in >$LINUXSRC/drivers/net/ppp.c
145   else
146     sed 's/#define USE_SKB_PROTOCOL 1/#define USE_SKB_PROTOCOL 0/' <$LINUXSRC/drivers/net/ppp.c.in >$LINUXSRC/drivers/net/ppp.c
147   fi
148   rm $LINUXSRC/drivers/net/ppp.c.in
149 }
150
151 #
152 #  Install the files.
153
154 installfile () {
155   BASE=`basename $1`
156   if newer $1 $BASE; then
157     echo $1 is newer than $BASE, skipping
158     return 0
159   fi
160   BACKUP=`echo $1 | sed 's/.c$/.old.c/;s/.h$/.old.h/'`
161   if [ -f $1 -a $BACKUP != $1 ]; then
162     echo Saving old $1 as `basename $BACKUP`
163     mv $1 $BACKUP
164     bombiffailed
165   fi
166   echo Installing new $1
167   cp $BASE $1
168   bombiffailed
169   touch $1
170   bombiffailed
171   if [ "$2" = "yes" ]; then
172     update_ppp
173   fi
174 }
175
176 #
177 # Patch the bad copies of the sys/types.h file
178 #
179 patch_include () {
180   echo -n "Ensuring that sys/types.h includes sys/bitypes.h"
181   fgrep "<sys/bitypes.h>" /usr/include/sys/types.h >/dev/null
182   if [ ! "$?" = "0" ]; then
183     echo -n '.'
184     rm -f /usr/include/sys/types.h.rej
185     (cd /usr/include/sys; patch -p0 -f -F30 -s) <patch-include
186     if [ ! "$?" = "0" ]; then
187        touch /usr/include/sys/types.h.rej
188     fi
189     if [ -f /usr/include/sys/types.h.rej ]; then
190        echo " --- FAILED!!!! You must fix this yourself!"
191        echo "The /usr/include/sys/types.h file must include the file"
192        echo "<sys/bitypes.h> after it includes the <linux/types.h> file."
193        echo -n "Please change it so that it does."
194        rm -f /usr/include/sys/types.h.rej
195     else
196        echo -n " -- completed"
197     fi
198   else
199     echo -n " -- skipping"
200   fi
201   echo ""
202 }
203
204 #
205 # Check for the root user
206 test_root() {
207   my_uid=`id -u`
208   my_name=`id -u -n`
209   if [ $my_uid -ne 0 ]; then
210     echo
211     echo "********************************************************************"
212     echo "Hello, $my_name. Since you are not running as the root user, it"
213     echo "is possible that this script will fail to install the needed files."
214     echo "If this happens then please use the root account and re-execute the"
215     echo "'make kernel' command.  (This script is paused for 10 seconds.)"
216     echo "********************************************************************"
217     echo
218     sleep 10s
219   fi
220 }
221
222 test_root
223
224 echo
225 echo "Notice to the user:"
226 echo
227 echo "It is perfectly legal for this script to run without making any changes"
228 echo "to your system. This means that the system currently contains the"
229 echo "necessary changes to support this package. Please do not attempt to"
230 echo "force this script to replace any file nor make any patch. If you do so"
231 echo "then it is probable that you are actually putting older, buggier, code"
232 echo "over the newer, fixed, code. Thank you."
233 echo
234 echo Installing into kernel version $KERNEL in $LINUXSRC
235 echo
236
237 if [ -f $LINUXSRC/drivers/net/ppp.h ]; then
238   echo Moving old $LINUXSRC/drivers/net/ppp.h file out of the way
239   mv $LINUXSRC/drivers/net/ppp.h $LINUXSRC/drivers/net/ppp.old.h
240   bombiffailed
241 fi
242
243 for FILE in $LINUXSRC/drivers/net/bsd_comp.c \
244             $LINUXSRC/drivers/net/ppp_deflate.c \
245             $LINUXSRC/drivers/net/zlib.c \
246             $LINUXSRC/drivers/net/zlib.h \
247             $LINUXSRC/include/linux/if_ppp.h \
248             $LINUXSRC/include/linux/if_pppvar.h \
249             $LINUXSRC/include/linux/ppp-comp.h \
250             $LINUXSRC/include/linux/ppp_defs.h
251   do
252   installfile $FILE no
253 done
254
255 installfile $LINUXSRC/drivers/net/ppp.c yes
256
257 for FILE in if.h if_arp.h route.h
258   do
259   if [ ! -f $LINUXSRC/include/linux/$FILE ]; then
260     echo Installing new $1
261     cp $FILE $LINUXSRC/include/linux/$FILE
262     bombiffailed
263     touch $LINUXSRC/include/linux/$FILE
264     bombiffailed
265   fi
266 done
267
268 echo -n 'Adding BSD compression module to drivers makefile...'
269 NETMK=$LINUXSRC/drivers/net/Makefile
270 fgrep bsd_comp.o $NETMK >/dev/null
271 if [ ! "$?" = "0" ]; then
272    echo -n '.'
273    rm -f $NETMK.orig $NETMK.rej
274    if [ "$VERSION.$PATCHLEVEL" = "1.2" ]; then
275       (cd $LINUXSRC; patch -p1 -f -F30 -s) <patch-1.2
276       if [ ! "$?" = "0" ]; then
277          touch $NETMK.rej
278       fi
279    else
280       if [ "$VERSION.$PATCHLEVEL" = "1.3" ]; then
281          (cd $LINUXSRC; patch -p1 -f -F30 -s) <patch-1.3
282          if [ ! "$?" = "0" ]; then
283             touch $NETMK.rej
284          fi
285       else
286          touch $NETMK.rej
287       fi
288    fi
289 #
290    if [ -f $NETMK.rej ]; then
291       rm -f $NETMK.rej
292       if [ -f $NETMK.orig ]; then
293          mv $NETMK.orig $NETMK
294       fi
295       sed 's/ppp.o$/ppp.o bsd_comp.o/g' <$NETMK >$NETMK.temp
296       bombiffailed
297       echo -n '.'
298       mv $NETMK $NETMK.orig
299       bombiffailed
300       echo -n '.'
301       mv $NETMK.temp $NETMK
302       bombiffailed
303    fi
304 #
305    if [ -f $NETMK.orig ]; then
306       mv $NETMK.orig $NETMK.old
307    fi
308 else
309    echo -n '(already there--skipping)'
310 fi
311 echo
312 echo -n 'Adding Deflate compression module to drivers makefile...'
313 NETMK=$LINUXSRC/drivers/net/Makefile
314 fgrep ppp_deflate.o $NETMK >/dev/null
315 if [ ! "$?" = "0" ]; then
316    echo -n '.'
317    sed 's/bsd_comp.o$/bsd_comp.o ppp_deflate.o/g' <$NETMK >$NETMK.temp
318    bombiffailed
319    echo -n '.'
320    mv $NETMK $NETMK.orig
321    bombiffailed
322    echo -n '.'
323    mv $NETMK.temp $NETMK
324    bombiffailed
325 else
326    echo -n '(already there--skipping)'
327 fi
328 echo
329
330 #
331 # install header stub files in /usr/include/net
332
333 for FILE in if_ppp.h \
334             if_pppvar.h \
335             ppp-comp.h \
336             if.h \
337             if_arp.h \
338             route.h \
339             ppp_defs.h
340   do
341   if [ ! -f /usr/include/net/$FILE ]; then
342     echo Installing stub include file in /usr/include/net/$FILE
343     echo "#include <linux/$FILE>" > /usr/include/net/$FILE
344     bombiffailed
345     chown 0:0 /usr/include/net/$FILE
346     bombiffailed
347     chmod 444 /usr/include/net/$FILE
348     bombiffailed
349     touch /usr/include/net/$FILE
350     bombiffailed
351   fi
352 done
353
354 for FILE in ip.h \
355             tcp.h
356   do
357   if [ ! -f /usr/include/netinet/$FILE ]; then
358     echo Installing stub include file in /usr/include/netinet/$FILE
359     if [ ! -f $LINUXSRC/include/linux/$FILE ]; then
360       echo "#include \"$LINUXSRC/net/inet/$FILE\"" >/usr/include/netinet/$FILE
361     else
362       echo "#include <linux/$FILE>" > /usr/include/netinet/$FILE
363     fi
364     chown 0:0 /usr/include/netinet/$FILE
365     bombiffailed
366     chmod 444 /usr/include/netinet/$FILE
367     bombiffailed
368     touch /usr/include/netinet/$FILE
369     bombiffailed
370   fi
371 done
372
373 patch_include
374
375 echo "Kernel driver files installation done."
376
377 if [ "$VERSION.$PATCHLEVEL" = "1.2" ]; then
378   echo
379   echo "Please make sure that you apply the kernel patches in the"
380   echo "linux/Other.Patches directory. You should apply both the 1.2.13 and"
381   echo "slhc.patch files or the driver in the kernel may not compile."
382   echo "The instructions are in each of these files and the README.Linux"
383   echo "document."
384 fi
385
386 exit 0