#!/bin/sh
TEXDIR=/usr/TeX/lib/tex
LOCALDIR=/usr/TeX/lib/tex
DESTDIR=$LOCALDIR/fonts
if test "$TMPDIR" = ""
then
   TEMPDIR=/tmp/mtpk.$$
else
   TEMPDIR=$TMPDIR/mtpk.$$
fi
NAME=$1
DPI=$2
BDPI=$3
MAG=$4
MODE=localfont
GFNAME=$NAME.$DPI'gf'
PKNAME=$NAME.$DPI'pk'
TFMNAME=$NAME.'tfm'
trap "cd /; /bin/rm -rf $TEMPDIR $DESTDIR/pktmp.$$" 0 1 2 15
if test ! -d $DESTDIR
then
   mkdir $DESTDIR
fi
if test "$6" != ""
then
   DESTDIR=$DESTDIR"$6"
   if test ! -d $DESTDIR
   then
      mkdir $DESTDIR
   fi
fi
mkdir $TEMPDIR
cd $TEMPDIR
if test -r $DESTDIR/$PKNAME
then
   echo "$DESTDIR/$PKNAME already exists!"
   exit 0
fi
if test "$6" = ""
then
   if test -r $TEXDIR/fonts/$PKNAME
   then
      echo $TEXDIR/fonts/$PKNAME already exists!
      exit 0
   fi
else
   if test -r $TEXDIR/fonts/$6"$PKNAME"
   then
      echo $TEXDIR/fonts/$6"$PKNAME" already exists!
      exit 0
   fi
fi
echo "mf \"\\mode:=$MODE; mag:=$MAG; scrollmode; input $NAME\" < /dev/null"
mf "\mode:=$MODE; mag:=$MAG; scrollmode; input $NAME" < /dev/null
if test ! -r $GFNAME
then
   echo "Metafont failed for some reason on $GFNAME"
   exit 1
fi
gftopk -v ./$GFNAME ./$PKNAME
mv $PKNAME $DESTDIR/pktmp.$$
mv $TFMNAME $DESTDIR/pktmptfm.$$
cd $DESTDIR
mv pktmp.$$ $PKNAME
mv pktmptfm.$$ $TFMNAME
exit 0
