
shrc_check_login_shell ()
{
	LOGIN_SHELL=`$EMPRESSPATH/empinstl/instbin/chkuser -shell`
	INST_ALTER_STARTUP_FILE=yes

	if test "$LOGIN_SHELL" = ""
	then
		#
		# if the shell entry of /etc/passwd is empty, we assume
		# it uses /bin/sh as the default shell.
		# For example, the chsh command in Linux (RedHat 4.2)
		# empty the shell field of the passwd if the user changes
		# his shell to /bin/sh.
		#
		LOGIN_SHELL=/bin/sh
	fi

	case $LOGIN_SHELL in
	  */bash)
		SHELL_CLASS=sh
		SHELL_STARTUP_FILE=$HOME/.profile
		test -f $HOME/.bash_profile && \
			SHELL_STARTUP_FILE=$HOME/.bash_profile
		;;
	  */csh)
		SHELL_CLASS=csh
		SHELL_STARTUP_FILE=$HOME/.cshrc

		#
		# if /bin/csh is a symbolic link to /bin/tcsh
		#
		if test -f /bin/tcsh && cmp -s $LOGIN_SHELL /bin/tcsh && \
			test -f $HOME/.tcshrc
		then
			SHELL_STARTUP_FILE=$HOME/.tcshrc
		fi
		;;
	  */sh)
		SHELL_CLASS=sh
		SHELL_STARTUP_FILE=$HOME/.profile

		#
		# If /bin/sh is a symbolic link to /bin/bash.
		#
		if test -f /bin/bash && \
			cmp -s $LOGIN_SHELL /bin/bash && \
			test -f $HOME/.bash_profile
		then
			SHELL_STARTUP_FILE=$HOME/.bash_profile
		fi
		;;
	  */ksh)
		SHELL_CLASS=sh
		SHELL_STARTUP_FILE=$HOME/.profile
		;;
	  */tcsh)
		SHELL_CLASS=csh
		SHELL_STARTUP_FILE=$HOME/.cshrc
		test -f $HOME/.tcshrc && SHELL_STARTUP_FILE=$HOME/.tcshrc
		;;
	  *)
		LOGIN_SHELL=unknown
		SHELL_CLASS=unknown
		SHELL_STARTUP_FILE=
		INST_ALTER_STARTUP_FILE=no
		;;
	esac
}

shrc_construct_startup_file ()
{
	test "$LOGIN_SHELL" = "unknown" && return

	if test "$SHELL_CLASS" = "sh"
	then
		cat <<EOM
# ### $MSPACKAGE Installation Setup Block ###
# Do not modify lines within the $MSPACKAGE Installation Setup Block
. $INSTALL_DIR/bin/setenv.sh
# ### $MSPACKAGE Installation Setup Block End ###
EOM
	elif test "$SHELL_CLASS" = "csh"
	then
		cat <<EOM
# ### $MSPACKAGE Installation Setup Block ###
# Do not modify lines within the $MSPACKAGE Installation Setup Block
source $INSTALL_DIR/bin/setenv.csh
# ### $MSPACKAGE Installation Setup Block End ###
EOM
	fi
}

shrc_update_startup_file ()
{
	test "$SHELL_CLASS" = "" && return
	test "$SHELL_STARTUP_FILE" = "" && return
	test "$INST_ALTER_STARTUP_FILE" = "yes" || return

	echo_message "$MSG_INFO_UPDATE_STARTUP_FL" $SHELL_STARTUP_FILE
	
	if test -f $SHELL_STARTUP_FILE
	then
		X=$SHELL_STARTUP_FILE.`date "+%y-%m-%d-%T"`
		mv $SHELL_STARTUP_FILE $X

		# Remove the stuff from older version of Empress

		sed -e '
/Empress Installation Setup Block/,/Empress Installation Setup Block End/d
/eXcalibur Installation Setup Block/,/eXcalibur Installation Setup Block End/d
		' < $X > $SHELL_STARTUP_FILE
	fi

	shrc_construct_startup_file >> $SHELL_STARTUP_FILE
	echo_message "$MSG_INFO_DONE"
}

shrc_inform_setup_empress ()
{
	MSG=$MSG_INFO_STARTUP_FL_NOT_UPDATED

	if test "$INST_ALTER_STARTUP_FILE" = "yes" 
	then
		MSG=$MSG_INFO_STARTUP_FL_UPDATED
	fi

	X="source $INSTALL_DIR/bin/setenv.csh"
	test "$SHELL_CLASS" = "sh" && X=". $INSTALL_DIR/bin/setenv.sh"

	echo_message "$MSG" "$SHELL_STARTUP_FILE" "$X"
}
