# Global bashrc file
#
# $Id: bashrc,v 1.16 2001/03/26 19:59:44 ghudson Exp $

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

initdir=/usr/athena/lib/init



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



# Set up standard system/user environment configuration (including setup of
# environment variables, attachment of lockers, and setting of search path)

if [ "${ENV_SET:+set}" != set ]; then

	export ENV_SET=t			# Avoid unnecessary repeat
	export HOSTTYPE="`/bin/athena/machtype`"

	umask 077				# Strictly protect files
						#  (does not apply in AFS)
	ulimit -c 0				# Don't allow coredumps
	export EDITOR=emacs			# Set default editor
	export VISUAL=emacs			# Set default screen editor
	export MM_CHARSET=iso-8859-1

	# Set standard Athena path variables (generic path for all users).
	# PATH will get set later after .bash_environment is run.
	case "$HOSTTYPE" in
	sgi)
		athena_path=/srvd/patch:/usr/athena/bin:/bin/athena:/usr/sbin
		athena_path=$athena_path:/usr/bsd:/sbin:/usr/bin:/bin
		athena_path=$athena_path:/usr/bin/X11:/usr/andrew/bin
		athena_path=$athena_path:/usr/athena/etc:/usr/etc
		MANPATH=/usr/athena/man:/usr/freeware/catman:/usr/share/catman
		MANPATH=$MANPATH:/usr/share/man:/usr/catman:/usr/man
		;;
	sun4)
		athena_path=/srvd/patch:/usr/athena/bin:/bin/athena
		athena_path=$athena_path:/usr/openwin/bin:/usr/openwin/demo
		athena_path=$athena_path:/usr/bin:/usr/ccs/bin:/usr/andrew/bin
		athena_path=$athena_path:/usr/athena/etc:/usr/sbin:/sbin
		athena_path=$athena_path:/usr/ucb
		MANPATH=/usr/athena/man:/usr/openwin/man:/usr/dt/man:/usr/man
		;;
	linux)
		athena_path=/srvd/patch:/usr/athena/bin:/bin/athena:/usr/bin
		athena_path=$athena_path:/bin:/usr/X11R6/bin:/usr/andrew/bin
		athena_path=$athena_path:/usr/athena/etc:/usr/sbin:/sbin
		MANPATH=/usr/athena/man:/usr/man:/usr/X11R6/man
		;;
	*)
		echo "Standard dotfiles do not support system type $HOSTTYPE."
	esac
	export MANPATH

	# Default "more" behavior
	case $HOSTTYPE in
	sgi)
		MORE=-se
		;;
	*)
		MORE=-s
		;;
	esac
	export MORE

	# Set miscellaneous system-dependent variables.
	case $HOSTTYPE in
	sgi)
		# The following set the default error message format
		# to omit the label and severity components, per the
		# standard IRIX /etc/profile.
		export MSGVERB=text:action
		export NOMSGLABEL=1
		export NOMSGSEVERITY=1
		;;
	sun4)
		export LD_LIBRARY_PATH=/usr/openwin/lib
		export OPENWINHOME=/usr/openwin
		;;
	esac
	
	export ATHENA_SYS=`/bin/athena/machtype -S`
	export ATHENA_SYS_COMPAT=`/bin/athena/machtype -C`

	if [ -z "$ATHENA_SYS" ]; then
		export ATHENA_SYS=@sys
	fi

	if [ "${PRINTER+set}" != set -a -e /var/athena/clusterinfo ]; then
		PRINTER=`awk '/LPR/ { print $3 }' /var/athena/clusterinfo`
		if [ -n "$PRINTER" ]; then export PRINTER; fi
	fi

	# Reset the HOME variable to correspond to the actual location
	# of the user's home directory.  This will avoid having long
	# pathnames being printed when /mit/<user> is a symlink to a
	# path within AFS.

	# Since this code is being invoked only at the beginning of
	# the session, and prior to the inclusion of any of the user's
	# other dotfiles, we can assume that the current directory is
	# the user's home directory.

	x=`/bin/pwd`
	if [ -n "$x" ]; then
		export HOME=$x
	fi
	unset x

	# Special version of ADD for the .bash_environment file.

	add () {
		eval "$( /bin/athena/attach -Padd -b -P"$athena_path" "$@" )"
	}

	# Run user environment customizations identified in your
	# ~/.bash_environment file.  This is the place to include your
	# own environment variables, attach commands, and other system
	# wide setup commands.  You can also cancel default behaviors
	# listed above.
	# ~/.bash_environment is not sourced if NOCALLS is set (i.e.,
	# if you selected the xlogin "Ignore your customizations"
	# option when you logged in).

	if [ "${NOCALLS+set}" != set -a -r ~/.bash_environment ]; then
		. ~/.bash_environment
	fi
	
	# On IRIX, limits are reset on exec of a setuid program, e.g.
	# xterm. So record now what the user wanted coredumpsize to
	# be so we can fix it later.
	export COREDUMPSIZE_LIMIT=`ulimit -c`

	# Standard Athena path
	PATH=`/usr/athena/bin/athdir $HOME`:$athena_path:.
	unset athena_path

	# Make sure applications can properly find their appdefs, etc.

	if [ "${XUSERFILESEARCHPATH+set}" != set ]; then
		XUSERFILESEARCHPATH=/usr/athena/lib/X11/app-defaults/%N
	else
		XUSERFILESEARCHPATH=$XUSERFILESEARCHPATH:/usr/athena/lib/X11/app-defaults/%N
	fi

	if [ sgi = "$HOSTTYPE" -a "${skip_sgi+set}" != set -a "${NOCALLS+set}" != set ]; then
		XUSERFILESEARCHPATH="$HOME/.desktop-$host/%N:$HOME/.desktop-$host/0.0/%N:$XUSERFILESEARCHPATH"
	fi

	export XUSERFILESEARCHPATH


	if [ sun4 = "$HOSTTYPE" ]; then
		if [ "${XFILESEARCHPATH+set}" != set ]; then
			XFILESEARCHPATH="/usr/openwin/lib/locale/%L/%T/%N%S:/usr/openwin/lib/%T/%N%S"
		else
			XFILESEARCHPATH="$XFILESEARCHPATH:/usr/openwin/lib/locale/%L/%T/%N%S:/usr/openwin/lib/%T/%N%S"
		fi
		export XFILESEARCHPATH
	fi
fi
	

# *******************  BASH SETUP   *******************

# Set up standard bash shell initializations

set -o noclobber		# Don't overwrite files with redirection

if [ "${PS1+set}" = set ]; then
	if [ sgi = "$HOSTTYPE" -a -t 0 ]; then
		# Have no better way to do this at the moment.
		stty sane intr ^C
	fi
	PS1="athena$ "
	HISTSIZE=20
	CDPATH=.:~
fi

# Fix coredumpsize limit in case it was reset
[ -n "$COREDUMPSIZE_LIMIT" ] && ulimit -c $COREDUMPSIZE_LIMIT

#   alias for re-establishing authentication
renew () { kinit $USER && fsid -a && zctl load /dev/null ; }

#   alias for a convenient way to change terminal type
term () { set -f; unset TERMCAP; eval "$( tset -s -I -Q "$@" )"; set +f; }

#   aliases dealing with mail
alias mail=Mail
Mail () { more /usr/prototype_user/README.mail ; }

#   aliases dealing with x window system
xresize () { set -f; eval "$( resize -u )"; set +f ; }

if [ "${XSESSION+set}" = set ]; then
	if [ -z "$XSESSION" ]; then
		logout () { end_session && exit; }		# logout for X
	else
		logout () { kill -HUP $XSESSION && exit; }	# logout for X
	fi
fi

#   aliases dealing with adding locker programs

add_flags=
add () { eval "$( /bin/athena/attach -Padd -b $add_flags "$@" )" ; }

alias setup='echo "setup is not supported in bash yet"'


# All of the bash initializing commands above can be overridden by using
# "unset" or "unalias" commands (or by changing things using "set" or
# "alias" again) in your ~/.bashrc.mine file, which is sourced here.
# ~/.bashsrc.mine is not sourced if the xlogin "Ignore your customizations"
# option was selected to begin the session.

if [ "${NOCALLS+set}" != set -a -r ~/.bashrc.mine ]; then
	. ~/.bashrc.mine
fi
