#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-workbone

VERSION=2.40
ARCH=i386
BUILD=3

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
if [ ! -d $PKG ]; then
  mkdir -p $PKG # place for the package to be built
fi

cd $TMP
tar xzvf $CWD/workbone_$VERSION.orig.tar.gz
cd workbone-2.4
chown -R root.root .
zcat $CWD/workbone_$VERSION-3.diff.gz | patch -p1 --verbose
zcat $CWD/workbone.1.diff.gz | patch -p1 --verbose
make
strip workbone
mkdir -p $PKG/usr/bin
cat workbone > $PKG/usr/bin/workbone
chmod 755 $PKG/usr/bin/workbone
chown -R root.bin $PKG/usr/bin
mkdir -p $PKG/usr/man/man1
cat workbone.1 | gzip -9c > $PKG/usr/man/man1/workbone.1.gz
mkdir -p $PKG/usr/doc/workbone-$VERSION
cp -a README $PKG/usr/doc/workbone-$VERSION
chmod 644 $PKG/usr/doc/workbone-$VERSION/README
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# Build the package:
cd $PKG
makepkg -l y -c n $TMP/workbone-$VERSION-$ARCH-$BUILD.tgz

# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP/workbone-$VERSION.orig
  rm -rf $PKG
fi