#!/bin/sh
# update-fmtutil
# License: GPL

VARD=/var/lib/texmf/web2c
TXMF=/etc/texmf
CNFDIR=${TXMF}/fmt.d

if [ "x$1" = "x-v" ]; then
  VERBOSE=true
else
  VERBOSE=false
fi

if [ -L "${VARD}/fmtutil.cnf" ]; then
    echo "Didn't run update-fmtutil as you requested!"
    exit 0
fi

if [ -f ${CNFDIR}/00tetex.cnf ] ; then
CNFFILES=`/bin/ls -1 ${CNFDIR}/*.cnf`
else
echo "update-fmtutil; Something seems wrong."
exit 1
fi

if [ "${VERBOSE}" = "true" ]; then
  if [ -f "${VARD}/fmtutil.cnf" ]; then
    echo -n "Regenerating ${VARD}/fmtutil.cnf ... " >&2
  else
    echo -n "Generating ${VARD}/fmtutil.cnf ... " >&2
  fi
fi

(echo "### This file is automatically generated by update-fmtutil"; \
echo "#"; \
echo "# Please do not edit this file directly. If you want to change or add"; \
echo "# anything please take a look at the files in ${CNFDIR}, and"; \
echo "# invoke update-fmtutil."; \
echo "#"; \
echo "###" ) > ${VARD}/fmtutil.cnf_$$

for i in ${CNFFILES}; do
    echo "### From file: $i" >> ${VARD}/fmtutil.cnf_$$
    cat $i >> ${VARD}/fmtutil.cnf_$$
    echo "### End of file: $i" >> ${VARD}/fmtutil.cnf_$$
done
#cat ${CNFFILES} > ${VARD}/fmtutil.cnf_$$
mv ${VARD}/fmtutil.cnf_$$ ${VARD}/fmtutil.cnf

if [ "$VERBOSE" = "true" ]; then
  echo "done"
fi
