
: TNIX/UNIX version - 06FEB1984
:	Keyshell Version Number 2	*/

: save - version 1 - 8SEP83

: Save is shell subroutine called by setksh.
: It saves the current ColorKey+ configuration under a name supplied
: by the user.  

: If the user\'s ColorKey+ Interface is configured then we can save it.
: The saved configuration will be saved to the user\'s directory
: $HOME/.saveksh.  The files .setTEK and .setKSH are shoved into the .ksh 
: directory and the whole thing is moved over to a directory .saveksh.

if test -d $HOME/.saveksh	
then
	echo
	echo "Saved ColorKey+ Configurations:"
	echo
	ls -1 $HOME/.saveksh
fi

echo
echo "Please enter the name under which to save the current configuration."
echo
echo -n "Enter the name (<CR> returns to main menu): "
read newname

if test -z "$newname" 			
then 
	echo "...Current configuration not changed..."
	exit 1
fi	

: Warn the user that he is about to overwrite a currently saved configuration.

if test -d $HOME/.saveksh/${newname}
then
	echo -n "Configuration $newname already exists.  Do you wish to overwrite ('y' or 'n')? : "
	read INPUT
	case $INPUT in
	'y' | 'Y')
			continue=0
			:;;
		*)
			continue=
			echo "...Current configuration not changed..."
			echo "...Saved configuration '$newname' not changed...";;
	esac
else
	continue=0
fi

if test $continue
then
	echo -n "...Saving current ColorKey+ configuration..."

	if test ! -d $HOME/.saveksh		
	then 
		mkdir $HOME/.saveksh
		chmod 0755 $HOME/.saveksh
	fi

	dst=$HOME/.saveksh/${newname}

	rm -r -f $dst

	if test -d $HOME/.ksh		
	then
		src=$HOME/.ksh
	else				
		src=$TEKPATH/tek/ksh/deflt
	fi

	trap "rm -r -f $dst; echo '...Save aborted...'; exit" 2 3
		mkdir $dst
		chmod 0755 $dst
		cp $src/* $dst
		cp $HOME/.setTEK $dst		
		cp $HOME/.setKSH $dst
	trap 2 3

	echo
	echo "...ColorKey+ configuration saved under new name '${newname}'"

fi					

