#!/bin/sh


#
# RSC configuration script
#


#
# location of rsc files
#
rsc_platform="`uname -i`"
rsc_path="/usr/platform/""$rsc_platform""/"
rscadm_bin="$rsc_path""rsc/rscadm"
rscconfig_bin="$rsc_path""rsc/rsc-config"
rsc_firmware="$rsc_path""lib/images/rscfw"
rsc_initscript="$rsc_path""rsc/rsc-initscript"
if [ $rsc_platform = "SUNW,UltraSPARC-IIi-Netract" ]
then
	rsc_console="/devices/pci@1f,0/pci@1/pci@1/pci@8/ebus@0/se@14,400000:ssp"
	rsc_device="/devices/pci@1f,0/pci@1/pci@1/pci@8/ebus@0/se@14,400000:sspctl"
elif [ $rsc_platform = "SUNW,UltraSPARC-IIe-NetraCT-40" ]
then
	rsc_console="/devices/pci@1f,0/pci@1/pci@1/pci@d/ebus@0/se@14,400000:ssp"
	rsc_device="/devices/pci@1f,0/pci@1/pci@1/pci@d/ebus@0/se@14,400000:sspctl"
fi
#
# variables with defaults
#
rsc_user_added='false'
rsc_reset_when_complete='false'
rsc_install_flash="true"
textdomain=SUNW_RSC_CFG


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


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

#
# Prompt for General RSC setup
#
GetRsc()
{
   
#   echo
#   cont="NO"
#   while test "$cont" != "YES"; do
#      pgettext "Update flash (y|n|?) [y]: "
#      read  input dummy
#      case "$input" in
#         ''|y|Y|yes|YES|Yes)
#            rsc_install_flash="true"
#            cont="YES"
#            ;;
#         n|N|no|NO|No)
#            rsc_install_flash="false"
#            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
#      pgettext "Set RSC date/time now (y|n|?) [y]: "
#      read  input dummy
#      case "$input" in
#         ''|y|Y|yes|YES|Yes)
#            rsc_set_date="true"
#            cont="YES"
#            ;;
#         n|N|no|NO|No)
#            rsc_set_date="false"
#            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_set_date="true"
   rsc_always_set_date="true"
   cont="NO"
	 echo
   rsc_server_hostname=`hostname`
   while test "$cont" != "YES"; do
      eval echo "\"`pgettext 'Server Hostname [${rsc_server_hostname}]: '`\c\""
      read  input dummy
      case "$input" in
         '')
            rsc_hostname=$rsc_server_hostname
            cont="YES"
            ;;
         *)
            rsc_hostname=$input
            cont="YES"
            ;;
      esac
   done
   
   cont="NO"
   while test "$cont" != "YES"; do
      pgettext "Edit customer info field (y|n|?) [n]: "
      read  input dummy
      case "$input" in
         y|Y|yes|YES|Yes)
            rsc_set_customerinfo="true"
            cont="NO"
            while test "$cont" != "YES"; do
               pgettext "   Customer Info (<= 40 characters): "
               read  input dummy
               case "$input" in
                  '')
                     cont="NO"
                     ;;
                  *)
                     rsc_customerinfo=$input
                     cont="YES"
                     ;;
               esac
            done
            cont="YES"
            ;;
         ''|n|N|no|NO|No)
            rsc_set_customerinfo="false"
            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
      pgettext "Enable RSC Ethernet Interface (y|n|s|?) [n]: "
      read  input dummy
      case "$input" in
         y|Y|yes|YES|Yes)
            cont="YES"
            rsc_config_ethernet="true"
            ;;
         ''|n|N|no|NO|No)
            rsc_config_ethernet="false"
            cont="YES"
            ;;
         s|S|skip|Skip|SKIP)
            rsc_config_ethernet="skip"
            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
      true)
         cont="NO"
         while test "$cont" != "YES"; do
            pgettext "   RSC IP Mode (config|dhcp|?) [config]: "
            read  input dummy
            case "$input" in
               ''|config|Config|CONFIG)
                  rsc_ip_mode="config"
                  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='true'
               ;;
            config)
               rsc_reset_when_complete='true'
               cont="NO"
               while test "$cont" != "YES"; do
                  pgettext "   RSC IP Address: "
                  read  input dummy
                  case "$input" in
                     '')
                        cont="NO"
                        ;;
                     *)
                        rsc_ip_addr=$input
                        cont="YES"
                        ;;
                  esac
               done

               cont="NO"
               while test "$cont" != "YES"; do
                  pgettext "   RSC IP Netmask [255.255.255.0]: "
                  read  input dummy
                  case "$input" in
                     '')
                        rsc_ip_netmask="255.255.255.0"
                        cont="YES"
                        ;;
                     *)
                        rsc_ip_netmask=$input
                        cont="YES"
                        ;;
                  esac
               done

               cont="NO"
               while test "$cont" != "YES"; do
                  pgettext "   RSC IP Gateway: "
                  read  input dummy
                  case "$input" in
                     '')
                        cont="NO"
                        ;;
                     *)
                        rsc_ip_gateway=$input
                        cont="YES"
                        ;;
                  esac
               done
               ;;

         esac
         ;;
   esac
}



GetNotify()
{
   cont="NO"
   while test "$cont" != "YES"; do
      pgettext "Enable RSC Alerts (y|n|s|?) [n]: "
      read  input dummy
      case "$input" in
         y|Y|yes|YES|Yes)
            cont="YES"
            rsc_config_notif="true"
            ;;
         ''|n|N|no|NO|No)
            rsc_config_notif="false"
            rsc_email_notif="false"
            rsc_pager_notif="false"
            cont="YES"
            ;;
         s|S|skip|Skip|SKIP)
            rsc_config_notif="skip"
            rsc_email_notif="false"
            rsc_pager_notif="false"
            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
      true)
         cont="NO"
         while test "$cont" != "YES"; do
            pgettext "   Enable Email Alerts (y|n) [n]: "
            read  input dummy
            case "$input" in
               y|Y|yes|YES|Yes)
                  cont="YES"
                  rsc_email_notif="true"
                  ;;
               ''|n|N|no|NO|No)
                  rsc_email_notif="false"
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done
         ;;
   esac
   
   case "$rsc_email_notif" in
      true)
         cont="NO"
         while test "$cont" != "YES"; do
            pgettext "      SMTP Server's IP address: "
            read  input dummy
            case "$input" in
               '')
                  cont="NO"
                  ;;
               *)
                  rsc_smtp_server=$input
                  cont="YES"
                  ;;
            esac
         done
# Disabled.  There is no smtp_backup setting!
#         cont="NO"
#         while test "$cont" != "YES"; do
#            pgettext "      Setup Backup SMTP Server (y|n) [n]: "
#            read  input dummy
#            case "$input" in
#               y|Y|yes|YES|Yes)
#                  cont="YES"
#                  rsc_setup_smtp_backup="true"
#                  ;;
#               ''|n|N|no|No|NO)
#                  cont="YES"
#                  rsc_setup_smtp_backup="false"
#                  ;;
#               *)
#                  cont="NO"
#                  ;;
#            esac
#         done
#         case "$rsc_setup_smtp_backup" in
#            true)
#               cont="NO"
#               while test "$cont" != "YES"; do
#                  pgettext "          SMTP Backup Server's IP address: "
#                  read  input dummy
#                  case "$input" in
#                     '')
#                        cont="NO"
#                        ;;
#                     *)
#                        rsc_smtp_backup_server=$input
#                        cont="YES"
#                        ;;
#                  esac
#               done
#               ;;
#         esac
         cont="NO"
         while test "$cont" != "YES"; do
            pgettext "      Email address: "
            read  input dummy
            case "$input" in
               '')
                  cont="NO"
                  ;;
               *)
                  rsc_email_addr=$input
                  cont="YES"
                  ;;
            esac
         done
         ;;
   esac
      

   case "$rsc_config_notif" in
      true)
         cont="NO"
         while test "$cont" != "YES"; do
            pgettext "   Enable Pager Alerts (y|n) [n]: "
            read  input dummy
            case "$input" in
               y|Y|yes|YES|Yes)
                  cont="YES"
                  rsc_pager_notif="true"
                  ;;
               ''|n|N|no|NO|No)
                  rsc_pager_notif="false"
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done
         ;;
   esac

   case "$rsc_pager_notif" in
      true)
         cont="NO"
         while test "$cont" != "YES"; do
            pgettext "      Pager 1 Number (#|?): "
            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="NO"
                  ;;
               *)
                  rsc_pager1_num=$input
                  cont="YES"
                  ;;
            esac
         done
         cont="NO"
         while test "$cont" != "YES"; do
            pgettext "      Pager 1 Modem Init String (<= 30 chars) [none]: "
            read  input dummy
            case "$input" in
               *)
                  rsc_pager1_init=$input
                  cont="YES"
                  ;;
            esac
         done
         cont="NO"
         while test "$cont" != "YES"; do
            pgettext "      Pager 1 Account Password (<= 6 chars) [none]: "
            read  input dummy
            case "$input" in
               *)
                  rsc_pager1_passwd=$input
                  cont="YES"
                  ;;
            esac
         done
         cont="NO"
         while test "$cont" != "YES"; do
            pgettext "      Pager 1 baud rate (300|1200|2400|4800|9600) [300]: "
            read  input dummy
            case "$input" in
               300|1200|2400|4800|9600)
                  rsc_pager1_baud=$input
                  cont="YES"
                  ;;
               '')
                  rsc_pager1_baud="300"
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done
         cont="NO"
         while test "$cont" != "YES"; do
            pgettext "      Pager 1 data bits (7|8) [7]: "
            read  input dummy
            case "$input" in
               7|8)
                  rsc_pager1_data=$input
                  cont="YES"
                  ;;
               '')
                  rsc_pager1_data="7"
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done
         cont="NO"
         while test "$cont" != "YES"; do
            pgettext "      Pager 1 parity (even|odd|none) [even]: "
            read  input dummy
            case "$input" in
               even|odd|none|Even|Odd|None|EVEN|ODD|NONE)
                  rsc_pager1_parity=$input
                  cont="YES"
                  ;;
               '')
                  rsc_pager1_parity="even"
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done
         cont="NO"
         while test "$cont" != "YES"; do
            pgettext "      Pager 1 stop bits (1|2) [1]: "
            read  input dummy
            case "$input" in
               1|2)
                  rsc_pager1_stop=$input
                  cont="YES"
                  ;;
               '')
                  rsc_pager1_stop="1"
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done

         cont="NO"
         while test "$cont" != "YES"; do
            pgettext "      Setup Pager 2 Number (y|n) [n]: "
            read  input dummy
            case "$input" in
               y|Y|yes|YES|Yes)
                  cont="YES"
                  rsc_setup_pager2="true"
                  ;;
               ''|n|N|no|No|NO)
                  cont="YES"
                  rsc_setup_pager2="false"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done
         case "$rsc_setup_pager2" in
            true)
               cont="NO"
               while test "$cont" != "YES"; do
                  pgettext "         Pager 2 Number (#|?): "
                  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="NO"
                        ;;
                     *)
                        rsc_pager2_num=$input
                        cont="YES"
                        ;;
                  esac
               done
               cont="NO"
               while test "$cont" != "YES"; do
                  pgettext "         Pager 2 Modem Init String (<= 30 chars) [none]: "
                  read  input dummy
                  case "$input" in
                     *)
                        rsc_pager2_init=$input
                        cont="YES"
                        ;;
                  esac
               done
               cont="NO"
               while test "$cont" != "YES"; do
                  pgettext "         Pager 2 Account Password (<= 6 chars) [none]: "
                  read  input dummy
                  case "$input" in
                     *)
                        rsc_pager2_passwd=$input
                        cont="YES"
                        ;;
                  esac
               done
               cont="NO"
               while test "$cont" != "YES"; do
                  pgettext "         Pager 2 baud rate (300|1200|2400|4800|9600) [300]: "
                  read  input dummy
                  case "$input" in
                     300|1200|2400|4800|9600)
                        rsc_pager2_baud=$input
                        cont="YES"
                        ;;
                     '')
                        rsc_pager2_baud="300"
                        cont="YES"
                        ;;
                     *)
                        cont="NO"
                        ;;
                  esac
               done
               cont="NO"
               while test "$cont" != "YES"; do
                  pgettext "         Pager 2 data bits (7|8) [7]: "
                  read  input dummy
                  case "$input" in
                     7|8)
                        rsc_pager2_data=$input
                        cont="YES"
                        ;;
                     '')
                        rsc_pager2_data="7"
                        cont="YES"
                        ;;
                     *)
                        cont="NO"
                        ;;
                  esac
               done
               cont="NO"
               while test "$cont" != "YES"; do
                  pgettext "         Pager 2 parity (even|odd|none) [even]: "
                  read  input dummy
                  case "$input" in
                     even|odd|none|Even|Odd|None|EVEN|ODD|NONE)
                        rsc_pager2_parity=$input
                        cont="YES"
                        ;;
                     '')
                        rsc_pager2_parity="even"
                        cont="YES"
                        ;;
                     *)
                        cont="NO"
                        ;;
                  esac
               done
               cont="NO"
               while test "$cont" != "YES"; do
                  pgettext "         Pager 2 stop bits (1|2) [1]: "
                  read  input dummy
                  case "$input" in
                     1|2)
                        rsc_pager2_stop=$input
                        cont="YES"
                        ;;
                     '')
                        rsc_pager2_stop="1"
                        cont="YES"
                        ;;
                     *)
                        cont="NO"
                        ;;
                  esac
               done
               ;;
         esac
         ;;
   esac
}



GetModem()
{
   cont="NO"
   while test "$cont" != "YES"; do
      pgettext "Enable RSC Modem Interface (y|n|s|?) [n]: "
      read  input dummy
      case "$input" in
         y|Y|yes|YES|Yes)
            cont="YES"
            rsc_config_modem="true"
            ;;
         ''|n|N|no|NO|No)
            rsc_config_modem="false"
            cont="YES"
            ;;
         s|S|skip|Skip|SKIP)
            rsc_config_modem="skip"
            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
      true)
         cont="NO"
         while test "$cont" != "YES"; do
            pgettext "   Enable PPP over modem (y|n) [n]: "
            read  input dummy
            case "$input" in
               y|Y|yes|Yes|YES)
                  rsc_enable_ppp="true"
                  cont="YES"
                  ;;
               ''|n|N|no|No|NO)
                  rsc_enable_ppp="false"
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done

         case "$rsc_enable_ppp" in
            true)
               cont="NO"
               while test "$cont" != "YES"; do
                  pgettext "      PPP Local IP Address [dynamic]: "
                  read  input dummy
                  case "$input" in
                     '')
                        rsc_ppp_local="0.0.0.0"
                        cont="YES"
                        ;;
                     *)
                        rsc_ppp_local=$input
                        cont="YES"
                        ;;
                  esac
               done
               cont="NO"
               while test "$cont" != "YES"; do
                  pgettext "      PPP Remote IP Address [dynamic]: "
                  read  input dummy
                  case "$input" in
                     '')
                        rsc_ppp_remote="0.0.0.0"
                        cont="YES"
                        ;;
                     *)
                        rsc_ppp_remote=$input
                        cont="YES"
                        ;;
                  esac
               done
               ;;
         esac

         cont="NO"
         while test "$cont" != "YES"; do
            pgettext "   Serial port baud rate (9600|19200|38400|57600|115200) [9600]: "
            read  input dummy
            case "$input" in
               9600|19200|38400|57600|115200)
                  rsc_sp_baud=$input
                  cont="YES"
                  ;;
               '')
                  rsc_sp_baud="9600"
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done

         cont="NO"
         while test "$cont" != "YES"; do
            pgettext "   Serial port data bits (7|8) [8]: "
            read  input dummy
            case "$input" in
               7|8)
                  rsc_sp_data=$input
                  cont="YES"
                  ;;
               '')
                  rsc_sp_data="8"
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done
         cont="NO"
         while test "$cont" != "YES"; do
            pgettext "   Serial port parity (even|odd|none) [none]: "
            read  input dummy
            case "$input" in
               even|odd|none|Even|Odd|None|EVEN|ODD|NONE)
                  rsc_sp_parity=$input
                  cont="YES"
                  ;;
               '')
                  rsc_sp_parity="none"
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done
         cont="NO"
         while test "$cont" != "YES"; do
            pgettext "   Serial port stop bits (1|2) [1]: "
            read  input dummy
            case "$input" in
               1|2)
                  rsc_sp_stop=$input
                  cont="YES"
                  ;;
               '')
                  rsc_sp_stop="1"
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done

         ;;

   esac
}



GetUser()
{
   cont="NO"
   while test "$cont" != "YES"; do
      pgettext "Setup RSC User Account (y|n|?) [y]: "
      read  input dummy
      case "$input" in
         ''|y|Y|yes|YES|Yes)
            cont="YES"
            rsc_config_user="true"
            ;;
         n|N|no|NO|No)
            rsc_config_user="false"
            cont="YES"
            ;;
         '?')
            pgettext "\n"\
"HELP\n"\
"   SETUP RSC USER ACCOUNT\n"\
"      RSC allows up to four 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
      true)
         cont="NO"
         while test "$cont" != "YES"; do
            pgettext "   Username: "
            read  input dummy
            case "$input" in
               '')
                  cont="NO"
                  ;;
               *)
                  rsc_username=$input
                  cont="YES"
                  ;;
            esac
         done
   
         cont="NO"
         while test "$cont" != "YES"; do
            pgettext "   User Permissions (c,u,a,r|none|?) [cuar]: "
            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"
                  ;;
               '')
                  rsc_user_perm="cuar"
                  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
      true)
         eval echo "\"`pgettext '  Customer Info     = ${rsc_customerinfo}'`\""
         ;;
      false)
         pgettext "  Set Customer Info = false\n"
         ;;
   esac
   echo
}



DisplayEthernet()
{
   pgettext "\n"\
"Ethernet Setup\n"\
"--------------\n"
   case "$rsc_config_ethernet" in
      true)
         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
         ;;
      skip)
         pgettext "- Skipping over ethernet setup\n"
         ;;
      *)
         pgettext "- Ethernet disabled\n"
         ;;
   esac
   echo
}



DisplayNotify()
{
   pgettext "\n"\
"Alert Setup\n"\
"-----------\n"
   case "$rsc_config_notif" in
      true)
         eval echo "\"`pgettext '  Email Enabled      = ${rsc_email_notif}'`\""
         case "$rsc_email_notif" in
            true)
               eval echo "\"`pgettext '  Email Address      = ${rsc_email_addr}'`\""
               eval echo "\"`pgettext '  SMTP Server        = ${rsc_smtp_server}'`\""
               case "$rsc_setup_smtp_backup" in
                  true)
                     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
            true)
               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
                  true)
                     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
         ;;
      skip)
         pgettext "- Skipping over alert setup\n"
         ;;
      *)
         pgettext "- Alerts disabled\n"
         ;;
   esac
   echo
}



DisplayModem()
{
   pgettext "\n"\
"Modem Setup\n"\
"-----------\n"
   case "$rsc_config_modem" in
      true)
         eval echo "\"`pgettext '  PPP Enabled           = ${rsc_enable_ppp}'`\""
         case "$rsc_enable_ppp" in
            true)
               case "$rsc_ppp_local" in
                  "0.0.0.0")
                     pgettext "  PPP Local IP Address  = Dynamic\n"
                     ;;
                  *)
                     eval echo "\"`pgettext '  PPP Local IP Address  = ${rsc_ppp_local}'`\""
                     ;;
               esac
               case "$rsc_ppp_remote" in
                  "0.0.0.0")
                     pgettext "  PPP Remote IP Address = Dynamic\n"
                     ;;
                  *)
                     eval echo "\"`pgettext '  PPP Remote IP Address = ${rsc_ppp_remote}'`\""
                     ;;
               esac
               
               ;;
         esac
         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}'`\""
         ;;
      skip)
         pgettext "- Skipping over modem setup\n"
         ;;
      *)
         pgettext "- Modem disabled, ppp disabled\n"
         ;;
   esac
   echo
}



DisplayUser()
{
   pgettext "\n"\
"User Setup\n"\
"----------\n"
   case "$rsc_config_user" in
      true)
         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|yes|YES|Yes)
            cont="YES"
            ;;
         n|N|no|NO|No)
            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|yes|YES|Yes)
            cont="YES"
            ;;
         n|N|no|NO|No)
            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|yes|YES|Yes)
            cont="YES"
            ;;
         n|N|no|NO|No)
            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|yes|YES|Yes)
            cont="YES"
            ;;
         n|N|no|NO|No)
            GetModem
            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|yes|YES|Yes)
            cont="YES"
            ;;
         n|N|no|NO|No)
            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 = "true"; 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"
   exit 1
}


Program()
{
   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|yes|YES|Yes)
            cont="YES"
            ;;
         n|N|no|NO|No)
            cont="NO"
            exit 1
            ;;
         *)
            cont="NO"
            ;;
      esac
   done
   
   case "$rsc_install_flash" in
      true)
         pgettext "Updating flash, this takes a few minutes\n"
         mybin="$rscadm_bin download $rsc_firmware"
         if test &$mybin; then
            passed=yes
         else
            echo; echo
            pgettext "ERROR: during update flash\n"
            Exit_Routine
         fi
	 sleep 1
	 
         mybin="$rscadm_bin resetrsc"
         if test &$mybin; then
            passed=yes
         else
            echo; echo
            pgettext "ERROR: couldn't reset rsc\n"
            Exit_Routine
         fi

         # wait for reset to complete
         pgettext "RSC resetting (60 seconds): "
         sleep 60
         pgettext "DONE\n"
         ;;
   esac
   
   # Make sure the RSC serial device has the correct permissions
   if test -c "$rsc_device"; then
      chmod 600 $rsc_device
   else
      echo; echo
      pgettext "ERROR: unable to find RSC serial device\n"
      Exit_Routine
   fi

   case "$rsc_always_set_date" in
      true)
         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"
         ;;
   esac

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

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

   case "$rsc_config_ethernet" in
      true)
         pgettext "Setting up ethernet interface: "
         case "$rsc_ip_mode" in
            config)
               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
               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
               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
            ;;
         esac
         mybin="$rscadm_bin set ip_mode $rsc_ip_mode"
         if test &$mybin; then
            passed=yes
         else
            echo; echo
            pgettext "ERROR: during set ip_mode\n"
            Exit_Routine
         fi
         pgettext "DONE\n"
         ;;
         
      false)
         pgettext "Disabling ethernet interface: "
         mybin="$rscadm_bin set ip_mode none"
         if test &$mybin; then
            passed=yes
         else
            echo; echo
            pgettext "ERROR: during set ip_mode\n"
            Exit_Routine
         fi
         pgettext "DONE\n"
         ;;
   esac

   case "$rsc_config_notif" in
      true)
         case "$rsc_email_notif" in
            true)
               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
               mybin="$rscadm_bin set mailhost $rsc_smtp_server"
               if test &$mybin; then
                  passed=yes
               else
                  echo; echo
                  pgettext "ERROR: during set mailhost\n"
                  Exit_Routine
               fi
               case "$rsc_setup_smtp_backup" in
                  true)
                     mybin="$rscadm_bin set mailhost_backup $rsc_smtp_backup_server"
                     if test &$mybin; then
                        passed=yes
                     else
                        echo; echo
                        pgettext "ERROR: during set mailhost_backup\n"
                        Exit_Routine
                     fi
                     ;;
               esac
               mybin="$rscadm_bin set mail_enabled true"
               if test &$mybin; then
                  passed=yes
               else
                  echo; echo
                  pgettext "ERROR: during set mail_enabled\n"
                  Exit_Routine
               fi
               pgettext "DONE\n"
               ;;
            false)
               pgettext "Disabling e-mail alerts: "
               mybin="$rscadm_bin set mail_enabled false"
               if test &$mybin; then
                  passed=yes
               else
                  echo; echo
                  pgettext "ERROR: during set mail_enabled\n"
                  Exit_Routine
               fi
               pgettext "DONE\n"
               ;;
         esac
         case "$rsc_pager_notif" in
            true)
               pgettext "Setting up pager alerts: "
               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
               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
               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
               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
               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
               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
               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
               case "$rsc_setup_pager2" in
                  true)
                     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 $rscadm_bin set page_init2 "$rsc_pager2_init"; then
                        passed=yes
                     else
                        echo; echo
                        pgettext "ERROR: during set page_init2\n"
                        Exit_Routine
                     fi
                     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
                     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
                     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
                     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
                     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
                     ;;
               esac
               mybin="$rscadm_bin set page_enabled true"
               if test &$mybin; then
                  passed=yes
               else
                  echo; echo
                  pgettext "ERROR: during set page_enabled\n"
                  Exit_Routine
               fi
               pgettext "DONE\n"
               ;;
            false)
               pgettext "Disabling pager alerts: "
               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
               pgettext "DONE\n"
               ;;
         esac
         ;;
      false)
         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
         mybin="$rscadm_bin set mail_enabled false"
         if test &$mybin; then
            passed=yes
         else
            echo; echo
            pgettext "ERROR: during set mail_enabled\n"
            Exit_Routine
         fi
         pgettext "DONE\n"
         ;;
   esac

## Added for SNMP configuration

		case "$rsc_config_snmp" in
			 true)
				 pgettext "Enabling  SNMP : "
				 mybin="$rscadm_bin set snmp_enabled true"
				 if test &$mybin; then
						passed=yes
				 else
						echo; echo
						pgettext "ERROR: during set snmp_enabled\n"
						Exit_Routine
				 fi
				 pgettext "DONE\n"
			   ;;	
			 false)
					pgettext "Disabling SNMP: "
					mybin="$rscadm_bin set snmp_enabled false"
				  if test &$mybin; then
              passed=yes
          else
              echo; echo
              pgettext "ERROR: during set snmp_enabled\n"
              Exit_Routine
          fi
					pgettext "DONE\n"
					;;
		esac

					




##Added for serial2_configuration
	 case "$rsc_config_serial2" in
			true)
					case "$rsc_serial2_mode" in
				     disabled)
				 				pgettext "Setting up Serial2 mode as disabled: "
				 				mybin="$rscadm_bin set serial2_mode $rsc_serial2_mode"
				 				if test &$mybin; then
									passed=yes
				 				else
									echo; echo
									pgettext "ERROR: during set serial2_mode\n"
									Exit_Routine
				 				fi
								;;
				     *)	
				 				pgettext "Setting up Serial2 Port: "
				 				mybin="$rscadm_bin set serial2_baud $rsc_serial2_baud"
				 				if test &$mybin; then
									passed=yes
				 				else
									echo; echo
									pgettext "ERROR: during set serial2_baud\n"
									Exit_Routine
				 				fi

				 				mybin="$rscadm_bin set serial2_mode $rsc_serial2_mode"
				 				if test &$mybin; then
									passed=yes
					  		else
									echo $rsc_serial2_mode
									echo; echo
									pgettext "ERROR: during set serial2_mode\n"
									Exit_Routine
							 	fi

							 mybin="$rscadm_bin set serial2_parity $rsc_serial2_parity"
							 if test &$mybin; then
									passed=yes
				 			else
									echo; echo
									pgettext "ERROR: during set serial2_parity\n"
									Exit_Routine
				 			fi
				 			mybin="$rscadm_bin set serial2_data $rsc_serial2_data"
				 			if test &$mybin; then
									passed=yes
				 			else
									echo; echo
									pgettext "ERROR: during set serial2_data\n"
									Exit_Routine
				 			fi
				 			mybin="$rscadm_bin set serial2_stop $rsc_serial2_stop"
				 			if test &$mybin; then
									passed=yes
				 			else
									echo; echo
									pgettext "ERROR: during set serial2_stop\n"
									Exit_Routine
				 			fi

				 			mybin="$rscadm_bin set serial2_hw_flowcontrol $rsc_serial2_flow"
				 			if test &$mybin; then
									passed=yes
				 			else
									echo; echo
									pgettext "ERROR: during set serial2_hw_flowcontrol\n"
									Exit_Routine
				 			fi

				 			mybin="$rscadm_bin set serial2_inactivity $rsc_serial2_inactivity"
				 			if test &$mybin; then
									passed=yes
				 			else
									echo; echo
									pgettext "ERROR: during set serial2_inactivity\n"
									Exit_Routine
				 			fi

   			 			#pgettext "DONE\n"
				 	;;	
		 esac
   	 pgettext "DONE\n"
		 ;;
	esac
#
##Comment out PCMCIA config settings.	
#
##   case "$rsc_config_modem" in
##      true)
##         pgettext "Setting up modem 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
#         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
#         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
#         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
#         mybin="$rscadm_bin set ppp_enabled $rsc_enable_ppp"
#         if test &$mybin; then
#            passed=yes
#         else
#            echo; echo
#            pgettext "ERROR: during set ppp_enabled\n"
#            Exit_Routine
#         fi
#         case "$rsc_enable_ppp" in
#            true)
#               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
#               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
#               ;;
#         esac
#         mybin="$rscadm_bin set serial_hw_handshake true"
#         if test &$mybin; then
#            passed=yes
#         else
#            echo; echo
#            pgettext "ERROR: during set serial_hw_handshake\n"
#            Exit_Routine
#         fi
#         pgettext "DONE\n"
#         ;;
#      false)
#         pgettext "Disabling modem interface: "
#         mybin="$rscadm_bin set serial_hw_handshake false"
#         if test &$mybin; then
#            passed=yes
#         else
#            echo; echo
#            pgettext "ERROR: during set serial_hw_handshake\n"
#            Exit_Routine
#         fi
#         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
#         pgettext "DONE\n"
#         ;;
#   esac

   case "$rsc_config_user" in
      true)
         pgettext "Adding user to RSC:\n"
         
         mybin="$rscadm_bin useradd $rsc_username"
         if test &$mybin; then
            passed=yes
         else
            echo; echo
            pgettext "ERROR: during set username\n"
            Exit_Routine
         fi
         rsc_user_added="true"
         if test $rsc_user_perm != "none"; 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
         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
         pgettext "User has been added to RSC\n"
         ;;
   esac

   case "$rsc_reset_when_complete" in
      true)
         pgettext "\n"\
"A RSC reset is required for some of the configuration variables\n"\
"to take effect.\n"
         cont="NO"
         while test "$cont" != "YES"; do
            pgettext "  Reset RSC now (y|n): "
            read  input dummy
            case "$input" in
               y|Y|yes|YES|Yes)
                  cont="YES"
                  ;;
               n|N|no|NO|No)
                  rsc_reset_when_complete='false'
                  cont="YES"
                  ;;
               *)
                  cont="NO"
                  ;;
            esac
         done
         ;;
   esac
   
   case "$rsc_reset_when_complete" in
      true)
         pgettext "Resetting RSC (60 seconds): "
         mybin="$rscadm_bin resetrsc"
         if test &$mybin; then
            passed=yes
         else
            echo; echo
            pgettext "ERROR: couldn't reset rsc\n"
            Exit_Routine
         fi
         sleep 60
         pgettext "DONE\n"
         ;;
   esac

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


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

checkEnvmonD()
{
   envrun="pgrep envmond" >/dev/null
   if test &$envrun; then
	pgettext "rsc-config cannot be run while envmond is running.\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|yes|YES|Yes)
            cont="YES"
            ;;
         n|N|no|NO|No)
            cont="NO"
            exit 1
            ;;
         *)
            cont="NO"
            ;;
      esac
   done
   echo
}

unconfigureRsc()
{
   mybin="$rscadm_bin set hostname 0"

   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set server hostname\n"
      exit 1
   fi
   mybin="$rscadm_bin set customerinfo 0"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set customerinfo\n"
      exit 1
   fi
   mybin="$rscadm_bin set ip_addr 0.0.0.0"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set ip_address\n"
      exit 1
   fi
   mybin="$rscadm_bin set ip_netmask 0.0.0.0"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set ip_netmask\n"
      exit 1
   fi
   mybin="$rscadm_bin set ip_gateway 0.0.0.0"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set ip_gateway\n"
      exit 1
   fi
   mybin="$rscadm_bin set ip_mode none"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set ip_mode\n"
      exit 1
   fi
   mybin="$rscadm_bin set mail_enabled false"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set mail_enabled\n"
      exit 1
   fi
   mybin="$rscadm_bin set mailuser 0"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set email address\n"
      Exit_Routine
   fi
   mybin="$rscadm_bin set mailhost 0.0.0.0"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set mailhost\n"
      Exit_Routine
   fi
   mybin="$rscadm_bin set page_enabled false"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set page_enabled\n"
      exit 1
   fi
   mybin="$rscadm_bin set ppp_enabled false"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set ppp_enabled\n"
      exit 1
   fi
   mybin="$rscadm_bin set serial_hw_handshake false"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set serial_hw_handshake\n"
      exit 1
   fi

}

### un configure remaining nvram variables
unconfigureREST()
{
   mybin="$rscadm_bin set tpe_link_test true"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set tpe_link_test\n"
      exit 1
   fi

   mybin="$rscadm_bin set serial2_baud 9600"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set serial2_baud\n"
      exit 1
   fi

   mybin="$rscadm_bin set serial2_mode disabled"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set serial2_mode\n"
      exit 1
   fi

   mybin="$rscadm_bin set serial2_parity none"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set serial2_parity\n"
      exit 1
   fi

   mybin="$rscadm_bin set serial2_stop 1"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set serial2_stop\n"
      exit 1
   fi

   mybin="$rscadm_bin set serial2_data 8"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set serial2_data\n"
      exit 1
   fi

   mybin="$rscadm_bin set snmp_enabled false"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set snmp_enabled\n"
      exit 1
   fi

   mybin="$rscadm_bin set snmp_host 0.0.0.0"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set snmp_host\n"
      exit 1
   fi

   mybin="$rscadm_bin set page_info1 0"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set page_info1\n"
      exit 1
   fi

   mybin="$rscadm_bin set page_init1 0"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set page_init1\n"
      exit 1
   fi

   mybin="$rscadm_bin set page_password1 0"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set page_password1\n"
      exit 1
   fi

   mybin="$rscadm_bin set page_parity1 even"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set page_parity1\n"
      exit 1
   fi

   mybin="$rscadm_bin set page_stop1 1"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set page_stop1\n"
      exit 1
   fi

   mybin="$rscadm_bin set page_data1 7"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set page_data1\n"
      exit 1
   fi

   mybin="$rscadm_bin set page_baud1 300"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set page_baud1\n"
      exit 1
   fi

   mybin="$rscadm_bin set page_info2 0"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set page_info2\n"
      exit 1
   fi

   mybin="$rscadm_bin set page_init2 0"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set page_init2\n"
      exit 1
   fi

   mybin="$rscadm_bin set page_password2 0"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set page_password2\n"
      exit 1
   fi

   mybin="$rscadm_bin set page_parity2 even"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set page_parity2\n"
      exit 1
   fi

   mybin="$rscadm_bin set page_stop2 1"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set page_stop2\n"
      exit 1
   fi

   mybin="$rscadm_bin set page_data2 7"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set page_data2\n"
      exit 1
   fi

   mybin="$rscadm_bin set page_baud2 300"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set page_baud2\n"
      exit 1
   fi

   mybin="$rscadm_bin set ppp_local_ip_addr 0.0.0.0"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set ppp_local_ip_addr\n"
      exit 1
   fi

   mybin="$rscadm_bin set ppp_remote_ip_addr 0.0.0.0"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set ppp_remote_ip_addr\n"
      exit 1
   fi

   mybin="$rscadm_bin set escape_char ~"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set escape char\n"
      exit 1
   fi

   mybin="$rscadm_bin set alarm1_prefix 03"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set alarm1_prefix\n"
      exit 1
   fi

   mybin="$rscadm_bin set alarm2_prefix 04"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set alarm2_prefix\n"
      exit 1
   fi

   mybin="$rscadm_bin set alarm3_prefix 05"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set alarm3_prefix\n"
      exit 1
   fi

   mybin="$rscadm_bin set solaris_watchdog_reboot false"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set solaris_watchdog_reboot\n"
      exit 1
   fi

   mybin="$rscadm_bin set panic_dump false"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set panic_dump\n"
      exit 1
   fi

   mybin="$rscadm_bin set serial2_hw_flowcontrol false"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set serial2_hw_flowcontrol\n"
      exit 1
   fi

   mybin="$rscadm_bin set serial2_inactivity false"
   if test &$mybin; then
      passed=yes
   else
      echo; echo
      pgettext "ERROR: during set serial2_inactivity\n"
      exit 1
   fi
}
###


# New functions added for serial2 settings

GetSerial2()
{
	cont="NO"
  while test "$cont" != "YES"; do
      pgettext "configure RSC serial2 variables (y|n|?) [n]: "
      read  input dummy
      case "$input" in
         y|Y|yes|YES|Yes)
            cont="YES"
            rsc_config_serial2="true"
            ;;
         ''|n|N|no|NO|No)
            rsc_config_serial2="false"
            cont="YES"
            ;;
         '?')
            pgettext "\n"\
"HELP\n"\
"   ENABLE RSC SERIAL2 INTERFACE\n"\
"      This option allows you to configure the following serial2 parameters :\n"\
"      serial2_mode, serial2_baud, serial2_data, serial2_parity, serial2_stop\n"\
"      serial2_hw_handshake\n"\
"         y - Configure serial2 variables\n"\
"         n - Not configure \n"\
"         ? - This message\n\n"
            cont="NO"
            ;;
         *)
            cont="NO"
            ;;

      esac
  done

	case "$rsc_config_serial2" in
     true)
        cont="NO"
        while test "$cont" != "YES"; do
           pgettext "      serial2_mode (disabled|tty|modem|rcc) [disabled]: "
           read  input dummy
           case "$input" in
              disabled|modem|tty|rcc)
                 rsc_serial2_mode=$input
                 cont="YES"
                 ;;
              '')
                 rsc_serial2_mode="disabled"
                 cont="YES"
                 ;;
              *)
                 cont="NO"
                 ;;
           esac
        done

	case "$rsc_serial2_mode" in
		 disabled)
			  cont="YES"
				;;
	
		 tty|modem|rcc) 
				cont="NO"
        while test "$cont" != "YES"; do
           pgettext "   Serial2 port baud rate (300|1200|2400|4800|9600|19200|38400|115200 [9600]: "
       	   read  input dummy
       	   case "$input" in
       	      300|1200|2400|4800|9600|19200|38400|115200)
       	         rsc_serial2_baud=$input
       	         cont="YES"
       	         ;;
       	      '')
					  		 rsc_serial2_baud="9600"
					  		 cont="YES"
					  		;;
       	       *)
       	         cont="NO"
       	         ;;
       	  esac
       done

       cont="NO"
       while test "$cont" != "YES"; do
          pgettext "   Serial2 port data bits (7|8) [8]: "
          read  input dummy
          case "$input" in
             7|8)
                rsc_serial2_data=$input
                cont="YES"
                ;;
             '')
                rsc_serial2_data="8"
                cont="YES"
                ;;
              *)
                cont="NO"
                ;;
          esac
       done

       cont="NO"
       while test "$cont" != "YES"; do
          pgettext "   Serial2 port stop bits (1|2) [1]: "
          read  input dummy
          case "$input" in
             1|2)
                rsc_serial2_stop=$input
                cont="YES"
                ;;
             '')
                rsc_serial2_stop="1"
                cont="YES"
                ;;
             *)
                cont="NO"
                ;;
          esac
       done

       cont="NO"
       while test "$cont" != "YES"; do
          pgettext "   Serial2 port parity (even|odd|none) [none]: "
          read  input dummy
          case "$input" in
             even|odd|none|Even|Odd|None|EVEN|ODD|NONE)
                rsc_serial2_parity=$input
                cont="YES"
                ;;
             '')
                rsc_serial2_parity="none"
                cont="YES"
                ;;
              *)
                cont="NO"
                ;;
          esac
       done

       cont="NO"
       while test "$cont" != "YES"; do
          pgettext "   Serial2 Hardware Flow control (true|false) [false]: "
          read  input dummy
          case "$input" in
             true|false|TRUE|FALSE|t|f|T|F)
                rsc_serial2_flow=$input
                cont="YES"
                ;;
             '')
                rsc_serial2_flow="false"
                cont="YES"
                ;;
              *)
                cont="NO"
                ;;
          esac
       done

       cont="NO"
       while test "$cont" != "YES"; do
          pgettext "   Serial2 Inactivity  (true|false) [false]: "
          read  input dummy
          case "$input" in
             true|false|TRUE|FALSE|t|f|T|F)
                rsc_serial2_inactivity=$input
                cont="YES"
                ;;
             '')
                rsc_serial2_inactivity="false"
                cont="YES"
                ;;
              *)
                cont="NO"
                ;;
          esac
       done
       ;;
		esac
		;;
  esac

}

#DisplaySerial2

DisplaySerial2()
{
	pgettext "\n"\
"Serial2 port Setup\n"\
"----------------------\n"

	case "$rsc_config_serial2" in 
		 true)

         case "$rsc_serial2_mode" in
						disabled)
							 pgettext "- Serial2 port is Disabled"
							 ;;
						tty|modem|rcc)
							eval echo "\"`pgettext '  Serial2 Mode           = ${rsc_serial2_mode}'`\""
							eval echo "\"`pgettext '  Serial2 Port Baud      = ${rsc_serial2_baud}'`\""
        			eval echo "\"`pgettext '  Serial2 Port Data Bits = ${rsc_serial2_data}'`\""
        			eval echo "\"`pgettext '  Serial2 Port Parity    = ${rsc_serial2_parity}'`\""
        			eval echo "\"`pgettext '  Serial2 Port Stop Bits = ${rsc_serial2_stop}'`\""
        			eval echo "\"`pgettext '  Serial2 Hw Flow control= ${rsc_serial2_flow}'`\""
        			eval echo "\"`pgettext '  Serial2 Inactivity     = ${rsc_serial2_inactivity}'`\""
							;;
				esac
				;;
		 *)
				pgettext "- Serial2 port not configured\n"
				;;
	esac
	echo
}


#VerifySerial2

VerifySerial2()
{
	
  cont="NO"
	while test "$cont" != "YES"; do
     echo
		 DisplaySerial2
		 pgettext "  Is this correct (y|n): "
		 read  input dummy
		 case "$input" in
		    y|Y|yes|YES|Yes)
           cont="YES"
           ;;
        n|N|no|NO|No)
           GetSerial2
           cont="NO"
           ;;
        *)
           cont="NO"
           ;;
     esac
  done
  echo
}
	

#GetSNMP
GetSNMP()
{
	cont="NO"
  while test "$cont" != "YES"; do
		pgettext "Enable RSC SNMP (y|n|?) [n]: "
		read  input dummy
		case "$input" in
	 	   y|Y|yes|YES|Yes)
		 		  cont="YES"
				  rsc_config_snmp="true"
				  ;;
	 	   n|N|no|NO|No)
				cont="YES"
				rsc_config_snmp="false"
				;;
			 '')
				cont="YES"
				rsc_config_snmp="false"
				;;
			'?')
				pgettext "\n"\
"HELP\n"\
"   ENABLE RSC SNMP\n"\
"         y - Enable RSC SNMP. configure IP address of the SNMP manager\n"\
"         n - Disable RSC SNMP\n"\
"         ? - This message\n\n"
				 cont="NO"
		     ;;
    esac
	done

	case "$rsc_config_snmp" in
		 true)	
        cont="NO"
        while test "$cont" != "YES"; do
           pgettext "      SNMP manager IP address: "
           read  input dummy
           case "$input" in
					 '')
								cont="NO"	
								;;
					 *)
								rsc_snmp_addr=$input
                cont="YES"
								;;
					esac
			 done
			 ;;
	esac
}


#DisplaySNMP

DisplaySNMP()
{
	pgettext "\n"\
"SNMP Setup\n"\
"-----------\n"

	case "$rsc_config_snmp" in 
		 true)
				pgettext "- SNMP Enabled\n"
				eval echo "\"`pgettext '  SNMP manager IP address = ${rsc_snmp_addr}'`\""
				;;
     false)
				pgettext "- SNMP disabled"
				;;
		 *)
				pgettext "- SNMP not configured\n"
				;;
	esac
	echo
}

#VerifySNMP	
	
VerifySNMP()
{
	
  cont="NO"
	while test "$cont" != "YES"; do
     echo
		 DisplaySNMP
		 pgettext "  Is this correct (y|n): "
		 read  input dummy
		 case "$input" in
		    y|Y|yes|YES|Yes)
           cont="YES"
           ;;
        n|N|no|NO|No)
           GetSerial2
           cont="NO"
           ;;
        *)
           cont="NO"
           ;;
     esac
  done
  echo
}
	

#
# main()
#
   # Make sure we are root
   checkRoot


if [ "$1" = "-u" ]; then
   pgettext "\n Setting basic parameters to Default..\n"
   pkill envmond
   sleep 2
   unconfigureRsc
   exit 0;
fi

if [ "$1" = "-unconfig" ];then
   pgettext "\n Setting all parameters to default..\n"
	 pkill envmond
	 sleep 2
	 unconfigureRsc
	 unconfigureREST
	 exit 0;
else
   checkEnvmonD
fi

# For configuration boots, don't install flash
if [ "$1" = "-c" ]; then
  rsc_install_flash="false"
fi
   # make sure user wants to continue
   checkContinue
   
   # get user configuration
   GetRsc
   GetEthernet
   GetNotify
	 GetSNMP
   #GetModem
	 GetSerial2
   GetUser
   
   # verify configuration
   pgettext "\n\n\n"\
"--------------------\n"\
"Verifying Selections\n"\
"--------------------\n"
   VerifyRsc
   VerifyEthernet
   VerifyNotify
   VerifySNMP	
   #VerifyModem
	 VerifySerial2
   VerifyUser
   
   # configure RSC
   Program

   # register with sysidconfig
   sysidconfig -a $rscconfig_bin >/dev/null 2>/dev/null
   
   # exit successfully
   pgettext "\n"\
"*******************************\n"\
"RSC has been successfully setup\n"\
"*******************************\n\n"
   exit 0
#
# end of main()
#

