#!/bin/sh
#
#   This script file makes a new TeX TFM font, because one wasn't
#   found.  Usage:
#
#   MakeTFM name [mode]
#
#   `name' is the name of the font, such as `cmr10'.
#   `mode', if supplied, is the mode to use.
#
#   Note that this file must execute Metafont, and place the result 
#   in the correct location.
#
# Customised to the debian distribution of TeX by
# Nils Rennebarth <nils@hertha.exp-math.uni-essen.de>
#
# This script must echo the name of the generated PK file (and nothing
# else) to standard output. Yes, this is different from the original dvips.

echo "Running MakeTeXPK $*" 1>&2
 
# TEMPDIR needs to be unique for each process because of the possibility
# of simultaneous processes running this script.
DESTDIR=/var/spool/texmf/fonts/tfm
if test "$TMPDIR" = ""
then
   TEMPDIR=/tmp/mttfm.$$
else
   TEMPDIR=$TMPDIR/mttfm.$$
fi

NAME=`echo $1 | sed 's/\.tfm$//'`
MODE=$2

umask 0

if test "$MODE" = ""
then MODE=nullmode
fi

TFMNAME=$NAME.'tfm'

# Clean up on normal or abnormal exit
trap "cd /; rm -rf $TEMPDIR $DESTDIR/tfmtmp.$$" 0 1 2 15

if test ! -d $DESTDIR
then
   mkdir $DESTDIR
fi

mkdir $TEMPDIR
cd $TEMPDIR

if test -r $DESTDIR/$TFMNAME
then
   echo "$DESTDIR/$TFMNAME already exists!" 1>&2
   exit 0
fi

echo mf "\mode:=$MODE; mag:=1; scrollmode; input $NAME" \\\</dev/null 1>&2
mf "\mode:=$MODE; mag:=1; scrollmode; input $NAME" </dev/null 1>&2
if test ! -r $TFMNAME
then
   echo "Metafont failed for some reason on $TFMNAME" 1>&2
   exit 1
fi

# Install the TFM file carefully, since others may be doing the same
# as us simultaneously.

chmod 644 $TFMNAME
mv $TFMNAME $DESTDIR/tfmtmp.$$
cd $DESTDIR
mv tfmtmp.$$ $TFMNAME
echo $DESTDIR/$TFMNAME
