#!/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)

    ENV_NAME=$(cat /etc/yandex/environment.type)
    if [ "${ENV_NAME}" != "stress" ]; then
        /usr/share/passport-admin-config-golovan/passport_golovan_config.py -i passportpythonapinginx -p "passport-python-api" > /etc/yandex/yasmagent/instances.d/passport-python-api-nginx || true
        invoke-rc.d yasmagent restart || true

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

    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
