#!/bin/sh
CWD=`pwd`
PKG=/tmp/package-dnsmasq

VERSION=2.20
ARCH=${ARCH:-sparc}
BUILD=${BUILD:-0}

rm -rf $PKG
mkdir -p $PKG
cd /tmp
rm -rf dnsmasq-$VERSION
tar xzvf $CWD/dnsmasq-$VERSION.tar.gz
cd dnsmasq-$VERSION

zcat $CWD/dnsmasq.leasedir.diff.gz | patch -p1 --verbose --backup --suffix=.orig
chown -R root.root .

make

mkdir -p $PKG/usr/sbin
cat src/dnsmasq > $PKG/usr/sbin/dnsmasq
chmod 755 $PKG/usr/sbin/dnsmasq
chown -R root.bin $PKG/usr/sbin
mkdir -p $PKG/usr/man/man8
cat dnsmasq.8 | gzip -9c > $PKG/usr/man/man8/dnsmasq.8.gz
mkdir -p $PKG/var/state/dnsmasq
( cd $PKG
  find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
  find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)
mkdir $PKG/etc
cat dnsmasq.conf.example > $PKG/etc/dnsmasq.conf.new
mkdir $PKG/etc/rc.d
zcat $CWD/rc.dnsmasq.gz > $PKG/etc/rc.d/rc.dnsmasq.new
mkdir -p $PKG/usr/doc/dnsmasq-$VERSION
cp -a \
  CHANGELOG COPYING FAQ UPGRADING_to_2.0 doc.html setup.html \
  $PKG/usr/doc/dnsmasq-$VERSION
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh

cd $PKG
makepkg -l y -c n ../dnsmasq-$VERSION-$ARCH-$BUILD.tgz

