#!/bin/sh -e

shopt -s nullglob

setup_fonts_cache ()
{
	[ -z "${UHU_PKG_QUIET+x}" ] && echo -n "  Running fc-cache ..."
	fc-cache -s -n
	if [ "$1" != "may_need_one_more_run" ]; then
		true > /var/lib/uhu-pkg/fonts-cache
		while [ ! /var/lib/uhu-pkg/fonts-cache -ot /var/lib/dpkg/info \
		     -a ! /var/lib/uhu-pkg/fonts-cache -nt /var/lib/dpkg/info ]; do
			sleep 0.1
			true > /var/lib/uhu-pkg/fonts-cache
		done
	fi
	[ -z "${UHU_PKG_QUIET+x}" ] && echo
}

if [ "$2" = "upgrade" -o "$2" = "purge" ]; then
	exit 0
fi

if [ ! -f /var/lib/uhu-pkg/fonts-cache ]; then
	setup_fonts_cache
fi
