#!/bin/sh
set -e

CONFIG_DIR="/etc/slapos"
LOG_DIR="/var/log/slapos"

case "$1" in
    purge)
	if [ -d "$CONFIG_DIR" ]; then
	    rm -f "${CONFIG_DIR}/slapos.cfg"
	    test -d "${CONFIG_DIR}/ssl/" && rm -rf "${CONFIG_DIR}/ssl/"
	    [ $(ls "$CONFIG_DIR" | wc -l) -eq 0 ] && rmdir "$CONFIG_DIR"
	fi

	test -d /var/cache/slapos/certificates/ && \
	    rm -rf /var/cache/slapos/certificates

	if [ -d "$LOG_DIR" ]; then
	    test -f "${LOG_DIR}/slapformat.log" && rm -f "${LOG_DIR}/slapformat.log"
	    [ $(ls "$LOG_DIR" | wc -l) -eq 0 ] && rmdir "$LOG_DIR"
	fi

	test -d /var/lib/slapos && rm -rf /var/lib/slapos/
	;;
esac

#DEBHELPER#

exit 0
