#!/bin/sh
# Make links named `lcircle10' for all TFM and GF/PK files, if no
# lcircle10's already exist.

prefix=/usr/local
libdir=${prefix}/lib
texlibdir=${libdir}/tex
texfontdir=${texlibdir}/fonts

# Directories for the different font formats, in case they're not all
# stored in one place.
textfmdir=${texfontdir}
texpkdir=${texfontdir}
texgfdir=${texfontdir}

tempfile=${TMPDIR-/tmp}/circ$$
tempfile2=${TMPDIR-/tmp}/circ2$$

# Find all the fonts with names that include `circle'.
cd ${texfontdir}
find . -name '*circle*' -print > ${tempfile}

# If they have lcircle10.tfm, assume everything is there, and quit.
if grep -s lcircle10.tfm ${tempfile}
then
  echo "Found lcircle10.tfm."
  rm -f ${tempfile}
  exit 0
fi

# No TFM file for lcircle.  Make a link to circle10.tfm if it exists,
# and then make a link to the bitmap files.
if grep circle10.tfm ${tempfile} > ${tempfile2}
then
  # We found circle10.tfm.  Continue below.
  true
else
  # No circle10.tfm.  Give up.
  echo "I can't find any circle fonts in ${texfontdir}."
  echo "If it isn't installed somewhere else, you need"
  echo "to get the Metafont sources from somewhere, e.g.,"
  echo "labrea.stanford.edu:pub/tex/latex/circle10.mf,"
  echo "and run Metafont on them."
  rm -f ${tempfile}
  exit 1
fi

# We have circle10.tfm.  (If we have it more than once, take the first
# one.)  Make the link.
ln `head -1 ${tempfile2}` ${textfmdir}/lcircle10.tfm
echo "Linked to `head -1 ${tempfile2}`."

# Now make a link for the PK files, if any.
grep 'circle10.*pk' ${tempfile} > ${tempfile2}
cd ${texpkdir}
for f in `cat ${tempfile2}`
do
  ln $f `dirname $f`/l`basename $f`
  echo "Linked to $f."
done

# And finally for the GF files.
grep 'circle10.*gf' ${tempfile} > ${tempfile2}
cd ${texgfdir}
for f in `cat ${tempfile2}`
do
  ln $f `dirname $f`/l`basename $f`
  echo "Linked to $f."
done

rm -f ${tempfile} ${tempfile2}

