#! /bin/sh
#
#	fmsetuptraining 2.0 2/24/89
#
#	Copyright (c) 1986-1989 by Frame Technology Corp.
#	sas
#
#	This script sets up the fmtraining directory in the home directory
#	of the user. It copies over all the files from
#	$FMHOME/.fminit2.0/english/training to ~/fmtraining.
#
#	Modification History:
#	19 May 1988	sas	1.25 International Version
#	15 June 1988	ejk	language passed as argument
#

if [ $# = 1 ]; then
	language="$1"
	dirlang="$1"
else
	language="usenglish"
	dirlang="english"
fi
# always use default pdl
dir=$FMHOME/.fminit2.0/$dirlang/training.$language

echo "
fmsetuptraining 2.0: Set up for FrameMaker Training Materials

fmsetuptraining creates the fmtraining directory in your home directory.
In it you will find and can edit all the documents mentioned in the
$dirlang version of Beginning FrameMaker and FrameMath Tutorial.
"

[ $FMHOME ] || {
	echo -n "Environment variable \$FMHOME is not set.

FrameMaker is not installed correctly on your machine.
Please see your system administrator and try again after fixing the problem.

fmsetuptraining terminated without completing.
"
	exit 1
}
[ -d "$dir" ] || {
	echo -n "Cannot find \$FMHOME/.fminit2.0/$dirlang/training.$language
directory ($dir).

FrameMaker is not installed correctly on your machine.
Please see your system administrator and try again after fixing the problem.

fmsetuptraining terminated without completing.
"
	 exit 1
}
[ -r "$dir" ] || {
	 echo -n "Sorry. You don't have read access to \$FMHOME/.fminit2.0/$dirlang/training.$language.
Please see your system administrator and try again after fixing the problem.

fmsetuptraining terminated without completing.
"
	 exit 1
}
#Check if $HOME/fmtraining is a directory.
if [ -d $HOME/fmtraining ]; then
	 echo "OK to overwrite existing directory ~/fmtraining? [n]"
	 echo "Type 'y' for yes, otherwise ~/fmtraining will be preserved."
	 read answer
	 [ "$answer" = "y" ] || {
		 echo "~/fmtraining preserved."
		 echo "Rename your ~/fmtraining directory and try again."
		 echo "fmsetuptraining terminated without completing."
		 exit 1
	 }
	 echo "~/fmtraining overwritten."
	 rm -r $HOME/fmtraining
fi
#Check if $HOME/fmtraining is a file.
if [ -f $HOME/fmtraining ]; then
	 echo "OK to overwrite existing file ~/fmtraining? [n]"
	 echo "Type 'y' for yes, otherwise ~/fmtraining will be preserved."
	 read answer
	 [ "$answer" = "y" ] || {
		 echo "~/fmtraining preserved."
		 echo "Rename your ~/fmtraining file and try again."
		 echo "fmsetuptraining terminated without completing."
		 exit 1
	 }
	 echo "~/fmtraining overwritten."
	 rm -r $HOME/fmtraining
fi
umask 22
(cd $HOME; mkdir fmtraining; cd fmtraining; cp -r $dir/* .)
echo "fmsetuptraining completed."
exit 0
