#!/bin/sh

VFONTMAP="/var/lib/texmf/vfontmap"
MAPDIR="/etc/texmf/vfontmap.d"
MAPFILES=`/bin/ls -1 ${MAPDIR}/*.map`
TMPDIR=`mktemp -d`
TMPFILE=`mktemp -p ${TMPDIR} vfmapXXXXXXX`

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

if [ "$VERBOSE" = "true" ]; then
    if [ -f "$VFONTMAP" ]; then
      echo -n "Regenerating $VFONTMAP... " >&2
    else
	echo -n "Generating $VFONTMAP... " >&2
    fi
fi

cat > ${TMPFILE} <<EOF
### This file is automatically generated by update-vfontmap
#
# Please do not edit this file directly.  If you want to change
# or add anything please take a look at the files in
# ${MAPDIR}, and invoke update-vfontmap.
#
###

EOF

for i in ${MAPFILES}; do
    echo "### From file: $i" >> ${TMPFILE}
    cat $i >> ${TMPFILE}
    echo "### End of file: $i" >> ${TMPFILE}
done

mv ${TMPFILE} ${VFONTMAP}
chmod 644 ${VFONTMAP}
rm -r ${TMPDIR}

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