#!/bin/sh
# ltcheckout checks ltmodem installation

BN=`basename $0`

## Check permissions
if [ $UID -ne 0 ]; then
   echo
   echo "The driver and module loading of $BN can requires Root permission!"
   echo "Please log in as root/superuser and rerun $BN"
   echo 
   exit 2
fi

if ! modprobe &>/dev/null ; then
  echo The essential utility modprobe is not on the command PATH
  echo Please log into a console as Root and verify access to the modutils suite with command:
  echo  "# modprobe -V"
  echo "before re-running $BN"
  echo
  exit
fi

MSG="If you cannot resolve the problems, please send $RECORD to discuss@linmodems.org"

OTHER=
if test -n "$OTHER" ; then
echo
echo This $BN tests the effectiveness of modem installations
echo with two supporting drivers.
echo It can be rerun for education or amusement.
echo
echo ===========================================
echo It was prototyped for the Lucent DSP modem.
echo Please keep any suggested enhancements MODEM generic.
echo As necessary MODEM specific issues can always be bracketed such as:
echo "# Definition of Environmental variable MODEM"
echo MODEM=Lucent_DSP
echo "if [ MODEM = Lucent_DSP ] ; then"
echo "	Do COMMANDS" 
echo "	Echo MESSAGES"
echo "fi"
echo ===========================================
echo
fi # OTHER

# Device File System status check
if test -e /dev/.devfsd ; then
  DEVFS=active
else
  DEVFS=
fi

LINK=/dev/modem
# typical symbolic link expected by ppp dialer utilities 
MODEM=LDSP
# LDSP short for Lucent Digital Signal Processor

# Modem installation specific definitions
if [ "$MODEM" = "LDSP" ] ; then
  SERIAL=lt_serial
  DSP=lt_modem
  GN=lt_
  # for GREP NAME or selective listing:  ls "$GR"*
  NODE=/dev/ttyLT0
  LINKS=/dev/ttyS1_replace_with_ttyLTO 
  # symbolic LINKS needed for wvdialconf test
  if test -n "$DEVFS" ; then
    NODE=/dev/tts/LT0
    SNODE=tts/LT0
    LINKS=/dev/ttySLT0
  fi
fi

WVDIAL=`which wvdialconf`
if test -z "$WVDIAL" ; then
  echo A direct test of your modem is included in this $BN script.
  echo While several other $BN tests will still be done,
  echo please install the package WVDIAL provided by your Linux distro.
  echo Then rerun $BN.
  echo 
fi


BN=`basename $0`
export BN=$BN
echo
echo This $BN utility currently 
echo "	checks for expected components of a Lucent DSP winmodem installation"
echo "	provides a minor tutorial"
echo "	if modem driver insertion is successfull"
echo "	runs a wvdialconf test"
echo "	unloads excess drivers if module loading fails"
echo "	Does not as yet have signficant problem solving action"
echo "	except for referrals to Documentation."
echo "Can readily be adapted to work with other winmodem installations."
echo

# creat TMP Modem workspace
WORK=`pwd`
echo "The current Working folder is:    $WORK."

if [ "'pwd'" = "/" ] ; then
  mkdir -p /tmp/ltmodem
  TMPM=/tmp/ltmodem/tmpfile
else
  mkdir -p tmp 
  TMPM=tmp/tmpfile
fi

SYS=`uname -r`
# for active SYStem kernel

# Setting up recording
# BLDrecord is an output from Lucent DSP installs
if [ -f SOMErecord.txt ] ; then
  RECORD=`pwd`/BLDrecord.txt
elif [ "`pwd`" = "/" ] ; then
  RECORD=/root/$BN.txt
else
  RECORD=`pwd`/$BN.txt
fi 


if [ "$RECORD" = "BLDrecord.txt" ] ; then
  echo "#============== $BN section =============== ">> $RECORD
else 
  echo > $RECORD
fi
echo

FAST=
if test -z "$FAST" ; then
# Just to jump to current development section, when FAST=something

read -p "To continue:	Enter"
echo "===================================================================="

echo "Now acquiring distribution data:"
DISTRO_FILES="redhat-release SuSE-release mandrake-release conectiva-release  \
   bluepoint-release  slackware-version  debian_version"
for i in $DISTRO_FILES
do
  if [ -a /etc/$i ]; then
    DISTRO=$i
    # generating short name
    DISTR=`ls /etc/$i | cut -d/ -f3 | cut -d"-" -f1`
    if [ "$DISTR" = "debian_version" ] ; then
       DISTR=debian
    fi
    DVERSION=`cat /etc/$i`
  fi
done
if [ -z $DISTRO ] ; then
  DISTRO="Not_identified"
  echo "The Linux distribution is $DISTR0"
  echo "	Please report the identifying /etc/FileName to discuss@linmodems.org"
else
  echo "The Linux distribution is:   $DISTR"
fi

echo "  End of distribution check."
echo

echo Diagnostic information is progressively being written to $RECORD .
echo "Often, contents of this record can aid in solving problems."
# Head for RECORD
echo "# this report may enable you to solve problems."  >> $RECORD
echo "# But if further help is needed  send $RECORD to discuss@linmodems.org" >> $RECORD
echo "# Please use as the following as the email Subject:" >> $RECORD
SUBJECT="$BN, $DISTR, $DVERSION, kernel $SYS"
echo SUBJECT=($SUBJECT) >> $RECORD
echo DEVFS=$DEVFS >> $RECORD
echo UNAME_A=`uname -a` >> $RECORD
VERS=`ls -d /usr/share/doc/ltmodem*`
echo VERS=$VERS >> $RECORD

echo
read -p "To continue:  Enter"
echo "===================================================================="

echo You will be requested to participate by prompts to Enter a pre-written command such as:
echo "  ls NoFile"
echo
read -p "Enter"
echo
echo with the resulting output appearing between the dotted lines. 
echo --------------------
ls NoFile
echo --------------------
echo
echo And with
echo --------------------
echo --------------------
echo meaning no output was generated.
echo
echo =================================================================
echo Proceeding to access PCI modem hardware information
read -p "Enter"
echo 

SCAN=`ls -dt /usr/share/doc/ltmodem-*/utils/scanPCI | sort -rn | cut -d' ' -f1`
if test -x utils/scanPCI ; then
  SCAN=utils/scanPCI
  echo Found utils/scanPCI
elif test -x $SCAN ; then
  echo Found $SCAN
else
  echo A scanPCI utility was not found
  SCAN=
  echo SCAN= >> $RECORD
fi
if test -n $SCAN ; then
#  echo Scanning for a PCI modem card
  $SCAN
fi


FAIL=
# To cancel any FAIL setting in earlier $RECORD

###  Report out prior actions
echo Proceeding to verify the presence of the modem drivers, please
read -p "Enter"
echo
# get version
echo The active System kernel is $SYS
SUBVER=`echo $SYS | cut -d. -f2`
if test -d /lib/modules/$SYS/ltmodem ; then
  MODULES_AT=/lib/modules/$SYS/ltmodem
  CUT="-f10-"
elif [ "$SUBVER" = "2" ] ; then
  MODULES_AT=/lib/modules/$SYS/misc/
  CUT="-f10-"
elif test $SUBVER -ge 4 ; then
  MODULES_AT=/lib/modules/$SYS/kernel/drivers/char
  CUT="-f12-"
  echo SUBVER=$SUBVER
else
  echo Could not identify candidate driver folders, exiting
  echo
  exit
fi
	
echo For kernels "$SUBVER".nn the modem drivers should have been installed within:
echo "  $MODULES_AT"
echo start modules section ------------------- >> $RECORD
echo MODULES_AT=$MODULES_AT >> $RECORD
sleep 2
echo
echo Changing directory:
echo "  cd $MODULES_AT"
cd $MODULES_AT

echo
echo The output to the next output should at least include:
echo -------------------
echo -rw-r--r--    1 root     root        SIZE  DATE_install $DSP.o
echo -rw-r--r--    1 root     root        SIZE  DATE_install $SERIAL.o
echo -------------------
echo wherein the driver with proprietary  DSP=Digital Signal Processor code is:
echo "  $DSP.o"
echo and the driver with Open Source code is:
echo "  $SERIAL.o"
echo 
# echo To prevent a command form acting when only display to console is desired
# echo a command name will be capitalized as for next LS list command below.
echo To display the resident drivers:
read -p "Enter "  
echo -------------------
ls -l "$GN"*
ls -l "$GN"* >> $RECORD 
echo -------------------

LTM=`find  /lib/modules/*/misc/ /lib/modules/*/kernel/drivers/char/ /lib/modules/*/ltmodem/  \
          -iname lt_*.o 2>/dev/null | cut -d'/' -f4-8`
if [ -f $DSP.o ] ; then
  echo "Found driver:	$DSP.o"
  SITE_D="$MODULES_AT"/"$DSP".o
  echo "SITE_D"="$SITE_D" >> $RECORD 
  # echo "SITE_D"="$SITE_D"
else
  echo
  echo "An essential driver has not been installed:     $DSP.o"
  echo "An essential driver has not been installed:     $DSP.o" >> $RECORD
  echo 
  echo LT_Modules installed are LTM=$LTM
  echo LTM=$LTM >> $RECORD
  echo Listing contents of $MODULES_AT/
  ls $MODULES_AT
  FAIL=$DSP.o
  echo $MSG
  echo $MSG >> $RECORD
  exit 2
fi

if [ -f $SERIAL.o ] ; then
  echo "Found driver:	$SERIAL.o"
  SITE_S="$MODULES_AT"/"$SERIAL".o
  # echo "SITE_S"="$SITE_S"
  echo "SITE_S"="$SITE_S" >> $RECORD
else
  echo
  echo "An essential driver has not been installed:     $SERIAL.o"
  echo "An essential driver has not been installed:     $SERIAL.o"  >> $RECORD
  echo Listing contents of $MODULES_AT/
  echo
  echo Exiting
  echo $MSG
  echo $MSG >> $RECORD
  exit 2
fi


ls "$GN"*.o~ &> $TMPM.drivers
if test -f $TMPM.drivers ; then
  echo
  echo The modules terminated with: "~"
  ls "$GN"*.o~
  echo are backup copies originating in a previous install,
  echo and renamed by the subsequent INSTALL command actions.
fi

echo
# echo FAIL=$FAIL
echo FAIL=$FAIL >> $RECORD
if test -z "$FAIL" ; then
  echo Modem drivers check completed.
  echo
  echo Changing back to the original Working folder:
  echo "        cd $WORK"
  cd $WORK
else
  echo The failure of $DSP residence must be corrected before proceeding.
fi
echo End modules installed section ------------------- >> $RECORD
echo >> $RECORD
echo =========================================================  
echo
echo There is a functional dependence between many kernel modules.
echo During boot up and module installations, these dependencies are written during a:
echo "	depmod -a"
echo "to FileNames:       /lib/modules/$SYS/modules.*"
read -p "Enter"
echo ---------------------
ls /lib/modules/$SYS/modules.*
echo ----------------------
echo
echo The "$GN" modules lines within then can be selectively displayed with:
echo "	grep "$GN" /lib/modules/$SYS/modules.* "
read -p "Enter"
grep "$GN" /lib/modules/$SYS/modules.* | grep -v "~" > $TMPM.depends
echo ----------------------
cat  $TMPM.depends
echo ----------------------
echo
echo For simplicity, some trimming of the PATHs can be done:
echo ----------------------
cat $TMPM.depends | cut -d/ $CUT
cat $TMPM.depends | cut -d/ $CUT >> $RECORD
echo ----------------------
echo The first line including only $DSP.o shows that its loading
echo has no prior dependencies.
echo The line with $SERIAL.o followed by $DSP.o 
echo means $SERIAL.o loading requires prior loading of $DSP.o
if grep "$GN" /lib/modules/$SYS/modules.* | grep isa-pnp > /dev/null ; then
  echo The line with $SERIAL and isa-pnp says $SERIAL loading
  echo is also dependent upon prior loading of isa-pnp.
  ISA=isa-pnp
fi
echo end modules dependencies section ------------------- >> $RECORD
echo
if test -z "$DEVFS" ; then
  echo Device node section  ------------------- >> $RECORD
  echo Driver loading is dependent upon the existence of a device node: $NODE
  echo through which the drivers communicate with the modem hardware.
  echo Checking for the modem device node:
  echo "        ls -l $NODE"
  read -p "Enter"
  echo ---------------
  ls -l $NODE &> $TMPM.node
  cat  $TMPM.node >> $RECORD
  cat  $TMPM.node 
  echo ---------------
  GROUP=`cat  $TMPM.node | cut -d' ' -f8-12` 
  if ! grep No $TMPM.node ; then
    echo The required $NODE exists, with access by members of Group: $GROUP.
    echo
    echo Current Group settings are easily displayed by using a GREP filtration: 
    echo "	grep $GROUP /etc/group"
    read -p "Enter"
    echo -------------------
    grep $GROUP /etc/group
    echo -------------------
    echo NODE=$NODE >> $RECORD
    echo GROUP=$GROUP >> $RECORD
    echo for further information: man group
  else
    echo The required $NODE does NOT exist!!
    if [ -L autoload ] ; then 
      NODE=
      echo NODE= >> $RECORD
      echo "Please rerun:       ./autoload"
      echo and then again:      $BN
      echo if there is a second failure, and
      echo $MSG
      echo
      exit 1
    fi
  fi
  echo
  echo "The expected symbolic link is:	$LINK to $NODE"
  echo "	ls -l $LINK"
  read -p "Enter"
  echo ----------------------
  ls -l $LINK > $TMPM.link.txt
  cat $TMPM.link.txt
  cat $TMPM.link.txt >> $RECORD
  echo ----------------------
  if grep $NODE $TMPM.link.txt > /dev/null ; then
    echo Passed symbolic link test.
    echo LINK=$LINK >> $RECORD 
  else
    echo Test for $LINK failed.
    echo LINK= >> $RECORD
    echo $MSG
  fi
echo
fi

fi # FAST

echo
echo Proceed to the driver loading test.
echo Driver loading section ---------------------------- >> $RECORD
# For illustration, remove drivers first
modprobe -r $SERIAL &> /dev/null
echo First check which drivers are loaded already with:
echo "	lsmod"
read -p "Enter"
echo ----------------------
lsmod
echo ----------------------
echo
echo "Looking through such long lists is a nuisance."
echo "So hereafter in this $BN, the information display will be commonly simplified"
echo "through use of the filtering expression:   grep "$GN""
echo "which will Only Pass lines containing: "$GN""
echo "	lsmod | grep "$GN""
read -p "Enter"
echo ----------------------
lsmod | grep "$GN"
echo ----------------------
echo
echo Thus the modem drivers are not now loaded.
echo

echo The drivers can be loaded sequentially by:
echo "	insmod $DSP"
if test -n "$ISA" ; then 
  echo "	insmod $ISA"
fi

echo "	insmod $SERIAL"
echo "or through use of the a Smart command which reads the dependency files,"
echo "and then loads all the pre-dependents in the proper order."
echo "Using -v to additionally specify Verbose Reporting, the command is:"

echo "	modprobe -v $SERIAL"
read -p "Enter"
echo "modprobe -v $SERIAL" >> $RECORD
modprobe -v $SERIAL  &> $TMPM.modprobe.txt 
echo ----------------- >> $RECORD
echo -----------------
cat $TMPM.modprobe.txt >> $RECORD
cat $TMPM.modprobe.txt
echo -------------------
echo ----------------- >> $RECORD

if grep taint $TMPM.modprobe.txt >/dev/null ; then
  TAINTED=$DSP
  echo
  echo Do not be overly concerned about the comment: will taint the kernel --
  echo It is mostly a service to developers doing debugging
  echo and also reflects the wish that all code had a GPL lincense.
  echo For some detail, see DOCs/Tainted.txt.
fi

echo
echo Checking for inserted modem drivers with:
echo "	lsmod | grep $GN"
read -p "Enter"
echo ---------------------
lsmod | grep "$GN"
echo ---------------------

if grep $DSP /proc/modules > /dev/null ; then
  echo Confirming that the drivers were successfully loaded.
  LOADED="$GN"drivers
else
  echo Since the "$GN"driver loading did not succeed, trouble shooting must be pursued.
  echo
  echo A less demanding test is loading only of $DSP.o by: 
  echo "	modprobe -v $DSP"
  read -p "Enter"
  modprobe -v $DSP  &> $TMPM.modprobe.txt 
  echo ------------------------
  cat $TMPM.modprobe.txt 
  echo ------------------------
  if grep taint $TMPM.modprobe.txt >/dev/null ; then
    if test -z "TAINTED" ; then
      TAINTED=$DSP
      echo
      echo Do not be overly concerned about the comment: will taint the kernel --
      echo It is mostly a service to developers doing debugging
      echo and also reflects the wish that all code had a GPL lincense.
      echo For some detail, see DOCs/Tainted.txt.
      echo 
    fi
  fi
  echo
  echo Proceed to check for loading with:
  echo "	lsmod | grep $GN"
  read -p "Enter"
  echo ---------------------
  lsmod | grep "$GN"
  echo ---------------------
  if grep taint $TMPM.modprobe.txt >/dev/null ; then
    if test -z "TAINTED" ; then
      TAINT=$DSP
      echo Do not be overly concerned about the taint comment.
      echo It is mostly a service to developers doing debugging
      echo and reflects the wish that all code had a GPL lincense.
      echo For some detail, see DOCs/Tainted.txt
      echo
    fi 
  fi

  if grep $DSP /proc/modules > /dev/null ; then
    echo The loading of $DSP.o was successful. A good first step.
    LOAD_D=$DSP
    echo LOAD_D=$DSP >> $RECORD
    echo Loading of $SERIAL.o can be tried again with:
    echo "	modprobe -v $SERIAL.o"
    read -p "Enter"
    modprobe -v $SERIAL  &> $TMPM.modprobe2.txt 
    cat $TMPM.modprobe2.txt >> $RECORD
    echo ----------------- >> $RECORD
    echo -----------------
    cat $TMPM.modprobe2.txt >> $RECORD
    cat $TMPM.modprobe2.txt
    echo -------------------
    echo ----------------- >> $RECORD
    if grep $SERIAL /proc/modules > /dev/null ; then
      echo 
      echo The loading of $SERIAL.o was successful.
      echo LOAD_S=$SERIAL >> $RECORD 
      LOADED="$GN"drivers
      LOADED="$GN"drivers >> $RECORD
      echo Strange that the first insertion failed.
    else
      echo
      if test -z "TAINTED" ; then
        TAINT=$DSP
        echo Do not be overly concerned about the comment: will taint the kernel --
        echo It is mostly a service to developers doing debugging
        echo and also reflects the wish that all code had a GPL lincense.
        echo For some detail, see DOCs/Tainted.txt.
      fi
      echo The failure of $SERIAL.o to load following success with $DSP
      echo could have a few causes:
      echo 1. The modem may not be a Lucent DSP type.  Lucent AMR and some ESS
      echo modems support the loading of $DSP.o and sometimes dialing as well,
      echo but ppp initiation fails often with a System hang.
      echo 2. The of Forcing parameters may be needed.  Read within DOCs/,
      echo Insert-param.html
      echo 3. There may be resource conflicts.  In this case, the problem may be
      echo lessened by some unloading of excess modules.
      LOADED=
     fi
  fi
fi
echo LOADED=$LOADED >> $RECORD
echo
echo end Module loading section ------------------- >> $RECORD
echo "Module loading section finished. To continue:"
read -p "Enter"
echo =============================================

##   Device system alternative
if test -n "$DEVFS" ; then
echo DEVFS node section  ------------------- >> $RECORD
echo "The current kernel is supporting a dynamic devfs, short for:    DEvice File System."
echo "as shown by the existence of a special device file:     /dev/.devfsd"
echo Display it with:
echo "        ls -l /dev/.devfsd"
read -p "Enter"
echo ----------------------
ls -l /dev/.devfsd
echo NODE_DEVFSD=/dev/.devfsd >> $RECORD
echo ls -l /dev/.devfsd >> $RECORD
echo -----------------------
echo
echo Under devfs action, device nodes are dynamically created, BUT, only as needed.
echo This creation is directly coupled with loading of the modem drivers.
echo Conversely, unloading of the modem drivers removes their device node.
echo diminishing the tracking load on the Operating system.
echo
echo The modem node created by the device file system has designation: $NODE
echo Nodes with serial-like functionality It can be displayed by:
echo "	ls -l /dev/tts/* "
read -p "Enter"
echo ----------------------
ls -l /dev/tts/*
echo ----------------------
echo with tts/0 corresponding to a non-devfs /dev/ttyS0 serial port.
echo 
if test -n "$LOADED" ; then
  echo All symbolic links to a node can be displayed by a query like:
  echo "	ls -l /dev/* | grep $SNODE "
  read -p "Enter"
  echo >> $RECORD
  echo "	ls -l /dev/* | grep $SNODE "  >> $RECORD
  ls -l /dev/* | grep $SNODE > $TMPM.snode
  echo ----------------- >> $RECORD
  echo ----------------------
  cat $TMPM.snode
  cat $TMPM.snode >> $RECORD
  echo ----------------------
  echo ----------------- >> $RECORD
  if grep "tts/LT0" $TMPM.snode > /dev/null ; then 
    echo The symbolic links are thus $LINK and $LINKS
    echo Dialer utilties should as kppp will default to $LINK ,
    echo The configuration test WVDIALCONF for dialer WVDIAL
    echo only searches for ports with name style /dev/ttySxxx
    echo and this need is served by $LINKS.
    echo
  fi
fi
echo ===========================================================
echo
echo Symbolic link support issues next.
read -p "Enter"
echo The links are dynamically created by action of a devfsd daemon
echo concurrent with creation of /dev/tts/LT0 by devfs.
# echo There are support lines for links creation 
if [ -f /etc/devfs/conf.d/ltmodem ] ; then
  TARGET="/etc/devfs/conf.d/ltmodem"
elif [ -f /etc/devfsd.conf ] ; then 
  TARGET="/etc/devfsd.conf"
else
  TARGET=
fi
if test -n "$TARGET" ; then
  echo "with guidance from the lines"
  echo "        within $TARGET":
  echo ---------------------------------  
  echo "# /dev/modem symbolic link to /dev/tts/LT0 "
  echo REGISTER        ^tts/LT0$       CFUNCTION GLOBAL symlink $devname modem
  echo UNREGISTER      ^tts/LT0$       CFUNCTION GLOBAL unlink modem
  echo ---------------------------------
  echo
  echo These can be selective displayed by:
  echo "        grep LT0 $TARGET"
  read -p "Enter " 
  echo ---------------------------------
  grep LT0 $TARGET 
  echo ---------------------------------
else
  TARGET=
  echo Strange, a file with expected devfsd daemon support lines was not found!
  echo $MSG
fi
echo TARGET=$TARGET >> $RECORD

echo Node test completed.
echo end DEVFS node section  ------------------- >> $RECORD
fi # DEVFS section


echo =================================================================
echo
if [ "$MODEM" = "LDSP" ] ; then
echo The next check is for lines supporting autoloading of modem drivers on demand.
echo "These lines should have been written to:   /etc/modules.conf"
echo ---------------------------------
echo "  # "$GN"drivers: autoloading and insertion parameter usage"
echo "  alias char-major-62 $SERIAL"
echo "  alias /dev/modem $SERIAL"
echo "  alias /dev/tts/LT0 $SERIAL"
echo "  # options $DSP vendor_id=0x115d device_id=0x0420 Forced=3,0x130,0x2f8"
echo "  # section for "$GN"drivers ends"
echo ---------------------------------

echo Expected lines are: >> $RECORD
echo ---------------------------------  >> $RECORD
echo "  # "$GN"drivers: autoloading and insertion parameter usage" >> $RECORD
echo "  alias char-major-62 $SERIAL" >> $RECORD
echo "  alias /dev/modem $SERIAL" >> $RECORD
echo "  alias /dev/tts/LT0 $SERIAL" >> $RECORD
echo "  # options $DSP vendor_id=0x115d device_id=0x0420 Forced=3,0x130,0x2f8" >> $RECORD
echo "  # section for "$GN"drivers ends" >> $RECORD
echo -------------------------------- >> $RECORD
echo of which the third alias line is only relevant to Systems using the device file system. >> $RECORD
echo These lines provide for loading of the modem drivers whenever >> $RECORD
echo there is a query to $NODE , either directly or through its symbolic links. >> $RECORD

echo of which the third alias line is only relevant to Systems using the device file system. 
echo These lines provide for loading of the modem drivers,  
echo whenever there is a query to $NODE , either directly or through its symbolic links. 

echo 
echo To selectively display related lines on your System:
echo "  grep "$GN" /etc/modules.conf"
read -p "Enter " 
echo ----------------------------------
grep "$GN" /etc/modules.conf
echo ----------------------------------
echo
echo >> $RECORD
echo Installed lines are: >> $RECORD
echo ---------------------------------- >> $RECORD
grep "$GN" /etc/modules.conf >> $RECORD
echo ---------------------------------- >> $RECORD
echo >> $RECORD
echo
echo "These lines should be complemented in ppp related alias lines, also in   /etc/modules.conf:"
echo -----------------------------------------
echo alias /dev/ppp          ppp_generic
echo alias char-major-108    ppp_generic
echo alias tty-ldisc-3       ppp_async  
echo alias tty-ldisc-14      ppp_synctty
echo alias ppp-compress-21   bsd_comp   
echo alias ppp-compress-24   ppp_deflate
echo alias ppp-compress-26   ppp_deflatecho 
echo ------------------------------------------
echo Display those on your system with command:
echo "	grep ppp /etc/modules.conf"
read -p "Enter " 
echo
echo ----------------------------------
grep ppp /etc/modules.conf
echo ----------------------------------
echo >> $RECORD
echo ---------------------------------- >> $RECORD
grep ppp /etc/modules.conf >> $RECORD
echo ---------------------------------- >> $RECORD
echo >> $RECORD
echo
echo "The $BN of installed components and their configuration lines is completed:"
echo "	The "$GN"drivers  $DSP.o and $SERIAL.o ."
if test -n "$DEVFS" ; then 
  echo "	The device nodes $NODE and its symbolic links $LINK  and $LINKS,"
  echo "	with support lines in $TARGET."
else
  echo "	The device nodes $NODE and its symbolic link $LINK"
fi
echo "	The driver autoloading support lines in /etc/modules.conf ."
if test -n "$LOADED" ; then
  echo "	Lastly, the loading of the the drivers is successful."
else
  if test -n "$LOAD_D" ; then
    echo But the failure in $SERIAL loading must be alleviated.
  else
    echo the failures in driver loading must be alleviated.
  fi
fi
echo "	"
echo #BN summary section done >> $RECORD
fi # End LDSP section

if test -n "$LOADED" ; then
# the configuration trial with WVDIALCONF
echo =======================================================================
read -p "To prepare for a modem test:   Enter" 
echo
WVDIALCONF=`which wvdialconf`
if test  -z "$WVDIALCONF" ; then
  echo Installation of the package WVDIAL provided by your Linux distro is recommended.
  echo Then rerun $BN
  echo 
  echo An alternative is to use MINICOM, whose usage is not served by this script however.
  echo "For MINICOM, use as the port setting:   $NODE"
  echo  
  exit 1
fi

if [ -x $WVDIALCONF ] ; then
  echo The dialout utility WVDIAL is present and executable,
  echo so let us proceed promptly towards this test.
  echo
  echo While the modem drivers will autoload when configuration steps are completed,
  echo "loading by manual command may be necessary for for the trial:	WVDIALCONF"
fi

echo
echo "The WVDIALCONFIG utility only screens for ports with name style:	/dev/ttySxxx"
echo Hence it is necessary to supply a suitable port name or symbolic link.
if [ -c /dev/ttyLT0 ] ; then
  echo "Such a supportive nomenclature is not provided by:     $LINK"
  echo But a temporary symbolic link can be made with:
  echo "        ln -sfv $NODE $LINKS"
  read -p "Enter" 
  echo ------------------
  ln -sfv $NODE $LINKS
  echo ------------------
  echo and checking with:
  "	ls -l $LINKS"
  read -p "Enter"
  echo ---------------
  ls -l $LINKS
  echo ---------------
  echo the test can proceed.
elif test -n "$DEVFS" ; then
  echo "Under the devfs there will suffice the symbolic link:        $LINKS"
  echo To verify its target:
  echo "        ls -l $LINKS"
  read -p "Enter " 
  echo -----------------
  ls -l $LINKS
  echo -----------------

else
  echo A modem device node could not be found!
  echo $MSG
fi
echo

echo ===============================================================
echo
read -p "To proceed with the WVDIALCONF trial:  Enter"
echo
echo The output will first be captured and parsed
echo "and a trial configuration file written here:      $WORK/wvdial.conf"
rm -f ./wvdial.conf > /dev/null
echo
echo "  wvdialconf $WORK/wvdial.conf "
read -p "Enter"
echo -------------------------------------
wvdialconf $WORK/wvdial.conf
echo -------------------------------------
if [ -f wvdial.conf ] ; then 
  echo Below change $LINKS  to $LINK  >>  $RECORD
  mv $RECORD $RECORD.TMPM
  cat $RECORD.TMPM  $WORK/wvdial.conf >>  $RECORD
  rm $RECORD.TMPM &> /dev/null
  echo SUCCESSFUL, Great! So your System should soon be on line under Linux!
  echo
  echo Here is the trial wvdial.conf
  cat wvdial.conf
  echo 
  echo It has been copied to $RECORD 
  echo After your edits, it should be copied to: /etc/wvdail.conf
  echo where it is expected by the companion dialout utility: wvdial
  if test -z "$DEVFS" ; then
    echo The symbolic link $LINKS
    rm -f $LINKS
    echo has now been deleted.
    echo For some RARE system configurations and hardware,
    echo it may cause System hangs upon bootup serial port scannning.
  else
    echo $LINK but NOT $LINKS is compatibile with the autoloading support
    echo specfied within /etc/modules.conf :
    echo "	alias /dev/modem lt_serial"
    echo Within wvdial.conf , replace $LINKS with $LINK 
  fi 
  echo 
  echo Knowing you are anxious to get on line, the rest of $BN will be skipped.
  echo The skipped section has an module unloading routine 
  echo useful for lessening resource conflicts, which is also contained in utils/
  echo
  echo For guidance on completing dialout scripts,
  echo read within DOCs/ wvdial.txt and dialout.txt
  echo
  rm "$TMPM"*
  exit 2
else
  echo FAILED, too bad.
  echo We still have work to do!
fi
fi  # end LOADED success Section

read -p "       to continue: Enter"
echo "========================================================"
echo 

if test -z "$LOADED" ; then
echo
echo Resource conflicts can block modem access. For example, conflicts have been reported
echo with drivers supporting Infrared communications and Sound on some laptops.
echo See DOCs/Ltmodem.html for URLs to these reports.
echo
echo Hence this next preparatory step, during which functions 
echo non-essential for ppp functionality will be shutdown.
echo These include support for Ethernet and Pcmcia and unloading of Non-essential modules.
echo If there are programs running using any of these functions,
echo please terminate them before proceeding further.
echo Otherwise there supporting modules will Not be unloaded
echo
echo Should you wish to avoid these actions,
echo "  abort now with:  Ctrl-C"
read -p "       or to continue: Enter"
echo "========================================================"
echo 

ETH=`ifconfig | grep eth | cut -d' ' -f1`
if test -n "$ETH" ; then
   echo There is an "$ETH", shutting it down
   echo ETH=$ETH >> $RECORD
   ifconfig $ETH down > /dev/null
else
   echo Ethernet not detected.
fi
echo


### Start of procedures to free up resources
###  
MODULES=`lsmod |  cut -d' ' -f1 | grep -v Module`
# just captures the module list compactly
echo The initial modules list is:
echo $MODULES
echo MODULES_INITIAL=$MODULES >> $RECORD
echo
echo Now attempting removals sequentially with: modprobe -r ModuleName
MODTMPM=$TMPM.lsmod
echo $MODULES > $MODTMPM 
for MODULE in $MODULES
do 
   if grep $MODULE $MODTMPM >/dev/null
     then
     modprobe -r $MODULE
     lsmod |  cut -d' ' -f1 | grep -v Module > $MODTMPM
     # which regenerates the shortened list
   fi
done
# with 1st round of removals
echo

if grep pcmcia $MODTMPM >/dev/null
  then
  echo PCMCIA=`grep pcmcia $MODTMPM` >>  $RECORD
  echo Now stopping any pcmcia support with:
  echo "        /etc/init.d/pcmcia stop"
  /etc/init.d/pcmcia stop
  echo
  echo Rerunning module removals.
  MODULES=`lsmod |  cut -d' ' -f1 | grep -v Module`
  echo The residual modules list is:
  echo $MODULES
  echo $MODULES > $MODTMPM 
  for MODULE in $MODULES
  do 
    if grep $MODULE $MODTMPM >/dev/null
    then
    modprobe -r $MODULE
    lsmod |  cut -d' ' -f1 | grep -v Module > $MODTMPM
    fi
  done
else 
  echo PCMCIA support modules not resident.
fi
rm "$TMPM"* &> /dev/null

echo After removals there remain:
MODULES_FINAL=`lsmod |  cut -d' ' -f1 | grep -v Module` 
echo $MODULES_FINAL
echo MODULES_FINAL=$MODULES_FINAL >> $RECORD
echo
echo With the potential resource conflicts now reduced,
echo please again run $BN
echo
fi # not LOADED



