# Prototype global .bash_login file
# $Id: bash_login,v 1.4 2001/03/26 19:59:29 ghudson Exp $

# This file is sourced by default user file ~/.bash_login

. ~/.bashrc

# SGI xwsh runs shells as login shells. We don't want this.
if [ "${XSESSION+set}" = set ]; then
	exit 0
fi

initdir=/usr/athena/lib/init

if [ ! -r ~/.hushlogin ]; then
	verbose_login=t		# Echo messages unless user has ~/.hushlogin.
fi

/bin/stty sane			# Use sane control characters

if [ sgi = "$HOSTTYPE" ]; then
	/bin/stty intr ^C
fi

# *******************   ENVIRONMENT SETUP   *******************

# The ~/.bashrc file sets environment variables, attaches lockers, and sets
# the command search path.  It has already been sourced at this point.

# Check that user home directory is available

if [ "${TMPHOME+set}" = set ]; then
	echo "WARNING:"
	echo ""
	echo "Your home directory is currently unavailable."
	echo "This is probably due to a problem with the"
	echo "fileserver on which your directory is stored."
	echo ""
	echo "You may use a temporary directory for this session."
	echo "If you do, any files you create and any mail you"
	echo "incorporate will be DELETED when you logout and lost forever."
	echo ""
	echo "Would you like to continue this session, using a TEMPORARY"
	echo -n "directory? (yes,no) [The default is no] "
	read answer
	case $answer in
	[yY]*)
		echo "Continuing with temporary directory..."
		mkdir ~/Mail
		;;
	*)
		kill -HUP $$
		;;
	esac
fi
	

# *******************   DEVICE SETUP   *******************

# On IRIX, the terminal type may not be set yet.
if [ "${TERM+set}" != set ]; then
	eval `tset -s -Q`
fi

# Set device type if interactive session (e.g., dialup)

case $term in
switch|network|dialup|unknown)
	# The standard terminal emulation is vt100.  To use a different
	# emulation, set the environmental variable DEF_TERM in your
	# ~/.bash_environment file to to the device you want to emulate
	# (one that the system will recognize).
	export DEF_TERM
	if [ "${DEF_TERM+set}" != set ]; then DEF_TERM=vt100; fi
	set -f; eval `tset -s -I -Q "?${DEF_TERM}"`; set +f
	;;
esac

# If the login is on an X display but the DISPLAY variable has not 
# been set, ask the user what the DISPLAY should be (e.g., rlogin)

if [ "${DISPLAY+set}" != set ]; then
	case $term in
	xterm*)
		echo -n "What DISPLAY are you using [default: none]? "
		read response
		if [ -n "$response" ]; then
			export DISPLAY
			case $response in
			*:*)
				echo "Setting DISPLAY to $response"
				DISPLAY="$response"
				;;
			*)
				echo "Setting DISPLAY to ${response}:0"
				DISPLAY="${response}:0"
				;;
			esac
		fi
		;;
	esac
fi


# *******************   ACTIVITY STARTUP   *******************

# Run standard system/user startup activities

# Run default system startup activities.  To skip these, put the command
# "set skip_tty_startup" in your ~/.bash_environment file.

if [ "${ZEPHYR_CLIENT+set}" != set ]; then
	export ZEPHYR_CLIENT
	ZEPHYR_CLIENT=zwgc
fi

if [ "${skip_tty_startup+set}" != set ]; then
	if [ "${verbose_login+set}" = set ]; then
		 echo "Running standard startup activities ..."
	fi
	set IGNOREEOF			# ^D won't log you out
	$ZEPHYR_CLIENT			# Start Zephyr client
	get_message -login		# Display current motd
	from -t -n			# Check for mail
	(olc who &) > /dev/null 2>&1	# Ping the OLC server
fi


# Run the tty-session customizing commands in your ~/.startup.tty file.

if [ -r ~/.startup.tty ]; then
	# Don't echo if noninteractive
	if [ "${verbose_login+set}" = set ]; then
		echo "Running custom startup activities listed in ~/.startup.tty ..."
	fi
	. ~/.startup.tty
fi


# Run notification system, lert. To skip this (a generally bad idea unless
# you plan to run it yourself), put the commend "set skip_lert" in your
# ~/.bash_environment file.

if [ "${skip_lert+set}" != set ]; then
	lert -q				# Don't want to see server errors.
fi
