#this script should exist under $GLOBUS_LOCATION of the node which is running RefextractService so that it can be sent with the Refextract job
echo "Running refextract script..."

#if refextract exists in execution node
if [ -d "$GLOBUS_LOCATION"/refextract_package ]; then
echo "Refextract is installed in execution node"
cp -r "$GLOBUS_LOCATION"/refextract_package .
#if refextract is not installed in execution node, we exit with error
else
echo "Refextract is NOT installed in execution node in directory $GLOBUS_LOCATION/refextract_package"
exit 1
fi

PACKAGE_PATH=./refextract_package
INIT_PATH=$PACKAGE_PATH/run.py

## Set the INVENIO location
export PYTHONPATH=$PACKAGE_PATH/lib/python

echo '>>> pythonpath: '$PYTHONPATH
echo '>>> python_main: '$PYTHON_MAIN
echo '>>> current dir:'
pwd
echo '>>> list of directories:'
ls
echo '>>> Running refextract: $INIT_PATH...'
python $INIT_PATH

# Delete temporary directory
echo "Deleting temporary directory of refextract"
rm -rf ./refextract_package
exit 0

