#!/bin/bash

set -euo pipefail


if [ -d python-for-mdq ] ; then
    echo "Activating 'python-for-nzut'"

    # Python 3.4 has unbound variables in its activate script
    # => supress this check just for the source step
    set +u
    source ./python-for-mdq/bin/activate
    set -u
    
    # version for git bash on Windows
    #source ./python-for-mdq/Scripts/activate

else
    echo "====" >&2
    echo "Warning: Failed to find:'python-for-mdq/'" >&2
    echo "Have you installed the Python venv for MDQ (Metadata Quality)?" >&2
    echo "====" >&2
fi



# For older Pythons, e.g. 3.4, don't want to update pip because it then
# installs a version of pip that uses python syntax that is ahead of
# the syntax that Python 3.4 supports.  I kid you not!
#
## Upgrade pip if needed to prevent potential warning messages about it
## being out of date
#





if python -c 'import sys; sys.exit(0 if sys.version_info[:2] == (3, 4) else 1)' 2>/dev/null; then
    echo "---"
    echo "Detected legacy Python v3.4"
    echo "Installer bepoke versions of packages (both 'apt install' and 'pip install')"
    echo "---"

    #sudo apt-get install --allow-unauthenticated pkg-config libfreetype6-dev libpng12-dev
    
    for pkg in pkg-config libfreetype6-dev libpng12-dev ; do
	apt list --installed $pkg >/dev/null 2>&1

	if [ $? != 0 ] ; then
	    sudo apt-get install --allow-unauthenticated $pkg
	fi
    done

    pip install numpy==1.15.4 kiwisolver==1.0.1 pyparsing==2.4.7 cycler==0.10.0 python-dateutil==2.8.1
    pip install -r requirements34.txt
    
else
    python -m pip install --upgrade pip

    pip install -r requirements.txt

fi

