#!/bin/sh
#
# Typist v2.2 - improved typing tutor program for UNIX systems
# Copyright (C) 1998  Simon Baldwin (simonb@sco.com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

# some constants
TYPIST_LIBRARY="/usr/local/lib/typist"
TERMINFO_1="/usr/share/terminfo"
TERMINFO_2="/usr/lib/terminfo"
ME="`basename $0`"
MYDIR="`dirname $0`"
REAL_TYPIST="typist_bin"

# if TYPIST_PATH is not set then set it as a courtesy
if [ -z "$TYPIST_PATH" ]; then

	# ensure that the library directory exists
	if [ -d $TYPIST_LIBRARY ]; then
		TYPIST_PATH="$TYPIST_LIBRARY"
		export TYPIST_PATH
	else
		echo "$ME: WARNING: TYPIST_PATH not set, and $TYPIST_LIBRARY not found" >&2
echo "  If TYPIST_PATH is not set, and cannot be set for you automatically," >&2
echo "  you will need to give the full path to each script file you run." >&2
echo "  Try 'man typist' for more." >&2
echo "  To fix this, set a value for the TYPIST_PATH environment variable." >&2
		sleep 3
	fi
fi

# try to set a suitable value for TERMINFO, since it can live in different
# places on different platforms
if [ -z "$TERMINFO" ]; then

	if [ -d $TERMINFO_1 ]; then
		TERMINFO=$TERMINFO_1
		export TERMINFO
	else
		if [ -d $TERMINFO_2 ]; then
			TERMINFO=$TERMINFO_2
			export TERMINFO
		else
			echo "$ME: WARNING: couldn't find a TERMINFO directory" >&2
echo "  Neither $TERMINFO_1 nor $TERMINFO_2 exist, and these are" >&2
echo "  the two primary locations for the terminfo database.  Typist may" >&2
echo "  fail if it can't find this database.  Try 'man terminfo' for more." >&2
echo "  To fix this, set a value for the TERMINFO environment variable." >&2
			sleep 3
		fi
	fi
fi

# run the binary from within our directory
if [ -x $MYDIR/$REAL_TYPIST ]; then
	exec $MYDIR/$REAL_TYPIST $*
fi

# if we get to here something is badly wrong
echo "$ME: ERROR: can't find the $REAL_TYPIST binary" >&2
exit 1
