#!/bin/sh

#
# @(#)(Sun Microsystems, Inc) $Id: update_rss_console %I% 2003/12/21 15:59:35 nish $
#

############################################################################

############################################################################
#                                                                          #
#	Name:  update_rss_console                                          #
#                                                                          #
#	Description:	This script provides for:                          #
#                                                                          #
#                       1.  Verifying and updating the site-specific       #
#                           values that the Remote Support System          #
#                           requires.                                      #
#                                                                          #
############################################################################

PRODUCT_TITLE="Remote Support System"
PRODUCT_SCRIPT=update_rss_console

SHELL=/bin/sh
PATH=/etc:/bin:/usr/bin:/usr/lbin:/usr/local/bin:/var
export PATH SHELL
EDITOR=${EDITOR:-vi}
LINE=${LINES:-24}; export LINES
TERM=${TERM:-vt100}; export TERM
#
# IGNORE HANGUP SIGNALS FOR INTERACTIVE USE
#
trap "" 1 2

RSS_SUN="RSS_SUN"

#  Remote Support Base Installation Directory
BASEDIR=/var/remote.support

#  Remote Support script Directory
SCRIPTSDIR="${BASEDIR}"/scripts

#  Remote Support files Directory
FILESDIR="${BASEDIR}"/files

#  Remote Support bin Directory
BINDIR="${BASEDIR}"/bin

#  Remote Support Base UUCP Directory
UUCPDIR=/etc/uucp

#  Remote Support Base PPP Directory
PPPDIR=/etc/ppp

#  Cron Directory
CRONDIR=/var/spool/cron/crontabs

#  TMP Directory
TMPDIR=/tmp

#  /usr/bin
USRBIN=/usr/bin

#  /etc/init.d
INITD=/etc/init.d

# Declare variable that states this will be the first reconfiguration.
FIRST_RECONFIG="1"

###
#
#  Function :  showcopyright
#
#  Purpose  :  Displays the Sun Microsystems copyright information.
#
#  Called By:  Main Body
#
###

showcopyright () {
tput clear

echo "

  ****************************************************************************
  *                        PROPRIETARY INFORMATION                           *
  *  The information contained herein is proprietary to Sun Microsystems     *
  *  and/or its vendors, and its use, disclosure or duplication  is          *
  *  protected by copyright.  No part of this product may be reproduced      *
  *  in any form by any means without prior written authorization from Sun.  *
  *                                                                          *
  *                          RESTRICTED RIGHTS                               *
  *  Use, duplication, or disclosure by the Government is subject to         *
  *  restrictions as set forth in the subdivision (c) (ii) of the Rights     *
  *  in Technical Data and Computer Software Clause at 252.227.7013.         *
  *  -------------------------------------------------------------------     *
  *                     Sun Microsystems, Inc.                               *
  *                     4150 Network Circle                                  *
  *                     Santa Clara, California 95054                        *
  *                                                                          *
  ****************************************************************************
  "
sleep 2

} # end showcopyright  ()


###
#
#  Function :  checkinstall
#
#  Purpose  :  Ensures the updates for the Remote Support System will  
#              succeed by checking for the existence of files that may 
#              be modified.
#
#  Called By:  main body
#
###

checkinstall () {

#
#  Check for the existence of the following RSS/system files
#

#LIST="${FILESDIR}/rss_params ${UUCPDIR}/Systems ${UUCPDIR}/Systems.alt ${PPPDIR}/chap-secrets ${PPPDIR}/options ${UUCPDIR}/Dialers ${UUCPDIR}/README_Dialer"
LIST="${FILESDIR}/rss_params ${UUCPDIR}/Systems ${UUCPDIR}/Systems.alt ${PPPDIR}/chap-secrets ${PPPDIR}/options ${UUCPDIR}/Dialers"


for FILE in ${LIST}
do
   if [ ! -f "${FILE}" ]
      then
         echo "
The file ${FILE} does not exist.
Please check the Remote Support System base installation.

"
         exit 255
   fi
done

DIALER_FILES=`ls ${UUCPDIR}/Dialer.* 2> /dev/null | wc -l `
if [ $DIALER_FILES -lt 1 ]
then
 echo "No Dialer(dot) files exist
Please check the Remote Support System base installation.

"
         exit 255
fi

} # end checkinstall ()



###
#
#  Function :  rss_update
#
#  Purpose  :  Display available options and carry out the requested function.
#
#  Called By:  Main Body
#
###

rss_update () {

RSS_UPDATE=""

while [ "${RSS_UPDATE}" != "quit" ]
do
   tput clear

   CHOICE=""

echo "
Select the function to perform:   

   1.  Verify/Update SSRR/PPP Files

   2.  Quit

   3.  Send Configuration to the SSRR Support Center.

Enter your choice: \c"

read CHOICE

   case "${CHOICE}" in
      '1')  RSS_UPDATE=update ;;
      '2')  RSS_UPDATE=quit ;;
      '3')  RSS_UPDATE=send ;;
	*)  RSS_UPDATE="" ;;
   esac
   
   
   case "${RSS_UPDATE}" in
       'update')  update_rss_files ;;
       'quit'  )  exit 0;;
       'send'  )  send_configuration ;;
	      *)  ;;
   esac
   
done

} # end rss_update ()


###
#
#  Function :  send_configuration
#
#  Purpose  :  send rss_params to the support center.
#
#  Called By:  rss_update.
#
###

send_configuration () {

#  Remote Support System:  sendtosupport
#  $1 - File to be sent (must be in /usr/spool/uucppublic), i.e., mcdfile.Z
#  $2 - Is the filetype being sent, from:
#          ckdtrace, notify, rss_fmon, errfile, mcd, crashout, hpfalert,
#          paniclog, misc, test
#  $3 - Subsystem (node) name where file originated (if known)
#  $4 - OPTIONAL, "beep" or "nobeep" overrides current SSRR setting


   if [ -s ${FILESDIR}/rss_params ]
   then
     NOW=`date +%Y%m%d_%H%M%S`
     cp ${FILESDIR}/rss_params /usr/spool/uucppublic/rss_params_$NOW
     $SCRIPTSDIR/sendtosupport rss_params_$NOW RSS_PARAMS $NODE1 nobeep
     echo "Sent rss_params to the Support Center."
     echo "continue. <CR>\c"; read XX
   else
     echo "No file ${FILESDIR}/rss_params <CR>\c"; read XX
   fi


} # end send_configuration



###
#
#  Function :  update_rss_files
#
#  Purpose  :  Update SSRR files with new values.          
#
#  Called By:  rss_update.
#
###

update_rss_files () {

prompt 

# Initialize variable to see if rss_params values differ from MCD values.

    DIFF_MCD=""

if [ "${FIRST_RECONFIG}" = "1" ]
then

    # Initialize variables to see which rss_params values differ from MCD.
    CHANGE_SYSTEM_NAME=""
    CHANGE_CUSTOMER_NAME=""
    CHANGE_SYSTEM_ID=""
    CHANGE_SYSTEM_CITY=""
    CHANGE_SYSTEM_STATE=""
    CHANGE_SYSTEM_COUNTRY=""
    CHANGE_SYSTEM_ADDRESS=""
    CHANGE_SYSTEM_ZIP=""
    CHANGE_CUSTOMER_CONTACT=""
    CHANGE_CUSTOMER_EMAIL=""
    CHANGE_CUSTOMER_PHONE=""
    CHANGE_NODE1=""
    CHANGE_NODE2=""
    CHANGE_NODE3=""
    CHANGE_NODE4=""
    CHANGE_NODE5=""
    CHANGE_NODE6=""
    CHANGE_DSPCONS=""
    CHANGE_MODEM_TYPE=""
    CHANGE_STORAGE_TYPE=""
    CHANGE_SP_IMAGE_VERS=""

    if [ "${OLD_SYSTEM_NAME}" != "${SYSTEM_NAME}" ]
        then 
            UPDATE_PERMISSIONS="1"
            CHANGE_SYSTEM_NAME="1"
            DIFF_MCD="1"
            if [ ! -z "${OLD_SYSTEM_NAME}" ]
            then
                UPDATE_PPP="1"
            fi

    fi

    if [ "${OLD_CUSTOMER_NAME}" != "${CUSTOMER_NAME}" ]
        then 
            CHANGE_CUSTOMER_NAME="1"
            DIFF_MCD="1"
    fi
    
    if [ "${OLD_SYSTEM_ID}" != "${SYSTEM_ID}" ]
        then 
            CHANGE_SYSTEM_ID="1"
            DIFF_MCD="1"
    fi
    
    if [ "${OLD_SYSTEM_CITY}" != "${SYSTEM_CITY}" ]
        then 
            CHANGE_SYSTEM_CITY="1"
            DIFF_MCD="1"
    fi
    
    if [ "${OLD_SYSTEM_STATE}" != "${SYSTEM_STATE}" ]
        then 
            CHANGE_SYSTEM_STATE="1"
            DIFF_MCD="1"
    fi
    
    if [ "${OLD_SYSTEM_COUNTRY}" != "${SYSTEM_COUNTRY}" ]
        then 
            CHANGE_SYSTEM_COUNTRY="1"
            DIFF_MCD="1"
    fi
    
    if [ "${OLD_SYSTEM_ADDRESS}" != "${SYSTEM_ADDRESS}" ]
        then 
            CHANGE_SYSTEM_ADDRESS="1"
            DIFF_MCD="1"
    fi
    
    if [ "${OLD_SYSTEM_ZIP}" != "${SYSTEM_ZIP}" ]
        then 
            CHANGE_SYSTEM_ZIP="1"
            DIFF_MCD="1"
    fi
    
    if [ "${OLD_CUSTOMER_CONTACT}" != "${CUSTOMER_CONTACT}" ]
        then 
            CHANGE_CUSTOMER_CONTACT="1"
            DIFF_MCD="1"
    fi
    
    if [ "${OLD_CUSTOMER_EMAIL}" != "${CUSTOMER_EMAIL}" ]
        then 
            CHANGE_CUSTOMER_EMAIL="1"
            DIFF_MCD="1"
    fi
    
    if [ "${OLD_CUSTOMER_PHONE}" != "${CUSTOMER_PHONE}" ]
        then 
            CHANGE_SYSTEM_PHONE="1"
            DIFF_MCD="1"
    fi
    
    if [ "${OLD_NODE1}" != "${NODE1}" ]
        then 
            CHANGE_NODE1="1"
            DIFF_MCD="1"
    fi
    
    if [ "${OLD_NODE2}" != "${NODE2}" ]
        then 
            CHANGE_NODE2="1"
            DIFF_MCD="1"
    fi
    
    if [ "${OLD_NODE3}" != "${NODE3}" ]
        then 
            CHANGE_NODE3="1"
            DIFF_MCD="1"
    fi
    
    if [ "${OLD_NODE4}" != "${NODE4}" ]
        then 
            CHANGE_NODE4="1"
            DIFF_MCD="1"
    fi
    
    if [ "${OLD_NODE5}" != "${NODE5}" ]
        then 
            CHANGE_NODE5="1"
            DIFF_MCD="1"
    fi
    
    if [ "${OLD_NODE6}" != "${NODE6}" ]
        then 
            CHANGE_NODE6="1"
            DIFF_MCD="1"
    fi
    
    if [ "${OLD_DSPCONS}" != "${DSPCONS}" ]
        then 
            CHANGE_DSPCONS="1"
            DIFF_MCD="1"
    fi

    if [ "${OLD_STORAGE_TYPE}" != "${STORAGE_TYPE}" ]
        then
            CHANGE_STORAGE_TYPE="1"
            DIFF_MCD="1"
    fi

    if [ "${OLD_SP_IMAGE_VERS}" != "${SP_IMAGE_VERS}" ]
        then
            CHANGE_SP_IMAGE_VERS="1"
            DIFF_MCD="1"
    fi

    if [ "${DIFF_MCD}" = "1" ]
        then
            UPDATE_RSS_PARAMS="1"
    fi
else
  FIRST_RECONFIG=""
  DIFF_MCD=""
fi

if [ "${RECONFIG}" = "y" ] || [ "${DIFF_MCD}" = "1" ]
   then
      reconfig 
fi

} # end update_rss_files ()



###
#
#  Function :  Prompt
#
#  Purpose  :  It displays the current values and prompts the user for any 
#              changes to the following information:
#
#	       1.  Customer Name (Should be 1 word or multiple words combined
#                  with underscores; i.e., Sun or Sun_Microsystems).
#	           (There are NO DEFAULTS).
#
#	       2.  The customer's contract number for Ichabod.
#	           (There are NO DEFAULTS).
#
#              3.  Customer Support Center's UUCP Host Machine Name (1 word, 
#                  no spaces; i.e., ichabod).  For Sun's Network Storage 
#                  Support Center, this entry MUST be 'ichabod' in all
#                  lower case.
#
#              4.  Customer Support Center's Phone Number  (including
#                  any special dial sequence required to access an outside
#                  line; i.e., 9,18005551212.  The ',' represents a pause to 
#                  wait for a secondary dialtone).
#
#  Called By:  update_rss_files
#
###

prompt () {

tput clear


. ${FILESDIR}/rss_params


## Defaulting the system_id to hostid if not yet set

if [ -z "${SYSTEM_ID}" ]
then
        SYSTEM_ID=`hostid`
fi


# Assign values to variable names before update the rss_params file

OLD_CUSTOMER_NAME="${CUSTOMER_NAME}"
OLD_SYSTEM_NAME="${SYSTEM_NAME}"
OLD_SYSTEM_ID="${SYSTEM_ID}"
OLD_SYSTEM_CITY="${SYSTEM_CITY}"
OLD_SYSTEM_STATE="${SYSTEM_STATE}"
OLD_SYSTEM_COUNTRY="${SYSTEM_COUNTRY}"
OLD_SYSTEM_ADDRESS="${SYSTEM_ADDRESS}"
OLD_SYSTEM_ZIP="${SYSTEM_ZIP}"
OLD_CUSTOMER_CONTACT="${CUSTOMER_CONTACT}"
OLD_CUSTOMER_EMAIL="${CUSTOMER_EMAIL}"
OLD_CUSTOMER_PHONE="${CUSTOMER_PHONE}"
OLD_NODE1="${NODE1}"
OLD_NODE2="${NODE2}"
OLD_NODE3="${NODE3}"
OLD_NODE4="${NODE4}"
OLD_NODE5="${NODE5}"
OLD_NODE6="${NODE6}"
OLD_DSPCONS="${DSPCONS}"
OLD_STORAGE_TYPE="${STORAGE_TYPE}"      # MN
OLD_SP_IMAGE_VERS="${SP_IMAGE_VERS}"    # MN
NEW_MODEM_TYPE="${MODEM_TYPE}"
OLD_MODEM_TYPE="${MODEM_TYPE}"
MODEM_DISP=`echo ${MODEM_TYPE} | sed -e 's/Dialer.//' -e 's/_/ /g'`
NEW_SYSTEM_TYPE="${SYSTEM_TYPE}"
NEW_UUCPHOST="${UUCPHOST}"
NEW_DIAL_STRING="${DIAL_STRING}"
NEW_ALT_DIAL="${ALT_DIAL}"
NEW_PHONE_TYPE="${PHONE_TYPE}"

tput clear

CORRECT=""
RECONFIG="n"

echo "
The current SSRR values are as follows:

Customer Name                              : "${CUSTOMER_NAME}"
System Name                         	   : "${SYSTEM_NAME}"
System I.D.                                : "${SYSTEM_ID}"
Installation City			   : "${SYSTEM_CITY}"
Installation State                         : "${SYSTEM_STATE}"
Installation Country                       : "${SYSTEM_COUNTRY}"
Installation Address                       : "${SYSTEM_ADDRESS}"
Installation Zip Code                      : "${SYSTEM_ZIP}"
Contact                                    : "${CUSTOMER_CONTACT}"
Contact Email                              : "${CUSTOMER_EMAIL}"
Contact Phone                              : "${CUSTOMER_PHONE}"
SSRR Support Tag                           : "${SYSTEM_TYPE}"
SSRR Host Name                             : "${UUCPHOST}"
SSRR Host Phone Number                     : "${DIAL_STRING}"
SSRR Host Alternate Phone Number           : "${ALT_DIAL}"
Phone Type (pulse or tone)		   : "${PHONE_TYPE}"
Modem Type (dialer script)                 : "${MODEM_DISP}"
Storage Type                               : "${STORAGE_TYPE}"
SP Software Image Version                  : "${SP_IMAGE_VERS}"

If the values are correct hit any key to continue.  Enter <m> to modify:  \c"

read CORRECT

while [ "${CORRECT}" = "m" ]
do

UPDATE_RSS_PARAMS="1"
RECONFIG="y"

CHANGE=""

echo "
Do you want to change customer information (y or n) ? \c"

read CHANGE

if [ "${CHANGE}" = "y" ]
then

NEW_CUSTOMER_NAME=""
echo "
Please enter the Customer Name (Should be one word or multiple words
combined with underscores)  Examples:   Sun
                                        Sun_Microsystems

Customer Name (or <CR> for '${CUSTOMER_NAME}'): \c"
read NEW_CUSTOMER_NAME
if [ ! -z "${NEW_CUSTOMER_NAME}" ]
then
        CUSTOMER_NAME="${NEW_CUSTOMER_NAME}"
fi

NEW_SYSTEM_NAME=""
echo "
Please enter the System Name (Should be up to 5 letters followed by
one or two numbers)  Examples:   usa1
                                 usa2
                                 quick2
System Name (or <CR> for '${SYSTEM_NAME}'): \c"
read NEW_SYSTEM_NAME
if [ ! -z "${NEW_SYSTEM_NAME}" ]
then
        SYSTEM_NAME="${NEW_SYSTEM_NAME}"
fi

NEW_SYSTEM_ID=""
echo "
Please enter the System ID (This can be a contract number, but must
be up to 8 letters or numbers)   Examples:   903H2718
                                             849H354A

System ID (or <CR> for '${SYSTEM_ID}'): \c"
read NEW_SYSTEM_ID
if [ ! -z "${NEW_SYSTEM_ID}" ]
then
        SYSTEM_ID="${NEW_SYSTEM_ID}"
fi

NEW_SYSTEM_CITY=""
echo "
Please enter the Installation City (Should be one word or multiple words
combined with underscores)  Examples:   Ft_Lauderdale
                                        Broomfield

Installation City (or <CR> for '${SYSTEM_CITY}'): \c"
read NEW_SYSTEM_CITY
if [ ! -z "${NEW_SYSTEM_CITY}" ]
then
        SYSTEM_CITY="${NEW_SYSTEM_CITY}"
fi

NEW_SYSTEM_STATE=""
echo "
Please enter the Installation State or Country (Should be one word)
                            Examples:   FL
                                        CO

Installation State or Country (or <CR> for '${SYSTEM_STATE}'): \c"
read NEW_SYSTEM_STATE
if [ ! -z "${NEW_SYSTEM_STATE}" ]
then
        SYSTEM_STATE="${NEW_SYSTEM_STATE}"
fi

NEW_SYSTEM_COUNTRY=""
echo "
Please enter the Installation Country (Should be one word)
                            Examples:   USA
                                        UK

Installation Country (or <CR> for '${SYSTEM_COUNTRY}'): \c"
read NEW_SYSTEM_COUNTRY
if [ ! -z "${NEW_SYSTEM_COUNTRY}" ]
then
        SYSTEM_COUNTRY="${NEW_SYSTEM_COUNTRY}"
fi

NEW_SYSTEM_ADDRESS=""
echo "
Please enter the Installation Address (Do not use commas)
                            Examples:   123 1st Lane
                                        12345 Broadway Suite 100

Installation Address (or <CR> for '${SYSTEM_ADDRESS}'): \c"
read NEW_SYSTEM_ADDRESS
if [ ! -z "${NEW_SYSTEM_ADDRESS}" ]
then
        SYSTEM_ADDRESS="${NEW_SYSTEM_ADDRESS}"
fi

NEW_SYSTEM_ZIP=""
echo "
Please enter the Installation Zip Code (Should be one word)
                            Examples:   12345
                                        12345-6789

Installation Zip Code (or <CR> for '${SYSTEM_ZIP}'): \c"
read NEW_SYSTEM_ZIP
if [ ! -z "${NEW_SYSTEM_ZIP}" ]
then
        SYSTEM_ZIP="${NEW_SYSTEM_ZIP}"
fi

NEW_CUSTOMER_CONTACT=""
echo "
Please enter the Installation Customer Contact 
                            Examples:   Jane Smith
                                        Jager Von Smith

Installation Customer Contact (or <CR> for '${CUSTOMER_CONTACT}'): \c"
read NEW_CUSTOMER_CONTACT
if [ ! -z "${NEW_CUSTOMER_CONTACT}" ]
then
        CUSTOMER_CONTACT="${NEW_CUSTOMER_CONTACT}"
fi

NEW_CUSTOMER_EMAIL=""
echo "
Please enter the Installation Customer Email Address 
                            Examples:   Jane.Smith@company.com
                                        jvsmith@domain.country.gov

Installation Customer Email Address (or <CR> for '${CUSTOMER_EMAIL}'): \c"
read NEW_CUSTOMER_EMAIL
if [ ! -z "${NEW_CUSTOMER_EMAIL}" ]
then
        CUSTOMER_EMAIL="${NEW_CUSTOMER_EMAIL}"
fi

NEW_CUSTOMER_PHONE=""
echo "
Please enter the Customer Contact Phone Number
                            Examples:   123-456-7890
                                        00987654321987

Installation Customer Contact Phone Number (or <CR> for '${CUSTOMER_PHONE}'): \c"
read NEW_CUSTOMER_PHONE
if [ ! -z "${NEW_CUSTOMER_PHONE}" ]
then
        CUSTOMER_PHONE="${NEW_CUSTOMER_PHONE}"
fi

NEW_SYSTEM_TYPE="$SYSTEM_TYPE"
#CHOICE=""
#while [ "${CHOICE}" != "1" ] && [ "${CHOICE}" != "2" ] && [ "${CHOICE}" != "3" ]
#do
#echo "
#Please enter the Storage Product type:
#                        1. Maserati
#                        2. Indy
#                        3. System1
#
#SYSTEM_TYPE (or <CR> for '${SYSTEM_TYPE}'): \c"
#read CHOICE
#
#case "${CHOICE}" in
#    '1')      NEW_SYSTEM_TYPE="Maserati" ;;
#    '2')      NEW_SYSTEM_TYPE="INF_SP" ;;
#    '3')      NEW_SYSTEM_TYPE="System1" ;;
#esac
#
#if [ -z "${CHOICE}" ]
#then
#CHOICE="${NEW_SYSTEM_TYPE}"
#        CHOICE="1"
#fi


#if [ "${SYSTEM_TYPE}" != "${NEW_SYSTEM_TYPE}" ]
#then
#    UPDATE_DIALERS="1"
#fi
#done

NEW_STORAGE_TYPE=""
echo "
Please enter the Storage Type. (Please enter the full name with the proper
capitalization)             Examples:   SE3910
                                        SE6320
                                        SE6920

Storage Type (or <CR> for '${STORAGE_TYPE}'): \c"
read NEW_STORAGE_TYPE
if [ ! -z "${NEW_STORAGE_TYPE}" ]
then
        STORAGE_TYPE="${NEW_STORAGE_TYPE}"
fi

NEW_SP_IMAGE_VERS=""
echo "

Please enter the version number of the SP Software Image (Should be one word 
separated with decimal points)        Examples:   1.0.2
                                                  2.4.1

SP Software Image Version(or <CR> for '${SP_IMAGE_VERS}'): \c"
read NEW_SP_IMAGE_VERS
if [ ! -z "${NEW_SP_IMAGE_VERS}" ]
then
        SP_IMAGE_VERS="${NEW_SP_IMAGE_VERS}"
fi



#NEW_NODE1=""
#echo "
#Please enter the hostname of this system (Should be one word)
#                            Examples:   bathsheba
#
#Hostname of this system (or <CR> for '${NODE1}'): \c"
#read NEW_NODE1
#if [ ! -z "${NEW_NODE1}" ]
#then
        NODE1="`uname -n`"
#fi

else
echo "
The customer information will remain the same.\n"
fi

NEW_UUCPHOST=""

echo "
Please enter the Customer Support Center's UUCP Host Machine Name (1 word, no
spaces, lower case; i.e., ichabod).  Examples:
        For all:       ichabod

SSRR Host (or <CR> to use current value of '${UUCPHOST}'):  \c" 
read NEW_UUCPHOST

if [ -z "${NEW_UUCPHOST}" ]
then
    NEW_UUCPHOST="${UUCPHOST}"
fi

if [ "${UUCPHOST}" != "${NEW_UUCPHOST}" ]
then
    UPDATE_SYSTEMS="1"
    UPDATE_PERMISSIONS="1"
fi

NEW_DIAL_STRING=""

echo "
Please enter the Customer Support Center Phone Number (Including any
special dial sequence required to access an outside line; i.e., 9,18005551212.
The ',' represents a pause to wait for a secondary dialtone.)
Examples: (Do not include spaces when entering the phone number).
        Dialing host ichabod
        From United States:    18005551212
        From United Kingdom:   001,800,5551212

SSRR Host Phone number (or <CR> for "${DIAL_STRING}"):  \c"
read NEW_DIAL_STRING

if [ -z "${NEW_DIAL_STRING}" ]
then
    NEW_DIAL_STRING="${DIAL_STRING}"
fi

if [ "${DIAL_STRING}" != "${NEW_DIAL_STRING}" ]
then
    UPDATE_SYSTEMS="1"
fi

NEW_ALT_DIAL=""

echo "
Please enter the Customer Support Center Alternate Phone Number (Including any
special dial sequence required to access an outside line; i.e., 9,18005551212.
The ',' represents a pause to wait for a secondary dialtone.)
Examples: (Do not include spaces when entering the phone number).
        Dialing host ichabod
        From United States:    18005551212
        From United Kingdom:   001,800,5551212

SSRR Host Alternate Phone number (or <CR> for "${ALT_DIAL}"):  \c"
read NEW_ALT_DIAL

if [ -z "${NEW_ALT_DIAL}" ]
then
    NEW_ALT_DIAL="${ALT_DIAL}"
fi

if [ "${ALT_DIAL}" != "${NEW_ALT_DIAL}" ]
then
    UPDATE_ALTSYS="1"
fi

NEW_PHONE_TYPE="${PHONE_TYPE}"
CHOICE=""

while [ "${CHOICE}" != "1" ] && [ "${CHOICE}" != "2" ] && [ "${CHOICE}" != "tone" ] && [ "${CHOICE}" != "pulse" ]
do
echo "
Please choose Dialing Method to use:

        1. Tone
        2. Pulse

Enter Phone Type (or <cr> for "${NEW_PHONE_TYPE}"): \c"

read CHOICE
if [ -z "${CHOICE}" ]
then
	CHOICE="${NEW_PHONE_TYPE}"
fi
done

case "${CHOICE}" in
    '1')  NEW_PHONE_TYPE=tone ;;
    'tone')  NEW_PHONE_TYPE=tone ;;
    '2')  NEW_PHONE_TYPE=pulse ;;
    'pulse')  NEW_PHONE_TYPE=pulse ;;
esac

if [ "${PHONE_TYPE}" != "${NEW_PHONE_TYPE}" ]
then
    UPDATE_DIALERS="1"
fi

##
## bbnew select modem type
## allow for custom (International??)
## allow for new types
## a new type could be a patch
##
CHOICE="NOTVALID"
while [ "${CHOICE}" != "VALID" ]
do
cd ${UUCPDIR}
echo "

Please choose a dialer file that matches the modem configuration
used by this Service Processor:
"
ls Dialer.* | sed -e 's/Dialer.//' -e 's/_/ /g' | nl
echo "

"
echo "Enter a number from those above or a <CR>
to keep ("${MODEM_DISP}"): \c"

read CHOICE

if [ "${CHOICE}" = "" ]
then
   NEW_MODEM_TYPE=$OLD_MODEM_TYPE
   CHOICE="VALID"
else
   MODEM_FILE=`ls Dialer.* | nl | grep "^     $CHOICE" | cut -c8-14`
   if [ "$MODEM_FILE" = "Dialer." ]
   then
      NEW_MODEM_TYPE=`ls Dialer.* | nl | grep "^     $CHOICE" | cut -c8-60`
   fi
   CHOICE="VALID"
fi
done


CUSTOM_DIALER=`ls "${NEW_MODEM_TYPE}" | nl | cut -c8-20`
#if [ "${CUSTOM_DIALER}" = "Dialer.Custom" ]
#then
#   echo "
#
#WARNING: You have chosen a customized dialer.
#WARNING: If you have not done so already, edit the file now
#WARNING: \"/etc/uucp/Dialer.Custom\"
#WARNING: to match your configuration before proceeding
#
#More information can be found in /etc/uucp/README_Dialer
#
#<CR> to continue. "
#read CR
#fi
#
if [ "${MODEM_TYPE}" != "${NEW_MODEM_TYPE}" ]
then
    UPDATE_DIALERS="1"
fi
cd $WHEREAMI
## end modem type
## end bbnew

NEW_MODEM_DISP=`echo ${NEW_MODEM_TYPE} | sed -e 's/Dialer.//' -e 's/_/ /g'`


#NEW_SYSTEM_TYPE="${SYSTEM_TYPE}"
#CHOICE=""
#NEW_SYSTEM_TYPE=INF_SP

tput clear

echo "
The following SSRR values have been specified:

Customer Information
   Customer Name                              : ${CUSTOMER_NAME}
   System Name                                : ${SYSTEM_NAME}
   System I.D.                                : ${SYSTEM_ID}
   Installation City                          : ${SYSTEM_CITY}
   Installation State or Country              : ${SYSTEM_STATE}
   Installation Country                       : ${SYSTEM_COUNTRY}
   Installation Address                       : ${SYSTEM_ADDRESS}
   Installation Zip Code                      : ${SYSTEM_ZIP}
   Contact                                    : ${CUSTOMER_CONTACT}
   Contact Email                              : ${CUSTOMER_EMAIL}
   Contact Phone                              : ${CUSTOMER_PHONE}
SSRR Support Tag                              : ${NEW_SYSTEM_TYPE}
SSRR Host Name                                : ${NEW_UUCPHOST}
SSRR Host Phone Number                        : ${NEW_DIAL_STRING}
SSRR Host Alternate Phone Number              : ${NEW_ALT_DIAL}
Phone Type (pulse or tone)                    : ${NEW_PHONE_TYPE}
Modem Type (dialer string)                    : ${NEW_MODEM_DISP}
Storage Type  (Type of StorEdge)              : ${STORAGE_TYPE}
SP Software Image Version                     : ${SP_IMAGE_VERS}

If the values are correct hit any key to continue.  Enter <m> to modify:  \c"

read CORRECT

done

} # end prompt ()



###
#
#  Function :  reconfig
#
#  Purpose  :  Backs up and modifies the following files if values have changed:
#
#		  /var/remote.support/files/rss_params
#	 	  /etc/uucp/Systems
#	 	  /etc/uucp/Dialers
#	 	  /etc/uucp/Permissions
#
#  Called By:  update_rss_files
#
###

reconfig () {

echo "
Updating SSRR files ..."

sleep 2

#
#  Backup files to be modified
#

LIST=""

if [ "${UPDATE_RSS_PARAMS}" = "1" ]
then 
    LIST="${LIST} ${FILESDIR}/rss_params"
fi


if [ "${UPDATE_SYSTEMS}" = "1" ]
   then 
      LIST="${LIST} ${UUCPDIR}/Systems"
fi

if [ "${UPDATE_ALTSYS}" = "1" ]
   then 
      LIST="${LIST} ${UUCPDIR}/Systems.alt"
fi

if [ "${UPDATE_DIALERS}" = "1" ]
   then 
      LIST="${LIST} ${UUCPDIR}/Dialers"
fi

if [ "${UPDATE_PERMISSIONS}" = "1" ]
   then 
      LIST="${LIST} ${UUCPDIR}/Permissions"
fi

if [ "${UPDATE_PPP}" = "1" ]
   then 
      LIST="${LIST} ${PPPDIR}/chap-secrets ${PPPDIR}/options"
fi

if [ ! -z "${LIST}" ]
then
   for FILE in ${LIST}
   do
      rm -f ${FILE}*bak.${RSS_SUN}
   done

   for FILE in ${LIST}
   do
      cp ${FILE} ${FILE}.bak.${RSS_SUN}
   done
fi


if [ "${UPDATE_SYSTEMS}" = "1" ]
then 
    #
    #  Modify the /etc/uucp/Systems file
    #
    nawk '
	{   if ($1 == uucphost)
	    {   $1 = newuucphost;
		$5 = newdialstr;
	    }
	    print
	}' uucphost=$UUCPHOST newuucphost=$NEW_UUCPHOST \
	   dialstr=$DIAL_STRING newdialstr=$NEW_DIAL_STRING \
	${UUCPDIR}/Systems.bak.${RSS_SUN} > ${UUCPDIR}/Systems
fi

if [ "${UPDATE_ALTSYS}" = "1" ]
then 
    #
    #  Modify the /etc/uucp/Systems.alt file
    #
    nawk '
	{   if ($1 == uucphost)
	    {   $1 = newuucphost;
		$5 = newdialstr;
	    }
	    print
	}' uucphost=$UUCPHOST newuucphost=$NEW_UUCPHOST \
	   dialstr=$ALT_DIAL newdialstr=$NEW_ALT_DIAL \
	${UUCPDIR}/Systems.alt.bak.${RSS_SUN} > ${UUCPDIR}/Systems.alt
fi

if [ "${UPDATE_DIALERS}" = "1" ]
then 
    #
    #  Modify the /usr/lib/uucp/Dialers file
    #
## bb
## Modify /usr/lib/uucp/Dialers
## to contain the modem dial string string
##
    cp ${UUCPDIR}/Dialers ${UUCPDIR}/Dialers.bak.${RSS_SUN}
    grep -v "rsshayes" ${UUCPDIR}/Dialers > /tmp/Dialers
    cat ${UUCPDIR}/$NEW_MODEM_TYPE >> /tmp/Dialers

    if [ "${NEW_PHONE_TYPE}" = "pulse" ]
    then
	ATDIAL="ATDP"
    else
        ATDIAL="ATDT"
    fi
    nawk ' {   if ($1 == "rsshayes" || $1 == "rssmulti")
	    {   gsub(/ATD(T|P)/, atdial);
	    }
	    print
	}' atdial=$ATDIAL \
        ${UUCPDIR}/Dialers.bak.${RSS_SUN}  > ${UUCPDIR}/Dialers
        rm -f /tmp/Dialers
fi

if [ "${UPDATE_PERMISSIONS}" = "1" ]
then 
   echo "LOGNAME=nuucp MYNAME=${SYSTEM_NAME} MACHINE=${NEW_UUCPHOST}" > ${UUCPDIR}/Permissions
fi

if [ "${UPDATE_PPP}" = "1" ]
then 
   sed -e "s/${OLD_SYSTEM_NAME}/${SYSTEM_NAME}/" ${PPPDIR}/chap-secrets 2>&1 > ${PPPDIR}/chap-secrets.new
   mv ${PPPDIR}/chap-secrets.new ${PPPDIR}/chap-secrets
   chmod 600 ${PPPDIR}/chap-secrets
   sed -e "s/${OLD_SYSTEM_NAME}/${SYSTEM_NAME}/" ${PPPDIR}/options 2>&1 > ${PPPDIR}/options.new
   mv ${PPPDIR}/options.new ${PPPDIR}/options
   chgrp sys ${PPPDIR}/chap-secrets ${PPPDIR}/options
#
# Make change to the prompt for new system name
#
   sed -e "s/${OLD_SYSTEM_NAME}/${SYSTEM_NAME}/" /etc/profile 2>&1 > /etc/profile.new
   mv /etc/profile.new /etc/profile
   chgrp sys /etc/profile
   sed -e "s/${OLD_SYSTEM_NAME}/${SYSTEM_NAME}/" /etc/.login 2>&1 > /etc/.login.new
   mv /etc/.login.new /etc/.login
   chgrp sys /etc/.login
#
# Make change to uucp Sysname file for new system name
#
   sed -e "s/${OLD_SYSTEM_NAME}/${SYSTEM_NAME}/" ${UUCPDIR}/Sysname 2>&1 > ${UUCPDIR}/Sysname.new
   mv ${UUCPDIR}/Sysname.new ${UUCPDIR}/Sysname
   chown uucp ${UUCPDIR}/Sysname
   chgrp uucp ${UUCPDIR}/Sysname

echo "
Update of PPP files complete ...
"
fi

if [ "${UPDATE_RSS_PARAMS}" = "1" ]
then
	echo "NODE1=\"${NODE1}\"" >${FILESDIR}/rss_params
	echo "NODE2=\"${NODE2}\"" >>${FILESDIR}/rss_params
	echo "NODE3=\"${NODE3}\"" >>${FILESDIR}/rss_params
	echo "NODE4=\"${NODE4}\"" >>${FILESDIR}/rss_params
	echo "NODE5=\"${NODE5}\"" >>${FILESDIR}/rss_params
	echo "NODE6=\"${NODE6}\"" >>${FILESDIR}/rss_params
	echo "DSPCONS=\"${DSPCONS}\"" >>${FILESDIR}/rss_params
	echo "CUSTOMER_NAME=\"${CUSTOMER_NAME}\"" >>${FILESDIR}/rss_params
	echo "SYSTEM_NAME=\"${SYSTEM_NAME}\"" >>${FILESDIR}/rss_params
	echo "SYSTEM_ID=\"${SYSTEM_ID}\"" >>${FILESDIR}/rss_params
	echo "SYSTEM_TYPE=\"${NEW_SYSTEM_TYPE}\"" >>${FILESDIR}/rss_params
	echo "SYSTEM_CITY=\"${SYSTEM_CITY}\"" >>${FILESDIR}/rss_params
	echo "SYSTEM_STATE=\"${SYSTEM_STATE}\"" >>${FILESDIR}/rss_params
	echo "SYSTEM_COUNTRY=\"${SYSTEM_COUNTRY}\"" >>${FILESDIR}/rss_params
	echo "SYSTEM_ADDRESS=\"${SYSTEM_ADDRESS}\"" >>${FILESDIR}/rss_params
	echo "SYSTEM_ZIP=\"${SYSTEM_ZIP}\"" >>${FILESDIR}/rss_params
	echo "CUSTOMER_CONTACT=\"${CUSTOMER_CONTACT}\"" >>${FILESDIR}/rss_params
	echo "CUSTOMER_EMAIL=\"${CUSTOMER_EMAIL}\"" >>${FILESDIR}/rss_params
	echo "CUSTOMER_PHONE=\"${CUSTOMER_PHONE}\"" >>${FILESDIR}/rss_params
	echo "UUCPHOST=\"${NEW_UUCPHOST}\"" >>${FILESDIR}/rss_params
	echo "DIAL_STRING=\"${NEW_DIAL_STRING}\"" >>${FILESDIR}/rss_params
	echo "ALT_DIAL=\"${NEW_ALT_DIAL}\"" >>${FILESDIR}/rss_params
	echo "PHONE_TYPE=\"${NEW_PHONE_TYPE}\"" >>${FILESDIR}/rss_params
        echo "MODEM_TYPE=\"${NEW_MODEM_TYPE}\"" >>${FILESDIR}/rss_params
        echo "STORAGE_TYPE=\"${STORAGE_TYPE}\"" >>${FILESDIR}/rss_params
        echo "SP_IMAGE_VERS=\"${SP_IMAGE_VERS}\"" >>${FILESDIR}/rss_params
	chmod 644 ${FILESDIR}/rss_params
fi

RECONFIG="n"
ANSWER=""

if [ "${DIFF_MCD}" = "1" ]
   then
       echo "The following rss_params value are being updated.\n"
       if [ "${CHANGE_SYSTEM_NAME}" = "1" ]
           then 
               echo "SYSTEM_NAME ${OLD_SYSTEM_NAME} is now ${SYSTEM_NAME}"
               CHANGE_SYSTEM_NAME=""
       fi

       if [ "${CHANGE_CUSTOMER_NAME}" = "1" ]
           then 
               echo "CUSTOMER_NAME ${OLD_CUSTOMER_NAME} is now ${CUSTOMER_NAME}"
               CHANGE_CUSTOMER_NAME=""
       fi

       if [ "${CHANGE_SYSTEM_ID}" = "1" ]
           then 
               echo "SYSTEM_ID ${OLD_SYSTEM_ID} is now ${SYSTEM_ID}"
               CHANGE_SYSTEM_ID=""
       fi

       if [ "${CHANGE_SYSTEM_CITY}" = "1" ]
           then 
               echo "SYSTEM_CITY ${OLD_SYSTEM_CITY} is now ${SYSTEM_CITY}"
               CHANGE_SYSTEM_CITY=""
       fi

       if [ "${CHANGE_SYSTEM_STATE}" = "1" ]
           then 
               echo "SYSTEM_STATE ${OLD_SYSTEM_STATE} is now ${SYSTEM_STATE}"
               CHANGE_SYSTEM_STATE=""
       fi

       if [ "${CHANGE_SYSTEM_COUNTRY}" = "1" ]
           then
               echo "SYSTEM_COUNTRY ${OLD_SYSTEM_COUNTRY} is now ${SYSTEM_COUNTRY}"
               CHANGE_SYSTEM_COUNTRY=""
       fi

       if [ "${CHANGE_SYSTEM_ADDRESS}" = "1" ]
           then
               echo "SYSTEM_ADDRESS ${OLD_SYSTEM_ADDRESS} is now ${SYSTEM_ADDRESS}"
               CHANGE_SYSTEM_ADDRESS=""
       fi

       if [ "${CHANGE_SYSTEM_ZIP}" = "1" ]
           then
               echo "SYSTEM_ZIP ${OLD_SYSTEM_ZIP} is now ${SYSTEM_ZIP}"
               CHANGE_SYSTEM_ZIP=""
       fi

       if [ "${CUSTOMER_CONTACT}" = "1" ]
           then
               echo "CUSTOMER_CONTACT ${OLD_CUSTOMER_CONTACT} is now ${CUSTOMER_CONTACT}"
               CUSTOMER_CONTACT=""
       fi

       if [ "${CUSTOMER_EMAIL}" = "1" ]
           then
               echo "CUSTOMER_EMAIL ${OLD_CUSTOMER_EMAIL} is now ${CUSTOMER_EMAIL}"
               CUSTOMER_EMAIL=""
       fi

       if [ "${CUSTOMER_PHONE}" = "1" ]
           then
               echo "CUSTOMER_PHONE ${OLD_CUSTOMER_PHONE} is now ${CUSTOMER_PHONE}"
               CUSTOMER_PHONE=""
       fi

       if [ "${CHANGE_NODE1}" = "1" ]
           then 
               echo "NODE1 ${OLD_NODE1} is now ${NODE1}"
               CHANGE_NODE1=""
       fi

       if [ "${CHANGE_NODE2}" = "1" ]
           then 
               echo "NODE2 ${OLD_NODE2} is now ${NODE2}"
               CHANGE_NODE2=""
       fi

       if [ "${CHANGE_NODE3}" = "1" ]
           then 
               echo "NODE3 ${OLD_NODE3} is now ${NODE3}"
               CHANGE_NODE3=""
       fi

       if [ "${CHANGE_NODE4}" = "1" ]
           then 
               echo "NODE4 ${OLD_NODE4} is now ${NODE4}"
               CHANGE_NODE4=""
       fi

       if [ "${CHANGE_NODE5}" = "1" ]
           then 
               echo "NODE5 ${OLD_NODE5} is now ${NODE5}"
               CHANGE_NODE5=""
       fi

       if [ "${CHANGE_NODE6}" = "1" ]
           then 
               echo "NODE6 ${OLD_NODE6} is now ${NODE6}"
               CHANGE_NODE6=""
       fi

       if [ "${CHANGE_DSPCONS}" = "1" ]
           then 
               echo "DSPCONS ${OLD_DSPCONS} is now ${DSPCONS}"
               CHANGE_DSPCONS=""
       fi
       if [ "${CHANGE_STORAGE_TYPE}" = "1" ]
           then
               echo "STORAGE_TYPE ${OLD_STORAGE_TYPE} is now ${STORAGE_TYPE}"
               CHANGE_STORAGE_TYPE=""
       fi

       if [ "${CHANGE_SP_IMAGE_VERS}" = "1" ]
           then
               echo "SP_IMAGE_VERS ${OLD_SP_IMAGE_VERS} is now ${SP_IMAGE_VERS}"
               CHANGE_SP_IMAGE_VERS=""
       fi

fi

ppp_update

echo "
Update of SSRR files complete ...

Hit any key to continue ... \c"

read ANSWER

} # end reconfig  ()


###
#
#  Function :  ppp_update
#
#  Purpose  :  Check and update /etc/ppp files to set system_name.
#
#  Called By:  Main Body
#
###

ppp_update () {

if [ ` grep "msp0" ${PPPDIR}/chap-secrets | wc -l` != 0 ]; then
   sed -e "s/msp0/${SYSTEM_NAME}/" ${PPPDIR}/chap-secrets 2>&1 > ${PPPDIR}/chap-secrets.new
   mv ${PPPDIR}/chap-secrets ${PPPDIR}/chap-secrets.bak.${RSS_SUN}
   mv ${PPPDIR}/chap-secrets.new ${PPPDIR}/chap-secrets
   chmod 600 ${PPPDIR}/chap-secrets
   sed -e "s/msp0/${SYSTEM_NAME}/" ${PPPDIR}/options 2>&1 > ${PPPDIR}/options.new
   mv ${PPPDIR}/options ${PPPDIR}/options.bak.${RSS_SUN}
   mv ${PPPDIR}/options.new ${PPPDIR}/options
   chgrp sys ${PPPDIR}/chap-secrets ${PPPDIR}/options
   echo "
Updated PPP files for ${SYSTEM_NAME} ... 
"
fi


} # end ppp_update  ()



###
#
#  main body of the script
#
###

stty erase "^H"


#
#  Verify that the user executing the Update Script is root	
#

ID=`id`
UID=`expr "${ID}" : 'uid=\([0-9][0-9]*\)'`
case X${UID} in
	X0 ) ;;		#LOGINNAME was root, continue
	*  ) echo "
Error:  You must be root to execute '${PRODUCT_SCRIPT}'.  Exiting ...
"
	     exit 1 ;;  # Exit with error status
esac


###
#
#  Execute main body of the script
#
###


showcopyright		# Call up the Encore copyright

checkinstall		# Check for base installation of SSRR

rss_update              # Enable/disable/update SSRR

