#! /bin/sh
# postinst script for xetex
#
# see: dh_installdeb(1)

# set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
#

case "$1" in
    configure)

	texhash

	# ensure our entries are present in fmtutil.cnf
	fmtutil_cnf=`kpsewhich --format="web2c files" fmtutil.cnf`
	if [ "`fgrep -c xetex ${fmtutil_cnf}`" == "0" ]; then
	        cat >> ${fmtutil_cnf} <<'__EOT__'

# XeTeX formats
xetex   xetex   -       *xetex.ini
xelatex xetex   language.dat    *xelatex.ini

__EOT__
	fi

	# use system-wide setup if available
	fmtutil=`type -p fmtutil-sys` || fmtutil=`type -p fmtutil`

	# it's OK for this patch to fail (only needed on older TeX systems)
	patch -N -r /tmp/fmtutilpatch.rej -p0 `which fmtutil` <<'__EOT__' >/dev/null 2>&1 || true
*** /usr/bin/fmtutil    2006-04-12 10:57:49.000000000 +0100
--- fmtutil     2006-04-21 16:41:22.000000000 +0100
***************
*** 493,498 ****
--- 493,499 ----
    inifile=`echo $lastarg | sed 's%^\*%%'`

    case "$engine" in
+     xetex)  fmtfile="$format.fmt"; kpsefmt=tex;;
      *etex)  fmtfile="$format.efmt"; kpsefmt=tex;;
      omega)  fmtfile="$format.oft";  kpsefmt=tex;;
      eomega) fmtfile="$format.eoft"; kpsefmt=tex;;
__EOT__

	formats="xetex xelatex"
	for f in ${formats}; do
	# enable our entries if necessary (in case of pre-existing disabled ones)
	        ${fmtutil} --enablefmt ${f}
	        ${fmtutil} --byfmt ${f}
	done

	# create symlinks for the newly-built formats
	texlinks --silent

    ;;

    abort-upgrade|abort-remove|abort-deconfigure)

    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0


