#! /bin/sh
# postrm maintainer script for zoneminder-core package

set -e

# Source the debconf stuff
if [ -f /usr/share/debconf/confmodule ]; then
    . /usr/share/debconf/confmodule
fi

if [ "$1" = "purge" ]; then

    # Ask the user if we have to remove the cache directory even if not empty
    if [ -d /var/cache/zoneminder ] \
      && [ ! $(find /var/cache/zoneminder -maxdepth 0 -type d -empty 2>/dev/null) ]; then
        RET=""
        db_input high zoneminder/ask_delete || true
        db_go || true
        db_get zoneminder/ask_delete
        if [ "$RET" = "true" ]; then
            RET=""
            db_input high zoneminder/ask_delete_again || true
            db_go || true
            db_get zoneminder/ask_delete_again
            if [ "$RET" = "true" ]; then
                rm -rf /var/cache/zoneminder
            fi
        fi
    fi
fi

#DEBHELPER#

# postrm rm may freeze without that
db_stop

exit 0
