#!/bin/bash
set -e

pkg=king-probe

export LC_ALL=C.UTF-8
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 -a /usr/share/doc/${pkg}/examples/* "${AUTOPKGTEST_TMP}"

cd "${AUTOPKGTEST_TMP}"

gunzip -r *
cd data

# For change of results see here: https://github.com/rlabduke/probe/issues/9

set -x
echo -e "\e[93m\e[1mTest 1\e[0m"
king-probe 6ins.pdb1 >> 6ins.kin
tail +2 6ins.kin > 6ins.kin.head
echo "e6f6d229b1a5d3a73fcb841dd26a1096  6ins.kin.head" > checksum
md5sum --check checksum
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 2\e[0m"
king-probe -count -self all 6ins.pdb1 > 6ins.dotinfo.table
tail +2 6ins.dotinfo.table > 6ins.dotinfo.table.head
echo "173ae675328752a3e2d6ac693c5870cf  6ins.dotinfo.table.head" > checksum
md5sum --check checksum
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 3\e[0m"
king-probe -unformated -self "all" 6ins.pdb1 > 6ins.rawinfo.table
tail +2 6ins.rawinfo.table > 6ins.rawinfo.table.head
echo "40815736c8cd023fd1a2854d9e66e3d9  6ins.rawinfo.table.head" > checksum
md5sum --check checksum
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 4\e[0m"
king-probe -out all 6ins.pdb1 >> 6ins.surfacedots.kin
tail +2 6ins.surfacedots.kin > 6ins.surfacedots.kin.head
echo "1aff859a65fc961274f6db4ea499ca25  6ins.surfacedots.kin.head" > checksum
md5sum --check checksum
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 5\e[0m"
king-probe -both chainE chainF 6ins.pdb1 >> 6insEF.kin
tail +2 6insEF.kin > 6insEF.kin.head
echo "42433d0201ba33d134be0a312930ca20  6insEF.kin.head" > checksum
md5sum --check checksum
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 6\e[0m"
king-probe -once all all 6ins.pdb1 1zni.pdb1 >> 6ins_1zni.kin
tail +2 6ins_1zni.kin > 6ins_1zni.kin.head
echo "e3cacbc705b23c3acfb233c5f19c8e58  6ins_1zni.kin.head" > checksum
md5sum --check checksum
echo -e "\e[92m\e[1mPassed\e[0m"
echo
