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

VERSION=3.6.8
ARCH=x86_64
BUILD=1

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

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

cd $TMP
rm -rf logrotate-$VERSION
tar xzvf $CWD/logrotate-$VERSION.tar.gz
cd logrotate-$VERSION
chown -R root.root .
zcat $CWD/logrotate.slackware.diff.gz | patch -p1
make clean
make
strip logrotate
cat logrotate > $PKG/usr/sbin/logrotate
cat logrotate.8 | gzip -9c > $PKG/usr/man/man8/logrotate.8.gz
mkdir -p $PKG/usr/doc/logrotate-$VERSION
cp -a \
  CHANGES COPYING READM* \
  $PKG/usr/doc/logrotate-$VERSION
chmod 644 $PKG/usr/doc/logrotate-$VERSION/*
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

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

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