#!/bin/sh

## Check permissions
if [ $UID -ne 0 ]; then
   echo
   echo "Drivers and modules can only be installed with Root permssion!"
   echo "Please log in as root/superuser and rerun $0"
   echo
   exit 1
fi

# Just a bridge between old ltuninst and "make uninstall"
echo
echo Removing the modem drivers in the kernel modules tree.
echo
cd source

mkdir -p /tmp/ltmodem
TMPM=/tmp/ltmodem/tmpfile

DEPMOD_PATH="/bin /usr/bin /usr/sbin /sbin"
for i in $DEPMOD_PATH
do
  if test -x $i/depmod
  then
    DEPMOD=$i/depmod
    echo Using $DEPMOD
  fi
done
if test -z "$DEPMOD" ; then
  echo
  echo "A search for the utility depmod Failed! "
  echo
  exit 2
fi

source SETTINGS
make uninstall &> $TMPM
cat $TMPM | grep "rm "

echo
echo Checking dependencies of remaining modules.
if grep depmod: $TMPM >/dev/null
then
  grep depmod: $TMPM
  echo --------------------------
  if grep "modules." $TMPM >/dev/null
  then
    echo Be only modestly concerned about a warning of the type:
    echo "    something .. ELF ..."
    echo Within /lib/modules/`uname -r`/ the files with names of type:
    echo "    `grep ELF $TMPM | cut -d/ -f5 | cut -d ' ' -f1` "
    echo are not themselves modules, but rather map the modules.
    echo "The ELF complaint recommends upgrade of the software package MODUTILS"
    modprobe -V &> $TMPM
    echo While the resident version is: `grep version $TMPM | cut -d' ' -f3`
    echo "	  a minimal version of 2.4.2 is recommended for 2.4.18 kernels and later."
    echo Do presently take corrective action.
    echo
    sleep 5
  fi
  echo
  grep -v ELF $TMPM  > $TMPM.b
  echo --------------------------
  if grep depmod: $TMPM.b >/dev/null ; then
    grep depmod: $TMPM.b
    echo The remaining faults are more serious and quick corrective action is recommended.
    echo
    sleep 5
  fi
else
  echo Dependencies check passed.
fi

cd ..
/bin/rm -r /tmp/ltmodem
echo
