#!/bin/sh
# postinst script for vyatta-debian-lldpd-config
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

sysconfdir=/opt/vyatta/etc

case "$1" in
    configure)
		# init of daemon is controlled by Vyatta configuration
		if [ -d /run/systemd/system ]; then
			deb-systemd-helper disable lldpd.service
		fi
		if [ -x "/etc/init.d/lldpd" ]; then
			update-rc.d lldpd disable >/dev/null
		fi
		adduser --system --disabled-password --disabled-login --home /var/run/lldpd \
				--no-create-home --quiet --force-badname --group _lldpd

		for i in /usr/sbin/lldpctl; do
		if ! dpkg-statoverride --list $i > /dev/null 2>&1; then
			dpkg-statoverride --update --add _lldpd adm 4750 $i
		fi
		done

		chown root:root /usr/sbin/lldpctl

    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
