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

PKG=$TMP/package-bootp

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

# Find the size of a file:
filesize() {
 SIZE=`ls -l -d -G $1 | cut -b23-32`
 echo -n $SIZE
}

echo "+===============+"
echo "| bootp-DD2.4.3 |"
echo "+===============+"
cd $TMP
tar xzvf $CWD/bootp-DD2.4.3.tar.gz
cd bootp-DD2.4.3
mkdir -p $PKG/usr/doc/bootp-DD2.4.3
cp -a Announce Changes Changes.Dynamic Installation Problems README \
  README.Dynamic ToDo ToDo.Dynamic bootptab.Dynamic bootptab.cmu \
  bootptab.mcs $PKG/usr/doc/bootp-DD2.4.3
chown -R root.root $PKG/usr/doc/bootp-DD2.4.3
chmod 644 $PKG/usr/doc/bootp-DD2.4.3/*
zcat $CWD/bootp-DD2.4.3.diff.gz | patch -p1 --backup
make -j 2
strip 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

# Build the package:
cd $PKG
tar czvf $TMP/bootp.tgz .

# Warn of zero-length files:
for file in `find . -type f -print` ; do
 if [ "`filesize $file`" = "0" ]; then
  echo "WARNING: zero length file $file"
 fi
 if [ "`filesize $file`" = "20" ]; then
  echo "WARNING: possible empty gzipped file $file"
 fi
done

# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
 rm -rf $TMP/bootp-DD2.4.3
 rm -rf $TMP/$dir
 rm -rf $PKG
fi
