#!/bin/sh
# Heavily based on the Slackware 12.2 SlackBuild
# Packager Absinthetized
#-----------------------------------------------
#Slackbuild made by Lorys (thank you)
#	    revisited by Absinthetized & Lorys
#-----------------------------------------------

#global info section
PKG=$TMP/package-tracepkg
NAME=tracepkg
VERSION=1.1.0rc3
ARCH=noarch
BUILD=2ajk

CWD=`pwd`
FRP=$(cd .. ; pwd)

#prepare packaging temporary directory

if [ "$TMP" = "" ]; then
 TMP=/tmp
fi

if [ ! -d $TMP ]; then
 mkdir -p $TMP
fi
if [ ! -d $PKG ]; then
 mkdir -p $PKG
fi

#extract source files
cd $TMP
tar xjvf $CWD/$NAME-$VERSION.tar.bz2
cd $NAME-$VERSION

#prepare executable files
TOOLDIR=$PKG/usr/sbin
mkdir -p $TOOLDIR
AUXDIR=$PKG/usr/libexec/tracepkg
mkdir -p $AUXDIR

cp -a tracepkg $TOOLDIR
cp -a builddb installdb upgradedb remove* resync dummydb refreshdb retrive* scandb core-functions $AUXDIR

#prepare configuration files
CONFDIR=$PKG/etc/$NAME
mkdir -p $CONFDIR
cp -a tracepkg.conf.new $CONFDIR

#gzip the man page(s)
mkdir -p $PKG/usr/man/man8
cat tracepkg.8 | gzip -9c > $PKG/usr/man/man8/tracepkg.8.gz

#prepare docs directory
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp changelog $PKG/usr/doc/$NAME-$VERSION
cp knownissues $PKG/usr/doc/$NAME-$VERSION
cp license   $PKG/usr/doc/$NAME-$VERSION
cd $CWD
cp -a *.SlackBuild slack-desc $PKG/usr/doc/$NAME-$VERSION

#prepare install directory
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $TMP/$NAME-$VERSION/doinst.sh > $PKG/install/doinst.sh

#build tgz :)
cd $PKG
chown -R root:root .
makepkg -l y -c n $FRP/$NAME-$VERSION-$ARCH-$BUILD.tgz

#clean up all temporary stuff if required
if [ "$1" = "--cleanup" ]; then
 rm -rf $TMP/$NAME-$VERSION
 rm -rf $PKG
fi

#EOF
