#!	/bin/csh -f
#
# Copyright 1993, 1994, 1995 by the Regents of the University of California.
# see the file "Copyright" in the distribution for conditions of use.
#
#
#	Menu option:
#	allow user to choose whether or not to have the menu system
#		invoked as the default environment
#
if( ! -e ~/.login ) then
	echo 'You are missing the file called ".login" which initializes your environment'
	echo I will copy a new one for you.
	cp /usr/skel/DOT/.login ~/.login
	if( $status == 0 ) then
		echo " "
		echo Copy succeeded.
		sleep 2
	else
		echo " "
		echo Copy failed.  Perhaps you are over your disk quota.
		echo 'Without a ".login", your menu option can not be changed.'
		echo 'Send mail to account "consult" for advice.'
		exit 1
	endif
endif
#
#	see if currently using menu system
set temp = `mktemp -c`
egrep 'exec menu|source /usr/skel/uclink.menu' ~/.login >> $temp
if( -z $temp ) then
	goto not_using
else
	goto using
endif
#
#============= currently using the menu system =================
#
using:
cat << "EOT"

You currently invoke the menu system upon logging on.

If you switch to invoking the UNIX shell, you will still be able to use
the menu system by typing "menu" at the uclink% prompt.

"EOT"
retry1:
echo -n 'Do you want to switch to use the UNIX shell (y/n): '
set x = $<
set y = ( $x )
if( $#y == 0 || $#y > 1 ) set x = "ERR"
if( $x == "n" || $x == "no" ) then
	echo Ok, no change will be made.
	goto done
else if( $x == "y" || $x == "yes" ) then
	egrep -v 'invoke UCLink menu system|exec menu|source /usr/skel/uclink.menu' ~/.login >! $temp
	set templ = `mktemp -p .tmp -d ~`
	/bin/cp $temp $templ
	if( $status ) goto quota_err
	/bin/mv -f $templ ~/.login

	echo ' '
	echo 'Ok, future logins will invoke the UNIX shell rather than the menu system.'
else
	echo "*** You must enter either "y" or "n"."
	echo ' '
	goto retry1
endif
goto done
#
#============= currently NOT using the menu system =================
#
not_using:
cat << "EOT"

You currently invoke the UNIX shell upon logging on.

If you switch to invoking the menu system, you will still be able
to escape to the UNIX shell by typing "x" anywhere in the menu.

"EOT"
retry1:
echo -n 'Do you want to switch to use the UCLink menu system (y/n): '
set x = $<
set y = ( $x )
if( $#y == 0 || $#y > 1 ) set x = "ERR"
if( $x == "n" || $x == "no" ) then
	echo Ok, no change will be made.
	goto done
else if( $x == "y" || $x == "yes" ) then
	/bin/cp ~/.login $temp
	echo "# " >> $temp
	echo "source /usr/skel/uclink.menu" >> $temp
	set templ = `mktemp -p .tmp -d ~`
	/bin/cp $temp $templ
	if( $status ) goto quota_err
	/bin/mv -f $templ ~/.login

	echo ' '
	echo 'Ok, future logins will invoke the menu system rather than the UNIX shell.'
else
	echo "*** You must enter either "y" or "n"."
	echo ' '
	goto retry1
endif
goto done

#==============================================

done:
if( $?temp ) then
	if( -e $temp ) /bin/rm $temp
endif
if( $?templ ) then
	if( -e $templ ) /bin/rm $templ
endif
exit

#==============================================

quota_err:

cat << "EOT"
Copy failed.  Perhaps you are over your disk quota.
Without a ".login", your menu option can not be changed.
Send mail to account "consult" for advice.
"EOT"

goto done
