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

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

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

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

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

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

(echo "%%% This file is automatically generated by update-texmf"; \
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-texmf."; \
echo "%"; \
echo "%%%" ) > ${VARD}/texmf.cnf_$$

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

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