#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 in glite..."

echo "Downloading refextract software..."
# the following wget is replaced by a valid http location before sending this script (WARNING: make sure that another @ doesn't ever exist in this script if it changes)
wget @

echo "Unpacking   refextract software..."
tar -xvf org.gcube.application.inspire-refextract-servicearchive*
mkdir ./refextract_package
cp ./RefExtract/RefExtract*.tar.gz ./refextract_package/
cd ./refextract_package
tar -xvf RefExtract*.tar.gz
cd ..

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 $PACKAGE_PATH/bin/refextract

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

exit 0
