#!/bin/sh -e

# Based on MPD's mpd.postrm script.

# This file is part of mpd-hits.
# Copyright (C) 2003-2005 by Warren Dukes.
# Copyright (C) Decklin Foster.
# Copyright (C) 2010 Dmitry Samoyloff.
#
# mpd-hits is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# mpd-hits is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with mpd-hits. If not, see <http://www.gnu.org/licenses/>.

ACTION="$1"
USER=mpd-hits
GROUP=mpd-hits

if [ "$ACTION" = "purge" ]; then
    # Remove init script symbolic links.
    update-rc.d mpd-hits remove defaults >/dev/null

    # Remove all mpd-hits statoverrides.
    for i in $(dpkg-statoverride --list | awk '/^mpd-hits / {print $4}'); do
        if dpkg-statoverride --list --quiet "$i" >/dev/null; then
            dpkg-statoverride --force --quiet --remove "$i"
        fi
    done

    # Remove created directories, including the statistics!
    echo Purging directories ...
    rm -rf /var/lib/mpd-hits /var/run/mpd-hits > /dev/null 2>&1

    # Remove user and group.
    echo Deleting mpd-hits user and group ...
    if getent passwd $USER >/dev/null; then
        deluser --quiet $USER
    fi
    if getent group $GROUP >/dev/null; then
        delgroup --quiet $GROUP
    fi
fi


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

#DEBHELPER#

exit 0
