#!/bin/bash

set -e

. /usr/share/debconf/confmodule

if [ -n "$DEBIAN_SCRIPT_DEBUG" ]; then set -v -x; DEBIAN_SCRIPT_TRACE=1; fi
${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 }

FILE_INI="/etc/virtuoso-opensource-6.1/virtuoso.ini"
FILE_ODBC_DSN="/usr/share/virtuoso-opensource-6.1/odbc.ini"

invoke-rc.d virtuoso-opensource-6.1 stop || true

# /etc/virtuoso-opensource-6.1/virtuoso.ini was a conffile in older
# versions of this package
dpkg-maintscript-helper rm_conffile \
	$FILE_INI '6.1.4+dfsg1-1~' 'virtuoso-opensource-6.1' -- "$@"

if [ "$1" == "purge" ]; then
	# log files can go without warning...
	rm -rf /var/log/virtuoso-opensource-6.1

	# ...but get explicit confirmation before removing databases
	db_input high virtuoso-opensource-6.1/check-remove-databases || true
	db_go || true
	db_get virtuoso-opensource-6.1/check-remove-databases || true
	if [ "$RET" == "true" ]; then
		rm -rf /var/lib/virtuoso-opensource-6.1
	fi

	rm -f $FILE_INI
	rm -f $FILE_ODBC_DSN

	update-rc.d virtuoso-opensource-6.1 remove >/dev/null || exit $?
fi

#DEBHELPER#
