#===========================================================================
# File Name :     agruninst
# Description:
#  This script uninstalls the Agere Soft Modem driver modules.
#  This script will remove the the driver modules for the Agere Serial Modem 
#  Interface driver and the Agere Modem Controller driver
#
# Revision History:
#   Name                   Date          Change
#   Soumyendu Sarkar       12/03/2002    Initial
#
# Copyright (c) 2002, 2003, 2004 Agere Systems.  All rights reserved.
#===========================================================================
#!/bin/sh

bak="-b"
verbose="-v"

echo Uninstalling Agere Soft Modem driver
a=$(ps -A | grep AgereMdmDaemon | cut -c1-5)
if [  "$a" != ""  ]
then
	kill $a
fi

/sbin/rmmod agrserial
/sbin/rmmod agrmodem
#rm -f /dev/ttyAGS14
rm -f /dev/ttyAGS3
rm -f /dev/modem

  sudo perl -pi -e "s/^#modem/modem/" /etc/ppp/options
  sudo perl -pi -e "s/^local/#local/" /etc/ppp/options
  sudo perl -pi -e "s/#local on the serial device/local on the serial device/" /etc/ppp/options

  if [ -e /etc/rc.d/rc3.d/S99agr_softmodem ]; then \
    rm -f /etc/rc.d/rc3.d/S99agr_softmodem; \
  fi
  if [ -e /etc/rc.d/rc5.d/S99agr_softmodem ]; then \
    rm -f /etc/rc.d/rc5.d/S99agr_softmodem; \
  fi

  if [ -e /etc/rc.d/halt ]; then \
    RC_DIR=`echo /etc/rc.d`; \
  else
    if [ -e /etc/rc.d/init.d/halt ]; then \
      RC_DIR=`echo /etc/rc.d/init.d`; \
    fi
  fi

  if [ -e $RC_DIR/agr_softmodem ]; then \
    rm -f $RC_DIR/agr_softmodem; \
  fi

if [ -e /lib/modules/`uname -r`/kernel/drivers/char/agrmodem.ko ]
then
  if [ $# -eq 1 ] || [ $# -eq 2 ]
  then
#   if [ $# -eq 1 ] && [ $1 = $verbose ]
#   then
      echo Renaming old modem controller module in /lib/modules/`uname -r`/kernel/drivers/char to agrmodem.old; \
#   fi
    mv /lib/modules/`uname -r`/kernel/drivers/char/agrmodem.ko /lib/modules/`uname -r`/kernel/drivers/char/agrmodem.old; \
  else
    rm -f /lib/modules/`uname -r`/kernel/drivers/char/agrmodem.*; \
    echo Removing modem controller module from /lib/modules/`uname -r`/kernel/drivers/char; \
  fi
fi

if [ -e /lib/modules/`uname -r`/misc/agrmodem.ko ]
then
  if [ $# -eq 1 ] || [ $# -eq 2 ]
  then
#   if [ $# -eq 1 ] && [ $1 = $verbose ]
#   then
      echo Renaming old modem controller module in /lib/modules/`uname -r`/misc to agrmodem.old; \
#   fi
    mv /lib/modules/`uname -r`/misc/agrmodem.ko /lib/modules/`uname -r`/misc/agrmodem.old; \
  else
    rm -f /lib/modules/`uname -r`/misc/agrmodem.*; \
    echo Removing modem controller module from /lib/modules/`uname -r`/misc; \
  fi
fi

if [ -e /lib/modules/`uname -r`/kernel/drivers/char/agrserial.ko ]
then
  if [ $# -eq 1 ] || [ $# -eq 2 ]
  then
#   if [ $# -eq 1 ] && [ $1 = $verbose ]
#   then
      echo Renaming old modem serial interface module in /lib/modules/`uname -r`/kernel/drivers/char to agrserial.old; \
#   fi
    mv /lib/modules/`uname -r`/kernel/drivers/char/agrserial.ko /lib/modules/`uname -r`/kernel/drivers/char/agrserial.old; \
  else
    rm -f /lib/modules/`uname -r`/kernel/drivers/char/agrserial.*; \
    echo Removing modem serial interface module from /lib/modules/`uname -r`/kernel/drivers/char; \
  fi
fi

if [ -e /lib/modules/`uname -r`/misc/agrserial.ko ]
then
  if [ $# -eq 1 ] || [ $# -eq 2 ]
  then
#  if [ $# -eq 1 ] && [ $1 = $verbose ]
#   then
      echo Renaming old modem serial interface module in /lib/modules/`uname -r`/misc to agrserial.old; \
#   fi
    mv /lib/modules/`uname -r`/misc/agrserial.ko /lib/modules/`uname -r`/misc/agrserial.old; \
  else
    rm -f /lib/modules/`uname -r`/misc/agrserial.*; \
    echo Removing modem serial interface module from /lib/modules/`uname -r`/misc; \
  fi
fi

