#!/bin/bash
set -e

pkg=iva

export LC_ALL=C.UTF-8
if [ "${AUTOPKGTEST_TMP}" = "" ] ; then
  AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
  # shellcheck disable=SC2064
  trap "rm -rf ${AUTOPKGTEST_TMP}" 0 INT QUIT ABRT PIPE TERM
fi

cp -a /usr/share/doc/${pkg}/examples/* "${AUTOPKGTEST_TMP}"

cd "${AUTOPKGTEST_TMP}"

set -x
/usr/bin/iva --threads 1 --trimmomatic /usr/share/java/trimmomatic.jar --pcr_primers hiv_pcr_primers.fa -f reads_1.fq.gz -r reads_2.fq.gz iva.out
set +x

echo "Finished running iva"
CONTIGS=iva.out/contigs.fasta
if [ -s "$CONTIGS" ]; then
    echo "Looks OK. Final output contigs file is: $(readlink -f "$CONTIGS")"
    exit 0
else
    echo "Something went wrong! Final output contigs file not found: $(readlink -f "$CONTIGS")" >&2
    exit 1
fi

# iva --test --trimmomatic /usr/share/java/trimmomatic.jar "${AUTOPKGTEST_TMP}"/test

