#!/bin/sh
# $FreeBSD: japanese/font-shinonome/files/pkg-install.in 300896 2012-07-14 13:54:48Z beat $

X_FONTSDIR=/usr/local/lib/X11/fonts

case "$2" in
POST-INSTALL)
	/usr/local/bin/fc-cache -s -f -v ${X_FONTSDIR}/misc
	cd ${X_FONTSDIR}/misc
	/usr/local/bin/mkfontdir ${X_FONTSDIR}/misc
	touch fonts.alias
	grep -v -- "-shinonome-" fonts.alias > fonts.alias.tmp
	(cat fonts.alias.tmp; grep -v "^!!" /usr/local/share/font-shinonome/fonts.alias) > fonts.alias
	rm -f fonts.alias.tmp
	;;
POST-DEINSTALL)
	/usr/local/bin/fc-cache -f -v ${X_FONTSDIR}/misc
	rm -f ${X_FONTSDIR}/misc/fonts.cache-1

	cd ${X_FONTSDIR}/misc

	/usr/local/bin/mkfontdir ${X_FONTSDIR}/misc
	if [ -r ${X_FONTSDIR}/misc/fonts.dir -a `/usr/bin/wc -l < ${X_FONTSDIR}/misc/fonts.dir` = 1 ]; then
		rm -f ${X_FONTSDIR}/misc/fonts.dir
	fi

	touch fonts.alias
	grep -v -- "-shinonome-" fonts.alias > fonts.alias.tmp
	if [ -s fonts.alias.tmp ]; then
		mv fonts.alias.tmp fonts.alias
	else
		rm -f fonts.alias.tmp fonts.alias
	fi

	for D in misc
	do
		rmdir ${X_FONTSDIR}/${D} > /dev/null 2>&1 || true
		if [ -d ${X_FONTSDIR}/${D} ]; then
			/usr/local/bin/fc-cache -s -f -v ${X_FONTSDIR}/${D} || true
		fi
	done
	;;
esac
