#!/bin/sh
#
# @author Markus Raab <markus@libelektra.org>
# @brief Resets all keys in the key database
# @date 02.08.2019
# @tags umount, stash, helper

if [ -z "$KDB" ]; then
	KDB=kdb
fi

fail() {
	echo "$*" 1>&2
	exit 1
}

if [ "$1" != "-f" ]; then
	fail "This is a very dangerous operation, read the man page first"
fi

"$KDB" reset-elektra -f || fail "Could not reset Elektra, will abort"

KDBSYSTEM=$("$KDB" file system:/)
KDBUSER=$("$KDB" file user:/)
KDBSPEC=$("$KDB" file spec:/)

"$KDB" rm -rf --without-elektra system || rm -f "$KDBSYSTEM"

"$KDB" rm -rf user || rm -f "$KDBUSER"
"$KDB" rm -rf spec || rm -f "$KDBSPEC"
