ctf-tools/bin/ctf-tools-pip
Riccardo Schirone 86d567e4da Fix tests
* Add virtualenvwrapper script before using its functionalities
* Setup PATH env var to correctly execute install scripts in travis
2016-09-21 13:57:21 +00:00

44 lines
1,012 B
Bash
Executable file

#!/bin/bash
set -e -o pipefail
#set -x
# let's stick with python 2 as default
PY_VERSION=2
# check this scripts file ending
if [[ "$0" =~ pip3 ]]; then
PY_VERSION=3
fi
if [[ "$0" =~ pip2 ]]; then
PY_VERSION=2
fi
PY_INTERPRETER=$(which "python$PY_VERSION" || which python)
CTF_TOOLS_VE="ctftools"
if [[ $PY_VERSION -eq 3 ]]; then
CTF_TOOLS_VE="${CTF_TOOLS_VE}3"
fi
if [[ -z "${WORKON_HOME+x}" ]]; then
export WORKON_HOME="$HOME/.virtualenvs"
fi
if [[ ! -d "$WORKON_HOME" ]]; then
mkdir -p "$WORKON_HOME"
fi
VE_DIR="$WORKON_HOME/$CTF_TOOLS_VE"
if [[ ! -d "$VE_DIR" || ! -e "$VE_DIR/bin/activate" ]]; then
echo "#### Creating python$PY_VERSION virtualenv '$CTF_TOOLS_VE' ####" >&2
virtualenv --system-site-packages -p "$PY_INTERPRETER" "$VE_DIR"
fi
if [[ -z "${VIRTUAL_ENV+x}" || "$VIRTUAL_ENV" != "$VE_DIR" ]]; then
if [[ -n "${VIRTUAL_ENV+x}" ]]; then
source ${VIRTUAL_ENV}/bin/activate
deactivate
fi
source "$VE_DIR/bin/activate"
fi
exec pip "$@"