#!/bin/bash
#
# installfont [options]
#
# installs a LaTeX font family (Postscript Type1, Truetype, Opentype)
# (font series from light to ultra bold + (faked) small caps + faked 
# slanted, but no expert fonts) for using them with LaTeX (MiKTeX) 
# The script tries to rename the fonts automatically (optional).
# Otherwise the *.afm and *.pfb files must be named in Karl Berry scheme
# (e.g. 5bbr8a.pfb)
# (tested with MiKTeX 2.8) v1.6a (03.11.2010)
# (C) Josef Kleber 2009-2012  License: LPPL
#
VERSION="v1.6b (2012/01/25)"
#
FONTFAMILY="5bb"
FONTNAME="Softmaker Barbedor"
FONTCOMMAND="FFBarbedor"
FONTSCALEPREFIX="Sbb"
FONTTYPE="pst1"
PACKAGENAME="barbedor"
PACKAGEDATE="2010/03/05"
PACKAGEVERSION="v1.0"
MAPFILENAME=""
OFN="false"
LOCALTEXMF=$(cygpath -u "C:\LocalTexMF")
FONTSUBDIR="MyFonts/Barbedor"
# Font encoding default: 8a (AdobeStandardEncoding)
FONTENCODING="8a"
# Font cut default: r (regular) don't change!
FONTCUT="r"
#
# Set the --admin switch for MiKTeX 2.8+
#ADMIN="--admin"
ADMIN=""
#
OTFFONTFEATURES="-fkern -fliga"
UNINSTALL="false"
INSTALLAS="rmdefault"
SMFFSTY="%"
LOG="false"
#
function printHelp()
{
  echo -e \
          "  `basename $0` [options]\n"\
          " installs a font family for using it with LaTeX\n\n"\
          " Options:\n\n"\
          " -f, --fontfamily  Name of the LaTeX font family, e.g. ptm (Adobe Times)\n\n"\
          " -n, --fontname  Font name, e.g. Adobe Times\n\n"\
          " -c, --fontcommand  Name of the command that will switch to the font\n\n"\
          " -P, --fontscaleprefix  prefix of the scale macro, which should be different\n"\
          "                        for each font (no digits allowed)\n\n"\
          " -t, --fonttype  Font type (pst1(default)|ttf|otf)\n\n"\
          " -p, --packagename  Name of the LaTeX package\n\n"\
          " -d, --packagedate  Date of the LaTeX package\n\n"\
          " -v, --packageversion  Version of the LaTeX package\n\n"\
          " -l, --localtexmf  root of your local TeX tree, e.g. /cygdrive/c/LocalTeXMF\n\n"\
          " -m, --mapfilename file name of the map file\n\n"\
          " -O. --origfontname  use original font names instead of Karl Berry names\n\n"\
          " -s, --fontsubdir  location where the fonts and support files should be\n"\
          "                   installed, e.g. MyFonts/AdobeTimes\n\n"\
          " -e, --fontencoding   encoding of the font\n"\
          "                      (default: 8a (AdobeStandardEncoding))\n\n"\
          " -o, --otffontfeatures  choosing Opentype font features\n"\
          "                        (default: -fkern -fliga)\n\n"\
          " -u, --uninstall  will uninstall the font family. You must specify\n"\
          "                  --localtexmf and --fontsubdir\n\n"\
          " -R, --rmdefault  installs font family as roman (serif) font family (default)\n\n"\
          " -S, --sfdefault  installs font family as sans serif font family\n\n"\
          " -T, --ttdefault  installs font family as typewriter font family\n\n"\
          " -a, --admin  set administrative mode (MiKTeX v2.8+)\n\n"\
          " -V, --version  will print the version number of `basename $0`\n\n"\
          " -L, --log  will write the terminal output of the main programms into the\n"\
          "            LOG file instead of the screen\n\n"\
          " -h, --help  will print this help statement\n\n"\
          " See http://latex.josef-kleber.de/index.htm or\n"\
          "     http://latex.josef-kleber.de/en_index.htm\n"\
          " for more information"
  exit 0;
}
function printVersion()
{
  echo "This is version $VERSION of `basename $0`"
  exit 0;
}
#
if [ $# -eq 0 ]
then
  echo -e "`basename $0`: Could not find command line arguments.\nUse the '--help' option for explanation."
  echo -e "Continue with default script variables? (y/n)"
  read ANSWER
  if [ $ANSWER = "n" -o $ANSWER = "N" ]
  then
    exit 1
  fi
fi
#
LONGOPTS="fontfamily:,fontname:,fontcommand:,fontscaleprefix:,fonttype:,packagename:,packagedate:,packageversion:,mapfilename:,origfilename,localtexmf:,fontsubdir:,fontencoding:,otffontfeatures:,uninstall,rmdefault,sfdefault,ttdefault,log,version,help,admin"
SHORTOPTS="f:n:c:P:t:p:d:v:m:Ol:s:e:o:uRSTVLha"
ARGS=$(getopt -l "$LONGOPTS" "$SHORTOPTS" "$@")
if [ $? -ne 0 ]
then
  echo -e "`basename $0`: Could not process command line arguments.\nUse the '--help' option for explanation."
  exit 1
fi
#
eval set -- "$ARGS"
#
while [ $# -gt 0 ]; do
  ARG=$1
  case "$ARG" in
      --help|-h)            shift; printHelp;;
      --admin|-a)           shift; ADMIN="--admin";;
      --version|-V)         shift; printVersion;;
      --rmdefault|-R)       shift; INSTALLAS="rmdefault";;
      --sfdefault|-S)       shift; INSTALLAS="sfdefault";;
      --ttdefault|-T)       shift; INSTALLAS="ttdefault";;
      --uninstall|-u)       shift; UNINSTALL="true";;
      --log|-L)             shift; LOG="true";;
      --fontfamily|-f)      shift; FONTFAMILY="$1"; shift;;
      --fontname|-n)        shift; FONTNAME="$1"; shift;;
      --fontcommand|-c)     shift; FONTCOMMAND="$1"; shift;;
      --fontscaleprefix|-P) shift; FONTSCALEPREFIX="$1"; shift;;
      --fonttype|-t)        shift; FONTTYPE="$1"; shift;;
      --packagename|-p)     shift; PACKAGENAME="$1"; shift;;
      --packagedate|-d)     shift; PACKAGEDATE="$1"; shift;;
      --packageversion|-v)  shift; PACKAGEVERSION="$1"; shift;;
      --mapfilename|-m)     shift; MAPFILENAME="$1"; shift;;
      --origfontname|-O)    shift; OFN="true";;
      --localtexmf|-l)      shift; LOCALTEXMF="$1"; shift;;
      --fontsubdir|-s)      shift; FONTSUBDIR="$1"; shift;;
      --fontencoding|-e)    shift; FONTENCODING="$1"; shift;;
      --otffontfeatures|-o) shift; FONTFAMILY="$1"; shift;;
      --)                   shift; break;;
      *)                    break;;
  esac
done
#
rm LOG 2>>/dev/null;
#
if [ -z $MAPFILENAME ]
then
  MAPFILENAME=$FONTFAMILY
fi
#
typeset -i STEP=0
#
if [ $UNINSTALL = "true" ]
then
  DIR="${LOCALTEXMF}/fonts/tfm/${FONTSUBDIR}/"
  echo -e "$\n\n$DIR"
  DIR="${LOCALTEXMF}/fonts/vf/${FONTSUBDIR}/"
  echo $DIR
  DIR="${LOCALTEXMF}/fonts/type1/${FONTSUBDIR}/"
  echo $DIR
  DIR="${LOCALTEXMF}/fonts/map/dvips/${FONTSUBDIR}/"
  echo $DIR
  DIR="${LOCALTEXMF}/tex/latex/${FONTSUBDIR}/"
  echo $DIR
  echo -e "\n\nDo you want to delete these directories? (y/n)"
  read ANSWER
  if [ $ANSWER = "y" -o $ANSWER = "Y" ]
  then
    DIR="${LOCALTEXMF}/fonts/tfm/${FONTSUBDIR}/"
    rm -f -r $DIR
    DIR="${LOCALTEXMF}/fonts/vf/${FONTSUBDIR}/"
    rm -f -r $DIR
    DIR="${LOCALTEXMF}/fonts/type1/${FONTSUBDIR}/"
    rm -f -r $DIR
    DIR="${LOCALTEXMF}/fonts/map/dvips/${FONTSUBDIR}/"
    rm -f -r $DIR
    DIR="${LOCALTEXMF}/tex/latex/${FONTSUBDIR}/"
    rm -f -r $DIR
    exit 0
  else
    exit 1
  fi
fi
#
if [ $FONTTYPE = "ttf" ]
then
  ((STEP++))
  echo -e "\n\n$STEP) Convert font(s) to Postscript Type1\n\n"
  for file in *.TTF;
  do
    mv "$file" "${file%TTF}ttf" 2>>/dev/null;
  done
  for file in *.ttf; 
  do
    ttf2pt1 -a -b -l adobestd "$file";
  done
fi
#
if [ $FONTTYPE = "otf" ]
then
  ((STEP++))
  echo -e "\n\n$STEP) Convert font(s) to Postscript Type1\n\n"
  for file in *.OTF;
  do
    mv "$file" "${file%OTF}otf" 2>>/dev/null;
  done
  for file in *.otf; 
  do
    otftotfm $OTFFONTFEATURES -e - "$file" 555;
  done
  for file in *.pfb; 
  do
    pf2afm "$file";
  done
  rm *.tfm
  rm *.enc
fi
#
echo -e "\n\nTry to rename the font(s) automatically? (y/n)"
read ANSWER
if [ $ANSWER = "y" -o $ANSWER = "Y" ]
then
  ((STEP++))
  echo -e "\n\n$STEP) Renaming fonts\n\n"
  mkdir -p Backup
  cp *.afm *.AFM ./Backup 2>>/dev/null
  cp *.pfb *.PFB ./Backup 2>>/dev/null
  for file in *.AFM;
  do
    mv "$file" "${file%AFM}afm" 2>>/dev/null;
  done
  for file in *.PFB;
  do
    mv "$file" "${file%PFB}pfb" 2>>/dev/null;
  done
  FONTNUMBER=$(ls -al *.pfb 2>>/dev/null | wc -l)
  if [ $FONTNUMBER -le 1 ]
  then
    if [ $FONTNUMBER -eq 0 ]
    then
      echo "No font(s) to rename!"
      exit 1
    else
      for file in *.afm; 
      do
        mv "$file" ${FONTFAMILY}${FONTCUT}${FONTENCODING}.afm;
      done
      for file in *.pfb; 
      do
        mv "$file" ${FONTFAMILY}${FONTCUT}${FONTENCODING}.pfb;
        echo -e "s/<${FONTFAMILY}${FONTCUT}${FONTENCODING}/<${file%.pfb}/" >>map.sed;
      done
    fi
  else
    mkdir -p Rename
    # rename small caps font(s)
    FILES=$(grep -e "Smc" -e "Caps" -e "SCOsF" *.afm | cut -d':' -f1 | uniq)
    for file in $FILES
    do
      FONTCUT="rc"
      FWEIGHT=$(grep -e "Light" "$file" | wc -l)
      if [ $FWEIGHT -gt 0 ]
      then
        FONTCUT="lc"
      else
        FWEIGHT=$(grep -e "Semibold" -e "SemiBold" "$file" | wc -l)
        if [ $FWEIGHT -gt 0 ]
        then
          FONTCUT="sc"
        else
          FWEIGHT=$(grep -e "Demi" -e "Demibold" -e "DemiBold" "$file" | wc -l)
          if [ $FWEIGHT -gt 0 ]
          then
            FONTCUT="dc"
          else
            FWEIGHT=$(grep -e "Extrabold" -e "ExtraBold" "$file" | wc -l)
            if [ $FWEIGHT -gt 0 ]
            then
              FONTCUT="xc"
            else 
              FWEIGHT=$(grep -e "Heavy" -e "Ultrabold" -e "UltraBold" "$file" | wc -l)
              if [ $FWEIGHT -gt 0 ]
              then
                FONTCUT="uc"
              else
                FWEIGHT=$(grep -e "Bold" -e "bold" "$file" | wc -l)
                if [ $FWEIGHT -gt 0 ]
                then
                  FONTCUT="bc"
                fi
              fi
            fi
          fi
        fi
      fi
      mv "$file" ./Rename/${FONTFAMILY}${FONTCUT}${FONTENCODING}.afm;
      mv "${file%afm}pfb" ./Rename/${FONTFAMILY}${FONTCUT}${FONTENCODING}.pfb;
      echo -e "s/<${FONTFAMILY}${FONTCUT}${FONTENCODING}/<${file%.afm}/" >>map.sed;
    done
    # rename the light font(s)
    FILES=$(grep -e "Light" *.afm | cut -d':' -f1 | uniq)
    for file in $FILES
    do
      ITALICANGLE=$(grep -e "ItalicAngle" "$file" | tr ' ' '+' | cut -d'+' -f2 | cut -d'.' -f1)
      if [ $ITALICANGLE -lt 0 -o $ITALICANGLE -gt 0 ]
      then
        FONTCUT="li"
      else
        FONTCUT="l"
      fi
      mv "$file" ./Rename/${FONTFAMILY}${FONTCUT}${FONTENCODING}.afm;
      mv "${file%afm}pfb" ./Rename/${FONTFAMILY}${FONTCUT}${FONTENCODING}.pfb;
      echo -e "s/<${FONTFAMILY}${FONTCUT}${FONTENCODING}/<${file%.afm}/" >>map.sed;
	  SMFFSTY="\RequirePackage{softmakerfreefont}%"
    done
    # rename the semi(bold) font
    FILES=$(grep -e "Semibold" -e "SemiBold" *.afm | cut -d':' -f1 | uniq)
    for file in $FILES
    do
      ITALICANGLE=$(grep -e "ItalicAngle" "$file" | tr ' ' '+' | cut -d'+' -f2 | cut -d'.' -f1)
      if [ $ITALICANGLE -lt 0 -o $ITALICANGLE -gt 0 ]
      then
        FONTCUT="si"
      else
        FONTCUT="s"
      fi
      mv "$file" ./Rename/${FONTFAMILY}${FONTCUT}${FONTENCODING}.afm;
      mv "${file%afm}pfb" ./Rename/${FONTFAMILY}${FONTCUT}${FONTENCODING}.pfb;
      echo -e "s/<${FONTFAMILY}${FONTCUT}${FONTENCODING}/<${file%.afm}/" >>map.sed;
	  SMFFSTY="\RequirePackage{softmakerfreefont}%"
    done
    # rename the demi(bold) font
    FILES=$(grep -e "FontName" -e "FullName" *.afm | grep -e "Demi" -e "Demibold" -e "DemiBold" | cut -d':' -f1 | uniq)
    for file in $FILES
    do
      ITALICANGLE=$(grep -e "ItalicAngle" "$file" | tr ' ' '+' | cut -d'+' -f2 | cut -d'.' -f1)
      if [ $ITALICANGLE -lt 0 -o $ITALICANGLE -gt 0 ]
      then
        FONTCUT="di"
      else
        FONTCUT="d"
      fi
      mv "$file" ./Rename/${FONTFAMILY}${FONTCUT}${FONTENCODING}.afm;
      mv "${file%afm}pfb" ./Rename/${FONTFAMILY}${FONTCUT}${FONTENCODING}.pfb;
      echo -e "s/<${FONTFAMILY}${FONTCUT}${FONTENCODING}/<${file%.afm}/" >>map.sed;
	  SMFFSTY="\RequirePackage{softmakerfreefont}%"
    done
    # rename the extra bold font
    FILES=$(grep -e "Extrabold" -e "ExtraBold" *.afm | cut -d':' -f1 | uniq)
    for file in $FILES
    do
      ITALICANGLE=$(grep -e "ItalicAngle" "$file" | tr ' ' '+' | cut -d'+' -f2 | cut -d'.' -f1)
      if [ $ITALICANGLE -lt 0 -o $ITALICANGLE -gt 0 ]
      then
        FONTCUT="xi"
      else
        FONTCUT="x"
      fi
      mv "$file" ./Rename/${FONTFAMILY}${FONTCUT}${FONTENCODING}.afm;
      mv "${file%afm}pfb" ./Rename/${FONTFAMILY}${FONTCUT}${FONTENCODING}.pfb;
      echo -e "s/<${FONTFAMILY}${FONTCUT}${FONTENCODING}/<${file%.afm}/" >>map.sed;
    done
    # rename the ultra bold/heavy font
    FILES=$(grep -e "Heavy" -e "Ultrabold" -e "UltraBold" *.afm | cut -d':' -f1 | uniq)
    for file in $FILES
    do
      ITALICANGLE=$(grep -e "ItalicAngle" "$file" | tr ' ' '+' | cut -d'+' -f2 | cut -d'.' -f1)
      if [ $ITALICANGLE -lt 0 -o $ITALICANGLE -gt 0 ]
      then
        FONTCUT="ui"
      else
        FONTCUT="u"
      fi
      mv "$file" ./Rename/${FONTFAMILY}${FONTCUT}${FONTENCODING}.afm;
      mv "${file%afm}pfb" ./Rename/${FONTFAMILY}${FONTCUT}${FONTENCODING}.pfb;
      echo -e "s/<${FONTFAMILY}${FONTCUT}${FONTENCODING}/<${file%.afm}/" >>map.sed;
	  SMFFSTY="\RequirePackage{softmakerfreefont}%"
    done
    # rename the bold font
    FILES=$(grep -e "Bold" -e "bold" *.afm | cut -d':' -f1 | uniq)
    for file in $FILES
    do
      ITALICANGLE=$(grep -e "ItalicAngle" "$file" | tr ' ' '+' | cut -d'+' -f2 | cut -d'.' -f1)
      if [ $ITALICANGLE -lt 0 -o $ITALICANGLE -gt 0 ]
      then
        FONTCUT="bi"
      else
        FONTCUT="b"
      fi
      mv "$file" ./Rename/${FONTFAMILY}${FONTCUT}${FONTENCODING}.afm;
      mv "${file%afm}pfb" ./Rename/${FONTFAMILY}${FONTCUT}${FONTENCODING}.pfb;
      echo -e "s/<${FONTFAMILY}${FONTCUT}${FONTENCODING}/<${file%.afm}/" >>map.sed;
    done
    # rename the regular font
    FILES=$(grep -e "Regular" -e "Medium" -e "Book" --exclude=installfont * | grep -e ".afm" | cut -d':' -f1 | uniq)
    for file in $FILES
    do
      ITALICANGLE=$(grep -e "ItalicAngle" "$file" | tr ' ' '+' | cut -d'+' -f2 | cut -d'.' -f1)
      if [ $ITALICANGLE -lt 0 -o $ITALICANGLE -gt 0 ]
      then
        FONTCUT="ri"
      else
        FONTCUT="r"
      fi
      mv "$file" ./Rename/${FONTFAMILY}${FONTCUT}${FONTENCODING}.afm;
      mv "${file%afm}pfb" ./Rename/${FONTFAMILY}${FONTCUT}${FONTENCODING}.pfb;
      echo -e "s/<${FONTFAMILY}${FONTCUT}${FONTENCODING}/<${file%.afm}/" >>map.sed;
    done
    mv ./Rename/* .
    rmdir ./Rename
  fi
  ls -al *.pfb *.afm
  echo -e "\n\nPlease check the font name(s). Continue? (y/n)"
  read ANSWER
  if [ $ANSWER = "n" -o $ANSWER = "N" ]
  then
    rm *.afm
    rm *.pfb
    rm *.sed
    mv ./Backup/* .
    rmdir ./Backup
    exit 1
  fi
fi
#
((STEP++))
echo -e "\n\n$STEP) Creating metrics and virtual fonts\n\n"
cat >${FONTFAMILY}-drv.tex <<EOF
\input fontinst.sty
\needsfontinstversion{1.926}
\recordtransforms{${FONTFAMILY}-rec.tex}
\latinfamily{${FONTFAMILY}}{}
\endrecordtransforms
\bye
EOF
if [ $LOG = "true" ]
then
  tex ${FONTFAMILY}-drv.tex >>LOG 2>&1
else
  tex ${FONTFAMILY}-drv.tex
fi
#
((STEP++))
echo -e "\n\n$STEP) Compiling metrics and virtual fonts\n\n"
for file in *.pl; 
do  
  if [ $LOG = "true" ]
  then
    pltotf $file ${file%pl}tfm >>LOG 2>&1
  else
    pltotf $file ${file%pl}tfm
  fi
done
for file in *.vpl; 
do  
  if [ $LOG = "true" ]
  then
    vptovf $file ${file%vpl}vf ${file%vpl}tfm >>LOG 2>&1
  else
    vptovf $file ${file%vpl}vf ${file%vpl}tfm
  fi
done
#
((STEP++))
echo -e "\n\n$STEP) Creating the map file\n\n"
cat >${FONTFAMILY}-map.tex <<EOF
\input finstmsc.sty
\resetstr{PSfontsuffix}{.pfb}
\adddriver{dvips}{${FONTFAMILY}.map}
\input ${FONTFAMILY}-rec.tex
\donedrivers
\bye
EOF
if [ $LOG = "true" ]
then
  tex ${FONTFAMILY}-map.tex >>LOG 2>&1
else
  tex ${FONTFAMILY}-map.tex
fi
if [ $OFN = "true" ]
then
  sed -f map.sed ${FONTFAMILY}.map >${MAPFILENAME}.map
  unix2dos ${MAPFILENAME}.map 2>>/dev/null;
  rm ${FONTFAMILY}.map
  UMAP="${MAPFILENAME}"
else
  UMAP="${FONTFAMILY}"
fi
#
((STEP++))
echo -e "\n\n$STEP) Creating the style file"
cat >${PACKAGENAME}.sty <<EOF
\NeedsTeXFormat{LaTeX2e}%
\ProvidesPackage{$PACKAGENAME}[$PACKAGEDATE $PACKAGEVERSION $FONTNAME]%
\RequirePackage{textcomp}%
\RequirePackage{xkeyval}%
\define@key{${PACKAGENAME}.sty}{scaled}[1.0]%
{%
  \def\\${FONTSCALEPREFIX}@scale{#1}%
}%
\define@key{${PACKAGENAME}.sty}{leading}[1.0]%
{%
  \linespread{#1}%
}%
\ExecuteOptionsX{scaled}%
\ProcessOptionsX\relax%
\renewcommand*{\\${INSTALLAS}}{$FONTFAMILY}%
\newcommand\\${FONTCOMMAND}{\fontfamily{$FONTFAMILY}\fontseries{m}\fontshape{n}\selectfont}%
\endinput%
EOF
unix2dos ${PACKAGENAME}.sty 2>>/dev/null;
#
((STEP++))
echo -e "\n\n$STEP) Insert scale factor into the fd files"
cat >installfont.sed <<EOF
9 i\\
\\n\\\\expandafter\\\\ifx\\\\csname ${FONTSCALEPREFIX}@scale\\\\endcsname\\\\relax\\n  \\\\let\\\\${FONTSCALEPREFIX}@@scale\\\\@empty\\n\\\\else\\n  \\\\edef\\\\${FONTSCALEPREFIX}@@scale{s*[\\\\csname ${FONTSCALEPREFIX}@scale\\\\endcsname]}\\n\\\\fi\\n
s/<-> /<-> \\\\${FONTSCALEPREFIX}@@scale /
EOF
#
for file in *.fd;
do
  mv $file ${file%fd}fdb;
  sed -f installfont.sed ${file%fd}fdb >$file;
  unix2dos $file 2>>/dev/null;
done
#
((STEP++))
echo -e "\n\n$STEP) Installing font(s) and support files"
DIR="${LOCALTEXMF}/fonts/tfm/${FONTSUBDIR}/"
if [ ! -d $DIR ]
then
  mkdir -p $DIR
fi
mv *.tfm $DIR
DIR="${LOCALTEXMF}/fonts/vf/${FONTSUBDIR}/"
if [ ! -d $DIR ]
then
  mkdir -p $DIR
fi
mv *.vf $DIR
DIR="${LOCALTEXMF}/fonts/type1/${FONTSUBDIR}/"
if [ $OFN = "true" ]
then
  cd Backup
  if [ ! -d $DIR ]
  then
    mkdir -p $DIR
  fi
  cp *.pfb $DIR
  cd ..
else
  if [ ! -d $DIR ]
  then
    mkdir -p $DIR
  fi
  cp *.pfb $DIR
fi
DIR="${LOCALTEXMF}/fonts/map/dvips/${FONTSUBDIR}/"
if [ ! -d $DIR ]
then
  mkdir -p $DIR
fi
mv *.map $DIR
DIR="${LOCALTEXMF}/tex/latex/${FONTSUBDIR}/"
if [ ! -d $DIR ]
then
  mkdir -p $DIR
fi
mv *.fd $DIR
DIR="${LOCALTEXMF}/tex/latex/${FONTSUBDIR}/"
if [ ! -d $DIR ]
then
  mkdir -p $DIR
fi
mv *.sty $DIR
#
((STEP++))
echo -e "\n\n$STEP) Update FileNameDataBase"
initexmf $ADMIN -u
((STEP++))
echo -e "\n\n$STEP) Include the map file"
echo -e "\n\n"
echo "Add the line 'Map ${UMAP}.map' to the file in the opening editor."
echo "Save the file, close the editor and press RETURN to continue." 
initexmf $ADMIN --edit-config-file updmap
read ANSWER
((STEP++))
echo -e "\n\n$STEP) Update map configuration"
initexmf $ADMIN --mkmaps
rm *.mtx
rm *.pl
rm *.vpl
rm *.log
rm *.tex
rm *.fdb
rm *.sed
if [ -d Backup ]
then
  rm *.afm
  rm *.pfb
  mv ./Backup/* .
  rmdir ./Backup
fi
echo -e "\n\nThe font(s) should be installed now!"
exit 0