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

VERSION=7.6
ARCH=${ARCH:-i486}
BUILD=1

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

cd $TMP
rm -rf tcp_wrappers-7.6
tar xzvf $CWD/tcp_wrappers_7.6.tar.gz || exit 1
cd tcp_wrappers-7.6

chown -R root:root .
find . -perm 666 -exec chmod 644 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -perm 600 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;
find . -perm 400 -exec chmod 644 {} \;
find . -perm 440 -exec chmod 644 {} \;
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 511 -exec chmod 755 {} \;
find . -perm 711 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;

sh extract-and-patch.sh
cd tcp_wrappers_7.6
make REAL_DAEMON_DIR=/usr/sbin linux
strip tcpd safe_finger tcpdchk tcpdmatch try-from
mkdir -p $PKG/usr/lib
cat libwrap.a > $PKG/usr/lib/libwrap.a
mkdir -p $PKG/usr/include
cat tcpd.h > $PKG/usr/include/tcpd.h
mkdir -p $PKG/usr/sbin
cat safe_finger > $PKG/usr/sbin/safe_finger
cat tcpd > $PKG/usr/sbin/tcpd
cat tcpdchk > $PKG/usr/sbin/tcpdchk
cat tcpdmatch > $PKG/usr/sbin/tcpdmatch
cat try-from > $PKG/usr/sbin/try-from
chmod 755 $PKG/usr/sbin/*
mkdir -p $PKG/usr/man/man{3,5,8}
cat hosts_access.3 | gzip -9c > $PKG/usr/man/man3/hosts_access.3.gz
cat hosts_access.5 | gzip -9c > $PKG/usr/man/man5/hosts_access.5.gz
cat hosts_options.5 | gzip -9c > $PKG/usr/man/man5/hosts_options.5.gz
cat tcpd.8 | gzip -9c > $PKG/usr/man/man8/tcpd.8.gz
cat tcpdchk.8 | gzip -9c > $PKG/usr/man/man8/tcpdchk.8.gz
cat tcpdmatch.8 | gzip -9c > $PKG/usr/man/man8/tcpdmatch.8.gz

mkdir -p $PKG/usr/doc/tcp_wrappers_7.6
cp -a \
  BLURB CHANGES DISCLAIMER README README.NIS \
  $PKG/usr/doc/tcp_wrappers_7.6

# Finish up the package:
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

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