#!/bin/sh
set -e
echo
echo BASENAME=`basename $0`
sleep 3
OLDFILE=ltmodem
NEWFILE=ltmodem2
# The update-modules command does not process:  *.dpkg-new 
SCAN=/usr/bin/scanmodem
mkdir -p /tmp/ltmodem
TMPM=/tmp/ltmodem/tmpfile
RECORD=/tmp/ltmodem/ModemData.txt
echo > test $RECORD
export TMPM=$TMPM
export RECORD=$RECORD
export BASENAME=$BASENAME

#  $OLDFILE is identical with new /etc/modutils/$NEWFILE 
if test -f /etc/devfs/conf.d/$OLDFILE -a -f /etc/devfs/conf.d/$NEWFILE ; then
  # so remove duplicate
  rm -f /etc/devfs/conf.d/$OLDFILE
fi
# $NEWFILE will not be removed during purging of earlier Packages including OLDFILE

# When both old $OLDFILE and new $NEWFILE exist
if test -f /etc/modutils/$OLDFILE ; then
  # Maintain and configuration options in OLDFILE
  mv /etc/modutils/$OLDFILE /etc/modutils/$NEWFILE
fi
  
# check if ltmodem drivers are NOT installed
DRIVERS=`find /lib/modules/ -name lt_modem.o  -mindepth 3 -maxdepth 5`
if test -z "$DRIVERS" ; then
  echo LTdrivers not found
  mv /etc/modutils/$NEWFILE /etc/modutils/$NEWFILE.dpkg-back
  # update-modules does not process .dpkg-new files into /etc/modules.conf
  # Leave inactive to avoid conflict with another /dev/modem symbolic link
else
  echo LTdrivers found:
  find /lib/modules/ -name lt_modem.o  -mindepth 3 -maxdepth 5 
  # Activate /etc/devfs/conf.d/ltmodem2 if necessary by cutting the leading #
  if grep "# REG" /etc/devfs/conf.d/ltmodem2 >/dev/null ; then
    cut -d' ' -f2- /etc/devfs/conf.d/ltmodem2 > $TMPM
    cp $TMPM /etc/devfs/conf.d/ltmodem2
  fi
fi
echo

# outputs advice on optimal package to install
if [ -x $SCAN ] ; then
  echo Checking the PCI bus for modem devices with $SCAN
  $SCAN
else 
  echo Expected $SCAN not found.
fi


# a DSP=1 is written by $SCAN if a supported modem is found
if grep "DSP=1" $RECORD >/dev/null ; then
cat <<END

  A supported modem is present with 
  a Digital Signal Processing (DSP) chipset from Agere Systems Inc.,
  Installation of the a ltmodem driver package is recommended
  or usage of a ltmodem-SomeVersion.tar.gz compiler kit.
  Both are available at http://www.heby.de/ltmodem

END
else
cat <<END

  A modem compatible with ltmodem drivers has not been found.
  But ISA bus and 16 bit PCMCIA modems would not be detected
  But the utilitiy $SCAN  may prove useful in generating information on other modems.

  Additionally much of the documentation written to /usr/share/doc/winmodemlt
  is of broader utility then application to modems supported by the Lucent DSP modem drivers.
  Perhaps browse these before purging this package.

END
fi


