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

VERSION=4.2
ARCH=sparc
BUILD=0


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

echo "+==============+"
echo "| netpipes-$VERSION |"
echo "+==============+"
cd $TMP
tar xzvf $CWD/netpipes-$VERSION-export.tar.gz
cd netpipes-$VERSION-export

mkdir -p $PKG/usr/doc/netpipes-$VERSION-export
cp -a COPYING README *.html $PKG/usr/doc/netpipes-$VERSION-export
chown root.root $PKG/usr/doc/netpipes-$VERSION-export/*
chmod 644 $PKG/usr/doc/netpipes-$VERSION-export/*

make

strip encapsulate faucet getpeername hose sockdown timelimit
for file in encapsulate faucet getpeername hose sockdown timelimit ; do
  cat $file > $PKG/usr/bin/$file
done
mkdir -p $PKG/usr/man/man1
for file in encapsulate faucet getpeername hose sockdown timelimit ; do
  cat $file.1 | gzip -9c > $PKG/usr/man/man1/$file.1.gz
done
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

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

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