#!/bin/sh
# yep, it's a grif script, nov 2k3
# requires ttmkfdir
#
# adding truetype fonts is hard
# until you know how to do it
# this script makes it extra slick
#
# ttf knowledge taken from 
# http://www.paulandlesley.org/linux/xfree4_tt.html
#

if [ ! -x /usr/bin/ttmkfdir ]; then
   echo "You need ttmkfdir, apt-get install it immediately!"
   exit 1
fi

if [ -z $1 ]; then
   echo "You must specify a directory to work in."
   exit 1
   elif [ ! -d $1 ]; then
      echo "You must specify a DIRECTORY to work in."
      exit 1
fi

 cd $1
 _DIR=`pwd`
 if [ -f /etc/X11/XF86Config-4 ]; then
  XC=/etc/X11/XF86Config-4
  XFC=`grep $_DIR $XC | sed 's/\t//g' | sed 's/\ //g' `
   else XC=/etc/X11/XF86Config
   XFC=`grep $_DIR $XC | sed 's/\t//g' | sed 's/\ //g' `
 fi
 ttmkfdir -o fonts.scale
 head -1 fonts.scale > fonts.dir
 tail +2 fonts.scale | tac >> fonts.dir
 cp fonts.dir fonts.scale
 if [ -z $XFC ]; then
  echo "Now add to your $XC, with the other fontpaths:"
  echo "FontPath \"$_DIR\""
  xset fp+ $_DIR
  echo "No need to restart X however, you can use the fonts now!"
   else xset fp rehash
   echo "No need to edit $XC. The new fonts are activated!"
 fi
