#!/bin/sh
# postrm script
#
# 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' <overwriter>
#          <overwriter-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package


clean_stuff()
{
    local _prefdir _sourcedir _sharedir
    _prefdir="/etc/apt/preferences.d"
    _sourcedir="/etc/apt/sources.list.d"
    _sharedir="/usr/share/yandex-search-common-apt"

    # For each distro remove custom repo
    if `lsb_release -c | grep -q precise` ; then
        rm -f ${_prefdir}/yandex-search-precise-pin
        rm -f ${_sourcedir}/yandex-precise.list
        rm -f ${_sourcedir}/yandex-search-precise.list
        rm -f ${_sourcedir}/ubuntu-security-precise.list
    elif `lsb_release -c | grep -q trusty` ; then
        rm -f ${_prefdir}/yandex-search-trusty-pin
        rm -f ${_sourcedir}/yandex-search-trusty.list
        rm -f ${_sourcedir}/yandex-trusty.list
        rm -f ${_sourcedir}/ubuntu-security-trusty.list
    elif `lsb_release -c | grep -q xenial` ; then
        rm -f ${_prefdir}/yandex-search-xenial-pin
        rm -f ${_sourcedir}/yandex-search-xenial.list
        rm -f ${_sourcedir}/yandex-xenial.list
        rm -f ${_sourcedir}/ubuntu-security-xenial.list
    elif `lsb_release -c | grep -q bionic` ; then
        rm -f ${_prefdir}/yandex-search-bionic-pin
        rm -f ${_sourcedir}/yandex-search-bionic.list
        rm -f ${_sourcedir}/yandex-bionic.list
        rm -f ${_sourcedir}/ubuntu-security-bionic.list
    else
        echo "WARNING: Unsupported Linux Distro"
    fi
}


case "$1" in
    remove|purge)
        clean_stuff
        ;;

    upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
        ;;

    *)
        echo "postrm 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

