#!/bin/sh

if [ "x$1" = "x" ]; then
	exit 1;
fi
if [ "x$2" != "xINSTALL" -a "x$2" != "xDEINSTALL" ]; then
	exit 1;
fi

export FONTDIR; FONTDIR=${PKG_PREFIX}/lib/X11/fonts/local

if [ "$2x" = "INSTALLx" -a ! -d ${FONTDIR} ]; then
	echo '**********************************************************************'
	echo "****** ${FONTDIR}/ doesn't exist."
	echo "****** Creating ${FONTDIR}/"
	echo '****** Please upgrade your XFree86 to 3.3.3 or upper,'
	echo "****** or add this directory to your /etc/XF86Config's FontPath entry."
	echo '**********************************************************************'
	mkdir ${FONTDIR}
fi

grepv() {
	awk -v SRC=$1 'BEGIN{while (getline < SRC) {ENTRY[$0]=1}} (ENTRY[$0] != 1) {print}' $2
}

if [ "$2" = "DEINSTALL" ] ; then
	FAFILE=${PKG_PREFIX}/share/doc/ja/k20fonts/fonts.alias
	echo "Updating ${FONTDIR}/fonts.alias"
	cd ${FONTDIR}
	touch fonts.alias
	cp fonts.alias fonts.alias.orig
	grepv ${FAFILE} fonts.alias.orig > fonts.alias
	rm -f fonts.alias.orig
fi

echo "**********************************************************"
echo "You should restart X server or do 'xset fp rehash' command"
echo "to enable this update."
echo "**********************************************************"

exit 0;
