#!/bin/sh
#
#
# Copyright (c) 1999-2000 by Sun Microsystems, Inc.
# All rights reserved.
#
#pragma ident	"@(#)rsc-config.sh	1.38	02/10/14 SMI"

#
# RSC configuration script
#

#
# location of rsc files
#
PLATFORM=`uname -i`
rsc_path="/usr/platform/${PLATFORM}/"
rscadm_bin="$rsc_path""rsc/rscadm"
rsc_firmware="$rsc_path""lib/images/rscfw"
rsc_initscript="$rsc_path""rsc/rsc-initscript"
rsc_device="/dev/rsc-control"

#
# platform-specific info
#
platforms="Sun Fire 280R/V480/V880"
littleneck="SUNW,Sun-Fire-280R"
lneck_name="Sun Fire 280R"
cherrystone="SUNW,Sun-Fire-480R"
cstone_name="Sun Fire V480"
daktari="SUNW,Sun-Fire-880"
dak_name="Sun Fire V880"

#
# variables with defaults
#
all_ok='false'
textdomain=SUNW_RSC_CFG
rsc_user_added='n'
rsc_reset_when_complete='n'
rsc_set_date='y'
rsc_hostname=`hostname`
rsc_set_customerinfo='n'
rsc_customerinfo=''
rsc_config_ethernet='n'
rsc_ip_mode='dhcp'
rsc_ip_addr=''
rsc_ip_netmask='255.255.255.0'
rsc_ip_gateway=''
rsc_config_notif='n'
rsc_email_notif='n'
rsc_pager_notif='n'
rsc_smtp_server=''
rsc_setup_smtp_backup='n'
rsc_smtp_backup_server=''
rsc_email_addr=''
rsc_pager_verbose='n'
pager_verbose='false'
rsc_pager1_num=''
rsc_pager1_init=''
rsc_pager1_passwd=''
rsc_pager1_baud='9600'
rsc_pager1_data='7'
rsc_pager1_parity='even'
rsc_pager1_stop='1'
rsc_setup_pager2='n'
rsc_pager2_num=''
rsc_pager2_init=''
rsc_pager2_passwd=''
rsc_pager2_baud='9600'
rsc_pager2_data='7'
rsc_pager2_parity='even'
rsc_pager2_stop='1'
rsc_config_modem='n'
rsc_enable_ppp='n'
rsc_ppp_local='0.0.0.0'
rsc_ppp_remote='0.0.0.0'
rsc_modem_data='8'
rsc_modem_parity='even'
rsc_modem_stop='1'
rsc_config_serial='n'
rsc_sp_baud='9600'
rsc_sp_data='8'
rsc_sp_parity='none'
rsc_sp_stop='1'
rsc_config_user='y'
rsc_username=''
rsc_user_perm='cuar'

#
# I18N Support Routine
#
pgettext () 
{
   gttext=gettext # Trick to fool shxgettext
   ${gttext} ${textdomain} "$1"
}


# There are six main stages to the configuration
#  1) General RSC
#  2) Ethernet 
#  3) Event/Alert Notification
#  4) Modem
#  5) Serial Port
#  6) User Account

#
# Prompt for General RSC setup
#
GetRsc()
{
# Always program RSC to avoid confusion
   rsc_install_flash="y"
   
#   echo
#   cont="NO"
#   while test "$cont" != "YES"; do
#      eval echo "\" `pgettext 'Update flash (y|n|?) [${rsc_install_flash}]: '`\c\""
#      read  input dummy
#      case "$input" in
#         ''|y|Y)
#            rsc_install_flash="y"
#            cont="YES"
#            ;;
#         n|N)
#            rsc_install_flash="n"
#            cont="YES"
#            ;;
#         '?')
#            pgettext "\n"\
#"HELP\n"\
#"   UPDATE FLASH\n"\
#"      The RSC flash must be updated before RSC\n"\
#"      will function correctly.  If you have already\n"\
#"      updated the RSC flash, you do not need to do\n"\
#"      it again.\n\n"
#            cont="NO"
#            ;;
#         *)
#            cont="NO"
#            ;;
#      esac
#   done

   cont="NO"
   while test "$cont" != "YES"; do
      eval echo "\"`pgettext 'Set RSC date/time now (y|n|?) [${rsc_set_date}]: '`\c\""
      read  input dummy
      case "$input" in
         '')
	    cont="YES"
	    ;;
	 y|Y)
            rsc_set_date="y"
            cont="YES"
            ;;
         n|N)
            rsc_set_date="n"
            cont="YES"
            ;;
         '?')
            pgettext "\n"\
"HELP\n"\
"   SET RSC DATE/TIME NOW\n"\
"      Set RSC's time and date to the servers current\n"\
"      time and date (recommended).\n\n"
            cont="NO"
            ;;
         *)
            cont="NO"
            ;;
      esac
   done

   #
   # always set date on server powerup (i.e. add startup script in /etc/rc.d)
   # This used to be configurable, but is now hard coded.
   #
   rsc_always_set_date="y"
   
   cont="NO"
   while test "$cont" != "YES"; do
      eval echo "\"`pgettext 'Server Hostname [${rsc_hostname}]: '`\c\""
      read  input dummy
      case "$input" in
         '')
            cont="YES"
            ;;
         *)
            rsc_hostname=$input
            cont="YES"
            ;;
      esac
   done
   
   cont="NO"
   while test "$cont" != "YES"; do
      eval echo "\"`pgettext 'Edit customer info field (y|n|?) [${rsc_set_customerinfo}]: '`\c\""
      read  input dummy
      case "$input" in
         y|Y)
            rsc_set_customerinfo="y"
            cont="NO"
            while test "$cont" != "YES"; do
               eval echo "\"`pgettext '   Customer Info (<= 40 char) [${rsc_customerinfo}]: '`\c\""
               read  input dummy
               case "$input" in
                  '')
                     cont="YES"
                     ;;
                  *)
                     rsc_customerinfo=$input
                     cont="YES"
                     ;;
               esac
            done
            cont="YES"
            ;;
         '')
            if [ ${rsc_set_customerinfo} = "y" ]
            then
                while test "$cont" != "YES"; do
                    eval echo "\"`pgettext '   Customer Info (<= 40 char) [${rsc_customerinfo}]: '`\c\""
                    read  input dummy
                    case "$input" in
                        '')
                        cont="YES"
                        ;;
                    *)
                        rsc_customerinfo=$input
                        cont="YES"
                    ;;
                    esac
                done
            else
                cont="YES"
            fi
            ;;

	 n|N)
            rsc_set_customerinfo="n"
            cont="YES"
            ;;
         '?')
            pgettext "\n"\
"HELP\n"\
"   EDIT CUSTOMER INFO FIELD\n"\
"      The customer info field is a forty byte field\n"\
"      which can be used to keep customer specific data.\n\n"
            cont="NO"
            ;;
         *)
	    cont="NO"
            ;;
      esac
   done
}
 

#
# Prompt for Ethernet setup
#
GetEthernet()
{
   cont="NO"
   while test "$cont" != "YES"; do
      eval echo "\"`pgettext 'Enable RSC Ethernet Interface (y|n|s|?) [${rsc_config_ethernet}]: '`\c\""
      read  input dummy
      case "$input" in
         y|Y)
            cont="YES"
            rsc_config_ethernet="y"
            ;;
         '')
	    cont="YES"
	    ;; 
	 n|N)
            rsc_config_ethernet="n"
            cont="YES"
            ;;
         s|S)
            rsc_config_ethernet="s"
            cont="YES"
            ;;            
         '?')
            pgettext "\n"\
"HELP\n"\
"   ENABLE RSC ETHERNET INTERFACE\n"\
"      This option enables/disables the ethernet interface. If enabled, it\n"\
"      then allows you to configure the RSC ip mode, ip address, etc.\n"\
"         y - Enable Ethernet Interface (more questions will follow)\n"\
"         n - Disable Ethernet Interface\n"\
"         s - Skip over this question.  Selecting this option allows\n"\
"             the user to skip over the ethernet configuration.  The\n"\
"             script will not modify RSC's current ethernet configuration.\n"\
"             This is useful only if you are NOT running this script\n"\
"             for the first time. (i.e. to reconfigure parts of RSC)\n"\
"         ? - This message\n\n"
            cont="NO"
            ;;
         *)
            cont="NO"
            ;;
      esac
   done


   # Configure RSC Ethernet Interface
   case "$rsc_config_ethernet" in
      y)
         cont="NO"
         while test "$cont" != "YES"; do
            eval echo "\"`pgettext '   RSC IP Mode (config|dhcp|?) [${rsc_ip_mode}]: '`\c\""
            read  input dummy
            case "$input" in
               config|Config|CONFIG)
                  rsc_ip_mode="config"
                  cont="YES"
                  ;;
               '')
		  cont="YES"
		  ;;
	       dhcp|Dhcp|DHCP)
                  rsc_ip_mode="dhcp"
                  cont="YES"
                  ;;
               '?')
            pgettext "\n"\
"HELP\n"\
"   ENABLE RSC ETHERNET INTERFACE\n"\
"      RSC IP MODE\n"\
"         config - manually configure IP address, netmask, etc.\n"\
"         dhcp   - obtain the IP settings from a dhcp server\n"\
"         ?      - This message\n\n"
                  cont="NO"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done

         case "$rsc_ip_mode" in
            dhcp)
               rsc_reset_when_complete='y'
               ;;
            config)
               rsc_reset_when_complete='y'
               cont="NO"
               while test "$cont" != "YES"; do
                  eval echo "\"`pgettext '   RSC IP Address [${rsc_ip_addr}]: '`\c\""
                  read  input dummy
                  case "$input" in
                     '')
                        cont="YES"
                        ;;
                     *)
                        rsc_ip_addr=$input
                        cont="YES"
                        ;;
                  esac
               done

               cont="NO"
               while test "$cont" != "YES"; do
                  eval echo "\"`pgettext '   RSC IP Netmask [${rsc_ip_netmask}]: '`\c\""
                  read  input dummy
                  case "$input" in
                     '')
                        cont="YES"
                        ;;
                     *)
                        rsc_ip_netmask=$input
                        cont="YES"
                        ;;
                  esac
               done

               cont="NO"
               while test "$cont" != "YES"; do
                  eval echo "\"`pgettext '   RSC IP Gateway [${rsc_ip_gateway}]: '`\c\""
                  read  input dummy
                  case "$input" in
                     '')
                        cont="YES"
                        ;;
                     *)
                        rsc_ip_gateway=$input
                        cont="YES"
                        ;;
                  esac
               done
               ;;

         esac
         ;;
   esac
}



GetNotify()
{
   cont="NO"
   while test "$cont" != "YES"; do
      eval echo "\"`pgettext 'Enable RSC Alerts (y|n|s|?) [${rsc_config_notif}]: '`\c\""
      read  input dummy
      case "$input" in
         y|Y)
            cont="YES"
            rsc_config_notif="y"
            ;;
         '')
	    cont="YES"
	    ;;
	 n|N)
            rsc_config_notif="n"
            rsc_email_notif="n"
            rsc_pager_notif="n"
            cont="YES"
            ;;
         s|S)
            rsc_config_notif="s"
            rsc_email_notif="n"
            rsc_pager_notif="n"
            cont="YES"
            ;;            
         '?')
            pgettext "\n"\
"HELP\n"\
"   ENABLE RSC ALERTS\n"\
"      This option enables/disables the RSC alert engine. If enabled, it\n"\
"      then allows you to configure how RSC will alert you. You can be\n"\
"      notified via e-mail and/or pager when critical events occur.\n"\
"         y - Enable RSC alert engine (more questions will follow)\n"\
"         n - Disable RSC alert engine\n"\
"         s - Skip over this question.  Selecting this option allows\n"\
"             the user to skip over the alert configuration.  The\n"\
"             script will not modify RSC's current alert configuration.\n"\
"             This is useful only if you are NOT running this script\n"\
"             for the first time. (i.e. to reconfigure parts of RSC)\n"\
"         ? - This message\n\n"
            cont="NO"
            ;;
         *)
            cont="NO"
            ;;
      esac
   done

   case "$rsc_config_notif" in
      y)
         cont="NO"
         while test "$cont" != "YES"; do
            eval echo "\"`pgettext '   Enable Email Alerts (y|n) [${rsc_email_notif}]: '`\c\""
            read  input dummy
            case "$input" in
               y|Y)
                  cont="YES"
                  rsc_email_notif="y"
                  ;;
               '')
		  cont="YES"
		  ;;
	       n|N)
                  rsc_email_notif="n"
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done
         ;;
   esac
   
   case "$rsc_email_notif" in
      y)
         cont="NO"
         while test "$cont" != "YES"; do
            eval echo "\"`pgettext '      SMTP Server IP address [${rsc_smtp_server}]: '`\c\""
            read  input dummy
            case "$input" in
               '')
                  cont="YES"
                  ;;
               *)
                  rsc_smtp_server=$input
                  cont="YES"
                  ;;
            esac
         done
         cont="NO"
         while test "$cont" != "YES"; do
            eval echo "\"`pgettext '      Setup Backup SMTP Server (y|n) [${rsc_setup_smtp_backup}]: '`\c\""
            read  input dummy
            case "$input" in
               y|Y)
                  cont="YES"
                  rsc_setup_smtp_backup="y"
                  ;;
               '')
		  cont="YES"
		  ;;
	       n|N)
                  cont="YES"
                  rsc_setup_smtp_backup="n"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done
         case "$rsc_setup_smtp_backup" in
            y)
               cont="NO"
               while test "$cont" != "YES"; do
                  eval echo "\"`pgettext '          SMTP Backup Server IP address [${rsc_smtp_backup_server}]: '`\c\""
                  read  input dummy
                  case "$input" in
                     '')
                        cont="YES"
                        ;;
                     *)
                        rsc_smtp_backup_server=$input
                        cont="YES"
                        ;;
                  esac
               done
               ;;
         esac
         cont="NO"
         while test "$cont" != "YES"; do
            eval echo "\"`pgettext  '      Email address [${rsc_email_addr}]: '`\c\""
            read  input dummy
            case "$input" in
               '')
                  cont="YES"
                  ;;
               *)
                  rsc_email_addr=$input
                  cont="YES"
                  ;;
            esac
         done
         ;;
   esac
      

   case "$rsc_config_notif" in
      y)
         cont="NO"
         while test "$cont" != "YES"; do
            eval echo "\"`pgettext '   Enable Pager Alerts (y|n) [${rsc_pager_notif}]: '`\c\""
            read  input dummy
            case "$input" in
               y|Y)
                  cont="YES"
                  rsc_pager_notif="y"
                  ;;
               '')
		  cont="YES"
		  ;;
	       n|N)
                  rsc_pager_notif="n"
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done
         ;;
   esac

   case "$rsc_pager_notif" in
      y)
         cont="NO"
         while test "$cont" != "YES"; do
            eval echo "\"`pgettext '      Enable Verbose Messages (y|n|?) [${rsc_pager_verbose}]: '`\c\""
            read  input dummy
            case "$input" in
               y|Y)
                  cont="YES"
                  rsc_pager_verbose="y"
                  pager_verbose="true"
                  ;;
               '')
                  cont="YES"
                  ;;
               n|N)
                  rsc_pager_verbose="n"
                  pager_verbose="false"
                  cont="YES"
                  ;;
               '?')
            pgettext "\n"\
"HELP\n"\
"   ENABLE RSC ALERTS\n"\
"      ENABLE PAGER ALERTS\n"\
"         ENABLE VERBOSE MESSAGES\n"\
"            y - A lengthy (upwards of 300+ characters) Alert message\n"\
"                is sent to the pager service when an event occurs.\n"\
"            n - A shorter (78 characters), condensed Alert message\n"\
"                is sent to the pager service when an event occurs.\n"\
"            ? - This message\n\n"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done

         cont="NO"
         while test "$cont" != "YES"; do
            eval echo "\"`pgettext '      Pager 1 Number (#|?) [${rsc_pager1_num}]: '`\c\""
            read  input dummy
            case "$input" in
               '?')
            pgettext "\n"\
"HELP\n"\
"   ENABLE RSC ALERTS\n"\
"      ENABLE PAGER ALERTS\n"\
"         PAGER 1 NUMBER\n"\
"            # - The following characters are valid for a phone number.\n"\
"                   0-9, '*', '#' - normal phone keys\n"\
"                   ','           - pause\n"\
"                   '@'           - pager pin follows the @ symbol\n"\
"                Consider the entry  '*70,9,18005555555@12345'.  Ignoring\n"\
"                single quotes, this entry would cancel call waiting\n"\
"                (assuming *70 did that), pause, dial 9 to get an outside\n"\
"                line, pause, dial the pager 1-800 number, and then enter\n"\
"                the user PIN number (12345) after the pager service has\n"\
"                answered.\n"\
"            ? - This message\n\n"
                  ;;
               '')
                  cont="YES"
                  ;;
               *)
                  rsc_pager1_num=$input
                  cont="YES"
                  ;;
            esac
         done
         cont="NO"
         while test "$cont" != "YES"; do
            eval echo "\"`pgettext '      Pager 1 Modem Init String (<= 15 chars) [${rsc_pager1_init}]: '`\c\""
            read  input dummy
            case "$input" in
	       '')
		  cont="YES"
		  ;;
               *)
                  rsc_pager1_init=$input
                  cont="YES"
                  ;;
            esac
         done
         cont="NO"
         while test "$cont" != "YES"; do
            eval echo "\"`pgettext '      Pager 1 Account Password (<= 6 chars) [${rsc_pager1_passwd}]: '`\c\""
            read  input dummy
            case "$input" in
	       '')
		  cont="YES"
		  ;;
               *)
                  rsc_pager1_passwd=$input
                  cont="YES"
                  ;;
            esac
         done
         cont="NO"
         while test "$cont" != "YES"; do
            eval echo "\"`pgettext '      Pager 1 baud rate (300|1200|2400|4800|9600) [${rsc_pager1_baud}]: '`\c\""
            read  input dummy
            case "$input" in
               300|1200|2400|4800|9600)
                  rsc_pager1_baud=$input
                  cont="YES"
                  ;;
               '')
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done
         cont="NO"
         while test "$cont" != "YES"; do
            eval echo "\"`pgettext '      Pager 1 data bits (7|8) [${rsc_pager1_data}]: '`\c\""
            read  input dummy
            case "$input" in
               7|8)
                  rsc_pager1_data=$input
                  cont="YES"
                  ;;
               '')
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done
         cont="NO"
         while test "$cont" != "YES"; do
            eval echo "\"`pgettext '      Pager 1 parity (even|odd|none) [${rsc_pager1_parity}]: '`\c\""
            read  input dummy
            case "$input" in
               even|odd|none|Even|Odd|None|EVEN|ODD|NONE)
                  rsc_pager1_parity=$input
                  cont="YES"
                  ;;
               '')
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done
         cont="NO"
         while test "$cont" != "YES"; do
            eval echo "\"`pgettext '      Pager 1 stop bits (1|2) [${rsc_pager1_stop}]: '`\c\""
            read  input dummy
            case "$input" in
               1|2)
                  rsc_pager1_stop=$input
                  cont="YES"
                  ;;
               '')
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done

         cont="NO"
         while test "$cont" != "YES"; do
            eval echo "\"`pgettext '      Setup Pager 2 Number (y|n) [${rsc_setup_pager2}]: '`\c\""
            read  input dummy
            case "$input" in
               y|Y)
                  cont="YES"
                  rsc_setup_pager2="y"
                  ;;
               '')
		  cont="YES"
		  ;;
	       n|N)
                  cont="YES"
                  rsc_setup_pager2="n"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done
         case "$rsc_setup_pager2" in
            y)
               cont="NO"
               while test "$cont" != "YES"; do
                  eval echo "\"`pgettext '         Pager 2 Number (#|?) [${rsc_pager2_num}]: '`\c\""
                  read  input dummy
                  case "$input" in
                     '?')
                        pgettext "\n"\
"HELP\n"\
"   ENABLE RSC ALERTS\n"\
"      ENABLE PAGER ALERTS\n"\
"         PAGER 2 NUMBER\n"\
"            # - The following characters are valid for a phone number.\n"\
"                   0-9, '*', '#' - normal phone keys\n"\
"                   ','           - pause\n"\
"                   '@'           - pager pin follows the @ symbol\n"\
"                Consider the entry  '*70,9,18005555555@12345'.  Ignoring\n"\
"                single quotes, this entry would cancel call waiting\n"\
"                (assuming *70 did that), pause, dial 9 to get an outside\n"\
"                line, pause, dial the pager 1-800 number, and then enter\n"\
"                the user PIN number (12345) after the pager service has\n"\
"                answered.\n"\
"            ? - This message\n\n"
                        ;;
                     '')
                        cont="YES"
                        ;;
                     *)
                        rsc_pager2_num=$input
                        cont="YES"
                        ;;
                  esac
               done
               cont="NO"
               while test "$cont" != "YES"; do
                  eval echo "\"`pgettext '         Pager 2 Modem Init String (<= 15 chars) [${rsc_pager2_init}]: '`\c\""
                  read  input dummy
                  case "$input" in
		     '')
			cont="YES"
			;;
                     *)
                        rsc_pager2_init=$input
                        cont="YES"
                        ;;
                  esac
               done
               cont="NO"
               while test "$cont" != "YES"; do
                  eval echo "\"`pgettext '         Pager 2 Account Password (<= 6 chars) [${rsc_pager2_passwd}]: '`\c\""
                  read  input dummy
                  case "$input" in
		     '')
			cont="YES"
			;;
                     *)
                        rsc_pager2_passwd=$input
                        cont="YES"
                        ;;
                  esac
               done
               cont="NO"
               while test "$cont" != "YES"; do
                  eval echo "\"`pgettext '         Pager 2 baud rate (300|1200|2400|4800|9600) [${rsc_pager2_baud}]: '`\c\""
                  read  input dummy
                  case "$input" in
                     300|1200|2400|4800|9600)
                        rsc_pager2_baud=$input
                        cont="YES"
                        ;;
                     '')
                        cont="YES"
                        ;;
                     *)
                        cont="NO"
                        ;;
                  esac
               done
               cont="NO"
               while test "$cont" != "YES"; do
                  eval echo "\"`pgettext '         Pager 2 data bits (7|8) [${rsc_pager2_data}]: '`\c\""
                  read  input dummy
                  case "$input" in
                     7|8)
                        rsc_pager2_data=$input
                        cont="YES"
                        ;;
                     '')
                        cont="YES"
                        ;;
                     *)
                        cont="NO"
                        ;;
                  esac
               done
               cont="NO"
               while test "$cont" != "YES"; do
                  eval echo "\"`pgettext '         Pager 2 parity (even|odd|none) [${rsc_pager2_parity}]: '`\c\""
                  read  input dummy
                  case "$input" in
                     even|odd|none|Even|Odd|None|EVEN|ODD|NONE)
                        rsc_pager2_parity=$input
                        cont="YES"
                        ;;
                     '')
                        cont="YES"
                        ;;
                     *)
                        cont="NO"
                        ;;
                  esac
               done
               cont="NO"
               while test "$cont" != "YES"; do
                  eval echo "\"`pgettext '         Pager 2 stop bits (1|2) [${rsc_pager2_stop}]: '`\c\""
                  read  input dummy
                  case "$input" in
                     1|2)
                        rsc_pager2_stop=$input
                        cont="YES"
                        ;;
                     '')
                        cont="YES"
                        ;;
                     *)
                        cont="NO"
                        ;;
                  esac
               done
               ;;
         esac
         ;;
   esac
}



GetModem()
{
   cont="NO"
   while test "$cont" != "YES"; do
      eval echo "\"`pgettext 'Enable RSC Modem Interface (y|n|s|?) [${rsc_config_modem}]: '`\c\""
      read  input dummy
      case "$input" in
         y|Y)
            cont="YES"
            rsc_config_modem="y"
            ;;
         '')
	    cont="YES"
	    ;;
	 n|N)
            rsc_config_modem="n"
            cont="YES"
            ;;
         s|S)
            rsc_config_modem="s"
            cont="YES"
            ;;            
         '?')
            pgettext "\n"\
"HELP\n"\
"   ENABLE RSC MODEM INTERFACE\n"\
"      This option enables/disables the RSC modem interface. If enabled, it\n"\
"      then allows you to configure the modem serial port interface, including\n"\
"      baud rate, number of data bits, enable/disable ppp, etc.\n"\
"         y - Enable Modem Interface (more questions will follow)\n"\
"         n - Disable Modem Interface\n"\
"         s - Skip over this question.  Selecting this option allows\n"\
"             the user to skip over the modem configuration.  The\n"\
"             script will not modify RSC's current modem configuration.\n"\
"             This is useful only if you are NOT running this script\n"\
"             for the first time. (i.e. to reconfigure parts of RSC)\n"\
"         ? - This message\n\n"
            cont="NO"
            ;;
         *)
            cont="NO"
            ;;
      esac
   done

   case "$rsc_config_modem" in
      y)
         cont="NO"
         while test "$cont" != "YES"; do
            eval echo "\"`pgettext '   Modem data bits (7|8) [${rsc_modem_data}]: '`\c\""
            read  input dummy
            case "$input" in
               7|8)
                  rsc_modem_data=$input
                  cont="YES"
                  ;;
               '')
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done
         cont="NO"
         while test "$cont" != "YES"; do
            eval echo "\"`pgettext '   Modem parity (even|odd|none) [${rsc_modem_parity}]: '`\c\""
            read  input dummy
            case "$input" in
               even|odd|none|Even|Odd|None|EVEN|ODD|NONE)
                  rsc_modem_parity=$input
                  cont="YES"
                  ;;
               '')
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done
         cont="NO"
         while test "$cont" != "YES"; do
            eval echo "\"`pgettext '   Modem stop bits (1|2) [${rsc_modem_stop}]: '`\c\""
            read  input dummy
            case "$input" in
               1|2)
                  rsc_modem_stop=$input
                  cont="YES"
                  ;;
               '')
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done

         cont="NO"
         while test "$cont" != "YES"; do
            eval echo "\"`pgettext '   Enable PPP over modem (y|n) [${rsc_enable_ppp}]: '`\c\""
            read  input dummy
            case "$input" in
               y|Y)
                  rsc_enable_ppp="y"
                  cont="YES"
                  ;;
               '')
		  cont="YES"
		  ;;
	       n|N)
                  rsc_enable_ppp="n"
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done

         case "$rsc_enable_ppp" in
            y)
               cont="NO"
               while test "$cont" != "YES"; do
                  eval echo "\"`pgettext '      PPP Local IP Address [${rsc_ppp_local}]: '`\c\""
                  read  input dummy
                  case "$input" in
                     '')
                        cont="YES"
                        ;;
                     *)
                        rsc_ppp_local=$input
                        cont="YES"
                        ;;
                  esac
               done
               cont="NO"
               while test "$cont" != "YES"; do
                  eval echo "\"`pgettext '      PPP Remote IP Address [${rsc_ppp_remote}]: '`\c\""
                  read  input dummy
                  case "$input" in
                     '')
                        cont="YES"
                        ;;
                     *)
                        rsc_ppp_remote=$input
                        cont="YES"
                        ;;
                  esac
               done
               ;;
         esac

         ;;

    esac
}



GetSerial()
{
   cont="NO"
   while test "$cont" != "YES"; do
      eval echo "\"`pgettext 'Enable RSC Serial Port Interface (y|n|s|?) [${rsc_config_serial}]: '`\c\""
      read  input dummy
      case "$input" in
         y|Y)
            cont="YES"
            rsc_config_serial="y"
            ;;
         '')
            cont="YES"
            ;;
         n|N)
            rsc_config_serial="n"
            cont="YES"
            ;;
         s|S)
            rsc_config_serial="s"
            cont="YES"
            ;;           
         '?')
            pgettext "\n"\
"HELP\n"\
"   ENABLE RSC SERIAL PORT INTERFACE\n"\
"      This option enables/disables the RSC serial port interface. If enabled,\n"\
"      it then allows you to configure the serial port interface, including\n"\
"      baud rate, number of data bits, etc.\n"\
"         y - Enable Serial Port  Interface (more questions will follow)\n"\
"         n - Disable Serial Port Interface\n"\
"         s - Skip over this question.  Selecting this option allows\n"\
"             the user to skip over the serial port configuration.  The\n"\
"             script will not modify RSC's current serial port configuration.\n"\
"             This is useful only if you are NOT running this script\n"\
"             for the first time. (i.e. to reconfigure parts of RSC)\n"\
"         ? - This message\n\n"
            cont="NO"
            ;;
         *)
            cont="NO"
            ;;
      esac
   done


   case "$rsc_config_serial" in
      y)

	 cont="NO"
	 while test "$cont" != "YES"; do
	    eval echo "\"`pgettext '   Serial port baud rate (9600|19200|38400|57600|115200) [${rsc_sp_baud}]: '`\c\""
	    read  input dummy
	    case "$input" in
	       9600|19200|38400|57600|115200)
	          rsc_sp_baud=$input
	          cont="YES"
	          ;;
	       '')
	          cont="YES"
	          ;;
	       *)
	          cont="NO"
	          ;;
	    esac
	 done
	 cont="NO"
	 while test "$cont" != "YES"; do
	    eval echo "\"`pgettext '   Serial port data bits (7|8) [${rsc_sp_data}]: '`\c\""
	    read  input dummy
	    case "$input" in
	       7|8)
	          rsc_sp_data=$input
	          cont="YES"
	          ;;
	       '')
	          cont="YES"
	          ;;
	       *)
	          cont="NO"
 	          ;;
	    esac
	 done
	 cont="NO"
	 while test "$cont" != "YES"; do
	    eval echo "\"`pgettext '   Serial port parity (even|odd|none) [${rsc_sp_parity}]: '`\c\""
	    read  input dummy
	    case "$input" in
	       even|odd|none|Even|Odd|None|EVEN|ODD|NONE)
	          rsc_sp_parity=$input
	          cont="YES"
	          ;;
	       '')
	          cont="YES"
	          ;;
	       *)
	          cont="NO"
	          ;;
	    esac
	 done
	 cont="NO"
	 while test "$cont" != "YES"; do
	    eval echo "\"`pgettext '   Serial port stop bits (1|2) [${rsc_sp_stop}]: '`\c\""
	    read  input dummy
	    case "$input" in
	       1|2)
	          rsc_sp_stop=$input
	          cont="YES"
	          ;;
	       '')
	          cont="YES"
	          ;;
	       *)
	          cont="NO"
	          ;;
	    esac
	 done
         ;;

    esac

}



GetUser()
{
   cont="NO"
   while test "$cont" != "YES"; do
      eval echo "\"`pgettext 'Setup RSC User Account (y|n|?) [${rsc_config_user}]: '`\c\""
      read  input dummy
      case "$input" in
         '')
	    cont="YES"
	    ;;
	 y|Y)
            cont="YES"
            rsc_config_user="y"
            ;;
         n|N)
            rsc_config_user="n"
            cont="YES"
            ;;
         '?')
            pgettext "\n"\
"HELP\n"\
"   SETUP RSC USER ACCOUNT\n"\
"      RSC allows up to sixteen individual user accounts.  This option will\n"\
"      allow you to setup one of those accounts.  You will be prompted\n"\
"      for a password later during the installation\n\n"
            cont="NO"
            ;;
         *)
            cont="NO"
            ;;
      esac
   done

   case "$rsc_config_user" in
      y)
         cont="NO"
         while test "$cont" != "YES"; do
            eval echo "\"`pgettext '   Username [${rsc_username}]: '`\c\""
            read  input dummy
            case "$input" in
               '')
                  if test -z "$rsc_username"; then
                      cont="NO"
                  else
                      cont="YES"
                  fi
                  ;;
               *)
                  rsc_username=$input
                  cont="YES"
                  ;;
            esac
         done
   
         cont="NO"
         while test "$cont" != "YES"; do
            eval echo "\"`pgettext  '   User Permissions (c,u,a,r|none|?) [${rsc_user_perm}]: '`\c\""
            read  input dummy
            case "$input" in
               '?')
            pgettext "\n"\
"HELP\n"\
"   SETUP RSC USER ACCOUNT\n"\
"      USER PERMISSIONS\n"\
"         There are four different permissions which can be controlled\n"\
"         for each user.\n"\
"            c - allow user to connect to console\n"\
"            u - allow user to setup other users\n"\
"            a - allow user to setup configuration variables\n"\
"            r - allow user to reboot/poweron/poweroff server\n"\
"         Example responses are:\n"\
"            none\n"\
"            c\n"\
"            cuar\n"\
"            ca\n"\
"            cua\n"\
"            a\n\n"
                  cont="NO"
                  ;;
               '')
                  cont="YES"
                  ;;
               none|None|NONE)
                  rsc_user_perm="none"
                  cont="YES"
                  ;;
               *)
                  rsc_user_perm=$input
                  cont="YES"
                  ;;
            esac
         done
         ;;
   esac
}



DisplayRsc()
{
   pgettext "\n"\
"General Setup\n"\
"-------------\n"
#   eval echo "\"`pgettext '  Update RSC Flash  = ${rsc_install_flash}'`\""
   eval echo "\"`pgettext '  Set RSC date now  = ${rsc_set_date}'`\""
   eval echo "\"`pgettext '  Server Hostname   = ${rsc_hostname}'`\""
   case "$rsc_set_customerinfo" in
      y)
         eval echo "\"`pgettext '  Customer Info     = ${rsc_customerinfo}'`\""
         ;;
      n)
         pgettext "  Set Customer Info = n\n"
         ;;
   esac
   echo
}



DisplayEthernet()
{
   pgettext "\n"\
"Ethernet Setup\n"\
"--------------\n"
   case "$rsc_config_ethernet" in
      y)
         case "$rsc_ip_mode" in
            dhcp)
               eval echo "\"`pgettext '  IP Mode      =  ${rsc_ip_mode}'`\""
               ;;
            config)
               eval echo "\"`pgettext '  IP Mode      = ${rsc_ip_mode}'`\""
               eval echo "\"`pgettext '  IP Address   = ${rsc_ip_addr}'`\""
               eval echo "\"`pgettext '  IP Netmask   = ${rsc_ip_netmask}'`\""
               eval echo "\"`pgettext '  IP Gateway   = ${rsc_ip_gateway}'`\""
               ;;
         esac
         ;;
      s)
         pgettext "- Skipping over ethernet setup\n"
         ;;
      *)
         pgettext "- Ethernet disabled\n"
         ;;
   esac
   echo
}



DisplayNotify()
{
   pgettext "\n"\
"Alert Setup\n"\
"-----------\n"
   case "$rsc_config_notif" in
      y)
         eval echo "\"`pgettext '  Email Enabled      = ${rsc_email_notif}'`\""
         case "$rsc_email_notif" in
            y)
               eval echo "\"`pgettext '  Email Address      = ${rsc_email_addr}'`\""
               eval echo "\"`pgettext '  SMTP Server        = ${rsc_smtp_server}'`\""
               case "$rsc_setup_smtp_backup" in
                  y)
                     eval echo "\"`pgettext '  SMTP Backup Server = ${rsc_smtp_backup_server}'`\""
                     ;;
               esac
               ;;
         esac
         eval echo "\"`pgettext '  Paging Enabled     = ${rsc_pager_notif}'`\""
         case "$rsc_pager_notif" in
            y)
               eval echo "\"`pgettext '  Verbose Alert Msg  = ${rsc_pager_verbose}'`\""
               eval echo "\"`pgettext '  Pager 1 Number     = ${rsc_pager1_num}'`\""
               eval echo "\"`pgettext '  Pager 1 Modem Init = ${rsc_pager1_init}'`\""
               eval echo "\"`pgettext '  Pager 1 Password   = ${rsc_pager1_passwd}'`\""
               eval echo "\"`pgettext '  Pager 1 Baud       = ${rsc_pager1_baud}'`\""
               eval echo "\"`pgettext '  Pager 1 Data Bits  = ${rsc_pager1_data}'`\""
               eval echo "\"`pgettext '  Pager 1 Parity     = ${rsc_pager1_parity}'`\""
               eval echo "\"`pgettext '  Pager 1 Stop Bits  = ${rsc_pager1_stop}'`\""
               case "$rsc_setup_pager2" in
                  y)
                     eval echo "\"`pgettext '  Pager 2 Number     = ${rsc_pager2_num}'`\""
                     eval echo "\"`pgettext '  Pager 2 Modem Init = ${rsc_pager2_init}'`\""
                     eval echo "\"`pgettext '  Pager 2 Password   = ${rsc_pager2_passwd}'`\""
                     eval echo "\"`pgettext '  Pager 2 Baud       = ${rsc_pager2_baud}'`\""
                     eval echo "\"`pgettext '  Pager 2 Data Bits  = ${rsc_pager2_data}'`\""
                     eval echo "\"`pgettext '  Pager 2 Parity     = ${rsc_pager2_parity}'`\""
                     eval echo "\"`pgettext '  Pager 2 Stop Bits  = ${rsc_pager2_stop}'`\""
                     ;;
               esac
               ;;
         esac
         ;;
      s)
         pgettext "- Skipping over alert setup\n"
         ;;
      *)
         pgettext "- Alerts disabled\n"
         ;;
   esac
   echo
}



DisplayModem()
{
   pgettext "\n"\
"Modem Setup\n"\
"-----------\n"
   case "$rsc_config_modem" in
      y)
         eval echo "\"`pgettext '  Modem Data Bits = ${rsc_modem_data}'`\""
         eval echo "\"`pgettext '  Modem Parity    = ${rsc_modem_parity}'`\""
         eval echo "\"`pgettext '  Modem Stop Bits = ${rsc_modem_stop}'`\""
         eval echo "\"`pgettext '  PPP Enabled     = ${rsc_enable_ppp}'`\""
         case "$rsc_enable_ppp" in
            y)
               case "$rsc_ppp_local" in
                  "0.0.0.0")
                     eval echo "\"`pgettext '  PPP Local IP Address  = ${rsc_ppp_local} (Dynamic)'`\""
                     ;;
                  *)
                     eval echo "\"`pgettext '  PPP Local IP Address  = ${rsc_ppp_local}'`\""
                     ;;
               esac
               case "$rsc_ppp_remote" in
                  "0.0.0.0")
                     eval echo "\"`pgettext '  PPP Remote IP Address = ${rsc_ppp_remote} (Dynamic)'`\""
                     ;;
                  *)
                     eval echo "\"`pgettext '  PPP Remote IP Address = ${rsc_ppp_remote}'`\""
                     ;;
               esac
               
               ;;
         esac

	 ;;

      s)
         pgettext "- Skipping over modem setup\n"
         ;;
      *)
         pgettext "- Modem disabled, ppp disabled\n"
         ;;
   esac
   echo
}



DisplaySerial()
{
   pgettext "\n"\
"Serial Port Setup\n"\
"-----------------\n"
   case "$rsc_config_serial" in
      y)
	 eval echo "\"`pgettext '  Serial Port Baud      = ${rsc_sp_baud}'`\""
	 eval echo "\"`pgettext '  Serial Port Data Bits = ${rsc_sp_data}'`\""
	 eval echo "\"`pgettext '  Serial Port Parity    = ${rsc_sp_parity}'`\""
	 eval echo "\"`pgettext '  Serial Port Stop Bits = ${rsc_sp_stop}'`\""
	 pgettext "\n"
         ;;
      s)
         pgettext "- Skipping over serial port setup\n"
         ;;
      *)
         pgettext "- Serial port disabled\n"
         ;;
   esac
   echo

}



DisplayUser()
{
   pgettext "\n"\
"User Setup\n"\
"----------\n"
   case "$rsc_config_user" in
      y)
         eval echo "\"`pgettext '  User Name        = ${rsc_username}'`\""
         eval echo "\"`pgettext '  User Permissions = ${rsc_user_perm}'`\""
         ;;
      *)
         pgettext "- no users added\n"
         ;;
   esac
   echo
}


VerifyRsc()
{
   cont="NO"
   while test "$cont" != "YES"; do
      echo
      DisplayRsc
      pgettext "  Is this correct (y|n): "
      read  input dummy
      case "$input" in
         y|Y)
            cont="YES"
            ;;
         n|N)
	    pgettext "\n"
            GetRsc
            cont="NO"
            ;;
         *)
            cont="NO"
            ;;
      esac
   done
   echo
}


VerifyEthernet()
{
   cont="NO"
   while test "$cont" != "YES"; do
      echo
      DisplayEthernet
      pgettext "  Is this correct (y|n): "
      read  input dummy
      case "$input" in
         y|Y)
            cont="YES"
            ;;
         n|N)
	    pgettext "\n"
            GetEthernet
            cont="NO"
            ;;
         *)
            cont="NO"
            ;;
      esac
   done
   echo
 }


VerifyNotify()
{
   cont="NO"
   while test "$cont" != "YES"; do
      echo
      DisplayNotify
      pgettext "  Is this correct (y|n): "
      read  input dummy
      case "$input" in
         y|Y)
            cont="YES"
            ;;
         n|N)
	    pgettext "\n"
            GetNotify
            cont="NO"
            ;;
         *)
            cont="NO"
            ;;
      esac
   done
   echo
}


VerifyModem()
{
   cont="NO"
   while test "$cont" != "YES"; do
      echo
      DisplayModem
      pgettext "  Is this correct (y|n): "
      read  input dummy
      case "$input" in
         y|Y)
            cont="YES"
            ;;
         n|N)
	    pgettext "\n"
            GetModem
            cont="NO"
            ;;
         *)
            cont="NO"
            ;;
      esac
   done
   echo
 }


VerifySerial()
{
   cont="NO"
   while test "$cont" != "YES"; do
      echo
      DisplaySerial
      pgettext "  Is this correct (y|n): "
      read  input dummy
      case "$input" in
         y|Y)
            cont="YES"
            ;;
         n|N)
            pgettext "\n"
            GetSerial
            cont="NO"
            ;;
         *)
            cont="NO"
            ;;
      esac
   done
   echo
 }

VerifyUser()
{
   cont="NO"
   while test "$cont" != "YES"; do
      echo
      DisplayUser
      pgettext "  Is this correct (y|n): "
      read  input dummy
      case "$input" in
         y|Y)
            cont="YES"
            ;;
         n|N)
	    pgettext "\n"
            GetUser
            cont="NO"
            ;;
         *)
            cont="NO"
            ;;
      esac
   done
   echo
}


Exit_Routine()
{
   # Clean up user if there, ignore error if not there
   if test $rsc_user_added = "y"; then
      $rscadm_bin userdel $rsc_username
   fi
   pgettext "\n"\
"********************************\n"\
"      SETUP SCRIPT FAILED!      \n"\
"********************************\n\n"\
"Please re-run the install script.  Make sure you check all\n"\
"inputs to make sure they are valid.\n\n"
   all_ok='false'
}


Program()
{
  all_ok='true'
  echo
   cont="NO"
   while test "$cont" != "YES"; do
      pgettext "This script will now update RSC, continue? (y|n): "
      read  input dummy
      case "$input" in
         y|Y)
            cont="YES"
            ;;
         n|N)
            cont="NO"
            exit 1
            ;;
         *)
            cont="NO"
            ;;
      esac
   done
   
   if test "$rsc_install_flash" = "y" -a "$all_ok" = "true"; then
      pgettext "Updating flash, this takes a few minutes\n"
      mybin="$rscadm_bin download $rsc_firmware"
      if test &$mybin; then
         passed=yes
         # wait for reset to complete
         pgettext "Resetting RSC (takes about 90 seconds): "
         sleep 90
         ./rscadm status > /dev/null 2>&1
         if [ $? -ne 0 ]; then
            sleep 30
         fi
         pgettext "DONE\n"
      else
         echo; echo
         pgettext "ERROR: during update flash\n"
         Exit_Routine
      fi
   fi
   
   # Make sure the RSC serial device has the correct permissions
   if test -c "$rsc_device" -a "$all_ok" = "true"; then
      chmod 600 $rsc_device
   else
      echo; echo
      pgettext "ERROR: unable to find RSC serial device\n"
      Exit_Routine
   fi

   if test "$rsc_always_set_date" = "y" -a "$all_ok" = "true"; then
      pgettext "Setting up server to update RSC date on boot: "
      rm -f /etc/rc2.d/S99_rsc
      rm -f /etc/rc3.d/S99_rsc
      rm -f /etc/init.d/rsc
      rm -f /etc/rc2.d/S99rsc
      cp -f $rsc_initscript /etc/init.d/rsc
      cp -f $rsc_initscript /etc/rc2.d/S99rsc
      pgettext "DONE\n"
   fi

   if test "$all_ok" = "true"; then
      pgettext "Setting up server hostname: "
      mybin="$rscadm_bin set hostname $rsc_hostname"
      if test &$mybin; then
         passed=yes
         pgettext "DONE\n"
      else
         echo; echo  
         pgettext "ERROR: during set server hostname\n"
         Exit_Routine
      fi
   fi

   if test "$rsc_set_customerinfo" = "y" -a "$all_ok" = "true"; then
      pgettext "Setting up customer info field: "
      mybin="$rscadm_bin set customerinfo $rsc_customerinfo"
      if test &$mybin; then
         passed=yes
         pgettext "DONE\n"
      else
         echo; echo
         pgettext "ERROR: during set customerinfo\n"
         Exit_Routine
      fi
   fi

# Set tpe_link_test to default of TRUE.
   $rscadm_bin set tpe_link_test true
   if test "$rsc_config_ethernet" = "y" -a "$all_ok" = "true"; then
      pgettext "Setting up ethernet interface: "
      if test "$rsc_ip_mode" = "config"; then
         mybin="$rscadm_bin set ip_addr $rsc_ip_addr"
         if test &$mybin; then
            passed=yes
         else
            echo; echo
            pgettext "ERROR: during set ip_address\n"
            Exit_Routine
         fi
         if test "$all_ok" = "true"; then
            mybin="$rscadm_bin set ip_netmask $rsc_ip_netmask"
            if test &$mybin; then
               passed=yes
            else
               echo; echo
               pgettext "ERROR: during set ip_netmask\n"
               Exit_Routine
            fi
         fi
         if test "$all_ok" = "true"; then
            mybin="$rscadm_bin set ip_gateway $rsc_ip_gateway"
            if test &$mybin; then
               passed=yes
            else
               echo; echo
               pgettext "ERROR: during set ip_gateway\n"
               Exit_Routine
            fi
         fi
      fi 

      if test "$all_ok" = "true"; then
         mybin="$rscadm_bin set ip_mode $rsc_ip_mode"
         if test &$mybin; then
            passed=yes
            pgettext "DONE\n"
         else
            echo; echo
            pgettext "ERROR: during set ip_mode\n"
            Exit_Routine
         fi
      fi
   else
      if test "$rsc_config_ethernet" = "s" -a "$all_ok" = "true"; then
         pgettext "Skipping ethernet interface setup...\n"
      else
         pgettext "Disabling ethernet interface: "
         mybin="$rscadm_bin set ip_mode none"
         if test &$mybin; then
            passed=yes
            pgettext "DONE\n"
         else
            echo; echo
            pgettext "ERROR: during set ip_mode\n"
            Exit_Routine
         fi
      fi
   fi

   if test "$rsc_config_notif" = "y" -a "$all_ok" = "true"; then
      if test "$rsc_email_notif" = "y" -a "$all_ok" = "true"; then
         pgettext "Setting up e-mail alerts: "
         mybin="$rscadm_bin set mailuser $rsc_email_addr"
         if test &$mybin; then
            passed=yes
         else
            echo; echo
            pgettext "ERROR: during set email address\n"
            Exit_Routine
         fi
         smtp_server=${rsc_smtp_server}
         if test "$rsc_setup_smtp_backup" = "y"; then
            smtp_server=${smtp_server}:${rsc_smtp_backup_server}
         fi
         if test "$all_ok" = "true"; then
            mybin="$rscadm_bin set mailhost $smtp_server"
            if test &$mybin; then
               passed=yes
            else
               echo; echo
               pgettext "ERROR: during set mailhost\n"
               Exit_Routine
            fi
         fi
         if test "$all_ok" = "true"; then
            mybin="$rscadm_bin set mail_enabled true"
            if test &$mybin; then
               passed=yes
               pgettext "DONE\n"
            else
               echo; echo
               pgettext "ERROR: during set mail_enabled\n"
               Exit_Routine
            fi
         fi
      else
         pgettext "Disabling e-mail alerts: "
         mybin="$rscadm_bin set mail_enabled false"
         if test &$mybin; then
            passed=yes
            pgettext "DONE\n"
         else
            echo; echo
            pgettext "ERROR: during set mail_enabled\n"
            Exit_Routine
         fi
      fi
      if test "$rsc_pager_notif" = "y" -a "$all_ok" = "true"; then
         pgettext "Setting up pager alerts: "
         mybin="$rscadm_bin set page_verbose $pager_verbose"
         if test &$mybin; then
            passed=yes
         else
            echo; echo
            pgettext "ERROR: during set pager verbose messages\n"
            Exit_Routine
         fi
         if test "$all_ok" = "true"; then
            mybin="$rscadm_bin set page_info1 $rsc_pager1_num"
            if test &$mybin; then
               passed=yes
            else
               echo; echo
               pgettext "ERROR: during set pager 1 number\n"
               Exit_Routine
            fi
         fi
         if test "$all_ok" = "true"; then
            if $rscadm_bin set page_init1 "$rsc_pager1_init"; then
               passed=yes
            else
               echo; echo
               pgettext "ERROR: during set page_init1\n"
               Exit_Routine
            fi
         fi
         if test "$all_ok" = "true"; then
            if $rscadm_bin set page_password1 "$rsc_pager1_passwd"; then
               passed=yes
            else
               echo; echo
               pgettext "ERROR: during set page_password1\n"
               Exit_Routine
            fi
         fi
         if test "$all_ok" = "true"; then
            mybin="$rscadm_bin set page_baud1 $rsc_pager1_baud"
            if test &$mybin; then
               passed=yes
            else
               echo; echo
               pgettext "ERROR: during set page_baud1\n"
               Exit_Routine
            fi
         fi
         if test "$all_ok" = "true"; then
            mybin="$rscadm_bin set page_data1 $rsc_pager1_data"
            if test &$mybin; then
               passed=yes
            else
               echo; echo
               pgettext "ERROR: during set page_data1\n"
               Exit_Routine
            fi
         fi
         if test "$all_ok" = "true"; then
            mybin="$rscadm_bin set page_parity1 $rsc_pager1_parity"
            if test &$mybin; then
               passed=yes
            else
               echo; echo
               pgettext "ERROR: during set page_parity1\n"
               Exit_Routine
            fi
         fi
         if test "$all_ok" = "true"; then
            mybin="$rscadm_bin set page_stop1 $rsc_pager1_stop"
            if test &$mybin; then
               passed=yes
            else
               echo; echo
               pgettext "ERROR: during set page_stop1\n"
               Exit_Routine
            fi
         fi

         if test "$rsc_setup_pager2" = "y" -a "$all_ok" = "true"; then
            mybin="$rscadm_bin set page_info2 $rsc_pager2_num"
            if test &$mybin; then
               passed=yes
            else
               echo; echo
               pgettext "ERROR: during set pager 2 number\n"
               Exit_Routine
            fi
            if test "$all_ok" = "true"; then
               if $rscadm_bin set page_init2 "$rsc_pager2_init"; then
                  passed=yes
               else
                  echo; echo
                  pgettext "ERROR: during set page_init2\n"
                  Exit_Routine
               fi
            fi
            if test "$all_ok" = "true"; then
               if $rscadm_bin set page_password2 "$rsc_pager2_passwd"; then
                  passed=yes
               else
                  echo; echo
                  pgettext "ERROR: during set page_password2\n"
                  Exit_Routine
               fi
            fi
            if test "$all_ok" = "true"; then
               mybin="$rscadm_bin set page_baud2 $rsc_pager2_baud"
               if test &$mybin; then
                  passed=yes
               else
                  echo; echo
                  pgettext "ERROR: during set page_baud2\n"
                  Exit_Routine
               fi
            fi
            if test "$all_ok" = "true"; then
               mybin="$rscadm_bin set page_data2 $rsc_pager2_data"
               if test &$mybin; then
                  passed=yes
               else
                  echo; echo
                  pgettext "ERROR: during set page_data2\n"
                  Exit_Routine
               fi
            fi
            if test "$all_ok" = "true"; then
               mybin="$rscadm_bin set page_parity2 $rsc_pager2_parity"
               if test &$mybin; then
                  passed=yes
               else
                  echo; echo
                  pgettext "ERROR: during set page_parity2\n"
                  Exit_Routine
               fi
            fi
            if test "$all_ok" = "true"; then
               mybin="$rscadm_bin set page_stop2 $rsc_pager2_stop"
               if test &$mybin; then
                  passed=yes
               else
                  echo; echo
                  pgettext "ERROR: during set page_stop2\n"
                  Exit_Routine
               fi
            fi
         fi
         if test "$all_ok" = "true"; then
            mybin="$rscadm_bin set page_enabled true"
            if test &$mybin; then
               passed=yes
               pgettext "DONE\n"
            else
               echo; echo
               pgettext "ERROR: during set page_enabled\n"
               Exit_Routine
            fi
         fi

      else
         pgettext "Disabling pager alerts: "
         mybin="$rscadm_bin set page_enabled false"
         if test &$mybin; then
            passed=yes
            pgettext "DONE\n"
         else
            echo; echo
            pgettext "ERROR: during set page_enabled\n"
            Exit_Routine
         fi
      fi

   else
      if test "$rsc_config_notif" = "s" -a "$all_ok" = "true"; then
         pgettext "Skipping RSC alert engine setup...\n"
      else
         pgettext "Disabling RSC alert engine: "
         mybin="$rscadm_bin set page_enabled false"
         if test &$mybin; then
            passed=yes
         else
            echo; echo
            pgettext "ERROR: during set page_enabled\n"
            Exit_Routine
         fi
         if test "$all_ok" = "true"; then
            mybin="$rscadm_bin set mail_enabled false"
            if test &$mybin; then
               passed=yes
               pgettext "DONE\n"
            else
               echo; echo
               pgettext "ERROR: during set mail_enabled\n"
               Exit_Routine
            fi
         fi
      fi
   fi

   if test "$rsc_config_modem" = "y" -a "$all_ok" = "true"; then 
      pgettext "Setting up modem interface: "

      mybin="$rscadm_bin set modem_data $rsc_modem_data"
      if test &$mybin; then
         passed=yes
      else
         echo; echo
         pgettext "ERROR: during set modem_data\n"
         Exit_Routine
      fi
      if test "$all_ok" = "true"; then
         mybin="$rscadm_bin set modem_parity $rsc_modem_parity"
         if test &$mybin; then
            passed=yes
         else
            echo; echo
            pgettext "ERROR: during set modem_parity\n"
            Exit_Routine
         fi
      fi
      if test "$all_ok" = "true"; then
         mybin="$rscadm_bin set modem_stop $rsc_modem_stop"
         if test &$mybin; then
            passed=yes
         else
            echo; echo
            pgettext "ERROR: during set modem_stop\n"
            Exit_Routine
         fi
      fi

      if test "$rsc_enable_ppp" = "y" -a "$all_ok" = "true"; then
	 mybin="$rscadm_bin set ppp_enabled true"
	 if test &$mybin; then
	    passed=yes
	 else
	    echo; echo
	    pgettext "ERROR: during set ppp_enabled\n"
	    Exit_Routine
         fi

         if test "$all_ok" = "true"; then
            mybin="$rscadm_bin set ppp_local_ip_addr $rsc_ppp_local"
            if test &$mybin; then
               passed=yes
            else
               echo; echo
               pgettext "ERROR: during set ppp_local_ip_addr\n"
               Exit_Routine
            fi
         fi
         if test "$all_ok" = "true"; then
            mybin="$rscadm_bin set ppp_remote_ip_addr $rsc_ppp_remote"
            if test &$mybin; then
               passed=yes
            else
               echo; echo
               pgettext "ERROR: during set ppp_remote_ip_addr\n"
               Exit_Routine
            fi
         fi
      else
         if test "$all_ok" = "true"; then
	    mybin="$rscadm_bin set ppp_enabled false"
	    if test &$mybin; then
	       passed=yes
	    else
	        echo; echo
	        pgettext "ERROR: during set ppp_enabled\n"
	        Exit_Routine
	    fi
         fi
      fi

      if test "$all_ok" = "true"; then
         pgettext "DONE\n"
      fi

   else
      if test "$rsc_config_modem" = "s" -a "$all_ok" = "true"; then
         pgettext "Skipping modem interface setup...\n"
      else
         if test "$all_ok" = "true"; then
            pgettext "Disabling modem interface: "
            mybin="$rscadm_bin set ppp_enabled false"
            if test &$mybin; then
               passed=yes
               pgettext "DONE\n"
            else
               echo; echo
               pgettext "ERROR: during set ppp_enabled\n"
               Exit_Routine
            fi
         fi
      fi
   fi


   if test "$rsc_config_serial" = "y" -a "$all_ok" = "true"; then
      pgettext "Setting up serial port interface: "

      mybin="$rscadm_bin set serial_baud $rsc_sp_baud"
      if test &$mybin; then
         passed=yes
      else
         echo; echo
         pgettext "ERROR: during set serial_baud\n"
         Exit_Routine
      fi
      if test "$all_ok" = "true"; then
         mybin="$rscadm_bin set serial_data $rsc_sp_data"
         if test &$mybin; then
            passed=yes
         else
            echo; echo
            pgettext "ERROR: during set serial_data\n"
            Exit_Routine
         fi
      fi
      if test "$all_ok" = "true"; then
         mybin="$rscadm_bin set serial_parity $rsc_sp_parity"
         if test &$mybin; then
            passed=yes
         else
            echo; echo
            pgettext "ERROR: during set serial_parity\n"
            Exit_Routine
         fi
      fi
      if test "$all_ok" = "true"; then
         mybin="$rscadm_bin set serial_stop $rsc_sp_stop"
         if test &$mybin; then
            passed=yes
         else
            echo; echo
            pgettext "ERROR: during set serial_stop\n"
            Exit_Routine
         fi
      fi
      if test "$all_ok" = "true"; then
         pgettext "DONE\n"
      fi

   else
      if test "$rsc_config_serial" = "s" -a "$all_ok" = "true"; then
         pgettext "Skipping serial port interface setup...\n"
      else
         if test "$all_ok" = "true"; then
            pgettext "Disabling serial port interface: "
            pgettext "DONE\n"
         fi
      fi
   fi


   while test "$rsc_config_user" = "y" -a "$all_ok" = "true"; do
      pgettext "Adding user to RSC:\n"
         
      mybin="$rscadm_bin useradd $rsc_username"
      if test &$mybin; then
         passed=yes
      else
         echo; echo
 	 pgettext "when this script completes,\n"\
"use the rscadm command to correct the error.\n\n"
	 rsc_user_added="n";
	 break;
      fi
      rsc_user_added="y"
      if test $rsc_user_perm != "none" -a "$all_ok" = "true"; then
         mybin="$rscadm_bin userperm $rsc_username $rsc_user_perm"
         if test &$mybin; then
            passed=yes
         else
            echo; echo
            pgettext "ERROR: during set user permissions\n"
            Exit_Routine
         fi
      fi
      if test "$all_ok" = "true"; then
         pgettext "\n"\
"A valid password is between 6 and 8 characters, has at least\n"\
"two alphabetic characters, and at least one numeric or special\n"\
"character.  The password must differ from the user's login name\n"\
"and any reverse or circular shift of that login name.\n"\
"Setting User Password Now ...\n\n"
         mybin="$rscadm_bin userpassword $rsc_username"
         if test &$mybin; then
            passed=yes
         else
            echo; echo
            pgettext "ERROR: during set user password\n"
            Exit_Routine
         fi
      fi
      if test "$all_ok" = "true"; then
         pgettext "User has been added to RSC\n"
      fi
      rsc_config_user="n"
   done

   if test "$rsc_reset_when_complete" = "y" -a "$all_ok" = "true"; then
      pgettext "Resetting RSC (takes about 90 seconds):\n"
      mybin="$rscadm_bin resetrsc"
      if test &$mybin; then
         passed=yes
         sleep 90
         ./rscadm status > /dev/null 2>&1
         if [ $? -ne 0 ]; then
            sleep 30
         fi
         pgettext "DONE\n"
      else
         echo; echo
         pgettext "ERROR: couldn't reset RSC\n"
         Exit_Routine
      fi
   fi

   if test "$rsc_set_date" = "y" -a "$all_ok" = "true"; then
      pgettext "Setting up RSC date: "
      mybin="$rscadm_bin date -s"
      if test &$mybin; then
         passed=yes
         pgettext "DONE\n"
      else
         echo; echo
         pgettext "ERROR: during set date\n"
         Exit_Routine
      fi
   fi
}


checkRoot()
{
   set -e
   $rscadm_bin help > /dev/null
   set +e
}


checkPlatform()
{
    uname_out=`uname -i`
    if [ ${uname_out} = ${littleneck} ]
    then
        platform=${lneck_name}
    elif [ ${uname_out} = ${cherrystone} ]
    then
        platform=${cstone_name}
    elif [ ${uname_out} = ${daktari} ]
    then
        platform=${dak_name}
    else
        eval echo "\"`pgettext 'This machine is not a ${platforms};'`\""
        pgettext "this script cannot be run on this system.\n"
        pgettext "\n"\
"********************************\n"\
"      SETUP SCRIPT FAILED!      \n"\
"********************************\n\n"
       exit 1
    fi
}


checkContinue()
{
   echo; echo
   cont="NO"
   while test "$cont" != "YES"; do
      pgettext "Continue with RSC setup (y|n): "
      read  input dummy
      case "$input" in
         y|Y)
            cont="YES"
            ;;
         n|N)
            cont="NO"
            exit 1
            ;;
         *)
            cont="NO"
            ;;
      esac
   done
   echo
}




#
# main()
#
   # Make sure we're running on a supported platform
   checkPlatform

   # Make sure we are root
   checkRoot

   while test "$all_ok" != "true"; do

      # make sure user wants to continue
      checkContinue
   
      # get user configuration
      GetRsc
      GetEthernet
      GetNotify
      GetModem
      GetSerial
      GetUser
   
      # verify configuration
      pgettext "\n\n\n"\
"--------------------\n"\
"Verifying Selections\n"\
"--------------------\n"
      VerifyRsc
      VerifyEthernet
      VerifyNotify
      VerifyModem
      VerifySerial
      VerifyUser
   
      # configure RSC
      Program

   done
 
   if test "$all_ok" = "true"; then  
      # exit successfully
      pgettext "\n"\
"*******************************\n"\
"RSC has been successfully setup\n"\
"*******************************\n\n"
   fi
   exit 0
#
# end of main()
#
