File nss-mdns.spec of Package nss-mdns

#
# spec file for package nss-mdns (Version 0.10)
#
# Copyright (c) 2009 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#

# norootforbuild


Name:           nss-mdns
# lynx is not needed, text version of README is already present
#BuildRequires:  lynx
Version:        0.10
Release:        41
Group:          Productivity/Networking/DNS/Utilities
License:        LGPLv2.1+
Url:            http://0pointer.de/lennart/projects/nss-mdns/
Summary:        Host Name Resolution Via Multicast DNS (Zeroconf) for glibc
Source:         %{name}-%{version}.tar.bz2
Source2:        baselibs.conf
Patch:          unaligned.diff
PreReq:         sed grep
Requires:       avahi
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%description
nss-mdns is a plug-in for the GNU Name Service Switch (NSS)
functionality of the GNU C Library (glibc) providing a hostname
resolution via Multicast DNS (aka Zeroconf, aka Apple Rendezvous, aka
Apple Bonjour), and effectively allowing name resolution by common
Unix/Linux programs in the ad-hoc mDNS domain .local.

nss-mdns provides only client functionality, which means that you have
to run a mDNS responder daemon separately from nss-mdns if you want to
register the local hostname via mDNS. I recommend Avahi.

By default, nss-mdns tries to contact a running avahi-daemon to resolve
hostnames and addresses and makes use of its superior record cacheing.



Authors:
--------
    Lennart Poettering <mzaffzqaf@0pointer.de>

%prep
%setup -q
%patch

%build
%configure --libdir=/%{_lib}

%install
%makeinstall

%post
/sbin/ldconfig
# Perl-fu to add mdns4_minimal to the hosts line of /etc/nsswitch.conf
if [ -f /etc/nsswitch.conf ] ; then
    perl -ibak -pe '
    sub insert {
	my @bits = split(" ", shift);
	if (grep { $_ eq "mdns4_minimal" || $_ eq "mdns4"
		    || $_ eq "mdns6_minimal" || $_ eq "mdns6"
		    || $_ eq "mdns_minimal" || $_ eq "mdns" } @bits) {
		return join " ", @bits;
		}
	    return join " ", map {
		$_ eq "dns" ? ("mdns4_minimal", "[NOTFOUND=return]", $_) : $_
		} @bits;
	    }
    s/^(hosts:\s+)(.*)$/$1.insert($2)/e;
    ' /etc/nsswitch.conf
fi

%preun
# Perl-fu to remove mdns4_minimal from the hosts line of /etc/nsswitch.conf
if [ "$1" -eq 0 -a -f /etc/nsswitch.conf ] ; then
    perl -ibak -pe '
    my @remove = (
	"mdns4_minimal [NOTFOUND=return]",
	"mdns4_minimal",
	"mdns4",
	"mdns6_minimal [NOTFOUND=return]",
	"mdns6_minimal",
	"mdns6",
	"mdns_minimal [NOTFOUND=return]",
	"mdns_minimal",
	"mdns",
	);
    sub remove {
	my $s = shift;
	foreach my $bit (@remove) {
	    $s =~ s/\s+\Q$bit\E//g;
	    }
	return $s;
	}
    s/^(hosts:\s+)(.*)$/$1.remove($2)/e;
    ' /etc/nsswitch.conf
fi

%postun
/sbin/ldconfig
# Build a regexp removing all no more provided libraries.
# If there are no known libraries installed, remove also related "[NOTFOUND=return]"
REMOVE_REGEXP=
REAL_REMOVE=true
for NSS_NAME in mdns mdns4 mdns4_minimal mdns_minimal mdns6 mdns6_minimal ; do
    if test -f %{_lib}/libnss_$NSS_NAME.so.2 ; then
	REAL_REMOVE=false
    else
	REMOVE_REGEXP="${REMOVE_REGEXP}
	    s/\\([[:space:]][[:space:]]*\\)$NSS_NAME\\([[:space:]][[:space:]]*\\)/\\1/g;
	    s/\\([[:space:]][[:space:]]*\\)$NSS_NAME\$//g;"
    fi
done
if $REAL_REMOVE ; then
    REMOVE_REGEXP="s/\\(mdns[46]*_minimal\\)[[:space:]][[:space:]]*\\[NOTFOUND=return\\]/\\1/;$REMOVE_REGEXP"
fi
sed -i "/^hosts:/{$REMOVE_REGEXP}" etc/nsswitch.conf

%files
%defattr(-,root,root)
%doc LICENSE README doc/*.html doc/*.css
/%{_lib}/libnss_mdns.so.2
/%{_lib}/libnss_mdns4.so.2
/%{_lib}/libnss_mdns4_minimal.so.2
/%{_lib}/libnss_mdns6.so.2
/%{_lib}/libnss_mdns6_minimal.so.2
/%{_lib}/libnss_mdns_minimal.so.2

%clean
rm -rf $RPM_BUILD_ROOT

%changelog
openSUSE Build Service is sponsored by