#!/bin/sh

set -e

# Postrm script for DokuWiki by Matti Pll <mpo@iki.fi>
# Based on postrm for PHPWiki written by Matthew Palmer.

# No need to handle the Web server in postrm
#if [ "$1" = "remove" ]; then
#    for srv in apache apache2 apache-ssl apache-perl; do
#	if [ -e /etc/$srv/httpd.conf ]; then
#	    
#	    # Remove dokuwiki from the apache configuration
#	    rm -f /etc/$srv/conf.d/dokuwiki.conf
#	    
#	    # Restart apache
#	    if which invoke-rc.d >/dev/null 2>&1; then
#		invoke-rc.d $srv force-reload
#	    else
#		/etc/init.d/$srv force-reload
#	    fi
#	fi
#    done
#fi

if [ "$1" = "purge" ] && [ -e /usr/share/debconf/confmodule ]; then
    . /usr/share/debconf/confmodule
    db_get dokuwiki/system/purgepages || true
    if [ "$RET" = "true" ]; then
	rm -rf /var/lib/dokuwiki/*
    fi
fi

#DEBHELPER#

if [ "$1" = "purge" ]; then
    for srv in apache apache2 apache-ssl apache-perl; do
	    rm -f /etc/$srv/conf.d/dokuwiki.conf
    done

    for ext in '' '~' '%' .bak .ucf-new .ucf-old .ucf-dist;  do
        rm -f /etc/dokuwiki/apache.conf$ext
        rm -f /var/lib/dokuwiki/acl/acl.auth.php$ext
        rm -f /var/lib/dokuwiki/acl/users.auth.php$ext
        rm -f /etc/dokuwiki/htaccess$ext
    done

    if [ -x /usr/bin/ucf ]; then
	ucf --purge /etc/dokuwiki/apache.conf
	ucf --purge /var/lib/dokuwiki/acl/acl.auth.php
	ucf --purge /var/lib/dokuwiki/acl/users.auth.php
        ucf --purge /etc/dokuwiki/htaccess
    fi

    if [ -x /usr/bin/ucfr ]; then
        ucfr --purge dokuwiki /etc/dokuwiki/apache.conf
	ucfr --purge dokuwiki /var/lib/dokuwiki/acl/acl.auth.php
	ucfr --purge dokuwiki /var/lib/dokuwiki/acl/users.auth.php
	ucfr --purge dokuwiki /etc/dokuwiki/htaccess
    fi

#    rm -f /etc/dokuwiki/*.dpkg-*
fi

# Remove some configuration files backups, cf. preinst upgrade.
if [ "$1" = "abort-upgrade" ] ; then
    rm /usr/share/dokuwiki/.htaccess.upgrade
fi

