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

VERSION=3.0.12
ARCH=i386
BUILD=1

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/_pidentd.tar.gz

echo "+================+"
echo "| pidentd-$VERSION |"
echo "+================+"
cd $TMP
tar xzvf $CWD/pidentd-$VERSION.tar.gz
cd pidentd-$VERSION
# Disable attempt at writing a PID file... doesn't work since
# a) it runs as "nobody" b) there may be multiple copies active
# Also, don't return full username (stops email address harvesting).
zcat $CWD/pidentd.conf.diff.gz | patch -p1 --backup --verbose
mkdir -p $PKG/usr/doc/pidentd-$VERSION
cp -a BUGS ChangeLog FAQ INSTALL README Y2K doc/rfc* $PKG/usr/doc/pidentd-$VERSION
chown -R root.root $PKG/usr/doc/pidentd-$VERSION
chmod 644 $PKG/usr/doc/pidentd-$VERSION/*
./configure --prefix=/usr \
            --sysconfdir=/etc \
            --with-des-includes=/usr/include/openssl \
            i386-slackware-linux
make
strip src/identd src/ibench src/idecrypt src/ikeygen
cat src/identd > $PKG/usr/sbin/in.identd
cat src/ibench > $PKG/usr/sbin/ibench
cat src/idecrypt > $PKG/usr/sbin/idecrypt
cat src/ikeygen > $PKG/usr/sbin/ikeygen
cat etc/identd.conf > $PKG/etc/identd.conf.new
mkdir -p $PKG/usr/man/man8
cat doc/identd.8 | gzip -9c > $PKG/usr/man/man8/identd.8.gz
echo ".so man8/identd.8" | gzip -9c > $PKG/usr/man/man8/in.identd.8.gz
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

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

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