abinfo "Installing IANA-Etc data files ..."
install -Dvm644 "$SRCDIR"/protocol-numbers.xml \
        "$PKGDIR"/usr/share/iana-etc/protocol-numbers.iana
install -Dvm644 "$SRCDIR"/service-names-port-numbers.xml \
        "$PKGDIR"/usr/share/iana-etc/port-numbers.iana
# ipmitool requires a txt-formatted file of enterprise numbers
install -Dvm644 "$SRCDIR"/enterprise-numbers.txt \
		"$PKGDIR"/usr/share/iana-etc/enterprise-numbers.txt
# ... and being placed in /usr/share/misc/enterprise-numbers
install -dvm755 "${PKGDIR}/usr/share/misc/"
ln -vs "../iana-etc/enterprise-numbers.txt" \
		"${PKGDIR}/usr/share/misc/enterprise-numbers"

abinfo "Generating /etc/protocols ..."
mkdir -pv "$PKGDIR"/etc

gawk '
BEGIN {
	print "# Full data: /usr/share/iana-etc/protocol-numbers.iana\n"
	FS="[<>]"
}

{
	if (/<record/) { v=n=0 }
	if (/<value/) v=$3
	if (/<name/ && !($3~/ /)) n=$3
	if (/<\/record/ && (v || n=="HOPOPT") && n) printf "%-12s %3i %s\n", tolower(n),v,n
}
' "$SRCDIR"/protocol-numbers.xml > "$PKGDIR"/etc/protocols

abinfo "Generating /etc/services ..."
gawk '
BEGIN {
	print "# Full data: /usr/share/iana-etc/port-numbers.iana\n"
	FS="[<>]"
}

{
	if (/<record/) { n=u=p=c=0 }
	if (/<name/ && !/\(/) n=$3
	if (/<number/) u=$3
	if (/<protocol/) p=$3
	if (/Unassigned/ || /Reserved/ || /historic/) c=1
	if (/<\/record/ && n && u && p && !c) printf "%-15s %5i/%s\n", n,u,p
}' "$SRCDIR"/service-names-port-numbers.xml > "$PKGDIR"/etc/services

echo 'whois              43/tcp    nicname' >> "$PKGDIR"/etc/services
echo 'whois              43/udp    nicname' >> "$PKGDIR"/etc/services
