]> git.ozlabs.org Git - ppp.git/blob - linux/kinstall.sh
Added packet filtering, subnet spec for allowed IP addr; select
[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 #
84 # convenience function to exit if the last command failed
85
86 function bombiffailed () {
87   STATUS=$?
88   if [ $STATUS -ne 0 ]; then
89     echo "=== kinstall.sh exiting with failure status $STATUS"
90     exit $STATUS
91   fi
92 }
93
94 #
95 # convenience function to compare two files marked with ==FILEVERSION
96 # version numbers; returns success if $1 is newer than $2
97
98 function newer () {
99   if [ -r $1 ] && f1rev=`fgrep "==FILEVERSION " $1 | sed 's/[^0-9]//g'`; then
100     if [ -r $2 ] && f2rev=`fgrep "==FILEVERSION " $2 | sed 's/[^0-9]//g'`; then
101       if [ "$f1rev" != "" ]; then
102         # return true if f2rev is empty or f1rev => f2rev
103         [ "$f2rev" = "" ] || [ $f1rev -ge $f2rev ]
104       else
105         # f1rev is empty, so false
106         false
107       fi
108     else
109       true  # no FILEVERSION in $2, so $1 is newer
110     fi
111   else
112     false  # no FILEVERSION in $1, so not newer
113   fi
114 }
115
116 #
117 #  Change the USE_SKB_PROTOCOL for correct operation on 1.3.x
118 function update_ppp () {
119   mv $LINUXSRC/drivers/net/ppp.c $LINUXSRC/drivers/net/ppp.c.in
120   if [ "$VERSION.$PATCHLEVEL" = "1.3" ]; then
121     sed 's/#define USE_SKB_PROTOCOL 0/#define USE_SKB_PROTOCOL 1/' <$LINUXSRC/drivers/net/ppp.c.in >$LINUXSRC/drivers/net/ppp.c
122   else
123     sed 's/#define USE_SKB_PROTOCOL 1/#define USE_SKB_PROTOCOL 0/' <$LINUXSRC/drivers/net/ppp.c.in >$LINUXSRC/drivers/net/ppp.c
124   fi
125   rm $LINUXSRC/drivers/net/ppp.c.in
126 }
127
128 #
129 #  Install the files.
130
131 function installfile () {
132   BASE=`basename $1`
133   if newer $1 $BASE; then
134     echo $1 is newer than $BASE, skipping
135     return 0
136   fi
137   BACKUP=`echo $1 | sed 's/.c$/.old.c/;s/.h$/.old.h/'`
138   if [ -f $1 -a $BACKUP != $1 ]; then
139     echo Saving old $1 as `basename $BACKUP`
140     mv $1 $BACKUP
141     bombiffailed
142   fi
143   echo Installing new $1
144   cp $BASE $1
145   bombiffailed
146   touch $1
147   bombiffailed
148   if [ "$2" = "yes" ]; then
149     update_ppp
150   fi
151 }
152
153 if [ -f $LINUXSRC/drivers/net/ppp.h ]; then
154   echo Moving old $LINUXSRC/drivers/net/ppp.h file out of the way
155   mv $LINUXSRC/drivers/net/ppp.h $LINUXSRC/drivers/net/ppp.old.h
156   bombiffailed
157 fi
158
159 for FILE in $LINUXSRC/drivers/net/bsd_comp.c \
160             $LINUXSRC/include/linux/if_ppp.h \
161             $LINUXSRC/include/linux/if_pppvar.h \
162             $LINUXSRC/include/linux/ppp-comp.h \
163             $LINUXSRC/include/linux/ppp_defs.h
164   do
165   installfile $FILE no
166 done
167
168 installfile $LINUXSRC/drivers/net/ppp.c yes
169
170 for FILE in if.h if_arp.h route.h
171   do
172   if [ ! -f $LINUXSRC/include/linux/$FILE ]; then
173     echo Installing new $1
174     cp $FILE $LINUXSRC/include/linux/$FILE
175     bombiffailed
176     touch $LINUXSRC/include/linux/$FILE
177     bombiffailed
178   fi
179 done
180
181 echo -n 'Adding BSD compression module to drivers makefile...'
182 NETMK=$LINUXSRC/drivers/net/Makefile
183 fgrep bsd_comp.o $NETMK >/dev/null
184 if [ ! "$?" = "0" ]; then
185    echo -n '.'
186    rm -f $NETMK.orig $NETMK.rej
187    if [ "$VERSION.$PATCHLEVEL" = "1.2" ]; then
188       (cd $LINUXSRC; patch -p1 -f -F30 -s) <patch-1.2
189       if [ ! "$?" = "0" ]; then
190          touch $NETMK.rej
191       fi
192    else
193       if [ "$VERSION.$PATCHLEVEL" = "1.3" ]; then
194          (cd $LINUXSRC; patch -p1 -f -F30 -s) <patch-1.3
195          if [ ! "$?" = "0" ]; then
196             touch $NETMK.rej
197          fi
198       else
199          touch $NETMK.rej
200       fi
201    fi
202 #
203    if [ -e $NETMK.rej ]; then
204       rm -f $NETMK.rej
205       if [ -e $NETMK.orig ]; then
206          mv $NETMK.orig $NETMK
207       fi
208       sed 's/ppp.o$/ppp.o bsd_comp.o/g' <$NETMK >$NETMK.temp
209       bombiffailed
210       echo -n '.'
211       mv $NETMK $NETMK.orig
212       bombiffailed
213       echo -n '.'
214       mv $NETMK.temp $NETMK
215       bombiffailed
216    fi
217 #
218    if [ -e $NETMK.orig ]; then
219       mv $NETMK.orig $NETMK.old
220    fi
221 else
222    echo -n '(already there--skipping)'
223 fi
224 echo
225
226 #
227 # install header stub files in /usr/include/net
228
229 for FILE in if_ppp.h \
230             if_pppvar.h \
231             ppp-comp.h \
232             if.h \
233             if_arp.h \
234             route.h \
235             ppp_defs.h
236   do
237   if [ ! -f /usr/include/net/$FILE ]; then
238     echo Installing stub include file in /usr/include/net/$FILE
239     echo "#include <linux/$FILE>" > /usr/include/net/$FILE
240     bombiffailed
241     chown 0:0 /usr/include/net/$FILE
242     bombiffailed
243     chmod 444 /usr/include/net/$FILE
244     bombiffailed
245     touch /usr/include/net/$FILE
246     bombiffailed
247   fi
248 done
249
250 for FILE in ip.h \
251             tcp.h
252   do
253   if [ ! -f /usr/include/netinet/$FILE ]; then
254     echo Installing stub include file in /usr/include/netinet/$FILE
255     if [ ! -f $LINUXSRC/include/linux/$FILE ]; then
256       echo "#include \"$LINUXSRC/net/inet/$FILE\"" >/usr/include/netinet/$FILE
257     else
258       echo "#include <linux/$FILE>" > /usr/include/netinet/$FILE
259     fi
260     chown 0:0 /usr/include/netinet/$FILE
261     bombiffailed
262     chmod 444 /usr/include/netinet/$FILE
263     bombiffailed
264     touch /usr/include/netinet/$FILE
265     bombiffailed
266   fi
267 done
268
269 echo "Kernel driver files installation done."
270 exit 0