#===========================================================================
# File Name :     agrinst
#
# Copyright (c) 2002, 2003, 2004 Agere Systems, Inc.  All rights reserved.
#
# Description:
#  Installation script for Agere Soft Modem driver modules
#  This script installs 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
#===========================================================================
#!/bin/sh

group="uucp"
mode="666"

#device="/dev/ttyAGS14"
device="/dev/ttyAGS3"
verbose="-v"

echo Installing Agere Softmodem driver version 2.1.80-Red Flag NE 5.0

if [ -e ./agrmodem.ko ] && [ -e ./agrserial.ko ]
then
a=$(ps -A | grep AgereMdmDaemon | cut -c1-5)
if [  "$a" != ""  ]
then
	kill $a
fi
 
  if [ $# -eq 1 ] && [ $1 = $verbose ]
  then
    ./agruninst -v > /dev/null 2>/dev/null; \
  else
    ./agruninst -b > /dev/null 2>/dev/null; \
  fi

  if [ -d /lib/modules/`uname -r`/kernel/drivers/char/ ]
  then
#	  if [ $# -eq 1 ] && [ $1 = $verbose ]
#     then
    	  echo copying agrmodem.ko and agrserial.ko to /lib/modules/`uname -r`/kernel/drivers/char; \
#   fi

    cp ./agrmodem.ko /lib/modules/`uname -r`/kernel/drivers/char/; \
    cp ./agrserial.ko /lib/modules/`uname -r`/kernel/drivers/char/; \

  else

    if [ -d /lib/modules/`uname -r`/misc ]
    then
      :
    else
	    mkdir /lib/modules/`uname -r`/misc; \
    fi

#	  if [ $# -eq 1 ] && [ $1 = $verbose ]
#     then
    	  echo copying agrmodem.ko and agrserial.ko to /lib/modules/`uname -r`/misc; \
#   fi
    cp ./agrmodem.ko /lib/modules/`uname -r`/misc/; \
    cp ./agrserial.ko /lib/modules/`uname -r`/misc/; \
  fi

  chmod +x agr_softmodem
  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/halt ]; then \
    cp -f ./agr_softmodem $RC_DIR/agr_softmodem; \
    if [ -d /etc/rc.d/rc3.d ]; then \
      ln -s $RC_DIR/agr_softmodem /etc/rc.d/rc3.d/S99agr_softmodem; \
    fi
    if [ -d /etc/rc.d/rc5.d ]; then \
      ln -s $RC_DIR/agr_softmodem /etc/rc.d/rc5.d/S99agr_softmodem; \
    fi
  fi

  mknod $device c 62 67
#  ln -s $device /dev/modem
  chgrp $group $device
  chmod $mode $device

  ./agr_auxinst copy
  $RC_DIR/agr_softmodem start
  #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
else
  echo some files needed for installation are missing; \
fi


