]> git.ozlabs.org Git - ppp.git/blob - linux/kinstall.sh
Added updetach option.
[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 2.0.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 #
73 # convenience function to exit if the last command failed
74
75 bombiffailed () {
76   STATUS=$?
77   if [ $STATUS -ne 0 ]; then
78     echo "=== kinstall.sh exiting with failure status $STATUS"
79     exit $STATUS
80   fi
81 }
82
83 #
84 # convenience function to compare two files marked with ==FILEVERSION
85 # version numbers; returns success if $1 is newer than $2
86
87 newer () {
88   file1=$1
89   file2=$2
90   pat='==FILEVERSION[ \t]+[0-9]+[ \t]*=='
91
92   # Find the revision in the kernel
93   f1rev=""
94   if [ -r $file1 ]; then
95     f1rev=`egrep "$pat" $file1 | head -1 | sed 's/[^0-9]//g'`
96   fi
97
98   # Find the revision of the local file
99   f2rev=""
100   if [ -r $file2 ]; then
101     f2rev=`egrep "$pat" $file2 | head -1 | sed 's/[^0-9]//g'`
102   fi
103
104   # Make the strings the same length to avoid comparison problems
105   f1rev=`echo "0000000000"$f1rev | tail -c 10`
106   f2rev=`echo "0000000000"$f2rev | tail -c 10`
107
108   # Test the order of the two revisions
109   if [ $f1rev -ge $f2rev ]; then
110     true ; return
111   fi
112
113   false ; return
114 }
115
116 #
117 #  Install the files.
118
119 installfile () {
120   BASE=`basename $1`
121   if newer $1 $BASE; then
122     echo $1 is newer than $BASE, skipping
123     return 0
124   fi
125   BACKUP=`echo $1 | sed 's/.c$/.old.c/;s/.h$/.old.h/'`
126   if [ -f $1 -a $BACKUP != $1 ]; then
127     echo Saving old $1 as `basename $BACKUP`
128     mv $1 $BACKUP
129     bombiffailed
130   fi
131   echo Installing new $1
132   cp $BASE $1
133   bombiffailed
134   touch $1
135   bombiffailed
136 }
137
138 #
139 # Check for the root user
140 test_root() {
141   my_uid=`id -u`
142   my_name=`id -u -n`
143   if [ $my_uid -ne 0 ]; then
144     echo
145     echo "********************************************************************"
146     echo "Hello, $my_name. Since you are not running as the root user, it"
147     echo "is possible that this script will fail to install the needed files."
148     echo "If this happens then please use the root account and re-execute the"
149     echo "'make kernel' command.  (This script is paused for 10 seconds.)"
150     echo "********************************************************************"
151     echo
152     sleep 10s
153   fi
154 }
155
156 test_root
157
158 echo
159 echo "Notice to the user:"
160 echo
161 echo "It is perfectly legal for this script to run without making any changes"
162 echo "to your system. This means that the system currently contains the"
163 echo "necessary changes to support this package. Please do not attempt to"
164 echo "force this script to replace any file nor make any patch. If you do so"
165 echo "then it is probable that you are actually putting older, buggier, code"
166 echo "over the newer, fixed, code. Thank you."
167 echo
168 echo Installing into kernel version $KERNEL in $LINUXSRC
169 echo
170
171 if [ -f $LINUXSRC/drivers/net/ppp.h ]; then
172   echo Moving old $LINUXSRC/drivers/net/ppp.h file out of the way
173   mv $LINUXSRC/drivers/net/ppp.h $LINUXSRC/drivers/net/ppp.old.h
174   bombiffailed
175 fi
176
177 for FILE in $LINUXSRC/drivers/net/bsd_comp.c \
178             $LINUXSRC/drivers/net/ppp_deflate.c \
179             $LINUXSRC/drivers/net/zlib.c \
180             $LINUXSRC/drivers/net/zlib.h \
181             $LINUXSRC/include/linux/if_ppp.h \
182             $LINUXSRC/include/linux/if_pppvar.h \
183             $LINUXSRC/include/linux/ppp-comp.h \
184             $LINUXSRC/include/linux/ppp_defs.h
185   do
186   installfile $FILE no
187 done
188
189 installfile $LINUXSRC/drivers/net/ppp.c yes
190
191 echo -n 'Adding BSD compression module to drivers makefile...'
192 NETMK=$LINUXSRC/drivers/net/Makefile
193 fgrep bsd_comp.o $NETMK >/dev/null
194 if [ ! "$?" = "0" ]; then
195    if [ -f $NETMK.orig ]; then
196       mv $NETMK.orig $NETMK
197    fi
198    sed 's/ppp.o$/ppp.o bsd_comp.o/g' <$NETMK >$NETMK.temp
199    bombiffailed
200    echo -n '.'
201    mv $NETMK $NETMK.orig
202    bombiffailed
203    echo -n '.'
204    mv $NETMK.temp $NETMK
205    bombiffailed
206 else
207    echo -n '(already there--skipping)'
208 fi
209 echo
210 echo -n 'Adding Deflate compression module to drivers makefile...'
211 NETMK=$LINUXSRC/drivers/net/Makefile
212 fgrep ppp_deflate.o $NETMK >/dev/null
213 if [ ! "$?" = "0" ]; then
214    echo -n '.'
215    sed 's/bsd_comp.o$/bsd_comp.o ppp_deflate.o/g' <$NETMK >$NETMK.temp
216    bombiffailed
217    echo -n '.'
218    mv $NETMK $NETMK.orig
219    bombiffailed
220    echo -n '.'
221    mv $NETMK.temp $NETMK
222    bombiffailed
223 else
224    echo -n '(already there--skipping)'
225 fi
226 echo
227
228 #
229 # install header stub files in /usr/include/net
230
231 for FILE in if_ppp.h \
232             if_pppvar.h \
233             ppp-comp.h \
234             if.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 echo "Kernel driver files installation done."
251
252 exit 0