#!/bin/sh
#
# Automatic installation script of Fontmap.
#
# You need Ghostscript.
#
# 2 Apr 1997
# Choi Jun Ho <junker@jazz.snu.ac.kr>
#

# when install: add Fontmap.local to gs's Fontmap.

if [ "$2" = "PRE-INSTALL" ]; then
  exit 0
fi

# POST-INSTALL
if [ ! -d ${PKG_PREFIX}/share/ghostscript ]; then
  echo "Ghostscript seems not to be installed in $PKG_PREFIX..."
  echo "No Fontmap modification is done"
  exit 0
fi

# modify Fontmap
#
# finding ghostscript directory is some of heuristics...
#
# get today
backupdate=`date "+%y%m%d%H%M"`
if [ X$TMPDIR = X ]; then
  TMPDIR=/tmp
fi

for gsdir in \
  ${PKG_PREFIX}/share/ghostscript/[0-9]*
do
  echo -n "Checking Fontmap in directory $gsdir..."
  # only when gsdir/.hlatexpsfont_installed exists
  if [ ! -e $gsdir/.hlatexpsfont_installed ]; then
    if [ -e $gsdir/Fontmap ]; then
      cp $gsdir/Fontmap $gsdir/Fontmap.backup.$backupdate
    fi
    cat $gsdir/Fontmap $PKG_PREFIX/share/fonts/HLaTeX-0.95-pfb/Fontmap.local \
        > $TMPDIR/Fontmap.new
    mv $TMPDIR/Fontmap.new $gsdir/Fontmap
    touch $gsdir/.hlatexpsfont_installed
    echo "done."
  else
    echo "already installed"
  fi
done
