#!/bin/bash

FMTUTIL="etc/texmf/web2c/fmtutil.cnf"
FMTUTILLOCAL="etc/texmf/web2c/fmtutil-local.cnf"

cp usr/share/texmf-dist/web2c/fmtutil-hdr.cnf $FMTUTIL
for file in var/lib/texmf/arch/installedpkgs/*.fmts; do
    echo >> $FMTUTIL
    echo "# $file" >> $FMTUTIL
    cat $file >> $FMTUTIL
done
if [[ -f "$FMTUTILLOCAL" ]]; then
    echo >> $FMTUTIL
    echo "# $FMTUTILLOCAL" >> $FMTUTIL
    cat "$FMTUTILLOCAL" >> $FMTUTIL
fi

/usr/bin/fmtutil-sys --all --cnffile $FMTUTIL > /dev/null