#!/bin/sh
#
# install-x11-fonts
# $Id: install-x11-fonts,v 1.1 2001/06/06 13:57:24 bdenney Exp $
#
# This is designed help people to get the Bochs fonts installed on their 
# system.
#

X11_FONT_PATH_CHOICES="/usr/lib/X11/fonts /usr/openwin/lib/X11/fonts"
FONTS=vga.pcf
FONT_SOURCE_PATH_CHOICES="font /usr/local/bochs/latest"

die () {
cat <<EOF

install-x11-fonts failed.
To try it again, su root and run $0.
EOF
exit 1
}

echo -n "Looking for fonts to install... "
found=0
for sourcepath in $FONT_SOURCE_PATH_CHOICES; do
  #echo -n "  $sourcepath/ ... "
  if test -f $sourcepath/vga.pcf; then
    echo $sourcepath/
    found=1
    break
  fi
done

if test ! $found = 1; then 
  echo FAILE
  echo "ERROR: I could not find the Bochs fonts to install.  I looked in:"
  echo "  $FONT_SOURCE_PATH_CHOICES"
  die
fi

FONT_SOURCE_PATH=$sourcepath

echo -n "Looking for X11 Font Path... "
found=0
for fontpath in $X11_FONT_PATH_CHOICES; do
  if test -d $fontpath -a -d $fontpath/misc; then
    echo $fontpath
    found=1
    break
  fi
done

if test ! $found = 1; then
  echo FAILED
  cat <<EOF
ERROR: I could not find your X11 Font Path, so I can't guarantee that the
Bochs VGA Font is installed correctly.  Please figure out where the X11 fonts
are found on your system and post a bug report about the RPM Post-Install 
Script.  I already looked in:
  $X11_FONT_PATH_CHOICES
EOF
  die
fi

added_font=0
for f in $FONTS; do
  echo -n "Installing $f... "
  if test ! -f $FONT_SOURCE_PATH/$f; then
    echo FAILED
    echo "ERROR: $f is on the list of fonts to install, and it wasn't found "
    echo "       in $FONT_SOURCE_PATH"
    die
  elif test ! -f $fontpath/misc/$f; then
    echo ok
    added_font=1
    cp $FONT_SOURCE_PATH/$f  $fontpath/misc
    if test ! $? = 0; then
      echo ERROR: Copy failed; die
    fi
  else
    echo "ok    (it was already there)"
  fi
done

echo Running mkfontdir...
mkfontdir $fontpath
ret=$?
if test $ret != 0; then
  echo ERROR: mkfontdir returned $ret
  die
fi

if test $added_font = 1; then
cat <<EOF
NOTE: If you have trouble loading X fonts in this session, you might need
to type "xset fp rehash."
EOF
fi

echo Done installing Bochs fonts for X11.
