#!/bin/sh
#
#   This script file makes a new TeX PK font, because one wasn't
#   found.  Parameters are:
#
#   name dpi bdpi magnification [mode]
#
#   `name' is the name of the font, such as `cmr10'.  `dpi' is
#   the resolution the font is needed at.  `bdpi' is the base
#   resolution, useful for figuring out the mode to make the font
#   in.  `magnification' is a string to pass to MF as the
#   magnification.  `mode', if supplied, is the mode to use.
#
#   Note that this file must execute Metafont, and then gftopk,
#   and place the result in the correct location for the PostScript
#   driver to find it subsequently.  If this doesn't work, it will
#   be evident because MF will be invoked over and over again.
#
#   Of course, it needs to be set up for your site.
#

DESTDIR=/usr/tex/lib/tex/pk
TFMDIR=/usr/tex/lib/tex/tfm
TEMPDIR=/usr/tmp

NAME=$1
DPI=$2
BDPI=$3
MAG=$4
MODE=$5
FINALNAME=$DESTDIR/$NAME.$DPI'pk'

cd $TEMPDIR

if test -r $FINALNAME
then
   echo "$FINALNAME already exists!"
   exit 1
fi

if test ! -w $DESTDIR
then
   mkdir $DESTDIR
   if test ! -w $DESTDIR
   then
      echo "Can't write to $DESTDIR"
      exit 1
   fi
fi

if test "$MODE" = ""
then
   if test $BDPI = 360
   then
      MODE=bj
   else
      echo "I don't know the mode for $BDPI"
      echo "Have your system admin update MakeTeXPK"
      exit 1
   fi
fi

trap "rm -f $NAME.log $NAME.$DPI'pk' $NAME.$DPI'gf' $NAME.tfm" 0 1 2 3 15

/usr/TeX/bin/mf "\mode:=$MODE; mag:=$MAG; scrollmode; input $NAME" end
if test ! -r $NAME.$DPI'gf'
then
   echo "Metafont failed for some reason on $NAME.$DPI"gf
   exit 1
fi
/usr/TeX/bin/gftopk $NAME.$DPI'gf' $NAME.$DPI'pk'
chmod 666 $NAME.$DPI'pk' $NAME.tfm
mv $NAME.$DPI'pk' $DESTDIR
mv $NAME.tfm $TFMDIR
exit 0
