#!/bin/sh

set -e

# Unlike postrm, I can be sure, that runit-helper is present on
# postinst.
NAME='ubus' ENABLE='yes' ONUPGRADE='restart' /lib/runit-helper/runit-helper postinst "$@"

case "$1" in
    configure)	 
		if [ -f "/etc/init.d/ubus" ]; then
			chmod +x /etc/init.d/ubus
			#[ "x$(invoke-rc.d ubus status)" != "x" ] && invoke-rc.d ubus restart
			if ! dpkg-query -f'${db:Status-Status}\n' -W runit-init 2>/dev/null | grep -q ^installed; then
				[ "x$(pidof ubusd)" != "x" ] && invoke-rc.d ubus restart
			fi
			update-rc.d ubus defaults >/dev/null
			[ "x$(pidof ubusd)" = "x" ] && invoke-rc.d ubus start
		fi
		if ! getent group netaid > /dev/null; then
            addgroup --quiet --system netaid || true
        fi
		;;

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

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

#DEBHELPER#
