#!/bin/sh
# Set initial variables:
PKGNAM=bootp
VERSION=${VERSION:-2.4.3}
BUILD=${BUILD:-2}

. /etc/pkghelpers
pkghelpers_env

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

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

cd $TMP
rm -rf bootp-$VERSION
tar xzvf $CWD/bootp_$VERSION.orig.tar.gz
cd bootp-$VERSION
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 {} \;
zcat $CWD/bootp_2.4.3-15.diff.gz | patch -p1 --verbose || exit 1
mkdir -p $PKG/usr/doc/bootp-$VERSION
cp -a \
  Announce ConvOldTab.sh Installation Problems README ToDo bootptab.cmu bootptab.mcs \
  $PKG/usr/doc/bootp-$VERSION
make -j12 || exit 1
strip --strip-unneeded bootpd bootpef bootpgw bootptest
for file in bootpd bootpef bootpgw bootptest ; do
  cat $file > $PKG/usr/sbin/$file
done
gzip -9c bootptab.5 > $PKG/usr/man/man5/bootptab.5.gz
for file in bootpd.8 bootpef.8 bootptest.8 ; do
  gzip -9c $file > $PKG/usr/man/man8/$file.gz
done
( cd $PKG/usr/man/man8
  ln -sf bootpd.8.gz bootpgw.8.gz
)
zcat $CWD/bootptab.gz > $PKG/etc/bootptab.new
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# Build the package:
cd $PKG
pkghelpers_fixup
pkghelpers_makepkg