#!	/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.
#
#
#	help user reinitialize his/her account back to UCLink
#	default environment
#
#	Step 1 - Introduction
#
cd
cat << "EOT"

This menu entry allows you to reset your login environment to
the UCLink default environment for new accounts.

Your basic login environment is defined by two files named
".login" and ".cshrc".

You will be given the option to save your existing copies
of those files first, and you will be able to select whether
to include the UCLink menu system in your normal login environment.

"EOT"
echo -n "Would you like to proceed and reset your login environment (y/n): "
repeat1:
set r = $<
set s = ( $r )
if( $#s > 1 ) set r = "ERR"
if( $#s == 0 || $r == 'n' ) exit 0
if( $r != "y" ) then
	echo "*** invalid response"
	echo -n 'Enter "y" to continue, "n" to quit: '
	echo " "
	goto repeat1
endif

#
#	Step 2 - optionally save current .login and .cshrc
#
echo " "

repeat2:
cat << "EOT"

Do you want to save copies of your current ".login" and ".cshrc"
"EOT"
echo -n "files in the files ".login.old" and ".cshrc.old" (y/n): "

set r = $<
set s = ( $r )
if( $#s == 0 || $#s > 1 ) set r = "ERR"
if( $r == 'n' ) goto step3
#
if( $r == 'y' ) then
	/bin/cp -p .login  .login.old
	cmp -s .login .login.old
	if( $status ) goto quota_err
	echo 'Current ".login" copied to ".login.old".'

	/bin/cp -p .cshrc  .cshrc.old
	cmp -s .cshrc .cshrc.old
	if( $status ) goto quota_err
	echo 'Current ".cshrc" copied to ".cshrc.old".'
else if( $r == 'n' ) then
	echo "Ok."
else
	echo " "
	echo '*** invalid response, you must enter "y" or "n".'
	goto repeat2
endif
echo " "
#
#	Step 3 - choose menu or nonmenu environment and copy
#
step3:
repeat3:
cat << "EOT"

Do you want your login environment to be the UCLink menu system or
to be the UNIX shell. '

"EOT"
echo -n 'Enter "m" for the menu system, "u" for the UNIX prompt: '
set r = $<
set s = ( $r )
if( $#s > 1 || $#s == 0 ) set r = "ERR"
if( $r == 'm' ) then
	set login_file = .login
else if( $r == 'u' ) then
	set login_file = .login_nomenu
else
        echo " "
        echo "*** invalid response"
        goto repeat3
endif

/bin/cp /usr/skel/$login_file  .login
cmp -s /usr/skel/$login_file .login
if( $status ) goto quota_err
echo New ".login" copied ok.

/bin/cp /usr/skel/.cshrc  .cshrc
cmp -s /usr/skel/.cshrc .cshrc
if( $status ) goto quota_err
echo New ".cshrc" installed ok.

exit 0

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

quota_err:

cat << "EOT"

The operation failed, probably due to quota problems.  For information
on quotas and how to manage your disk space please refer to the
information in Gopher.  Type "gopher" and then select:

        Using UCLink
        Tips on Disk Usage and Quotas
        How to manage your disk usage

For additional information, send mail to consult.
"EOT"
exit 1
