#!/bin/sh -e

case "$1" in
    configure)
	# continue below
    ;;

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

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

umask 022

echo "Rebuilding ld cache..."
/sbin/ldconfig

if [ ! -f /usr/local/bin/ntopng ] && [ ! -L /usr/local/bin/ntopng ] ; then
   ln -s /usr/bin/ntopng /usr/local/bin/ntopng
fi

if [ -d /usr/local/share/ntopng ] ; then
    mv /usr/local/share/ntopng /usr/local/share/ntopng.disabled
fi


# Start service after upgrade/install
echo "(Re)Starting ntopng..."
if grep -q systemd /proc/1/comm; then
    systemctl daemon-reload
    systemctl reset-failed
    systemctl enable ntopng
    systemctl restart ntopng
else
    update-rc.d ntopng defaults 93 >/dev/null
    /etc/init.d/ntopng restart
fi

exit 0
