#!/bin/sh set -e # Automatically added by dh_makeshlibs if [ "$1" = "configure" ]; then ldconfig fi # End automatically added section log() { echo "$*" } # try to insert mdns entries to the "hosts" line in /etc/nsswitch.conf to # automatically enable nss-mdns support; do not change the configuration if the # "hosts" line already references some mdns lookups insert_mdns() { log "Checking NSS setup..." # abort if /etc/nsswitch.conf does not exist if ! [ -e /etc/nsswitch.conf ]; then log "Could not find /etc/nsswitch.conf." return fi perl -i -pe ' sub insert { # this also splits on tab my @bits=split(" ", shift); # do not break configuration if the "hosts" line already references # mdns if (grep { $_ eq "mdns4_minimal" || $_ eq "mdns4" || $_ eq "mdns" || $_ eq "mdns_minimal" || $_ eq "mdns6" || $_ eq "mdns6_minimal"} @bits) { return join " ", @bits; } # change "dns" into "mdns4_minimal [NOTFOUND=return] dns mdns4" return join " ", map { $_ eq "dns" ? ("mdns4_minimal","[NOTFOUND=return]",$_,"mdns4") : $_ } @bits; } s/^(hosts:\s+)(.*)/$1.insert($2)/e; ' /etc/nsswitch.conf } action="$1" if [ configure = "$action" ]; then if [ -z "$2" ]; then log "First installation detected..." # first install: setup the recommended configuration (unless # nsswitch.conf already contains mdns entries) insert_mdns else # upgrade version="$2" if dpkg --compare-versions "$version" lt 0.8-4.2; then log "Upgrade from unconfigured version detected." # versions prior to 0.8-4.2 did not setup nss-mdns automatically, # do it now insert_mdns elif dpkg --compare-versions "$version" lt 0.8-6; then log "Already configured version detected, skipping NSS setup." # versions 0.8-4.2 and 0.8-5 installed the same configuration as # this postinst, so nothing needs to be done : elif dpkg --compare-versions "$version" lt 0.8-6.1; then log "Upgrade from possibly broken version detected." if [ -e /etc/nsswitch.conf ]; then # version 0.8-6 broke the configuration in multiple ways: 1) # for systems which were upgraded from 0.8-4.2 or 0.8-5 to # 0.8-6, the hosts line will look like: # hosts: files dns # cleanup from this specially formatted line into the default # one: sed -i \ 's/^hosts: files dns $/hosts: files dns/' \ /etc/nsswitch.conf # 2) for systems which re-installed 0.8-6 or installed 0.8-6 as the # first version, the hosts line will look like: # hosts: files mdns_minimal dns mdns # cleanup from this specially formatted line into the default one: sed -i -r \ '/^hosts:/s/\/dns/' \ /etc/nsswitch.conf fi insert_mdns fi fi fi