#!/bin/sh

. $BUILDVARS

BUILD=1sml
APP=dnsmasq
VERSION=2.80
PKG=$TMP/package-$APP

rm -rf "$PKG"
mkdir -p $PKG $PKGDEST
cd "$TMP"
rm -rf "$APP-$VERSION"

tar -xvf $CWD/$APP-$VERSION.tar.?z || exit 1
cd "$APP-$VERSION" || exit 1
chown -R root:root .

# The version will be shown as 9.10.8-P1-Ubuntu when
# dig @nameserver VERSION.BIN TXT CHAOS is run
# So will AUTHORS.BIND
sed -i 's/Simon Kelley/BURP/g' src/option.c
sed -i 's/dnsmasq-/9.10.8-P1-/g' src/option.c
mv bld/get-version bld/get-version.bak
cd bld
cat << EOF >>get-version
#!/bin/sh
echo "Ubuntu"
EOF
chmod +x get-version
cd ../

make $jobs || exit 1

mkdir -p $PKG/etc $PKG/bin 
mkdir -p $PKG/share/man/man8
cp man/dnsmasq.8 $PKG/share/man/man8/
cp dnsmasq.conf.example $PKG/etc ; chmod 640 $PKG/etc/dnsmasq.conf.example
cp src/dnsmasq $PKG/bin ; chmod 755 $PKG/bin/dnsmasq

install -Dm 755 src/dnsmasq $PKG/bin/dnsmasq
install -Dm 644 man/dnsmasq.8 $PKG/share/man/man8/dnsmasq.8
install -Dm 600 dnsmasq.conf.example $PKG/etc/dnsmasq.conf.example

cd $PKG
mkdir -p etc/service/dnsmasq var/service
install -Dm 755  $CWD/dnsmasq.run etc/service/dnsmasq/run
touch etc/service/dnsmasq/down
ln -s ../../etc/service/dnsmasq var/service/dnsmasq

strdoc
/bin/makepkg -l y -c n $PKGDEST/$APP-$VERSION-$ARCH-$BUILD.tgz
