#!/bin/bash

set -e

case "$1" in
    remove)
        service mpfs-core-uwsgi-browser stop &>/dev/null
        service mpfs-queue-browser stop &>/dev/null || true
        service mpfs-queue-sync stop &>/dev/null || true

        if [ -L /etc/init.d/mpfs-core-uwsgi-browser ]; then
            update-rc.d -f mpfs-core-uwsgi-browser remove
            rm /etc/init.d/mpfs-core-uwsgi-browser
        fi

        if [ -L /etc/init.d/mpfs-queue-browser ]; then
            update-rc.d -f mpfs-queue-browser remove
            rm /etc/init.d/mpfs-queue-browser
        fi

        if [ -L /etc/init.d/mpfs-queue-sync ]; then
            rm /etc/init.d/mpfs-queue-sync
            update-rc.d -f mpfs-queue-sync remove
        fi
        [ -x /etc/init.d/nginx ] && ( nginx -t -c /etc/nginx/nginx.conf && service nginx restart )

        rm /usr/lib/python2.7/dist-packages/mpfs
    ;;
    purge|upgrade|failed-upgrade|abort-remove|abort-upgrade|disappear)
        echo "postrm called with argument: '$1'" >&2
    ;;
    *)
        echo "postrm called with unknown argument '$1'" >&2
        exit 0
    ;;
esac

