#!/bin/sh
# postrm script for yandex-passport-tasks
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postrm> `remove'
#        * <postrm> `purge'
#        * <old-postrm> `upgrade' <new-version>
#        * <new-postrm> `failed-upgrade' <old-version>
#        * <new-postrm> `abort-install'
#        * <new-postrm> `abort-install' <old-version>
#        * <new-postrm> `abort-upgrade' <old-version>
#        * <disappearer's-postrm> `disappear' <r>overwrit>r> <new-version>
# for details, see /usr/share/doc/packaging-manual/

YA_ENV_TYPE=$(cat /etc/yandex/environment.type)

cleanYasmConfig() {
    if [ "${YA_ENV_TYPE}" = "stress" ]; then
        return
    fi

    echo "Clean yasm config..."

    if [ -f "/etc/yandex/yasmagent/instances.d/id-frontend" ]; then
        rm -f "/etc/yandex/yasmagent/instances.d/id-frontend" || /bin/true
    fi

    if [ -f "/usr/local/yasmagent/CONF/agent.id-front.conf" ]; then
        rm -f "/usr/local/yasmagent/CONF/agent.id-front.conf" || /bin/true
    fi

    invoke-rc.d yasmagent restart || true
}

case "$1" in
    purge|remove)
        cleanYasmConfig;
    ;;
    *)
    ;;
esac

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

#DEBHELPER#

exit 0
