#!/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

echo -e "\e[93m\e[1mTest 1\e[0m"
king-probe 6ins.pdb1 >> 6ins.kin
tail +2 6ins.kin > 6ins.kin.head
echo "2e8e38fca908f21e53f47bd3a9411219  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 "23e6de91706f44a691ab0571ea50bcbb  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 "2a063119f359eb3ac5728788b372c8db  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 "bcea879aa884d7686e5213a9e9c935b4  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 "29f07cd1e66b932f66db395264a6160a  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 "b14361cd9e8fe621e74174bc24042adb  6ins_1zni.kin.head" > checksum
md5sum --check checksum
echo -e "\e[92m\e[1mPassed\e[0m"
echo
