#!/bin/sh
# Heavily based on the Slackware 12.2 SlackBuild
# http://archivemail.sourceforge.net/
# Packager baldelario ~at~ gmail ~dot~ com
# http://www.slacky.it

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-archivemail
rm -rf $PKG
mkdir -p $PKG/usr/bin

NAME=archivemail
VERSION=0.7.2
ARCH=${ARCH:-i686}
BUILD=3bj

cd $TMP
rm -rf $NAME-$VERSION
tar xzf $CWD/$NAME-$VERSION.tar.gz
cd $NAME-$VERSION
chown -R root:root .
cat archivemail > $PKG/usr/bin/archivemail
chmod 755 $PKG/usr/bin/*

mkdir -p $PKG/usr/man/man1
cat archivemail.1 > $PKG/usr/man/man1/archivemail.1
gzip -9 $PKG/usr/man/man?/*

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a $CWD/archive_mail.pdf examples/* CHANGELOG FAQ README TODO PKG-INFO $PKG/usr/doc/$NAME-$VERSION
chown -R root:root $PKG/usr/doc
find $PKG/usr/doc -type f -exec chmod 644 {} \;

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
cd $PKG
requiredbuilder -y -v -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP
fi
