#!/bin/sh
#
# tetex-algorithm2e.SlackBuild
# 2013-03-27
#
# Algorithm2e is an environment for writing algorithms in LaTeX2e.
# An algorithm is defined as a floating object like figures.
# It provides macros that allow you to create different sorts of key
# words, thus a set of predefined key words is given. You can also
# change the typography of the keywords.

PRGNAM=tetex-algorithm2e
VERSION=5.0
ARCH="noarch"
BUILD=${BUILD:-1}
TAG=${TAG:-scr}

HOMEPAGE="http://www.ctan.org/tex-archive/macros/latex/contrib/algorithm2e"
SOURCE="algorithm2e.zip"
DOWNLOAD="http://mirror.ctan.org/macros/latex/contrib/${SOURCE}"
MD5SUM="aaf98ccb76386248301cf93a840ecf74"

REQUIRES="tetex"

MAINTAINER="Gernot Walzl"
EMAIL="gernot.walzl@gmx.at"

DESC="Algorithm2e

is an environment for writing algorithms in LaTeX2e.
An algorithm is defined as a floating object like figures.
It provides macros that allow you to create different sorts of key
words, thus a set of predefined key words is given. You can also
change the typography of the keywords.

${HOMEPAGE}"

# EOF info


# set initial variables
CWD=$(pwd)
TMP=${TMP:-/tmp}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

# exit on error
set -e

# download the source if needed
if [ ! -f $CWD/$SOURCE ]; then
  wget -O $CWD/$SOURCE $DOWNLOAD || exit 1
fi

# check for correct source file
if [ "$(md5sum $CWD/$SOURCE | cut -f 1 -d ' ')" != "$MD5SUM" ]; then
  exit 1
fi

# extract the application source
cd $TMP || exit 1
unzip $CWD/$SOURCE || exit 1

# change to the application source directory
cd algorithm2e || exit 1

# fix permissions
chown -R root:root .
chmod -R u+w,go+r-w,a-s .

# install everything into the package directory
rm -rf $PKG
mkdir -p $PKG/install
mkdir -p $PKG/usr/share/texmf/tex/latex/algorithm2e
mkdir -p $PKG/usr/share/texmf/doc/latex/algorithm2e
mv tex/* $PKG/usr/share/texmf/tex/latex/algorithm2e/
mv README doc/* $PKG/usr/share/texmf/doc/latex/algorithm2e/

# add some description to the package
if [ "$DESC" != "" ]; then
  echo "$DESC" | sed 's/^/'$PRGNAM': /g' > $PKG/install/slack-desc
fi

# append dependency information to the package
if [ "$REQUIRES" != "" ]; then
  for REQ in $REQUIRES; do
    echo "$REQ" >> $PKG/install/slack-required
  done
fi

# doinst.sh
cat > $PKG/install/doinst.sh << EOF
#!/bin/sh
texhash
EOF

# build the package
cd $PKG
PKGVERSION=$(echo $VERSION | sed 's/-/./g')
makepkg -l y -c n \
  $OUTPUT/$PRGNAM-$PKGVERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz} \
  || exit 1

# make everything clean
cd $CWD
rm -rf $PKG
rm -rf $TMP/algorithm2e
