# Prototype file for setting up course-specific environment
# $Author: svalente $
# $Source: /afs/sipb/project/sipb-athena/xdm/init/RCS/env_setup,v $
# $Header: /afs/sipb/project/sipb-athena/xdm/init/RCS/env_setup,v 1.1 1995/03/23 02:51:45 svalente Exp $

# Just in case this alias is not already set,
alias extend 'if (-d \!:2) if ("$\!:1" \!~ *"\!:2"*) set extendyes && \\
	if ($?extendyes && $?verboseadd) echo \!:2 added to end of \$\!:1 && \\
	if ($?extendyes) setenv \!:1 ${\!:1}:\!:2 && \\
	unset extendyes'

echo "Attaching $SUBJECT ... "
set setup_dir = `/bin/athena/attach -p $SUBJECT`

if (! $status) then

	# Record information to remove setup later
	set setup_filsys = $SUBJECT

	# Set prompt to reflect changed environment
	set prompt = "$SUBJECT% "

	if ( -r $setup_dir/.attachrc) then
		unsetenv SUBJECT	# to prevent infinite loops
		echo "Running commands in $setup_dir/.attachrc ... "
		source $setup_dir/.attachrc
        else
		# Do minimal environment setup
		extend PATH $setup_dir/${bindir}
		extend MANPATH $setup_dir/man
        endif  
else
	echo ""
        echo "The $SUBJECT filesystem could not be attached."
	set filsys = `hesinfo $SUBJECT filsys`
	if ($#filsys < 3) then
		echo "Check your spelling of the filesystem name."
	else
		echo -n "The $filsys[1] fileserver"
		if ($filsys[1] != AFS) echo -n " named $filsys[3]"
		echo " may be down."
	endif
	if ($?XSESSION) then
		echo "Type exit to get rid of this window."
	else
		kill -HUP $$	# cause shell to exit
	endif
endif
unsetenv SUBJECT	# to prevent infinite loops
