#!/bin/sh

# Fix nl_shared.conf to have proper config_base value
if grep -q "^config_base=/change/me" ./etc/nl_shared.conf; then
  pwd=`pwd`
  sed -i '' "s:config_base=/change/me:config_base=${pwd}:" ./etc/nl_shared.conf
fi

# Pick up shared variable definitions
. ./etc/nl_shared.conf

# Remove various files created when running.
rm -f ${log_file} \
skipped.log \
${parser_output}* \
nl_*.log \
./var/log/*.log \
./var/run/*.state \
./var/run/*.pid

# Drop and re-create the entire test DB in both sqlite and mysql (if a
# mysql server is found to be running on localhost)

# sqlite
nl_loader -u sqlite://${sqlite_db} -D < /dev/null

# mysql
mysqladmin --no-defaults -h localhost -s ping > /dev/null 2>&1
if [ "$?" = "0" ]; then
  nl_loader -u mysql://localhost -D -p read_default_file='./my.cnf' < /dev/null
fi
