#!/bin/sh

#
# Configuration reset script for raperca
#

. /etc/raperca/init-functions

init_dirs

reset() {
    # Restore default config
    for f in "$CONFDIR"/spxconfig.xml "$CONFDIR"/logconfig.xml; do
        cp -f $f.spxsave $f
    done
    # Make sure that the shadow dir is mounted
    mount_shadow_dir
    # Clean all generated files
    clean "$TMPDIR" "$CACHEDIR" "$CONTENTDIR" "$SHADOWCONTENTDIR" "$LOGDIR" \
	"$USRCOMPORTDIR" "$SPOOLDIR" "$VARDIR" "$CAPTUREDIR"
    # Put back the default content
    copy_default_content
    # Zap all locks from the dav lock database 
    clean_davlockdb
    # Remove the passwords / admin / content / log access restriction
    rm -f /etc/apache/conf.d/95-raperca-cont-prot.conf \
	/etc/apache/conf.d/95-raperca-adm-prot.conf \
	/etc/apache/conf.d/95-raperca-log-prot.conf \
	/etc/apache/conf.d/95-raperca-ro.conf \
	/etc/raperca/htpasswd /etc/raperca/spxpasswd.xml
    # Remove some status files
    rm -f /var/lib/raperca/logrotate.status
    # Restore uploader default config
    for f in /etc/raperca/{uploader.ics,uploaderlog.xml,uploaderconf.xml}; do
	cp -f $f.spxsave $f
    done
    # Remove the spool files
    find /var/spool/raperca -mindepth 1 -depth -type f -print0 | xargs -0r rm -f --
}

#
# Main
#

case "$1" in
    reset)
        reset
    ;;
    *)
        echo "Usage $0 {reset}" >&2
	exit 1
    ;;
esac
