#!/bin/sh cat - </dev/null fi if [ ! -f $MICROCODE ]; then echo "Cannot find microcode $MICROCODE" | tee -a $LOGFILE exit 1 fi if [ ! -f $TARBALL ]; then echo "Cannot find tarball $TARBALL" | tee -a $LOGFILE exit 1 fi error=0 PPP_VERSION=`$PPPD --version 2>&1 | awk '{ print $3 }'` KERNEL=`$UNAME -r` KERNEL_MAJOR=`echo $KERNEL | cut -d"." -f1,2` KERNEL_MINOR=`echo $KERNEL | cut -d"." -f3` USB_TYPE=`$LSPCI -v |grep -i usb|grep HCI` if [ "${PPP_VERSION}" == "2.4.0" ] || [ "${PPP_VERSION}" == "2.4.1" ]; then echo "PPP version $PPP_VERSION okay." else if [ "$KERNEL_MAJOR" == "2.4" ]; then echo "PPP Version ${PPP_VERSION} should be 2.4.0 or 2.4.1" | tee -a $LOGFILE error=`expr $error + 1` else echo "With the 2.2.18 kernel you should get away with $PPP_VERSION" | tee -a $LOGFILE echo "... maybe." | tee -a $LOGFILE fi fi if [ -z "${USB_TYPE}" ]; then echo "No USB Bus found!" | tee -a $LOGFILE error=`expr $error + 2` fi echo ${USB_TYPE} | grep -q UHCI if [ "$?" -eq "0" ]; then USB_TYPE=UHCI else USB_TYPE=OHCI fi echo $KERNEL|grep -q "2.4" if [ "$?" -ne "0" ]; then echo $KERNEL | grep -q "2.2.18" if [ "$?" -ne "0" ]; then echo "Sorry, only 2.4 and 2.2.18 kernels have been made to work with the $PRODNAME" | tee -a $LOGFILE error=`expr $error + 4` fi else echo $KERNEL | egrep -q "2.4.1(8|9)" if [ "$?" -ne "0" ]; then echo "You probably need the HDLC kernel patch n_hdlc.c.diff" | tee -a $LOGFILE error=`expr $error + 8` fi fi ls -l /dev/ppp|grep -wq 108 if [ "$?" -ne "0" ]; then cd /dev ./MAKEDEV ppp if [ "$?" -ne "0" ]; then echo "MAKEDEV failed" | tee -a $LOGFILE error=`expr $error + 16` fi fi if [ "`id -u`" != "0" ]; then echo "You must be logged in as root to use this script" exit 1 fi } get_tarball() { mkdir /tmp/speedtouch.$$ cd /tmp/speedtouch.$$ echo "$TARBALL" |grep -q "gz$" if [ "$?" -eq "0" ]; then tar xzf $TARBALL cd `basename $TARBALL .tar.gz` else bzcat $TARBALL | tar xf - cd `basename $TARBALL .tar.bz2` fi if [ "$PREFIX" != "/" ]; then config="./configure --prefix $PREFIX/usr" else config="./configure" fi echo "Configururing SpeedTouch Driver..." | tee -a $LOGFILE if [ "$QUIET" == "YES" ]; then $config > /dev/null 2>&1 res=$? else $config res=$? fi check_err $res "Software Configuration" echo "Building SpeedTouch Driver..." | tee -a $LOGFILE if [ "$QUIET" == "YES" ]; then make > /dev/null 2>&1 res=$? else make res=$? fi check_err $res "Software Build" echo "Installing SpeedTouch Driver..." | tee -a $LOGFILE if [ "$QUIET" == "YES" ]; then make install > /dev/null res=$? else make install res=$? fi check_err $res "Software Installation" } create_ppp_files() { echo "Creating ppp files in $PREFIX/etc/ppp" >> $LOGFILE cd $PREFIX/etc/ppp cat - > options << EOF #------------------ /etc/ppp/options Beginning ------------- noauth usepeerdns lock noipdefault #------------------ /etc/ppp/options End ------------------ EOF mkdir peers 2>/dev/null cat - > peers/adsl <> peers/adsl echo "sync" >> peers/adsl echo "user \"$ISP_LOGIN\"" >> peers/adsl cat - >> peers/adsl << EOF noauth noaccomp nopcomp noccp novj holdoff 4 persist maxfail 25 usepeerdns #------------------/etc/ppp/peers/adsl EOF------------------ EOF echo "\"$ISP_LOGIN\" \"*\" \"$ISP_PASSWORD\" \"*\"" >> chap-secrets echo "\"$ISP_LOGIN\" \"*\" \"$ISP_PASSWORD\" \"*\"" >> pap-secrets chmod 600 pap-secrets chap-secrets } add_line() { grep -q "$1" $3 || echo "$2" >> $3 } modify_modules_conf() { if [ -f /etc/modules.conf ]; then MODCONF=$PREFIX/etc/modules.conf else MODCONF=$PREFIX/etc/conf.modules fi echo "Original modules.conf: " >> $LOGFILE cat $MODCONF >> $LOGFILE add_line "ppp_generic" "alias char-major-108 ppp_generic" $MODCONF add_line "dev/ppp" "alias /dev/ppp ppp_generic" $MODCONF add_line "ppp_async" "alias tty-ldisc-3 ppp_async" $MODCONF add_line "n_hdlc" "alias tty-ldisc-13 n_hdlc" $MODCONF add_line "ppp_synctty" "alias tty-ldisc-14 ppp_synctty" $MODCONF add_line "bsd_comp" "alias ppp-compress-21 bsd_comp" $MODCONF add_line "ppp-compress-24" "alias ppp-compress-24 ppp_deflate" $MODCONF add_line "ppp-compress-26" "alias ppp-compress-26 ppp_deflate" $MODCONF echo "New modules.conf: " >> $LOGFILE cat $MODCONF >> $LOGFILE echo "--- end of new modules.conf" >> $LOGFILE } do_modprobe() { echo "Doing modprobes ... ">> $LOGFILE modprobe ppp_generic | tee -a $LOGFILE modprobe ppp_synctty | tee -a $LOGFILE modprobe n_hdlc | tee -a $LOGFILE modprobe usbcore | tee -a $LOGFILE mount none /proc/bus/usb -t usbdevfs > /dev/null 2>&1 if [ "$USB_TYPE" == "UHCI" ]; then modprobe usb-uhci | tee -a $LOGFILE if [ "$?" -ne "0" ]; then modprobe uhci | tee -a $LOGFILE fi else modprobe usb-ohci | tee -a $LOGFILE fi echo "lsmod output:" lsmod >> $LOGFILE } select_options() { ans="N" while [ "$ans" != "Y" ]; do cat - << EOF Country/ISP VPI VCI Belgium, ? 8 35 Denmark, Orang 8 35 France, wanado 8 35 France, ? 8 67 Italy, ? 8 35 Netherlands, ? 8 48 UK, BTopenworld 0 38 US, BellSouth 8 35 EOF echo "Please select your VPI VCI numbers (eg, 0 38) for UK" read VPI VCI echo "Please enter your ISP Login ID (eg another@hg1.btinternet.com)" read ISP_LOGIN echo "Please enter your ISP Password" read ISP_PASSWORD echo "Settings: " echo " VPI / VCI : $VPI / $VCI" echo " Login : $ISP_LOGIN" echo " Password : $ISP_PASSWORD" echo "Are these correct? (Y/N)" read ans ans=`echo ${ans}N|tr '[a-z]' '[A-Z]'|cut -c1` done echo "VPI: $VPI VCI: $VCI" >> $LOGFILE } setup_etc_conf() { CONF=$PREFIX/etc/speedtouch.conf echo "# SpeedTouch Config File" > $CONF echo "# The speedtouch rc script assumes /usr/local/sbin is in the path..." >> $CONF echo "PATH=\$PATH:/usr/local/sbin" >> $CONF echo "# LOAD_ directives should be 1 for modules, 0 if built into the kernel" >> $CONF echo "LOAD_USBCORE=1" >> $CONF echo "LOAD_USBINTERFACE=1" >> $CONF echo "LOAD_NHDLC=1" >> $CONF echo "# USB Interface - UHCI or OHCI" >> $CONF USB=`echo $USB_TYPE | tr '[:upper:]' '[:lower:]'` echo "DEFAULT_USBINTERFACE=\"$USB\"" >> $CONF echo "# Path to microcode (mgmt.o or alcudsl.sys from the official Alcatel drivers" >> $CONF echo "MICROCODE=\"$MICROCODE\"" >> $CONF echo "# Set this to 1 if you have configured the script" >> $CONF echo "CONFIGURED=1" >> $CONF cp /usr/local/etc/init.d/speedtouch /etc/rc.d/init.d/ } check_router() { route=`netstat -rn|grep "^0\.0\.0\.0"|awk '{ print $2 }'` if [ ! -z "${route}" ]; then echo "You have a default router : $route (removing it for you!)" | tee -a $LOGFILE route delete default gw $route fi } # main script starts here echo "If you have any problems with this script, mail me" echo "(http://steve-parker.org/mail/) with the file" echo "$LOGFILE for diagnosis." if [ -f $LOGFILE ]; then mv $LOGFILE ${LOGFILE}.old fi echo "Starting speedtouch.sh script" > $LOGFILE date >> $LOGFILE echo "Called as $0 from `pwd`" >> $LOGFILE check_config if [ "$error" -ne "0" ]; then echo "Not ready to install the software at this time. - code $error" | tee -a $LOGFILE exit 1 fi select_options echo "No further user interaction is required." | tee -a $LOGFILE get_tarball create_ppp_files modify_modules_conf do_modprobe check_router setup_etc_conf echo echo echo echo "The modem lights should start flashing for 20 seconds..." | tee -a $LOGFILE $MODEM_RUN -m -f $MICROCODE res=$? if [ "$res" -eq "0" ]; then echo "Phew! That was the hard part! Should be plain sailing now..." | tee -a $LOGFILE else echo "The modem_run command failed (code $res)- check your kernel config" | tee -a $LOGFILE exit 1 fi sleep 10 echo "Running : $PPPD call adsl" | tee -a $LOGFILE $PPPD call adsl echo "pppd return code $?" >> $LOGFILE sleep 10 ifconfig ppp0 | grep "inet addr:" echo "--- ifconfig -a output ---" >> $LOGFILE ifconfig -a >> $LOGFILE echo "--- netstat -rn output ---" >> $LOGFILE netstat -rn >> $LOGFILE echo "--- /etc/resolv.conf ---" >> $LOGFILE cat /etc/resolv.conf >> $LOGFILE echo "--- end of diags ---" >> $LOGFILE if [ "$?" -eq "0" ]; then echo "Looks like we're online... " | tee -a $LOGFILE ping -c1 www.google.com > /dev/null if [ "$?" -eq "0" ]; then echo "Hey look, I can see the Net from here!" | tee -a $LOGFILE else echo "Cannot ping www.google.com - trying steve-parker.org by numeric IP" | tee -a $LOGFILE ping -c1 195.224.68.226 > /dev/null if [ "$?" _eq "0" ]; then echo "Looks like DNS might be iffy" | tee -a $LOGFILE else echo "I can't ping even without DNS" | tee -a $LOGFILE fi fi else echo "Oops - don't seem to have connected. " | tee -a $LOGFILE echo "Are you sure your password and login are correct?" | tee -a $LOGFILE fi echo "All done. Run :"| tee -a $LOGFILE echo "chkconfig --add speedtouch" | tee -a $LOGFILE echo "as root to automatically dial-in when the PC boots up" | tee -a $LOGFILE if [ ! -z "${route}" ]; then echo echo "You have a default route configured." grep -q "GATEWAY=" /etc/sysconfig/network 2>/dev/null if [ "$?" -eq "0" ]; then echo "You need to remove the GATEWAY= line from /etc/sysconfig/network." else echo "You need to disable this, as there can only be one default route." fi echo fi exit 0