4e45f8462389ef93ab102f826de46ee52db398d6
[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 -p python2.7 $1
11     elif command -v virtualenv2; then
12         virtualenv2 -p python2.7 $1
13     elif command -v virtualenv; then
14         virtualenv -p python2.7 $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 [[ ! $(rpm -qa | grep python-2.7) ]]; then
29     echo "Python 2.7 not found, but required...attempting to install"
30     sudo yum install -y python-2.7*
31 fi
32
33 if [ ! -f "$BASEDIR/venv/updated" -o $BASEDIR/requirements.pip -nt $BASEDIR/venv/updated ]; then
34     source $BASEDIR/venv/bin/activate
35     pip install -r $BASEDIR/requirements.pip
36     touch $BASEDIR/venv/updated
37     echo "Requirements installed."
38     deactivate
39 fi
40 set +e