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

VERSION=1.4.5
ARCH=sparc
BUILD=2

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

# Explode the package framework:
cd $PKG
explodepkg $CWD/_silo.tar.gz

echo "+===========+"
echo "| silo-$VERSION |"
echo "+===========+"
cd $TMP
tar xjvf $CWD/silo-$VERSION.tar.bz2
cd silo-$VERSION
make
make DESTDIR=$PKG install
mv $PKG/etc/silo.conf $PKG/etc/silo.conf-sample
chmod 644 $PKG/etc/silo.conf-sample
gzip -9 $PKG/usr/share/man/man{1,8,5}/*

mkdir -p $PKG/usr/doc/silo-$VERSION
cp COPYING ChangeLog docs/* $PKG/usr/doc/silo-$VERSION

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

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

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