#! /bin/sh
#
#       $Header: /cx3/license_c40/data/install/RCS/install,v 12.64 1999/03/19 09:36:15 exk Exp $
#
#	MSI Administration Program.  This program provides installation
#	support for MSI products.
#
PROGNAME=`basename $0`
PATH=/usr/bsd:/bin:/usr/bin:/usr/sbin:.:$PATH
export PATH
LICENSE_NEW=license.new
SERV_UPDATE=./.serv.update
HOST_UPDATE=./.host.update
LM_INSTALL=./.lm.install
#---------- Default values for port numbers
LICENSE_DEFAULT=744
MSI_LIC_NO_TEXT=no_text
export MSI_LIC_NO_TEXT
C2_FLAG=0


##########################################################################
#
#	necho() - echo a line to stdout without a carriage return. This
#	is done is a function due to the ways that different systems handle
#	the no return option of echo.
#
##########################################################################

necho () {
    echo $NR1 "${1}${NR2}"
}

##########################################################################
#       Pause() - wait until the user presses RETURN to continue
##########################################################################
Pause () {
    echo ""
    necho "Press <ENTER> to continue "
    read x
}

##########################################################################
#
#	ask() - Ask a question, and continue prompting until a valid answer
#	is received. "$1" holds the question to ask, and "$2" holds a list of
#	valid answers.
#
##########################################################################

ask () {
    alist=`echo $2 | sed -e 's@ @/@g'`
    anslist=" $2 "
    while /bin/true
    do
	necho "$1 <$alist> "
	read mcaseans
	ans=`echo $mcaseans | tr "[A-Z]" "[a-z]" | tr -d "[/]"`
	if [ "`echo "$anslist" | sed -e 's/ '"$ans"' /X_X_X/'`" != "$anslist" ]
	then
	    ASK_ANSWER=$ans
	    return
	else
	    echo "Invalid response. Choices are: <$alist>"
	    echo " "
	fi
    done
}

##########################################################################
#
#	yesno() - ask a yes or no question, and get either a 'y' or an 'n'
#	for an answer. Return 0 for a yes answer, and 1 for a no 
#	answer.
#
##########################################################################

yesno () {
    ask "$1?" "y n"
    if [ "$ASK_ANSWER" = y ]
    then
	return 0
    else
	return 1
    fi
}

############################################################################
#	get_hex(): gets a hexadecimal number form the user. The first
#	argument is the prompt string. The second argument is the required
#	length of the string (which should be one more than you really want
#	to accommodate for the trailing newline character). If you don't
#	care about the length, simply leave the second argument blank.
############################################################################
get_hex () {
    ok=NOT
    length=0
    if [ "$2" != "" ]
    then
	length=`eval expr $2 + 1`
	plength=$2
    fi
    while [ "$ok" = "NOT" ]
    do
	necho "$1 "
	read GET_HEX
	if [ "$GET_HEX" = "" ]
	then
	    ok=YUP
	else
	    leftover=`echo "$GET_HEX" | sed -e 's/[a-fA-F0-9]*//'`
	    if [ "$leftover" != "" ]
	    then
		echo "Answer must be hexadecimal (0-9a-f)"
	    else
		if [ "$length" != "0" ]
		then
		    len=`echo "$GET_HEX" | wc -c | sed -e 's/[ 	][ 	]*//g'`
		    if [ "$len" != "$length" ]
		    then
			echo "The string must be $plength characters"
		    else
			ok=YUP
		    fi
		else
		    ok=YUP
		fi
	    fi
	fi
    done
}


############################################################################
#  closing_msg () prints a message when installation is completed.         #
############################################################################
closing_msg () {

echo ""
if [ $C2_FLAG = 1 ]
then
Pause
echo ""
echo "--------------------- CERIUS2 INFO -----------------------------"
   echo ""
   echo "To start cerius2, type the following line at prompt"
   echo "(modifying the path as necessary):"
   echo ""
   echo "> alias cerius2 $USER_INSTALL_ROOT/bin/cerius2"
   echo ""
   echo "Add this line to your .cshrc file or see documentation for"
   echo "details on setting up workstation and multi-platform accounts."
   echo ""
   echo "Type this alias name as the command to run the program:"
   echo ""
   echo "> cerius2"
   echo ""
fi
echo "---------------------- LICENSE PACK INFO -----------------------"
echo ""
echo "\nTo have automatic access to the License Pack tools"
echo "(e.g. install_license, lmup -b, lmstat, etc.),"
echo ""
echo "> source $MSI_LIC_PACK_DIR/msi_lic_cshrc"
echo "\nWe recommend that your license administrator either"
echo "place this line in their .cshrc file, or create an alias:"
echo ""
echo "alias set_msi_lic 'source $MSI_LIC_PACK_DIR/msi_lic_cshrc'"
echo ""
echo "to set the license environment automatically or as needed."
echo ""
echo "---------------------- DOCUMENTATION INFO -----------------------"
echo ""
echo "The most complete version of all MSI product documentation is"
echo "maintained on MSI's web site, at www.msi.com/doc.  This site "
echo "includes the most current release notes, various search options, "
echo "and if desired, tools to help licensed users download documentation "
echo "sets for local access.  If you are a customer or consortium member"
echo "and don't have a password to access this documentation, please contact"
echo "support@msi.com."
echo ""
}

##########################################################################
# 
#	run_as_root(): This function runs the passed argument as root.
#	To do this, it does a 'su root -c $1'.  If root is already
#	running this command, then no password will be required.
#	Otherwise, the user will need to enter the root password
#
##########################################################################

run_as_root () {

    tries=2
    while /bin/true
    do
        echo "Enter the root password at the \"Password:\" prompt."
	echo ""
if [ ! -z "$ROOT_OVRD" ]
then
    temp_root=$ROOT_OVRD
else
    temp_root=root
fi
#        su root -c "$1"
	 su $temp_root -c "$1"
	if [ "$?" = 0 ]
	then
	    return 0
	fi
	if [ "$tries" = 0 ]
	then
	    echo "Giving up..."
	    return 1
	else
	    tries=`expr $tries - 1`
            echo "You have entered an incorrect password. Please try again."
	fi
    done
}

##########################################################################
#
#       chk_user_passwd() - Verify that the current user has a password.
#
##########################################################################
chk_user_passwd () {

# CASE 1: If an entry is above the '+::0:0::', then it will be consulted
# before all other entries and the YP.

endline=`awk "/\+/ {print NR}" /etc/passwd`
if [ "$endline" != "" ]
then
    id_line=`awk "NR == 1, NR == $endline {print}" /etc/passwd | grep \^$RUN_USER:`
fi

if [ "$id_line" != "" ]
then
	location="local password file"
	continue
# Case 2: The YP is running.
elif [ "$YP_FLAG" = yp_on ]
then
	id_line=`ypmatch $RUN_USER passwd`
	if [ "$id_line" != "" ]
	then
		location="Yellow Pages database"
		continue
	fi
# CASE 3: Not in top of passwd file, YP not running, search the entire passwd
# file.
else
	id_line=`grep \^$RUN_USER: /etc/passwd`
	location="local password file"
	
fi
if [ "$id_line" != "" ]
then
	passwd_chk=`echo $id_line|cut -d: -f2`
	if [ "$passwd_chk" = "" ]
	then
		echo "ERROR: User $RUN_USER does not have a password in the $location"
		return 1
	fi
fi
return 0
}

##########################################################################
# 
#	find_service(): This function determines whether or not the specified
#	service is currently defined in the /etc/services file. If the
#	yp_on flag is passed in, then the yellow pages version of the file
#	is checked. otherwise, /etc/services is checked. If the service
#	is defined, then the global variable SERVICE_PORT is set to the
#	port number, for use by the calling routine.
#
#	Arguments:
#	    $1: service to look for
#	    $2: yp_on/yp_off, to indicate if yellow pages is running.
#	Returns:
#	    0 - if service exists
#	    1 - if service does not exist
#	Global Variables Accessed/Updated:
#	    SERVICE_PORT (Updated): gets the port number for the service
#
##########################################################################

find_service () {

    svc=$1
    ypflag=$2

    if [ "$ypflag" = "yp_on" ]
    then
	servline=`ypcat services | grep "^${svc}"`
    else     # Yellow Pages not running
	servline=`grep "^${svc}" /etc/services`
    fi

    if [ "$servline" = "" ]
    then
        return 1
    else
        SERVICE_PORT=`echo "$servline" | awk '{print $2}' | sed -e 's@/[a-zA-Z0-9_]*@@'`
        return 0
    fi
}
	    
##########################################################################
# 
#	missing_service(): This function is called when an entry is missing
#	from the services file. If we're in verification mode, then
#	simply issue a message. If we're in update mode, then attempt to 
#	add the specified service to the /etc/services file. If Yellow Pages
#	is running, issue a warning message and don't update the file.
#	The third argument is a default port number for this service. If 
#	a default is given, it will be used unless that port number is
#	already assigned to another service. 
#
#	Arguments:
#	    $1: mode (verify or update)
#	    $2: service to add
#	    $3: (optional) default port number for this service
#	Returns:
#	    None
#	Global Variables Accessed/Modified:
#	    YP_FLAG
#
##########################################################################

missing_service () {

    mode="$1"
    srvc="$2"
    portnum_def="$3"
#
#	If Yellow Pages is running, issue a message
#
    if [ "$YP_FLAG" = "yp_on" ]
    then
	if [ "$portnum_def" = "" ]
	then
	    echo "NOTICE: This system is running Yellow Pages"
	    echo "$srvc must be added to the Yellow Pages master services file."
	else
	    echo "NOTICE: This system is running Yellow Pages"
	    echo "$srvc (default: $portnum_def) must be added to the Yellow Pages"
	    echo "master services file."
	fi
	return 1
    fi
#
#	In verification mode, we are done
#
    if [ "$mode" = "verify" ]
    then
	return 1
    fi
#
#	Update the file
#
    if [ "$portnum_def" = "" ]
    then
        necho "Enter Port Number for service $srvc: "
    else
        necho "Enter Port Number for service $srvc: <default: $portnum_def> "
    fi
    read portnum
    [ "$portnum" = "" ] && portnum=$portnum_def
    while /bin/true
    do
	sline=`grep -v "^[ 	]*#" /etc/services | grep "[ 	]$portnum/" 2> /dev/null`
	if [ "$sline" != "" ]
	then
	    echo "ERROR: port number $portnum already assigned to service `echo $sline | awk '{print $1}'`"
	    necho "Enter Port Number for service $srvc: "
	    read portnum
	else
	    echo "echo "'"'"$srvc		$portnum/tcp"'"'" >> /etc/services" >> $SERV_UPDATE
	    echo "echo "'"'"$srvc entry (port number $portnum) added to services file"'"' >> $SERV_UPDATE
	    return 0
	fi
    done
}

##########################################################################
# 
#	services_main(): This function is the mainline for the services
#	file maintenance program. It parses command line arguments,
#	then checks for each entry which should be in services.
#
#	Arguments:
#	    $*: command line arguments.
#	Returns:
#	    None
#	Global Variables Accessed/Updated:
#	    YP_FLAG (Accessed)
#	    SERVICE_PORT (Accessed)
#	    LICENSE_DEFAULT (Accessed)
#
##########################################################################

services_main () {

    if [ "$1" = "-v" ]
    then
	mode=verify
    elif [ "$1" = "-u" ]
    then
	mode=update
    else
	echo "Usage: $PROGNAME -v|-u"
	exit 1
    fi

    license_type="$1"
    sys_ok=yes

#
#	Check each item.
#
    /bin/rm -f $SERV_UPDATE
    if [ "$license_type" != "demo" ]
    then
	if find_service "$LICENSE_SERVICE" "$YP_FLAG"
	then
	    echo "$LICENSE_SERVICE defined at port $SERVICE_PORT"
	else
	    missing_service "$mode" "$LICENSE_SERVICE" "$LICENSE_DEFAULT"
	    if [ "$?" != 0 ]
	    then
	        return 1
	    fi
	fi
    fi
    if [ "$mode" = "update" ]
    then
        if [ -f "$SERV_UPDATE" ]
        then
	    echo " "
	    echo "You must be root to update the /etc/services file."
	    chmod 777 $SERV_UPDATE
	    run_as_root $SERV_UPDATE
	    /bin/rm -f $SERV_UPDATE
	    echo " "
        else
	    echo " "
	    echo "Your services file does not require modification."
	    echo " "
        fi
    fi
    return 0
}

##########################################################################
# 
#	host_main(): This function is the mainline for the hosts.equiv
#	file maintenance program. It parses command line arguments,
#	then determines what needs to be added to hosts.equiv, and adds
#	it if necessary. If the user is root, then only update mode is
#	available, and the hostname to add must be passed on the command
#	line. If the user is not root, then update mode will attempt to add
#	any entries which are required to hosts.equiv, by 'su'ing the
#	command, and asking the user for the root password.
#
#	Arguments:
#	    $*: command line arguments.
#	Returns:
#	    None
#	Global Variables Accessed/Updated:
#	    YP_FLAG (Accessed)
#
##########################################################################

host_usage () {
    echo "Usage: $PROGNAME -v"
    echo "   or: $PROGNAME -u [hostname]"
    exit 1
}

host_main () {

    update_required=no
    if [ "$1" = "-v" ]
    then
	mode=verify
	shift
    elif [ "$1" = "-u" ]
    then
	mode=update
	shift
	if [ "$1" != "" ]
	then
	    host_to_add=$1
	    update_required=yes
	    shift
	fi
    else
	host_usage
    fi
    if [ "$1" != "" ]
    then
	host_usage
    fi

    if [ "$mode" = "update" ]
    then
	if [ "$RUN_USER" = "root" -a "$host_to_add" = "" ]
	then
	    echo "root must specify a host-name to be added"
	    exit 1
	#elif [ "$RUN_USER" != "root" -a "$host_to_add" != "" ]
	#then
	    #message
	fi
    fi
    if [ "$mode" = "verify" -a "$RUN_USER" = "root" ]
    then
	echo "You cannot be root to verify the hosts.equiv file."
	return 1
    fi
    if [ "$mode" = "verify" ]
    then
	if chk_user_passwd
	then
	    : OK, the user has a password.
	else
	    echo "You cannot verify the hosts.equiv file from a user account that does not"
	    echo "have a password."
	    return 1
	fi
    fi

#   Determine whether or not the required entries already exist in hosts.equiv.

    hn=`hostname`
    if [ "$Platform" = "hp" ]
    then
        remsh localhost date >> /dev/null 2>&1
        if [ "$?" != "0" ]
        then
	    localhost_entry=missing
	    update_required=yes
        else
	    localhost_entry=OK
        fi
        remsh $hn date >> /dev/null 2>&1
        if [ "$?" != "0" ]
        then
	    this_host_entry=missing
	    update_required=yes
        else
	    this_host_entry=OK
        fi
    else
        chk=`rsh localhost date 2>&1`
        if [ "$chk" = "Permission denied." ]
        then
	    localhost_entry=missing
	    update_required=yes
        else
	    localhost_entry=OK
        fi
        chk=`rsh $hn date 2>&1`
        if [ "$chk" = "Permission denied." ]
        then
	    this_host_entry=missing
	    update_required=yes
        else
	    this_host_entry=OK
        fi
    fi

#   In verify mode, just echo information.

    if [ "$mode" = "verify" ]
    then
	rs=0
        if [ "$localhost_entry" = "missing" ]
        then
	    echo "The localhost entry appears to be missing from your /etc/hosts.equiv file."
	    rs=1
        else
	    echo "localhost is OK in hosts.equiv."
        fi
        if [ "$this_host_entry" = "missing" ]
        then
	    echo "The $hn entry appears to be missing from your /etc/hosts.equiv file."
	    rs=1
        else
	    echo "$hn is OK in hosts.equiv."
        fi
	return $rs

#   in update mode, try to add the entries, if possible.

    else
	if [ "$update_required" = no ]
	then
	    echo "Your /etc/hosts.equiv file does not require modification."
	    return
	fi
	netgroupstuff=`grep "^[+-]@" /etc/hosts.equiv 2> /dev/null`
	if [ "$netgroupstuff" != "" ]
	then
	    echo "Your /etc/hosts.equiv file is using netgroup information."
	    echo "Please update this file manually."
	    return 1
	fi

	if [ "$YP_FLAG" = "yp_on" ]
	then
	    echo "This system is running Yellow Pages."
	    if yesno "Do you want to update your local hosts.equiv file anyway"
	    then
		: OK, fall through
	    else
		echo " "
		echo "Please update your hosts.equiv file manually, then continue with"
		echo "the installation."
		echo " "
		return 1
	    fi
	fi

	if [ "$host_to_add" != "" ]
	then
	    echo "echo Adding $host_to_add to /etc/hosts.equiv" >> $HOST_UPDATE
	    echo "echo $host_to_add >> /etc/hosts.equiv" >> $HOST_UPDATE
	else
	    if [ "$localhost_entry" = "missing" ]
	    then
	        echo "echo Adding localhost to /etc/hosts.equiv" >> $HOST_UPDATE
		echo "echo localhost >> /etc/hosts.equiv" >> $HOST_UPDATE
	    fi
	    if [ "$this_host_entry" = "missing" ]
	    then
	        echo "echo Adding $hn to /etc/hosts.equiv" >> $HOST_UPDATE
		echo "echo $hn >> /etc/hosts.equiv" >> $HOST_UPDATE
	    fi
	fi
    	echo "You must have root permission to update the /etc/hosts.equiv file."
	/bin/chmod 777 $HOST_UPDATE
	run_as_root $HOST_UPDATE
	/bin/rm -f $HOST_UPDATE
    fi
}

##########################################################################
# 
#	edit_files(): This function edits the .setquanta and 
#	polygen.amd files.
#
##########################################################################

edit_files () {

warning_if_root

    #Remove any preceding /tmp_mnt 
    INSTALL_ROOT=`echo $INSTALL_ROOT | sed 's%^/tmp_mnt%%g'`

    echo "The directory into which you installed $ProductName, with all"
    echo "symbolic links resolved, is:"
    echo ""
    echo "   $INSTALL_ROOT"
    echo ""
    echo "This is the directory path which will be placed in the"
    echo "$ProductName configuration files."
    echo ""
    if yesno "Do you want to use this path"
    then
	USER_INSTALL_ROOT=$INSTALL_ROOT
    else
	necho "Enter directory path: "
	read USER_INSTALL_ROOT
    fi
    
    ask_it=0
    if [ ! -z "$MSI_LIC_PACK_DIR" ] 
    then
       echo ""
       echo "The License Pack to support this installation is:"
       echo ""
       echo "     $MSI_LIC_PACK_DIR"
       echo ""
       if yesno "Do you want to use this License Pack"
       then
          :  #do nothing
       else
          ask_it=1
       fi 
    else
       echo ""
       echo "The License Pack Directory could not be automatically determined."
       ask_it=1
    fi


    if [ "$ask_it" = 1 ]
    then
       not_ok=1
       while [ $not_ok = 1 ]
       do
          echo ""
          necho "Enter <complete path>/License_Pack path: "
          read MSI_LIC_PACK_DIR
          # Check if entered License_Pack directory exists and
          # is not empty (contains at least bin directory)
          if [ -d $MSI_LIC_PACK_DIR -a "`basename $MSI_LIC_PACK_DIR`" = "License_Pack" -a -d $MSI_LIC_PACK_DIR/bin ]
          then
             not_ok=0
          else
             echo "Invalid path, try again."
          fi
       done
    fi

    prompt=0
    config=0
    applcomm_file=1

#   Check to see if we have a list of files to configure
#   that is specific to this platform

    eval PlatformSpecificFilesToConfigure=\$FilesToConfigure_$Platform
    [ -n "$PlatformSpecificFilesToConfigure" ] && FilesToConfigure="$PlatformSpecificFilesToConfigure"

    echo ""
    echo "The following files will now be configured: "
    echo ""
    for file in $FilesToConfigure
    do
#      if [ "$file" != "libraries/applcomm.db" ]
#   Added check below to make sure libraries/applcomm.db appears in the list during first time run of install
       if [ "$file" != "libraries/applcomm.db" -o ! -f "$USER_INSTALL_ROOT"/$file-orig ]
       then
          echo "     $file"
       fi
       if [ "$file" = "bin/cerius2" ]
       then
          C2_FLAG=1
       fi
    done 
    echo ""

    for file in $FilesToConfigure
    do
        if [ ! -f "$USER_INSTALL_ROOT"/$file ]
        then
	    echo "ERROR: $USER_INSTALL_ROOT/$file: file does not exist"
	    return 1
        fi
        if [ ! -w "$USER_INSTALL_ROOT"/$file ]
        then
	    echo "ERROR: $USER_INSTALL_ROOT/$file: file is not writable"
	    return 1
        fi

        if [ ! -f "$USER_INSTALL_ROOT"/$file-orig ]
        then
           cp $USER_INSTALL_ROOT/$file $USER_INSTALL_ROOT/$file-orig
        fi

        grep "%MSIInstallRoot%" $USER_INSTALL_ROOT/$file > /dev/null 2>&1
        if [ "$?" = 0 ]
        then
            sed -e "s@%MSIInstallRoot%@$USER_INSTALL_ROOT@g" $USER_INSTALL_ROOT/$file-orig > $USER_INSTALL_ROOT/$file
            #Configure License Pack Directory path if exists
            grep "%MSI_License_Pack_Dir%" $USER_INSTALL_ROOT/$file > /dev/null 2>&1
            if [ "$?" = 0 ] 
            then
               sed -e "s@%MSI_License_Pack_Dir%@$MSI_LIC_PACK_DIR@g" $USER_INSTALL_ROOT/$file > $USER_INSTALL_ROOT/$file-tmp
               /bin/mv $USER_INSTALL_ROOT/$file-tmp $USER_INSTALL_ROOT/$file
            fi

	    chmod 755 $USER_INSTALL_ROOT/$file
            echo "$USER_INSTALL_ROOT/$file configured"
        else
            if [ $prompt = 0 ]
            then
	       echo ""
	       echo "NOTICE: It appears that these files have"
	       echo "already been configured."
	       echo ""
               if yesno "Do you want to reconfigure them"
               then
                  prompt=1
                  config=1
               else
                  prompt=1
               fi
            elif [ $file = "libraries/applcomm.db" ]
            then
               echo ""
               echo "CAUTION: If you have customized the applcomm.db file you"
               echo "must reconfigure it by hand.  In this case, answer n below, "
               echo "otherwise, answer y to have it automatically configured."
               echo ""
               if yesno "Do you want it reconfigured now by this program"
               then
                  applcomm_file=1
               else
                  applcomm_file=0 
               fi
            fi
            if [ $config = 1 -a $applcomm_file = 1 ]
            then
               sed -e "s@%MSIInstallRoot%@$USER_INSTALL_ROOT@g" $USER_INSTALL_ROOT/$file-orig > $USER_INSTALL_ROOT/$file

               grep "%MSI_License_Pack_Dir%" $USER_INSTALL_ROOT/$file > /dev/null 2>&1
               if [ "$?" = 0 ] 
               then
                  sed -e "s@%MSI_License_Pack_Dir%@$MSI_LIC_PACK_DIR@g" $USER_INSTALL_ROOT/$file > $USER_INSTALL_ROOT/$file-tmp
                  /bin/mv $USER_INSTALL_ROOT/$file-tmp $USER_INSTALL_ROOT/$file
               fi

               chmod 755 $USER_INSTALL_ROOT/$file
               echo "$USER_INSTALL_ROOT/$file reconfigured."
            else
               break 
            fi
        fi


        #
        # Source newly configured msi_lic.sh to make sure User specified LP is used
        # 11/04/98 ddk
        #
        if [ "$file" = "install/msi_lic.sh" ]
        then
           . $USER_INSTALL_ROOT/$file
        fi 

        #
        # New section to set the path to the Oracle-Read interface for Cerius2
        # 06/24/98 exk
        #

        if [ "$file" = "bin/cerius2" ]
        then
           echo "";
           orcl_path=`grep "C2_ORACLE_HOME=" $USER_INSTALL_ROOT/$file | head -1 | awk -F= '{print $2}'`
           if [ "$orcl_path" = "%ORACLE_HOME%" ]
           then
              if yesno "Do you want to set the path to the Oracle-Read interface"
              then
                 if [ ! -d "$ORACLE_HOME" ]
                 then
                    echo ""
                    echo "\$ORACLE_HOME variable is either not set or pointing to a wrong location"
                    echo ""
                    if yesno "Do you want to enter another Oracle-Read path"
                    then
                       necho "Enter Oracle-Read path: "
                       read USER_ORACLE_HOME
                       if [ ! -d "$USER_ORACLE_HOME" ]
                       then
                          echo "ERROR: This directory does not exist"
                          return 1
                       fi
                    else
                       echo ""; echo "Oracle-Read path was not set"
                       USER_ORACLE_HOME=$orcl_path
                    fi
                 else 
                    echo "The default Oracle-Read path is:"
                    echo "   $ORACLE_HOME"; echo ""
                    if yesno "Do you want to use this path"
                    then
                       USER_ORACLE_HOME=$ORACLE_HOME
                    else
                       necho "Enter Oracle-Read path: "
                       read USER_ORACLE_HOME
                       if [ ! -d "$USER_ORACLE_HOME" ]
                       then
                          echo "ERROR: This directory does not exist"
                          return 1
                       fi
                    fi
                 fi
              else
                 USER_ORACLE_HOME=$orcl_path
              fi
           else
              echo ""; echo "NOTICE: It appears that the Oracle-Read interface path has been already set to:"
              echo "   $orcl_path"
              if yesno "Do you want to use this path"
              then
                 USER_ORACLE_HOME=$orcl_path
              else
                 necho "Enter Oracle-Read path: "
                 read USER_ORACLE_HOME
                 if [ ! -d "$USER_ORACLE_HOME" ]
                 then
                    echo "ERROR: This directory does not exist"
                    return 1
                 fi
              fi
           fi 

           cp $USER_INSTALL_ROOT/$file $USER_INSTALL_ROOT/$file-temp
           sed -e "/^C2_ORACLE_HOME/s@$orcl_path@$USER_ORACLE_HOME@" $USER_INSTALL_ROOT/$file-temp > $USER_INSTALL_ROOT/$file
           rm -rf $USER_INSTALL_ROOT/$file-temp

           #
           ### New section: Daylight path and license ###
           #   07/02/98 exk
           #

           dy=no
           echo ""
           dy_root=`grep "C2_DY_ROOT=" $USER_INSTALL_ROOT/$file | head -1 | awk -F= '{print $2}'`
           dy_license=`grep "C2_DY_LICENSEDATA=" $USER_INSTALL_ROOT/$file | head -1 | awk -F= '{print $2}'`
           if [ "$dy_root" = "%DY_ROOT%" ]
           then
              if yesno "Do you have a Daylight installation which you plan to use"
              then
                 if [ ! -d "$DY_ROOT" ]
                 then
                    echo ""; echo "\$DY_ROOT env variable is either not set or pointing to a wrong location"; echo ""
                    if yesno "Do you want to enter another DY_ROOT path"
                    then
                       necho "Enter DY_ROOT path: "
                       read USER_DY_ROOT
                       if [ ! -d "$USER_DY_ROOT" ]
                       then
                          echo "ERROR: This directory does not exist"
                          return 1
                       fi
                       dy=yes
                    else
                       echo ""; echo "DY_ROOT path was not set"
                       USER_DY_ROOT=$dy_root
                    fi
                 else
                    echo "\$DY_ROOT variable is set to:"
                    echo "   $DY_ROOT"; echo ""
                    if yesno "Do you agree to use it as your DY_ROOT path"
                    then 
                       USER_DY_ROOT=$DY_ROOT
                       dy=yes
                    else
                       necho "Enter another DY_ROOT path: "
                       read USER_DY_ROOT
                       if [ ! -d "$USER_DY_ROOT" ]
                       then
                          echo "ERROR: This directory does not exist"
                          return 1
                       fi
                    fi
                 fi
              else
                 USER_DY_ROOT=$dy_root
              fi
           else
              echo ""; echo "NOTICE: It appears that the DY_ROOT path has been already set to:"
              echo "   $dy_root"
              if yesno "Do you want to use this path"
              then
                 USER_DY_ROOT=$dy_root
                 dy=yes
              else
                 necho "Enter another DY_ROOT path: "
                 read USER_DY_ROOT
                 if [ ! -d "$USER_DY_ROOT" ]
                 then
                    echo "ERROR: This directory does not exist"
                    return 1
                 fi
                 dy=yes 
              fi
           fi

           if [ "$dy" = "yes" ]
           then
              echo ""
              echo "In order to run Daylight software, you need a valid license.  It is usually defined by \$DY_LICENSEDATA env variable."
              if [ "$dy_license" = "%DY_LICENSEDATA%" ]
              then
                 if [ ! -r "$DY_LICENSEDATA" -o -d "$DY_LICENSEDATA" ]
                 then
                    echo ""; echo "\$DY_LICENSEDATA env variable is either not set, or not readable, or pointing to a wrong location"; echo ""
                    necho "Enter the full pathname of the Daylight license: "
                    read USER_DY_LICENSEDATA
                    if [ ! -r "$USER_DY_LICENSEDATA" -o -d "$USER_DY_LICENSEDATA" ]
                    then
                       echo "NOTICE: You entered a file which is either a directory, or not readable, or missing."
                       echo "It is your responsibility to obtain a valid Daylight license."
                       USER_DY_LICENSEDATA=$dy_license
                       return 1
                    else
                       echo ""; echo "Note: This file exists.  It is your responsibility to make sure it is a valid license."
                    fi
                 else
                    echo ""; echo "\$DY_LICENSEDATA env variable is pointing to the following location:"
                    echo "   $DY_LICENSEDATA"            
                    if yesno "Do you agree to use this path"
                    then
                       USER_DY_LICENSEDATA=$DY_LICENSEDATA
                    else
                       necho "Enter another path for Daylight license: "
                       read USER_DY_LICENSEDATA
                       if [ ! -r "$USER_DY_LICENSEDATA" -o -d "$USER_DY_LICENSEDATA" ]
                       then
                          echo "NOTICE: You entered a file which is either a directory, or not readable, or missing."
                          echo "It is your responsibility to obtain a valid Daylight license."
                          USER_DY_LICENSEDATA=$dy_license
                          return 1
                       else
                           echo ""; echo "Note: This file exists.  It is your responsibility to make sure it is a valid license."
                       fi
                    fi
                 fi 
              else
                 echo "NOTICE: It appears that the license path has been already set to:"
                 echo "   $dy_license"
                 if yesno "Do you agree to use this path"
                 then
                    USER_DY_LICENSEDATA=$dy_license
                 else
                    necho "Enter another path for Daylight license: "
                    read USER_DY_LICENSEDATA
                    if [ ! -r "$USER_DY_LICENSEDATA" -o -d "$USER_DY_LICENSEDATA" ]
                    then
                       echo "NOTICE: You entered a file which is either a directory, or not readable, or missing."
                       echo "It is your responsibility to obtain a valid Daylight license."
                       USER_DY_LICENSEDATA=$dy_license
                       return 1
                    else
                       echo ""; echo "Note: This file exists.  It is your responsibility to make sure it is a valid license."
                    fi
                 fi
              fi
           else
              USER_DY_LICENSEDATA=$dy_license
           fi


           cp $USER_INSTALL_ROOT/$file $USER_INSTALL_ROOT/$file-temp
           sed -e "/^C2_DY_ROOT=/s@$dy_root@$USER_DY_ROOT@" $USER_INSTALL_ROOT/$file-temp > $USER_INSTALL_ROOT/$file
           rm -rf $USER_INSTALL_ROOT/$file-temp

           cp $USER_INSTALL_ROOT/$file $USER_INSTALL_ROOT/$file-temp
           sed -e "/^C2_DY_LICENSEDATA=/s@$dy_license@$USER_DY_LICENSEDATA@" $USER_INSTALL_ROOT/$file-temp > $USER_INSTALL_ROOT/$file
           rm -rf $USER_INSTALL_ROOT/$file-temp
        else

           ### Get current values of Daylight variables in applcomm.db
           app_dy_root=`grep "DY_ROOT=" $USER_INSTALL_ROOT/$file | head -1 | awk -F= '{print $2}'`
           app_dy_license=`grep "DY_LICENSEDATA=" $USER_INSTALL_ROOT/$file | head -1 | awk -F= '{print $2}'`

           cp $USER_INSTALL_ROOT/$file $USER_INSTALL_ROOT/$file-temp
           sed -e "/DY_ROOT=/s@$app_dy_root@$USER_DY_ROOT@" $USER_INSTALL_ROOT/$file-temp > $USER_INSTALL_ROOT/$file
           rm -rf $USER_INSTALL_ROOT/$file-temp

           cp $USER_INSTALL_ROOT/$file $USER_INSTALL_ROOT/$file-temp
           sed -e "/DY_LICENSEDATA=/s@$app_dy_license@$USER_DY_LICENSEDATA@" $USER_INSTALL_ROOT/$file-temp > $USER_INSTALL_ROOT/$file
           rm -rf $USER_INSTALL_ROOT/$file-temp
        fi


        #
        # %%% new section to set up default card deck for cerius2         
        # %%% mmasi June 94
        #
        grep "%MSIInstallDex%" $USER_INSTALL_ROOT/$file > /dev/null 2>&1
        if [ "$?" = 0 ]
        then
            echo ""
            echo "Cerius2 displays a deck of menu cards, with each card"
            echo "representing an application module. Select a default"
            echo "menu deck configuration from the following choices."
            echo "(You can customize your menu deck later, if you wish.)"
            echo ""                        
            echo "          1 = Materials Science" 
            echo "          2 = Drug Discovery Workbench" 
            echo "          3 = All" 
            ask "Enter the number of your default menu deck:" "1 2 3"       
            deck_type="$ASK_ANSWER"
            echo ""
            case $deck_type in
              1) C2_DEX='materials';;
              2) C2_DEX='ddw';;
              3) C2_DEX='user';;
            esac
 
            mv $USER_INSTALL_ROOT/$file $USER_INSTALL_ROOT/$file-tmp
            sed -e "s@%MSIInstallDex%@$C2_DEX@g" $USER_INSTALL_ROOT/$file-tmp > $USER_INSTALL_ROOT/$file
            chmod 755 $USER_INSTALL_ROOT/$file
            rm -rf $USER_INSTALL_ROOT/$file-tmp 
            echo "Default menu deck successfully configured."
        fi

    done

    return 0
}

##########################################################################
#
#	setup_license_dir(): set up the license directory, and make
#	sure that it exists.
#
##########################################################################

setup_license_dir() {
    LicenseDir=$MSI_LIC_PACK_DIR/licenses
    if [ -d "$LicenseDir" ]
    then
       return 0
    else
       return 1
    fi
}

##########################################################################
# 
#	lm_install_main(): This function installs the license manager.
#
##########################################################################

lm_install_main () {

warning_if_root security

    if setup_license_dir
    then
	: do nothing - it worked
    else
	return 1
    fi

    if [ -n "$fresh_demo" ]
    then
        LICENSE_FILE=$MSI_LIC_PACK_DIR/licenses/msilicense.demo
    fi
    
    if [ ! -f "$LICENSE_FILE" ]
    then
	echo "ERROR: License File ($LICENSE_FILE) file was not found."
        echo "Refer to the MSI License Guide for instructions on"
        echo "installing a license file after software installation."
	return 1
    fi

    fc=`grep "SERVER" $LICENSE_FILE | head -1 | awk '{print NF}'`
    if [ "$fc" = "4" ]
    then
        license_type=float
    else
        fch=`grep "INCREMENT" $LICENSE_FILE | head -1 | awk '{print $NF}'`
        if [ "$fch" = "DEMO" ]
        then
            license_type=demo
        else
            license_type=NL
        fi
    fi

    if [ "$license_type" = "demo" -o "$license_type" = "NL" ]
    then
        ins_daemons=no
        echo ""
        echo "No License Manager daemon is required to support this license."
        echo ""
    elif [ "$license_type" = "float" ]
    then
        ins_daemons=yes
        if yesno "Is this machine a License Server"
        then
                : let everything fall through
        else
               ins_daemons=no
               echo " "
               echo "Login to a license server, then"
               echo "source $MSI_LIC_PACK_DIR/msi_lic_cshrc, then:\n"
               lmup_msg
               echo "\n$ProductName not ready due to lack of license manager."
               exit 1
        fi

	if [ "$ins_daemons" = "yes" ]
	then

	    $MSI_LIC_PACK_DIR/bin/lmup -b

            if [ $status ]
            then
               echo "\nUnable to bring up the license daemon."
               exit 1
            fi
	fi
    fi
}

##########################################################################
#
#	create_ldf() - This routine is called to create a License
#	Data File. It verifies that the license file does not already exist,
#	then calls the license creation program.
#
##########################################################################

create_ldf () {

    $MSI_LIC_PACK_DIR/bin/get_license
    case $? in
       0) return 0;;
       1) return 1;;
       2) fresh_demo=yes; return 0;;
       *) return 1;;
    esac
}

##########################################################################
#
#	create_demo_ldf() - This routine is called to create a License
#	Data File. It verifies that the license file does not already exist,
#	then calls the license creation program.
#
##########################################################################

create_demo_ldf () {

    if setup_license_dir
    then
        if [ -f "$DEMO_LICENSE_FILE" ]
        then
	    echo "$DEMO_LICENSE_FILE already exists."
	    if yesno "Overwrite it"
	    then
	        /bin/mv $DEMO_LICENSE_FILE $DEMO_LICENSE_FILE.bak
	    else
	        echo "Aborting at user's request."
	        return 1
	    fi
        fi
	
	if $MSI_LIC_PACK_DIR/bin/gen_demo_license
        then
            return 0
        else
	    return 1
        fi
    else
	return 1
    fi
}

##########################################################################
#
#	pre_install_main() - This program does initial validation and
#	verification before the user actually tries to do the install.
#	Its purpose is simply to provide information, which is why it
#	has toms of echo statements.
#
##########################################################################

pre_install_main () {

#
#       Initialize the warning flag, so we'll know at the end if anything went
#       wrong
#
        warn_flag=""

    echo ""
    if [ "$RUN_USER" = "root" ]
    then
       warn_flag=true
       echo "WARNING: It is not recommended to run the install program as root because of"
       echo "possible security and permission problems."
       echo ""
       echo "If you decide to run install as root, you will not be able to start the License"
       echo "Manager.  You must do that as a non-privileged user."
       Pause
    fi

#
#	Check for license pack environment setup
#
   echo ""
   echo "An MSI License Pack is required for this MSI Release.  A License Pack"
   echo "is a centralized location for all license management tools as well "
   echo "as the license files to support multiple MSI Releases."
   echo ""
   if [ -z "$MSI_LIC_PACK_DIR" ]
   then
      echo ""
      echo "WARNING:  The location of the MSI License Pack could not"
      echo "be automatically determined.  You will be prompted for the"
      echo "correct location during installation."
      echo ""
      warn_flag=true 
   else 
      echo ""
      echo "ADVISORY:  The install program is currently configured to "
      echo "use the License Pack found at:" 
      echo ""
      echo "   $MSI_LIC_PACK_DIR"
      echo ""
      echo "If you have moved this License Pack or wish to use one at a"
      echo "different location, you will be able to enter this new location"
      echo "during installation."
      echo ""
   fi

   Pause


#
#	Check services information
#
    echo ""
    necho "ADVISORY: "
    if [ "$YP_FLAG" = "yp_on" ]
    then
	echo "This system IS running NIS (Yellow Pages)."
    else
	echo "This system IS NOT running NIS (Yellow Pages)."
    fi
    Pause

    if [ ! -z "PerformService" ]
    then
        if find_service "$LICENSE_SERVICE" "$YP_FLAG"
        then
	    : do nothing - it is OK
        else
	    echo "WARNING: The $LICENSE_SERVICE port is not defined."
	    warn_flag=true
	    if [ "$YP_FLAG" = "yp_on" ]
	    then
	        echo "Since this machine is running NIS, you must add this entry to your"
	        echo "YP master services file, and propagate this change to your network."
	        echo "The install script will look for the $LICENSE_SERVICE entry, and will stop if"
	        echo "it is not found. For details on adding this entry, please refer to"
	        echo "Appendix B of your Installation and Administration Guide"
	        echo " "
	    else
	        echo "If this entry is still not defined when you run the install script,"
	        echo "the install script will ask for the root password so that it can add this"
	        echo "entry to your /etc/services file. You can either let the install script"
	        echo "update the /etc/services file for you, or you can update it yourself before"
	        echo "running the install script"
	        echo " "
	    fi
            Pause
        fi
    fi

#
#	Check the hosts.equiv stuff
#
    if [ ! -z "PerformHostsEquiv" ]
    then
	if host_main -v >> /dev/null 2>&1
	then
	    :  everything was OK
	else
	    warn_flag=true
	    echo ""
            echo "WARNING: Your hosts.equiv file requires modification. $ProductName needs to be"
	    echo "able to connect to the current machine (via the \"rsh\" command) using the"
	    echo "actual hostname, and using the name \"localhost\"."
	    if [ "$YP_FLAG" = "yp_on" ]
	    then
		echo ""
		echo "If your hosts.equiv file is managed by NIS, or if it includes netgroup"
		echo "files which are managed by NIS, then you should update your YP master files,"
		echo "and propagate the change to your network. If hosts.equiv is not under YP"
		echo "control, then you should modify /etc/hosts.equiv before running install."
		echo ""
	    else
		echo ""
		echo "You can either modify /etc/hosts.equiv before running install, or you"
		echo "can let the install script modify the file for you."
		echo ""
	    fi
            Pause
	fi
    fi

#
#	Check the license management stuff
#
    if [ ! -z "PerformLicense" ]
    then
        pre_license_type="float"
        echo ""
        echo "ADVISORY: The MSI license manager consists of two daemons (msi, lmgrd)"
        echo "an ascii license file (msilicense.dat), an ascii license log file" 
        echo "(msilicense_<port_num>.log) and an ascii start-up file (msi_lmboot"
        echo "or rc.msi_lmboot)."
        echo ""
	echo "These files are used at system boot time to start the license "
        echo "daemons.  As a result, they need to be linked or copied to the "
        echo "/etc directory."
        echo ""
	echo "The install script will ask you for your root password so that "
        echo "it can copy or link these files into your /etc directory. "
        echo "If you prefer to setup these files manually, please refer to the" 
        echo "MSI License Guide for further instructions."
	echo ""
        Pause

        if [ -f "/etc/msilicense.dat" ]
        then
           echo ""
           echo "WARNING: /etc/msilicense.dat file already exists.  "
           echo "If you install a new license during installation and"
           echo "enable the daemon startup at bootup time, it will be overwritten."
           echo ""
           Pause
        fi
	
	anylms=`ps $psflags | grep -i lmgr | grep -v grep | wc -l`
	#ourlm=`ps $psflags | grep -i msilmgrd | grep -v grep | wc -l`
	#otherlms=`expr $anylms - $ourlm`
	#if [ "$otherlms" != 0 ]
	if [ $anylms -ne 0 ]
	then
	    warn_flags=true
	    echo ""
	    echo "WARNING: Your system is already running a FLEXlm License Manager"
            echo " (lmgrd and/or msilmgrd)."
            echo ""
  
	    echo "If the only License Manager that you are running came from MSI,"
            echo "and if you have past MSI installations using the msilmgrd daemon,"
            echo "you should remove these files and hookup your past MSI releases"
            echo "to the License Pack as described in the MSI License Guide."
            echo "New files will be created and installed during installation"
            echo "which can be managed using the MSI License Pack tools."
            echo ""
            echo "If you have received this license manager from any other" 
            echo "vendor, please refer to the MSI License Guide for further "
            echo "instructions."
	    echo " "
            Pause
	fi
	if [ "$pre_license_type" = float ]
	then
	    echo ""
            echo "ADVISORY: If you have a floating license, AND if this is the server" 
            echo "machine, then the install script will be able to install the" 
            echo "license file and enable the license manager for you."
            echo ""
	    echo "If this machine is not the license server, you can still install a "
            echo "license file but you will have to log onto the server to enable "
            echo "the license manager after completing installation.  Please "
            echo "refer to the MSI License Guide for further instructions on"
            echo "how to enable your license manager (bring up the license daemons)"
            echo "after installing the software."
            Pause
	fi


        echo ""
        echo "ADVISORY: "
        if [ -f ./miscdata.dat ] 
        then
           echo ""
           echo "License files for maintenance customers have been included with"
           echo "this installation.  If you are a maintenance customer you may be"
           echo "able to extract any licenses available for your server during installation."  
           echo ""
           echo "If you are not installing on the license server machine, then you "
           echo "will need to have the system identification number for that"
           echo "machine available for license extraction."
        fi
	echo ""
        echo "If you have received a license via Email or a demo password,"
        echo "you will need to know the path to the license file or have"
        echo "the demo password ready during the install process to complete"
        echo "license installation."
	echo ""
	echo "To receive a license file via email, please send a request"
	echo "to support@msi.com."
        Pause
	echo ""
	if [ ! -z "$warn_flag" ]
	then
	    echo ""
	    echo "Once you have dealt with the issues raised by $PROGNAME, you can run the"
	    echo "install script to complete the installation."
	    echo ""
	else
	    echo ""
	    echo "You can now run the install script to complete the installation."
	    echo ""
	fi
    fi
}

##########################################################################
#
#	demo_install_main (): do a demo install. A demo install will replace
#	the services and license steps with a simple installation of a
#	demo license file.
#
##########################################################################

demo_install_main () {
#    if [ ! -z "$PerformLicense" ]
#    then
#	echo "In order to complete a DEMO installation, you must have a"
#	echo "DEMO Date Key from MSI".
#	if yesno "Do you have this key"
#	then
#	    : do nothing - we are in good shape
#	else
#	    echo "Please contact MSI for a DEMO Date Key, then rerun this program"
#	    exit 1
#	fi
#    fi

warning_if_root

    StepNum=0
    if [ ! -z "$PerformEditFiles" ]
    then
        StepNum=`eval expr $StepNum + 1`
        echo " "
        echo "====================================================================="
        echo "Step $StepNum: Configuring start up files..."
        echo "====================================================================="
        echo " "
        edit_files
        if [ "$?" != 0 ]
        then
            echo "Demo Install aborting due to previous errors."
            exit 1
        fi
    fi

    if [ ! -z "$PerformLicense" ]
    then
	if create_demo_ldf
	then
	    : great
	else
	    echo "Sorry, the demo installation failed."
	    return 1
	fi
    fi
}

##########################################################################
#
#       lmup_msg: This is a message on how to enable the License Manager.
#
##########################################################################

lmup_msg () {

echo "To enable the License Manager, run lmup on a license server machine, OR"
echo "to enable the License Manager AND enable the daemon startup at bootup time,"
echo "run lmup -b on a license server machine (you will need a root password)."
}

##########################################################################
#
#       warning_if_root: This function checks if the user is a root
#	and issues a warning message.
#
##########################################################################

warning_if_root () {

if [ "$RUN_USER" = "root" -a -z "$risk" ]
then
    echo ""
    echo "WARNING: It is not recommended to run this program as root because of"
	if [ -z "$1" ]
	then
	    echo "possible permission problems."
	else
	    echo "possible security and permission problems."
            echo ""
	    echo "If you decide to continue, you will not be able to enable the License Manager."
	    echo "You must do that as a non-privileged user."
	fi
        echo ""
        if yesno "Do you still want to continue"
        then
#     Assign risk flag to true in order to prevent repeat warning message
#     since user already decided to continue.
            risk=true
        else
            echo "Exiting..."
            echo "Please rerun this program as a non-privileged user."
            echo ""
            exit 1
        fi
fi
}

##########################################################################
#
#	mainline: get the tape location, then prompt for input from the main
#	menu.
#
##########################################################################

#USER=`id | awk '{print $1}' | awk '{FS="("; print $2}' | awk '{FS=")"; print $1}'`
RUN_USER=`id | awk '{print $1}' | awk -F"(" '{print $2}' | awk -F")" '{print $1}'`
#
#	make sure we're in the install directory, and set INSTALL_ROOT
#
cdir=`pwd`

if [ "`basename $cdir`" != "install" ]
then
    echo "ERROR: $PROGNAME must be run from the $ProductName install directory."
    exit 1
elif [ ! -w "$cdir" ]
then
    echo "ERROR: You do not have write permission on the  install  directory."
    exit 1
fi

config_dir="%MSIInstallRoot%"
if [ -r ./msiroot_config ]
then
   config_dir=`cat ./msiroot_config | grep MSI_ROOT_CONFIG | awk '{print $2}'`
fi

if [ "$config_dir" != "%MSIInstallRoot%" ]
then
   INSTALL_ROOT="$config_dir"
else
   INSTALL_ROOT=`dirname $cdir`
fi


#
#       make sure License Pack was installed and configured
#

MSI_ROOT=`dirname $INSTALL_ROOT`

#Copy msi_lic.sh if it exists and installed_lp.sh doesn't
if [ -f "$MSI_ROOT/msi_lic.sh" -a ! -f $INSTALL_ROOT/install/installed_lp.sh ]
then
   cp -f $MSI_ROOT/msi_lic.sh $INSTALL_ROOT/install/installed_lp.sh
fi

if [ -z "$MSI_LIC_PACK_DIR" ]
then
   if [ -f "$INSTALL_ROOT/install/msi_lic.sh" ]
   then
      grep "%MSI_License_Pack_Dir%" "$INSTALL_ROOT/install/msi_lic.sh" > /dev/null 2>&1
      if [ $? != 0 ]
      then
         . $INSTALL_ROOT/install/msi_lic.sh
      elif [ -f "$INSTALL_ROOT/install/installed_lp.sh" ]
      then
         . $INSTALL_ROOT/install/installed_lp.sh
      fi
   elif [ -f "$INSTALL_ROOT/install/installed_lp.sh" ]
   then
      . $INSTALL_ROOT/install/installed_lp.sh
   fi
fi

#Remove any remaining msi_lic.sh if still exists
if [ -f "$MSI_ROOT/msi_lic.sh" ]
then
   /bin/rm -f $MSI_ROOT/msi_lic.sh
fi

LICENSE_FILE=$MSI_LIC_PACK_DIR/licenses/msilicense.dat

#
#	Make sure that the product config file exists, and include it.
#
if [ ! -f product.config ]
then
    echo "ERROR: The Product Configuration file is missing. This probably indicates"
    echo "that you are not running this script from the install directory."
    exit 1
fi
. product.config

#
#	Make sure that the platform config file exists, and include it.
#
if [ ! -f platform.config ]
then
    echo "ERROR: The Platform Configuration file is missing. This probably indicates"
    echo "that you are not running this script from the install directory."
    exit 1
fi
. platform.config

#
#	Set platform-specific variables, based on the platform
#
if [ "$Platform" = "sgi" -o "$Platform" = "decalpha" ]
then
    NR1=""
    NR2='\c'
    LMHostidFlag=""
    psflags="-ef"
elif [ "$Platform" = "hp" ]
then
    NR1=""
    NR2="\c"
    psflags="-ef"
    LMHostidFlag="ether"
else
   # NR1="-n"
    NR1=""
   # NR2=""
    NR2="\c"
    LMHostidFlag=""
    psflags="ax"
fi

LICENSE_SERVICE="FLEXlm"
#
#	Determine if yellow pages is running
#
if [ -f /usr/bin/ypwhich ]
then
    if /usr/bin/ypwhich >> /dev/null 2>&1
    then
	YP_FLAG=yp_on
    else
	YP_FLAG=yp_off
    fi
else
    YP_FLAG=yp_off
fi

#
#	Set up "Perform" variables, based on which steps need to be performed.
#
PerformHostsEquiv=""
PerformEditFiles=""
PerformServices=""
PerformLicense=""
if [ "`echo $StepsToPerform | grep hostsequiv `" != "" ]
then
    PerformHostsEquiv=true
fi
if [ "`echo $StepsToPerform | grep license `" != "" ]
then
    PerformLicense=true
fi
if [ "`echo $StepsToPerform | grep config `" != "" ]
then
    PerformEditFiles=true
fi
if [ "`echo $StepsToPerform | grep services `" != "" ]
then
    PerformServices=true
fi

#  Initialize "risk" flag to use it in the warning_if_root function
risk=""

#
#	Call the proper routine, based on how this program was called 
#
case $PROGNAME in
    update_services_file)	services_main $*;;
    update_hosts_equiv)		host_main $*;;
#    gen_license)		create_ldf;;
#    gen_demo_license)		create_demo_ldf;;
    enable_license_manager)	lm_install_main;;
    config_files)		edit_files;;
    pre_install)		pre_install_main;;
    demo_install)		demo_install_main;;
    install)			;;
    *)				echo "ERROR: $PROGNAME is an unknown program";
				exit 1;;
esac

if [ "$PROGNAME" != "install" ]
then
    echo "${PROGNAME}: Execution Complete"
    exit 0
fi

#============================================================================
#	MSI Standard Install
#
#	This remaining portion of the script is the standard install program.
#	This is meant to handle the simple configurations simply.
#
#	First, determine if its OK for root to run this script.
#============================================================================
if [ ! -z "$PerformHostsEquiv" ]
then
    if [ "$RUN_USER" = "root" ]
    then
        echo "ERROR: The $ProductName Standard Install program cannot be run by root."
        echo "Please log in as another user to run install."
        exit 1
    fi
fi

#
#	Issue a nice greeting, and insure that the user has run pre_install
#
echo "============================================================================="
echo "This is the $ProductName Standard Install program."
echo ""
echo "You should have already run the pre_install program, and resolved any issues"
echo "that it raised. If you have not run pre_install, or you still have "
echo "issues to resolve, then you should not continue with the installation."
echo ""
if yesno "Do you wish to continue with the installation"
then
    :
else
    echo "Standard Install aborted at user's request."
    exit 0
fi

warning_if_root security

#
#	Install Steps
#
StepNum=0
if [ ! -z "$PerformEditFiles" ]
then
    StepNum=`eval expr $StepNum + 1`
    echo " "
    echo "====================================================================="
    echo "Step $StepNum: Configuring start up files..."
    echo "====================================================================="
    echo " "
    edit_files
    if [ "$?" != 0 ]
    then
        echo "Standard Install aborting due to previous errors"
        exit 1
    fi
fi
if [ ! -z "$PerformHostsEquiv" ]
then
    StepNum=`eval expr $StepNum + 1`
    echo " "
    echo "====================================================================="
    echo "Step $StepNum: verifying/updating /etc/hosts.equiv..."
    echo "====================================================================="
    echo " "
    host_main -u
    if [ "$?" != 0 ]
    then
        echo "Standard Install aborting due to previous errors"
        exit 1
    fi
fi
if [ ! -z "$PerformServices" ]
then
    StepNum=`eval expr $StepNum + 1`
    echo " "
    echo "====================================================================="
    echo "Step $StepNum: verifying/updating services file..."
    echo "====================================================================="
    echo " "
    services_main -u
    if [ "$?" != 0 ]
    then
        echo "Standard Install aborting due to previous errors"
        exit 1
    fi
fi
if [ ! -z "$PerformLicense" ]
then
    StepNum=`eval expr $StepNum + 1`
    echo " "
    echo "====================================================================="
    echo "Step $StepNum: Installing a License File..."
    echo "====================================================================="
    echo " "
    if create_ldf
    then
        : OK, do nothing
    else
        echo "\nWARNING: No licenses installed."
        if [ -f "$LICENSE_FILE" ]
        then
          echo "\nAlthough the license installation was not completed,"
          echo "you still have a License File (msilicense.dat) in"
          echo "$MSI_LIC_PACK_DIR/licenses directory."
          echo "This could be from a previous installation on another machine"
          echo "(in which case you need to create a new one for this machine),"
          echo "or it could be from a previous install run on this machine"
          echo "or an emailed license (in either case, it might be OK to use)."
          echo ""
          echo "To obtain a new license file, contact MSI Scientific support."
        else
          echo ""
          echo "No permanent license file available."
          echo ""
          echo "Contact MSI Scientific support to obtain a valid license file."
        fi
        echo ""
        echo "To install a valid license do the following:"
        echo ""
        echo "   > source $MSI_LIC_PACK_DIR/msi_lic_cshrc"
        echo "   > get_license"
        echo ""
        echo ""
	lmup_msg
        echo "\nStandard Install exiting."
        closing_msg
        exit 1
    fi

    LM_LICENSE_FILE=`$MSI_LIC_PACK_DIR/bin/lmgetpath`
    export LM_LICENSE_FILE

  if [ -z "$fresh_demo" ]
  then

    StepNum=`eval expr $StepNum + 1`
    echo " "
    echo "====================================================================="
    echo "Step $StepNum: Enabling the License Manager"
    echo "====================================================================="
    echo " "
    echo "To enable the License Manager you must be running on the "
    echo "license server machine."
    echo " "

    if yesno "Do you want to enable the License Manager now"
    then
        lm_install_main work
    else
        echo " "
        echo "When you are ready:"
        echo "source $MSI_LIC_PACK_DIR/msi_lic_cshrc on a license server machine, then:\n"
	lmup_msg
        echo "\nStandard Install exiting."
        echo "$ProductName not ready due to lack of license manager."
        exit 1
    fi
  fi
fi

echo "\n$ProductName installation complete."
closing_msg
exit 0
