#!/bin/sh

set -e

if [ "$1" = configure ] ; then
	# /run transition (see #633035)
	if dpkg --compare-versions "$2" lt "0.2.0-7"; then
		if [ -f /lib/init/rw/sendsigs.omit.d/rpcbind ]; then
			mv /lib/init/rw/sendsigs.omit.d/rpcbind /run/rpcbind.pid
			ln -s /run/rpcbind.pid /run/sendsigs.omit.d/rpcbind
		fi
	fi
	if dpkg --compare-versions "$2" lt "0.2.0-8.1"; then
		update-rc.d -f rpcbind remove
	fi

	# run daemon as non-root (see #852066)
	adduser --force-badname --system --quiet --home /run/rpcbind --no-create-home _rpc
	if dpkg --compare-versions "$2" lt "1.2.5-0.1~"; then
		if [ -d /run/rpcbind ]; then
			chown _rpc:root /run/rpcbind
			[ -f /run/rpcbind/portmap.xdr ] && chown _rpc:root /run/rpcbind/portmap.xdr
			[ -f /run/rpcbind/rpcbind.xdr ] && chown _rpc:root /run/rpcbind/rpcbind.xdr
		fi
	fi
fi

#DEBHELPER#
