#!/bin/sh
# postinst script
#
# 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


case "$1" in
    configure)

    chown -R www-data:www-data /etc/yandex/logbroker-client/xiva/
    chown -R www-data:www-data /var/log/yandex/logbroker-client/xiva/

    echo "do not delete" > /etc/yandex/logbroker-client/xiva/logrotate.ping
    chmod 0644 /etc/yandex/logbroker-client/xiva/logrotate.ping || /bin/true

    /usr/share/passport-admin-config-golovan/passport_golovan_config.py -i passportlbcxiva -p "logbroker-client-xiva" > /etc/yandex/yasmagent/instances.d/lbc-xiva
    invoke-rc.d yasmagent restart

    if [ -x /bin/systemctl ]; then
        if ! systemctl is-enabled yandex-passport-xunistater@lbc-xiva > /dev/null; then
            systemctl enable yandex-passport-xunistater@lbc-xiva || true
        fi
        deb-systemd-invoke restart yandex-passport-xunistater@lbc-xiva || true
    else
        update-rc.d yandex-passport-xunistater defaults || true
        invoke-rc.d yandex-passport-xunistater restart || true
    fi

    if [ -x /bin/systemctl ]; then
        systemctl enable yandex-passport-logbroker-client-xiva
    fi
    service yandex-passport-logbroker-client-xiva restart || /bin/true

    ;;

    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
