#!	/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.
#
#
#		Create, edit or remove a .plan file
#		Create, replace or remove a .project file
#

cat << EOT
This menu entry allows you to create or remove a multi-line plan and
a single line project which are displayed when others use the finger
command to see information about your account, e.g.:

        Login name: jdoe        (messages off)  In real life: John Doe
        Directory: /h/uclink2_a/guest           Shell: /bin/csh
        On since Aug 10 21:03:07 on ttyk3 from annex136-5.Berke
        Project: graduating on time
        Plan:

        Learn about gopher, WEB, news, ...
        Win the lottery ...

In addition, permissions on your home directory will be changed so
that other users can see your plan and project.

You will need to use an editor to create a plan, but not to create
a project.

EOT
#
#	First the .plan file
#
if ( ! -e ~/.plan || -z ~/.plan ) goto noplan

#	already got a non-empty .plan file

retry1:
echo 'Enter "d" to display your plan, "r" to remove it,'
echo -n '"e" to edit it, "n" for no change: (d/r/e/n) '
set x = $<
set y = ( $x )
if( $#y == 0 || $#y > 1 ) set x = "ERR"
if( $x == "e" ) then
	goto editplan
else if( $x == "d" ) then
	echo ' '
	$PAGER ~/.plan
	echo ' '
	goto retry1
else if( $x == "r" ) then
	/bin/rm ~/.plan
	set removed
	goto project
else if( $x == "n" ) then
	goto project
else
	echo "*** Invalid entry"
	echo ' '
	goto retry1
endif

#	no preexisting none-empty plan

noplan:
retry2:
echo -n 'Do you want to create a plan (y/n): '
set x = $<
set y = ( $x )
if( $#y == 0 || $#y > 1 ) set x = "ERR"
if( $x == "n" ) goto project
if( $x != "y" ) then
	echo 'You must answer either "y" or "n".'
	echo ' '
	goto retry2
endif

editplan:
set file = ~/.plan
set embedded
source $MENU_LIB/edit_file
if( ! -e ~/.plan ) then
	echo "*** plan not set up"
	goto project
endif
if( -z ~/.plan ) then
	echo "*** empty plan ignored"
	goto project
endif
chmod a+r ~/.plan
set made

#===============================================================
project:
if( -e ~/.project && ! -z ~/.project ) goto gotproject

#	no existing non-empty .project

cat << "EOT"

Enter a single line as your project to be displayed by "finger".
If you do not want a project, just press Return.

"EOT"
echo -n "Project: "
set proj = $<
set y = ( $proj )
if( $#y > 0 ) then
	echo $proj > ~/.project
	chmod a+r ~/.project
	set made
endif

goto done

#	has existing .project

gotproject:
echo ' '
echo Your existing project is:
echo ' '
echo -n "Project: "
head -1 ~/.project
cat << "EOT"

Enter a single line as your project to be displayed by "finger",
or enter "-" to remove your project, or press Return for no change.

"EOT"
echo -n "Project: "
set proj = $<
set y = ( $proj )
if( $#y == 0 ) then
	goto done
else if( $#y == 1 ) then
#		just 'if( $proj == "-" )' didn't work, so added periods
	if( .$proj. == ".-." ) then
		/bin/rm ~/.project
		set removed
	else
		set setproj
	endif
else
	set setproj
endif

if( $?setproj ) then
	echo $proj >! ~/.project
	chmod a+r ~/.project
	set made
endif

done:

#	see if removed and nothing left, if so change permissions
if( ! $?removed ) goto check_made
if ( -e ~/.plan && ! -z ~/.plan ) goto check_made
if ( -e ~/.project && ! -z ~/.project ) goto check_made

set x = `ls -ld ~ | cut -c7,10`
if( $x == '--' ) goto check_made

chmod og-x ~
cat << "EOT"

Since you no longer have a plan or project, the permissions on your
home directory have been changed so that other accounts can no longer
search it.

"EOT"

#
check_made:
if( ! $?made ) exit
set x = `ls -ld ~ | cut -c7,10`
if( $x == 'xx' ) exit

chmod og+x ~
cat << "EOT"

The permissions on your home directory have been changed so that it is
searchable by others.  This is necessary for other accounts to access
your plan and/or project.  It does not give others access to any other
files unless you have changed the default permissions.

"EOT"
endif
