#!/bin/bash
#set -euo pipefail
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "protein databases necessary for full clustering analysis"
echo "are downloaded from bitbucket repository using git"
echo ""
cd $DIR
git clone https://bitbucket.org/petrnovak/re_databases.git 2> $DIR/.fetchdb.log 
GITEXIT=$?
if [ $GITEXIT -eq "0" ]
then
    echo "databases successfully downloaded"
    ln -sf $DIR/re_databases/* $DIR/databases/
fi
# cat $DIR/.fetchdb.log
if [ $GITEXIT -eq "128" ]
then
    if grep -q -F "Authentication failed" $DIR/.fetchdb.log
    then
        echo "get login credential from (neumann at umbr.cas.cz)!"
    fi
    if grep -q -F "already exist" $DIR/.fetchdb.log
    then
        echo "repository alredy exists, updating..."
        cd $DIR/re_databases
        git pull && ln -f -s $DIR/re_databases/* $DIR/databases/ && find . -type f -exec touch {} +
    fi

fi






