#!/bin/sh
#
# tetex-a0poster.SlackBuild
# 2013-06-14
#
# a0-poster - Support for designing posters on large paper
#
# Provides fonts in sizes of 12pt up to 107pt and also makes sure
# that in math formulas the symbols appear in the right size.
# Can also create a PostScript header file for dvips which ensures
# that the poster will be printed in the right size.
# Supported sizes are DIN A0, DIN A1, DIN A2 and DIN A3.

PRGNAM=tetex-a0poster
VERSION=1.22b
ARCH="noarch"
BUILD=${BUILD:-1}
TAG=${TAG:-scr}

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

REQUIRES="tetex"

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

DESC="a0-poster - Support for designing posters on large paper

Provides fonts in sizes of 12pt up to 107pt and also makes sure
that in math formulas the symbols appear in the right size.
Can also create a PostScript header file for dvips which ensures
that the poster will be printed in the right size.
Supported sizes are DIN A0, DIN A1, DIN A2 and DIN A3.

${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 a0poster || 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/a0poster
mkdir -p $PKG/usr/share/texmf/doc/latex/a0poster
mv a0poster.cls a0size.sty $PKG/usr/share/texmf/tex/latex/a0poster/
mv a0.* a0_eng.* $PKG/usr/share/texmf/doc/latex/a0poster/

# 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/a0poster
