diff --git a/bill_man b/bill_man index 72bdfd4..73a4766 100755 --- a/bill_man +++ b/bill_man @@ -1,3 +1,35 @@ #!/bin/bash -PATH=$VIRTUAL_ENV/bin:$PATH exec python bill_man.py $1 +PYTHON_VERSION="X$(python -V 2>&1)" +if [[ "X$?" == "X0" && "X$(echo ${PYTHON_VERSION}|cut -f 2 -d ' ' |cut -f 1 -d '.')" == "X3" ]] ; then + PYTHON="$(which python)" +fi + +PYTHON_VERSION="X$(python3 -V 2>&1)" +if [[ "X$?" == "X0" && "X$(echo ${PYTHON_VERSION}|cut -f 2 -d ' ' |cut -f 1 -d '.')" == "X3" ]] ; then + PYTHON="$(which python3)" +fi + +if [[ "X${PYTHON}" == "X" ]] ; then + (>&2 echo "python3 not detected") + exit 1 +else + (>&2 echo "detected python3 : ${PYTHON}") +fi + +if [[ "X${VIRTUAL_ENV}" == "X" ]] ; then + VIRTUAL_ENV="$(pwd)/venv" +fi + +if [[ ! -d "${VIRTUAL_ENV}" && ! -x "${VIRTUAL_ENV}/bin/activate" ]] ; then + (>&2 echo "virtual envioment not detected. let's installing.... in ${VIRTUAL_ENV}") + "${PYTHON}" -m venv "${VIRTUAL_ENV}" + source "${VIRTUAL_ENV}/bin/activate" + pip install -r requirements.txt +else + (>&2 echo "detected virtual environment : ${VIRTUAL_ENV}") + source "${VIRTUAL_ENV}/bin/activate" +fi +PYTHON="${VIRTUAL_ENV}/bin/python" + +exec python bill_man.py $@