#!/bin/sh

onexit()
{
  terminate Installation aborted
}


install_modemsup()
{
  message ""
  message "Installing modem support software v1.0.3"
  rm -rf $TMP_RDAINSTALL

  countries=`cd $AUXDIR/modem_config;echo *`
  (cd $AUXDIR; $BIN/country "$countries")

  message ""
  message "Installation should take about 2 minutes....."
  message ""
  if [ -f $TMP_RDAINSTALL/MultiTech ]; then
    remove_service

    PORT=`choose_port`
    validate_port $PORT

    write_modem $PORT initialise

    install_service
    
    install_portmon $PORT

    show_monitor

    if [ $PORT = "a" ]; then
      message ""
      case `ask "Do you have the modem connected to port A via a serial T switch [y/n]?" y Y n N` in
	[yY]) eeprom -i ttya-mode=19200,8,n,1,-
	      message ""
	      message "*****************************************************************************"
	      message "NOTE: An EEPROM command was issued to change the console speed to 19200 baud."
	      message "You need to do a PROM \"reset\" for this change to take effect."
	      message ""
	      message "Also, you should update the console connected to port A to 19200 baud."
	      message "*****************************************************************************"
	      message "";;
	*) break;;
      esac
    	      

      # update the console speed in /etc/ttydefs file
      grep '^console:9600 ' /etc/ttydefs > /dev/null 2>&1
      if [ $? -eq 0 ]; then
        save /etc/ttydefs
        cp /etc/ttydefs /tmp/ttydefs.$$
        sed -e '/console:9600 /s/\(.*\):9600 \(.*\):9600::\(.*\)/\1:19200 \2:19200::\3/' < /etc/ttydefs.$$ > /etc/ttydefs
        rm /tmp/ttydefs.$$
      fi    
    fi
  fi
}


# Main ...
# --------

case x"`uname -r`" in
  x4*) OS=4.x;;
  x5*) OS=5.x;;
  *) echo "Could not determine OS version.  Exiting!";
     exit 1;;
esac

trap onexit 1 2 3 15

PATH=$BIN:/bin:/usr/sbin:/usr/ucb export PATH
TMP=/tmp
BASEDIR=`pwd`
AUXDIR="$BASEDIR/.aux_install"
LIB=$AUXDIR/lib/$OS
BIN=$AUXDIR/bin/$OS

# don't change the following.  Other programs rely on this pathname
TMP_RDAINSTALL=/tmp/rda_install

#
# load in shell library functions for later use
#
 
. $LIB/utilities
. $LIB/check_port
. $LIB/check_os
. $LIB/install_eeprom
. $LIB/install_portmon
. $LIB/install_strmod
. $LIB/write_modem
. $LIB/choose_port
. $LIB/show_monitor
. $LIB/install_service
. $LIB/remove_service


install_modemsup

export OS MONITOR

exit 0
