#!/bin/ksh
unlockppp=1
quiet=0
provider=""
while [ $# -gt 0 ]
do
   case "$1" in
      -n )
          unlockppp=0
          shift
          ;;
      -q )
          quiet=1
          shift
          ;;
       * )
          if [ "$provider" = "" ]
          then
             provider=$1
             shift
          else
             echo "usage: detach [-q] [-n]"
             echo "   -q	Be quiet"
	     echo "   -n	Do not remove PPP lock"
             exit 1
          fi
          ;;
   esac
done
 
# Check UID
if [ "`/usr/ucb/whoami`" != "root" ]
then
   echo "Error: You must be root to execute `basename $0`"
   exit 1
fi
 
# By default detach from INFO2000
if [ "$provider" = "" ]
then
   provider="info2000"
fi
 
case "$provider" in
   info2000)
        isp_host=pm1
        ;;
      *)
        echo "Error: Unknown ISP ($provider)"
        exit 1
        ;;
esac
 
ifc_cmd=`egrep "^ifconfig.*$isp_host" /etc/asppp.cf`
ifc=`echo $ifc_cmd | awk '{print $2}'`
if [ -n "`ifconfig -a | grep $ifc`" ]
then
   id=`ps -e | grep aspppd | awk '{print $1}'`
   if test -n "$id"
   then
      kill -HUP $id
   fi
    eval $ifc_cmd
fi
route delete default $isp_host > /dev/null 2> /dev/null
# Do any other route manipulation or update /etc/resolv.conf if needed
 
if [ $quiet -eq 0 ]
then
   echo "Routing table after detaching from $provider:"
   netstat -rn
fi
 
if [ $unlockppp -eq 1 ]
then
   /opt/local/bin/pppunlock
   if [ $? -ne 0 -a $quiet -eq 0 ]
   then
      echo "detach: Failed to release PPP lock"
   fi
fi
exit 0