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

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

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

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

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

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

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

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

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