#!/usr/bin/env bash
#
# This script creates a virtualenv named 'env' and installs all
# python dependencies before activating the env and running Electrum.
# If 'env' already exists, it is activated and Electrum is started
# without any installations. Additionally, the PYTHONPATH environment
# variable is set properly before running Electrum.
#
# python-qt and its dependencies will still need to be installed with
# your package manager.

PYTHON_VER="$(python3 -c 'import sys; print(sys.version[:3])')"

cd $(dirname $0)
if [ -e ./env/bin/activate ]; then
    source ./env/bin/activate
else
    virtualenv env -p `which python3`
    source ./env/bin/activate
    python3 -m pip install .[fast]
fi

export PYTHONPATH="/usr/local/lib/python${PYTHON_VER}/site-packages:$PYTHONPATH"

./run_electrum "$@"

deactivate