#!/bin/sh
# set -x
#	SID	"@(#)xfontinstall	3.3 - 95/11/10"

# you may need to change these if you are experiencing difficulties

X11BIN=/usr/bin/X11
if [ ! -x $X11BIN/xset ] ; then
	X11BIN=/usr/X11/bin
	if [ ! -x $X11BIN/xset ] ; then
		X11BIN=/usr/openwin/bin
		if [ ! -x $X11BIN/xset ] ; then
			echo "Cannot Find X11 program xset"
			exit 1
		fi
	fi
fi
XFONTPATH=/usr/lib/X11/fonts/misc
FONT_TYPE=-pcf
if [ `uname` = SunOs ] ; then
	FONT_TYPE=-fb
	XFONTPATH=/usr/openwin/lib/fonts
elif [ `uname` = UnixWare ] ; then
	FONT_TYPE=-snf
fi


progName=`basename $0`

usage() {
	echo "$progName [-x] [-x11 X11_bin_dir] [-d font_destination]"
	echo "	[-fb | -pcf | -snf]"
}

showexpl() {
	usage
	cat <<!

Install ANGOSS sff fonts

-x		display this explanation
-x11		Where the X11 executables are (default=/usr/bin/X11)
-d		Where fonts are put (default=/usr/lib/X11/fonts/misc)
-fb		Font type = fb
-pcf		Font type = pcf
-snf		Font type = snf

Note!  You should be root to run this program.
!
}

# setarg varName argv         - argv is like -c parm ...
# sets varName to value parm, exiting if there are not enough values
#
setarg() {
	varName=$1; shift
	optName=$1; shift
	if [ $# -ge 1 ]; then
		eval $varName=$1
	else
		echo Missing argument to $optName >&2
		usage 2
		exit 1
	fi
}

while [ $# -ge 1 ] ; do
	case $1 in
	-x)		showexpl; exit;;
	-x11)		setarg X11BIN $*;;
 	-d)		setarg XFONTPATH $*;;
	-fb)		FONT_TYPE="-fb";;
	-pcf)		FONT_TYPE="-pcf";;
	-snf)		FONT_TYPE="-snf";;
	*) 	shift;;
	esac
	shift
done

if [ ! -d $XFONTPATH ] ; then
	echo "Can't find $XFONTPATH, please run xset -q to get directory"
	echo "Specify override (see xfontinstall -x)"
	exit 1
fi
if [ ! -f $X11BIN/mkfontdir ] ; then
	echo "Can't find $X11BIN/mkfontdir"
	echo "Specify override (see xfontinstall -x)"
	exit 1
fi
if [ ! -f $X11BIN/xset ] ; then
	echo "Can't find $X11BIN/xset"
	echo "Specify override (see xfontinstall -x)"
	exit 1
fi
if [ ! -f bin/xoac ] ; then
	echo "Can't find bin/xoac"
	echo "You must run this from the ANGOSS root, or you have not"
	echo "installed the X11 executable!"
	exit 1
fi

echo "Installing X fonts... "
cd resource/X11/fonts
./sff_install $FONT_TYPE $XFONTPATH
echo done
cd ../../..
echo "Running mkfontdir... "
$X11BIN/mkfontdir $XFONTPATH
echo done
echo "Rehashing font server"
$X11BIN/xset fp rehash
echo "done"
exit 0
