#!/bin/sh
#
# Updates texmf-dist hashes and format library.
#
# Arguments:	$ACTION = [run/targets]
#		$TARGET = [post-install/post-remove]
#		$PKGNAME
#		$VERSION
#		$UPDATE = [yes/no]
#
ACTION="$1"
TARGET="$2"
PKGNAME="$3"
VERSION="$4"
UPDATE="$5"

texhash=usr/bin/texhash
fmtutil=usr/bin/fmtutil-sys
updmap=usr/bin/updmap-sys
optional_engines="luahbtex,luajithbtex,luajittex,luatex,xetex"

case "$ACTION" in
targets)
	echo "post-install post-remove"
	;;
run)
	if [ -x ${texhash} ]; then
		echo "Updating texmf-dist hashes..." 
		${texhash} 2>&1 >/dev/null || true # silence strange errors
	fi
	if [ -x ${fmtutil} ]; then
		echo "Updating texmf-dist formats..."
		${fmtutil} --no-error-if-no-engine="${optional_engines}" \
			--quiet --all >/dev/null || true
	fi
	if [ -x ${updmap} ]; then
		echo "Syncing font map files..."
		yes y | ${updmap} --quiet --syncwithtrees >/dev/null
		echo "Updating font map files..."
		${updmap} --quiet >/dev/null
	fi
	;;
*)
	exit 1
	;;
esac

exit 0
# end
