#! /bin/bash

set -ex

VERSIONS_TO_INSTALL=${1}
if [[ ! -n ${VERSIONS_TO_INSTALL} ]]; then
  VERSIONS_TO_INSTALL=${PYTHON_VERSIONS}
fi
if [[ ! -n ${VERSIONS_TO_INSTALL} ]]; then
  echo "Either PYTHON_VERSIONS must be set or provide and argument containing required versions"
  exit 1
fi

IFS=',' read -r -a array <<< ${VERSIONS_TO_INSTALL}
for python_version in "${array[@]}"; do
  echo "###### Installing Python ${python_version} ######"
  YUM_PY_VERSION=$(echo ${python_version} | tr -d '.')
  yum install -y rh-python${YUM_PY_VERSION}-python-devel

  echo "###### Creating Virtualenv for Python ${python_version} ######"
  source /opt/rh/rh-python${YUM_PY_VERSION}/enable
  pip install pip wheel setuptools --upgrade
done
