#! /bin/sh

EXTRAS="AUTHORS BUGS LICENSE"

INSTALL_DIR=$GNUSTEP_INSTALLATION_DIR
if [ ! "$INSTALL_DIR" ]; then
	INSTALL_DIR=$GNUSTEP_SYSTEM_ROOT
fi
if [ ! "$INSTALL_DIR" ]; then
	INSTALL_DIR=/usr/GNUstep/System
fi
INSTALL_DIR=${INSTALL_DIR}/Library/Fonts

CMD="nfont"

if [ "$1" = "install" ]; then
	CMD="fontinstall"
elif [ "$1" = "clean" ]; then
	CMD="clean"
elif [ "$1" = "uninstall" ]; then
	CMD="uninstall"
fi

nfont ()
{
	# We do this because we want to use "$@" later on...
	DIR=${1}.nfont
	shift
	PLIST=$1
	shift

	# ok, now do the work
	if [ -d "${DIR}" ]; then
		echo -n Updating ${DIR}...
		cp "$PLIST" "$DIR/FontInfo.plist"
		for i in "$@"; do
			cp -up "$i" "$DIR/$i"
		done
	else
		echo -n Creating ${DIR}...
		mkdir "$DIR"
		cp "$PLIST" "$DIR/FontInfo.plist"
		cp -p "$@" "$DIR"
	fi
	echo done.
}

fontinstall ()
{
#	if [ ! -d "$1" ]; then
#		nfont "$@"
#	fi
	rm -fr "${INSTALL_DIR}/${1}.nfont"
	install -d -m755 "${INSTALL_DIR}/${1}.nfont"
	install -D -m644 "${1}.nfont"/* "${INSTALL_DIR}/${1}.nfont" 
	echo "Installed ${INSTALL_DIR}/${1}.nfont"
}

clean ()
{
	rm -fr "${1}.nfont"
	echo "Cleaned ${1}.nfont"
}

uninstall ()
{
	rm -fr "${INSTALL_DIR}/${1}.nfont"
	echo "Removed ${INSTALL_DIR}/${1}.nfont"
}

$CMD System				System.plist	$EXTRAS	DejaVuSans.ttf DejaVuSans-*.ttf DejaVuSansCondensed*.ttf
$CMD "System Monospace" Mono.plist		$EXTRAS	DejaVuSansMono*.ttf
$CMD "System Serif"		Serif.plist 	$EXTRAS	DejaVuSerif*.ttf
