19d9b49c4a555a11b94f5b2dae473b4df4e46a30
[releng.git] / utils / lab-reconfiguration / create_venv.sh
1 #!/bin/bash -e
2
3 # Script checks that venv exists. If it doesn't it will be created
4 # It requires python2.7 and virtualenv packages installed
5
6 BASEDIR=`dirname $0`
7
8 function venv_install() {
9     if command -v virtualenv-2.7; then
10         virtualenv-2.7 $1
11     elif command -v virtualenv2; then
12         virtualenv2 $1
13     elif command -v virtualenv; then
14         virtualenv $1
15     else
16         echo Cannot find virtualenv command.
17         return 1
18     fi
19 }
20
21 # exit when something goes wrong during venv install
22 set -e
23 if [ ! -d "$BASEDIR/venv" ]; then
24     venv_install $BASEDIR/venv
25     echo "Virtualenv created."
26 fi
27
28 if [ ! -f "$BASEDIR/venv/updated" -o $BASEDIR/requirements.pip -nt $BASEDIR/venv/updated ]; then
29     source $BASEDIR/venv/bin/activate
30     pip install -r $BASEDIR/requirements.pip
31     touch $BASEDIR/venv/updated
32     echo "Requirements installed."
33     deactivate
34 fi
35 set +e