# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=djbdns
pkgver=1.05
pkgrel=45
pkgdesc="Excellent high-performance DNS services"
url="http://cr.yp.to/djbdns.html"
arch="all"
license="public-domain"
depends=
subpackages="djbdns-common tinydns dnscache"
source="http://cr.yp.to/djbdns/$pkgname-$pkgver.tar.gz
http://www.fefe.de/dns/djbdns-1.05-test25.diff.bz2
	headtail.patch
	dnsroots.patch
	dnstracesort.patch
	djbdns-1.05-jumbo-josb.patch
	$pkgver-errno.patch
	$pkgver-response.patch
	tinydns.pre-install
	tinydns.initd
	tinydns.confd
	dnscache.pre-install
	dnscache.initd
	dnscache.confd
	dnscache.monthly
	"

_builddir="$srcdir"/$pkgname-$pkgver
prepare() {
	cd "$_builddir"
	for i in $source; do
		case $i in
		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
		*.diff.gz) msg $i; gunzip -c "$srcdir"/$i | patch -p1 || return 1;;
		esac
	done
	# remove all the generated headers. they came with the jumbo patch and should
	# never have been there...
	sed -n 's/^\([a-z0-9]\+\.h\):.*/\1/gp' Makefile Makefile.sig | xargs rm -f
}

build() {
	cd "$_builddir"
	echo "${CC:-"gcc"} ${CFLAGS}" > conf-cc
	echo "${CC:-"gcc"} ${LDFLAGS}" > conf-ld
	echo "/usr" > conf-home
	make -j1 || return 1
}

package() {
	cd "$_builddir"
	mkdir -p "$pkgdir"/etc/
	cp dnsroots.global "$pkgdir"/etc/
	mkdir -p "$pkgdir"/usr/bin
	cp *-conf dnscache tinydns walldns rbldns pickdns axfrdns \
		*-get *-data *-edit dnsip dnsipq dnsname dnstxt dnsmx \
		dnsfilter random-ip dnsqr dnsq dnstrace dnstracesort \
		"$pkgdir"/usr/bin/ 
	mkdir -p "$pkgdir"/usr/share/doc/djbdns
}

common() {
	pkgdesc="Base utilities of djbdns"
	replaces="djbdns"

	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/dnsqr "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/dnsip "$subpkgdir"/usr/bin
}

tinydns() {
	pkgdesc="A small and secure DNS server"
	install=tinydns.pre-install

	mkdir -p "$subpkgdir"/usr/bin "$subpkgdir"/etc/tinydns \
		"$subpkgdir"/var/cache/tinydns
	mv "$pkgdir"/usr/bin/tinydns* "$subpkgdir"/usr/bin
	install -D -m755 "$srcdir"/tinydns.initd \
		"$subpkgdir"/etc/init.d/tinydns
	install -D -m644 "$srcdir"/tinydns.confd \
		"$subpkgdir"/etc/conf.d/tinydns
}

dnscache() {
	pkgdesc="A recursive resolver"
	install=dnscache.pre-install
	depends=djbdns-common

	mkdir -p "$subpkgdir"/usr/bin \
		"$subpkgdir"/etc/dnscache/ip \
		"$subpkgdir"/etc/dnscache/servers

	cp "$pkgdir"/etc/dnsroots.global "$subpkgdir"/etc/dnscache/servers/@
	touch "$subpkgdir"/etc/dnscache/ip/127 || return 1

	mv "$pkgdir"/usr/bin/dnscache* "$subpkgdir"/usr/bin
	install -D -m755 "$srcdir"/dnscache.initd \
		"$subpkgdir"/etc/init.d/dnscache
	install -D -m644 "$srcdir"/dnscache.confd \
		"$subpkgdir"/etc/conf.d/dnscache
	install -D -m755 "$srcdir"/dnscache.monthly \
		"$subpkgdir"/etc/periodic/monthly/dnscache-hints-refresh
}

md5sums="3147c5cd56832aa3b41955c7a51cbeb2  djbdns-1.05.tar.gz
4593ed6a189a8bad8b58671841d36732  djbdns-1.05-test25.diff.bz2
0d2adaf9f1626043e8702b825cdccdd6  headtail.patch
7565048ebc981238879122c7f88cc143  dnsroots.patch
6fe7f473233f1c86b76261afd8345bf0  dnstracesort.patch
adb6745606cae593eb5ea6870fc27bd4  djbdns-1.05-jumbo-josb.patch
c7be73fe2fb4ae02d5096fa2c1f55a68  1.05-errno.patch
1292500c04baba3995d9753fe40fdc94  1.05-response.patch
f58af419816e9e50b94b88703325f94d  tinydns.pre-install
9f55917f26426cdf8e290397ebc95c08  tinydns.initd
7dcf6674c07d46c736b3c25d9c92384a  tinydns.confd
d4ac7c5ec5e27a0c218f0e1c51950272  dnscache.pre-install
56682f66cc25b01d9918c7aacfeefadc  dnscache.initd
2b3d02e88f70603c760bf368ab3ed636  dnscache.confd
8173f85e0d9b4496de389d1b43993d95  dnscache.monthly"
sha256sums="3ccd826a02f3cde39be088e1fc6aed9fd57756b8f970de5dc99fcd2d92536b48  djbdns-1.05.tar.gz
28c88de08822894cf252e54ed3be9abfdf4f492644ff74a7c479340bdce051ea  djbdns-1.05-test25.diff.bz2
daec7b45c91e2db2607697eeba8034e13c6d99c7d8d521f462955dc2fce968b2  headtail.patch
a9b5e70cd853e30f40f312ba42d4603691aa6b4e2498faedf3ec2b39817b3c03  dnsroots.patch
f1d83e1365f68571fa4e007d5219720f8d65eb3730040a087fceb0ce2d8806bf  dnstracesort.patch
99dc3b9f7e8db95923b18250887f3b11f96ba7171e00242e5bde90b3cf5ae570  djbdns-1.05-jumbo-josb.patch
0cf77c0386d422dc9ead4af71eb02f76d5a214ccd68e0e2c2cf9f774247cc19c  1.05-errno.patch
9d59a9b608c390743cf552c20a5143e1df8401366e95b8731da261895163ca3a  1.05-response.patch
191c7f79de2f20ce3f6506b4255b92f7b1977bea1f870c2d3c5a58cb8182e51d  tinydns.pre-install
c2ad98e796c04ad5e929dbab841253ca861e0fc84fd1a8545c911ab9afdee15e  tinydns.initd
bc4368780009bfada4f2f55f0c2c0847aec2a4670fa42f9872716877fccdf64c  tinydns.confd
cdd2bf24a75e11bec4a7fe1eefcf8fcdc7de57b406de3b5e0777d18fa5cb3fba  dnscache.pre-install
5b6cb1789e3055fc73f9be04a53430c3eaeadef9247c7695bee9c110bb22d6cd  dnscache.initd
7088d50f85ee576a7e96c6de4beb62fe0fb66f40ee083cb48528817f67a11fc3  dnscache.confd
6da908c5ca1f0d6ab9c500d3844dc870ea99288de6940027daf1a7dadc8bb5ae  dnscache.monthly"
sha512sums="20f066402801d7bec183cb710a5bc51e41f1410024741e5803e26f68f2c13567e48eba793f233dfab903459c3335bc169e24b99d66a4c64e617e1f0779732fa9  djbdns-1.05.tar.gz
41cca597dba971010b9844071e0349d3a4b25cc4b144e12721b0bc8250589fb374e40ece8908f1081762597048179b1177e88b9a5f97be0b47b63e3183e654bb  djbdns-1.05-test25.diff.bz2
be4c9aea40c737364a56f188ad2276d90deac0dffb73ba4b659490836c0fe92ffb65ccf23c6724b913b2d6354336727004be0cf5b43ebc47abe7004700dfe1e8  headtail.patch
0cd97d833e0aaee2b82ed27b56ce183e9ab9806ff1e77bc61b7f38ae3168aa7310b12d2ed330713c4da97e60881ee339f6af449142cc29823865d87270733211  dnsroots.patch
ae9cd51f24041aed135b5ba88d1efd0310b8095bccd6fb60a986756b460a4f98a93e163c3ddae7c146d56a9d41778d17449f772b91fdc58d9e69523cf6c2a6e9  dnstracesort.patch
af7c0a0a2f519ec16ac2a937664b7984aafeb19d04fbd6e0fd0afa5482f3cb0b4ac5cf6a846d574a8591f3cec725b4f828cca95344c3c774cb77ee5630ff6617  djbdns-1.05-jumbo-josb.patch
086d02600034d486f084fd2500aba9041dfa02110781594cdc3781a3ad7823f61f11c54c053c8c1241f58660527abe536906aba0e7f6c49ed3b8dbd74ba8f2b7  1.05-errno.patch
407207f8387e2344fdebe68ab2213adbd9f1e6034e343b4359c8c1fa6ce36b0878a8367e4ee05cb4a44c199d4956aef0c6c8e84ab4f5556178547346ab88b82d  1.05-response.patch
54e69ebe9b8cfe159584b271577a2ab58a9604f3bd92d651fc5f4f68e47111ac5f74a4170bd299af83371052a69ab817179f436965d14bfa4132d151bb488786  tinydns.pre-install
797671630dd1943a0b0f5fb35ad4972f846752595fb9ddb1f5e4f75db81a59ab23e3f96bc29c814b5fcefdfcd9d55c39aa2835618cad877a74c0707376130aff  tinydns.initd
31b52bd4dd0f78ff63e105ff3937fb9bf582628fe7a04bfcba91195d4fc4b55b60869f993a42ef55a228892647af07ed7ea22cfff72812430c7b8207debdd8f1  tinydns.confd
3d9cc830ab4d0907740b0f17bf31a467689b3abbaf78a9125a84d94520003274d4b235bec13f08224540c8b89f0d40640a31ae3cc8ff9c5a134242cf657976cf  dnscache.pre-install
31bf58ed6a049e02210ce1cbbea00b62e2fe92339cd861eb3ee35f16186a3904e85fcd2f056e2d788b8a284068d83a3767cef01519a6d0152f1958be8e418956  dnscache.initd
1b281a4892c1c9ad39a15c95d0fbd14b0ada69b31723250e33d96946bd19f3edc4b36ec90fb9b6b884d7907b7e86cc3980f116f16fe35fb7496feffd728b1ffa  dnscache.confd
70d3431db407d02f145cb1521d563559b536e89a6a88f50cf853036b2833d78b594398df30cc33c17debea23aa6a7112614741e13f8ec5d1429fad075273a9f6  dnscache.monthly"