#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# http://www.is-vn.bg/hamster/jimmy-en.html
# Packager baldelario ~at~ gmail ~dot~ com
# http://www.slacky.it
# Note: run this script as ~ user

CWD=`pwd`
TMP=${TMP:-$HOME/tgz}
PKG=$TMP/package-terminus-font
rm -rf $PKG
mkdir -p $PKG

NAME=terminus-font
VERSION=4.26
ARCH=noarch
BUILD=1bj
SOURCE=http://www.is-vn.bg/hamster/$NAME-$VERSION.tar.gz

if [ $UID -eq 0 ]; then
   echo "Do not run this SlackBuild as root !"
   exit 1
fi

if [ ! -e $NAME-$VERSION.tar.gz ]; then
wget -c $SOURCE
fi

cd $TMP
rm -rf $NAME-$VERSION
tar xvfz $CWD/$NAME-$VERSION.tar.gz
cd $NAME-$VERSION

./configure --prefix=/usr --x11dir=/usr/share/fonts/misc \
            --psfdir=/usr/share/kbd/consolefonts
make || exit 1
make DESTDIR=$PKG TESTDIR= install install-12b install install-uni install-ref install-pcf fontdir 

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a README* $PKG/usr/doc/$NAME-$VERSION

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/slack-desc > $PKG/usr/doc/$NAME-$VERSION/slack-desc
cat $CWD/$NAME.SlackBuild > $PKG/usr/doc/$NAME-$VERSION/$NAME.SlackBuild

cat <<EOF > $PKG/install/doinst.sh
#!/bin/sh
# Update mkfontscale and mkfontdir:
if [ -x /usr/bin/mkfontdir ]; then
  ( cd /usr/share/fonts/misc
    mkfontscale .
    mkfontdir .
  )
fi
# Update the X font indexes:
if [ -x /usr/bin/fc-cache ]; then
  echo -n "Updating font cache... "
  /usr/bin/fc-cache -f > /dev/null
fi
EOF

cd $PKG
echo
echo "We need to run makepkg as root."
su -c "chown -R root:root . ;
requiredbuilder -v -y -s $CWD $PKG ;
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz ; 
rm -rf $TMP"
