OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / user / pppd-2.3 / 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 LINUXSRC=/usr/src/linux
19
20 if [ $# -gt 1 ]; then
21    echo usage: $0 [linux-source-directory]
22    exit 1
23 fi
24
25 if [ $# -eq 1 ]; then
26    LINUXSRC=$1
27 fi
28
29 #
30 #  Make sure we can find the kernel source
31
32 LINUXMK=$LINUXSRC/Makefile
33
34 if [ ! -r $LINUXMK -o ! -d $LINUXSRC/drivers ]; then
35   echo There appears to be no kernel source distribution in $LINUXSRC.
36   echo Give the top-level kernel source directory as the argument to
37   echo this script.
38   echo usage: $0 [linux-source-directory]
39   exit 1
40 fi
41
42 #
43 #  Check that the kernel source Makefile includes the 
44 #    VERSION, PATCHLEVEL, SUBLEVEL version-numbering scheme
45 #    introduced in 1.0.1
46 if [ `egrep '^VERSION|^PATCHLEVEL|^SUBLEVEL' $LINUXMK | wc -l` -ne 3 ]; then
47   echo You appear to have a very old kernel. You must upgrade.
48   echo It is recommended that you upgrade to the most recent 2.0.x kernel.
49   exit 1
50 fi
51
52 #
53 #  Set the VERSION, PATCHLEVEL, SUBLEVEL variables
54 VERSION=`egrep '^VERSION' $LINUXMK | sed 's/[^0-9]//g'`
55 PATCHLEVEL=`egrep '^PATCHLEVEL' $LINUXMK | sed 's/[^0-9]//g'`
56 SUBLEVEL=`egrep '^SUBLEVEL' $LINUXMK | sed 's/[^0-9]//g'`
57
58 KERNEL=$VERSION.$PATCHLEVEL.$SUBLEVEL
59
60 #
61 #  Pass judgement on the kernel version
62 if [ $VERSION -lt 2 ]; then
63     echo You appear to be running $KERNEL. There is no support for
64     echo kernels predating 2.0.0.  It is recommended that you upgrade
65     echo to the most recent 2.0.x kernel.
66     exit 1
67 fi
68
69 #
70 # convenience function to exit if the last command failed
71
72 bombiffailed () {
73   STATUS=$?
74   if [ $STATUS -ne 0 ]; then
75     echo "=== kinstall.sh exiting with failure status $STATUS"
76     exit $STATUS
77   fi
78 }
79
80 #
81 # convenience function to compare two files marked with ==FILEVERSION
82 # version numbers; returns success if $1 is not older than $2
83
84 newer () {
85   file1=$1
86   file2=$2
87   pat='==FILEVERSION[ \t]+[0-9]+[ \t]*=='
88
89   # Find the revision in the kernel
90   f1rev=""
91   if [ -r $file1 ]; then
92     f1rev=`egrep "$pat" $file1 | head -1 | sed 's/[^0-9]//g'`
93   fi
94
95   # Find the revision of the local file
96   f2rev=""
97   if [ -r $file2 ]; then
98     f2rev=`egrep "$pat" $file2 | head -1 | sed 's/[^0-9]//g'`
99   fi
100
101   # Make the strings the same length to avoid comparison problems
102   f1rev=`echo "0000000000"$f1rev | tail -c 10`
103   f2rev=`echo "0000000000"$f2rev | tail -c 10`
104
105   # Test the order of the two revisions
106   if [ $f1rev -ge $f2rev ]; then
107     true ; return
108   fi
109
110   false ; return
111 }
112
113 #
114 #  Install the files.
115
116 installfile () {
117   BASE=`basename $1`
118 #
119 # SHA-1 (SHS) sources located in ../pppd/ directory
120 #
121   case $BASE in
122     sha*) BASE="../pppd/"$BASE;;
123   esac
124   if [ ! -e $BASE ]; then
125     if [ -e ../include/linux/$BASE ]; then
126       BASE=../include/linux/$BASE
127     else
128       echo Could not find source file $BASE !
129       false ; return
130     fi
131   fi
132   if newer $1 $BASE; then
133     echo $1 is not older than $BASE, skipping
134     return 0
135   fi
136   BACKUP=`echo $1 | sed 's/.c$/.old.c/;s/.h$/.old.h/'`
137   if [ -f $1 -a $BACKUP != $1 ]; then
138     echo Saving old $1 as `basename $BACKUP`
139     mv $1 $BACKUP
140     bombiffailed
141   fi
142   echo Installing new $1
143   cp $BASE $1
144   bombiffailed
145   touch $1
146   bombiffailed
147 }
148
149 #
150 # Check for the root user
151 test_root() {
152   my_uid=`id -u`
153   my_name=`id -u -n`
154   if [ $my_uid -ne 0 ]; then
155     echo
156     echo "********************************************************************"
157     echo "Hello, $my_name. Since you are not running as the root user, it"
158     echo "is possible that this script will fail to install the needed files."
159     echo "If this happens then please use the root account and re-execute the"
160     echo "'make kernel' command.  (This script is paused for 10 seconds.)"
161     echo "********************************************************************"
162     echo
163     sleep 10s
164   fi
165 }
166
167 test_root
168
169 echo
170 echo "Notice to the user:"
171 echo
172 echo "It is perfectly legal for this script to run without making any changes"
173 echo "to your system. This means that the system currently contains the"
174 echo "necessary changes to support this package. Please do not attempt to"
175 echo "force this script to replace any file nor make any patch. If you do so"
176 echo "then it is probable that you are actually putting older, buggier, code"
177 echo "over the newer, fixed, code. Thank you."
178 echo
179 echo Installing into kernel version $KERNEL in $LINUXSRC
180 echo
181
182 if [ -f $LINUXSRC/drivers/net/ppp.h ]; then
183   echo Moving old $LINUXSRC/drivers/net/ppp.h file out of the way
184   mv $LINUXSRC/drivers/net/ppp.h $LINUXSRC/drivers/net/ppp.old.h
185   bombiffailed
186 fi
187
188 for FILE in $LINUXSRC/drivers/net/bsd_comp.c \
189             $LINUXSRC/drivers/net/ppp_deflate.c \
190             $LINUXSRC/drivers/net/zlib.c \
191             $LINUXSRC/drivers/net/zlib.h \
192             $LINUXSRC/drivers/net/ppp_mppe.c \
193             $LINUXSRC/drivers/net/ppp_lzscomp.c \
194             $LINUXSRC/drivers/net/ppp_lzscomp.h \
195             $LINUXSRC/drivers/net/mppe.h \
196             $LINUXSRC/drivers/net/sha.h \
197             $LINUXSRC/drivers/net/sha1dgst.c \
198             $LINUXSRC/drivers/net/sha_locl.h \
199             $LINUXSRC/drivers/net/rc4_enc.c \
200             $LINUXSRC/drivers/net/rc4.h \
201             $LINUXSRC/include/linux/if_ppp.h \
202             $LINUXSRC/include/linux/if_pppvar.h \
203             $LINUXSRC/include/linux/ppp-comp.h \
204             $LINUXSRC/include/linux/ppp_defs.h
205   do
206   installfile $FILE no
207 done
208
209 installfile $LINUXSRC/drivers/net/ppp.c yes
210
211 echo -n 'Adding BSD compression module to drivers makefile...'
212 NETMK=$LINUXSRC/drivers/net/Makefile
213 fgrep bsd_comp.o $NETMK >/dev/null
214 if [ ! "$?" = "0" ]; then
215    if [ -f $NETMK.orig ]; then
216       mv $NETMK.orig $NETMK
217    fi
218    sed 's/ppp.o$/ppp.o bsd_comp.o/g' <$NETMK >$NETMK.temp
219    bombiffailed
220    echo -n '.'
221    mv $NETMK $NETMK.orig
222    bombiffailed
223    echo -n '.'
224    mv $NETMK.temp $NETMK
225    bombiffailed
226 else
227    echo -n '(already there--skipping)'
228 fi
229 echo
230 echo -n 'Adding Deflate compression module to drivers makefile...'
231 NETMK=$LINUXSRC/drivers/net/Makefile
232 fgrep ppp_deflate.o $NETMK >/dev/null
233 if [ ! "$?" = "0" ]; then
234    echo -n '.'
235    sed 's/bsd_comp.o$/bsd_comp.o ppp_deflate.o/g' <$NETMK >$NETMK.temp
236    bombiffailed
237    echo -n '.'
238    mv $NETMK $NETMK.orig
239    bombiffailed
240    echo -n '.'
241    mv $NETMK.temp $NETMK
242    bombiffailed
243 else
244    echo -n '(already there--skipping)'
245 fi
246 echo
247 echo -n 'Adding MPPE compression module to drivers makefile...'
248 NETMK=$LINUXSRC/drivers/net/Makefile
249 fgrep ppp_mppe.o $NETMK >/dev/null
250 if [ ! "$?" = "0" ]; then
251    if [ -f $NETMK.orig ]; then
252       mv $NETMK.orig $NETMK
253    fi
254    sed 's/bsd_comp.o$/bsd_comp.o ppp_mppe.o/g' <$NETMK >$NETMK.temp
255    bombiffailed
256    echo -n '.'
257    mv $NETMK $NETMK.orig
258    bombiffailed
259    echo -n '.'
260    mv $NETMK.temp $NETMK
261    bombiffailed
262 else
263    echo -n '(already there--skipping)'
264 fi
265 echo
266 #echo -n 'Adding LZS compression module to drivers makefile...'
267 #NETMK=$LINUXSRC/drivers/net/Makefile
268 #fgrep ppp_mppe.o $NETMK >/dev/null
269 #if [ ! "$?" = "0" ]; then
270 #   if [ -f $NETMK.orig ]; then
271 #      mv $NETMK.orig $NETMK
272 #   fi
273 #   sed 's/bsd_comp.o$/bsd_comp.o ppp_lzscomp.o/g' <$NETMK >$NETMK.temp
274 #   bombiffailed
275 #   echo -n '.'
276 #   mv $NETMK $NETMK.orig
277 #   bombiffailed
278 #   echo -n '.'
279 #   mv $NETMK.temp $NETMK
280 #   bombiffailed
281 #else
282 #   echo -n '(already there--skipping)'
283 #fi
284 #echo
285
286 #
287 # # install header stub files in /usr/include/net
288
289 # for FILE in if_ppp.h \
290 #             if_pppvar.h \
291 #             ppp-comp.h \
292 #           if.h \
293 #             ppp_defs.h
294 #   do
295 #   if [ ! -f /usr/include/net/$FILE ]; then
296 #     echo Installing stub include file in /usr/include/net/$FILE
297 #     echo "#include <linux/$FILE>" > /usr/include/net/$FILE
298 #     bombiffailed
299 #     chown 0:0 /usr/include/net/$FILE
300 #     bombiffailed
301 #     chmod 444 /usr/include/net/$FILE
302 #     bombiffailed
303 #     touch /usr/include/net/$FILE
304 #     bombiffailed
305 #   fi
306 # done
307
308 echo "Kernel driver files installation done."
309
310 exit 0