#!/bin/sh
set -e

TEMP=${AUTOPKGTEST_TMP:-${TMPDIR:-/tmp}}
TDIR=$(mktemp -d $TEMP/smokeXXXXXX)
TESTRUNNER='testrunner.sh'
export TERM=xterm-color
export LC_ALL=C.UTF-8

# create temporary directory
mkdir -p ${TDIR}

# copy testfiles
cp -a test ${TDIR}

# create fake (empty) out directory which is expected by
# the testrunner.sh script
mkdir -p ${TDIR}/out

# copy installed /etc/boxes/boxes-config and use it in
# tests
cp -a /etc/boxes/boxes-config ${TDIR}

# change directory to temporary test directory
cd ${TDIR}/test

# replace variables for binary and config to
# actually test the installed boxes binary
sed -i -e 's|boxesBinary=${OUT_DIR}/boxes$|boxesBinary=/usr/bin/boxes|g' ${TESTRUNNER}

# run the testrunner
./${TESTRUNNER} --suite
