#!/bin/bash
set -e

pkg=aevol

if [ "${AUTOPKGTEST_TMP}" = "" ] ; then
  AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
  # Double quote below to expand the temporary directory variable now versus
  # later is on purpose.
  # shellcheck disable=SC2064
  trap "rm -rf ${AUTOPKGTEST_TMP}" 0 INT QUIT ABRT PIPE TERM
fi

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

cd "${AUTOPKGTEST_TMP}"
gunzip -r *

for exampledir in $(find . -maxdepth 1 -mindepth 1 -type d) ; do
  cd $exampledir
  if [ $(basename $exampledir) = "eukaryote" ] ; then
    echo "Advise in README.md fails with:"
    echo "  ERROR in param file "param.in" on line 14: selfing is only valid in the eukaryote setting."
    echo "aevol_create_2b param.in --fasta WT0.fa"
    echo "aevol_eukaryote_2b_run --begin 0 --end 1000 --parallel -1"
  else
    aevol_create_2b param.in
    aevol_run_2b
  fi
  cd ..
done

