#!/bin/sh -e

PROKKADBPATH=/var/lib/prokka/db

if which prokka >/dev/null ; then
   # PROKKAVERSION=`prokka -v | sed 's/^.*[[:space:]]\+//'`
   # Sometimes prokka reports wrong version
   PROKKAVERSION=`apt-cache policy prokka | grep "^ \*\*\*" | sed 's/^ \*\*\* \([.0-9]\+\)[+-].*/\1/'`
else
   echo "prokka not installed."
   exit 1
fi
set -x
wget -np -N https://github.com/tseemann/prokka/archive/v${PROKKAVERSION}.tar.gz
for data in hmm kingdom ; do
    tar -xaf v${PROKKAVERSION}.tar.gz --no-anchored "$data"
    rm -rf ${PROKKADBPATH}/$data
    mv prokka-${PROKKAVERSION}/db/$data ${PROKKADBPATH}
done
prokka --setupdb
find ${PROKKADBPATH} -type f -exec chmod a+wr \{\} \;
for data in hmm kingdom ; do
    find ${PROKKADBPATH}/$data -type d -exec chmod a+wrx \{\} \;
done
