#!/bin/sh

#
# Cleanup left over files -- both before and after test run
#

. scripts/functions

if [ ! -f ${working}/CLEANUPMARKER ]; then
    print_debug "SKIPPED: cleanup. Looks like it is already clean."
    exit 0
fi

cwd=`pwd`

rm -rf ${tmp}/*
rm -rf ${working}/log
rm -rf ${working}/*.bsr ${working}/log*.sd
rm -rf ${working}/*.trace ${working}/*.traceback ${working}/*.bactrace
rm -rf ${working}/*.state
rm -rf ${working}/CLEANUPMARKER
rm -rf ${working}/plugins/*
find . -name "gigaslam.gif" -exec rm -f {} \;
# cleanup old config files
# don't delete mtx-changer.conf (and other files?)
rm -f  ${conf}/*.cert
rm -f  ${conf}/bareos*.conf
rm -f  ${conf}/bconsole*.conf
rm -rf ${conf}/*.d/
rm -f  ${conf}/*.pem
rm -rf ${conf}/bareos-dir-export/
rm -rf ${conf}/tls/


# bin directory does not always exist
if [ -d ${scripts} ]; then
  if [ -f ${scripts}/bareos ]; then
     ${scripts}/bareos stop 2>&1 >/dev/null
  fi
  ${scripts}/drop_bareos_tables ${DBTYPE} >/dev/null 2>&1
  print_debug "creating database (${DBTYPE})"
  ${scripts}/create_bareos_tables ${DBTYPE} >/dev/null 2>&1
  ${scripts}/make_bareos_tables ${DBTYPE} >/dev/null 2>&1
  ${scripts}/grant_bareos_privileges ${DBTYPE} >/dev/null 2>&1
fi
