#!/bin/bash
# Download and install the fonts that mozilla needs for mathml rendering.
# Good only for the fontconfig version, which needs truetype fonts.
# Ian Hutchinson Nov 2005. No guarantee. Use at your own risk.
FONTDIR=/usr/share/fonts/MathML/
IAM=`whoami`
#
if [ $# -ne 0 ] ; then
    echo "Usage: get_mathml_fonts.sh"
    echo "Download and install mathml fonts for Mozilla."
    echo "You need root privilege to do the actual installation."
    exit 2
fi
if [ $IAM. != root. ] ; then 
    echo "You don't appear to be root. Installation probably won't work."
    echo
fi
echo "Checking for font directory"
if [ -d $FONTDIR ]; then
    echo "Found $FONTDIR. This will be used for install."
else
    echo "Making directory $FONTDIR"
    mkdir $FONTDIR
fi
if [ ! -d $FONTDIR ]; then
    echo "Failed to find or create font directory. Quiting."
    exit 1
fi
#
if [ ! -d Mathematica_Fonts ] ; then mkdir Mathematica_Fonts; fi
cd Mathematica_Fonts
if [ -f MathFonts_TrueType.exe ] ; then
    echo "Already have the Mathematica Font package."
else
    wget http://support.wolfram.com/mathematica/systems/windows/general/files/MathFonts_TrueType_41.exe
fi
if [ -f MathFonts_TrueType_41.exe ]; then
    unzip MathFonts_TrueType_41.exe
    echo "Installing Mathematica fonts in $FONTDIR"
    cp *.ttf $FONTDIR
else
    echo "Failed to get MathFonts_TrueType_41.exe. Can't install."
fi

# End of mathematica installation
cd ..

if [ -f texcm-ttf.zip ] ; then
    echo "Already have the Computer Modern Font package."
else
    wget http://www.mozilla.org/projects/mathml/fonts/bakoma/texcm-ttf.zip
fi
if [ -f texcm-ttf.zip ]; then
    unzip texcm-ttf.zip
    echo "Installing Computer Modern Fonts in $FONTDIR"
    cp texcm-ttf/*.ttf $FONTDIR
else
    echo "Failed to get texcm-ttf.zip. Can't install."
fi
# End of MathType installation
fc-cache $FONTDIR
echo
# Check for success.
if [ -f $FONTDIR/math1___.ttf ] ; then 
    echo "Fonts installed. Now restart Mozilla. It must be an xft-enabled build."
else
    echo "Font installation does not appear to have been successful."
    echo "Unless run with root privilege, the font files won't be installed."
fi
