Publish opnfvdocs pieman branch
[releng.git] / utils / lab-reconfiguration / create_venv.sh
1 #!/bin/bash -e
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Cisco and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 # Script checks that venv exists. If it doesn't it will be created
11 # It requires python2.7 and virtualenv packages installed
12
13 BASEDIR=`dirname $0`
14
15 function venv_install() {
16     if command -v virtualenv-2.7; then
17         virtualenv-2.7 -p python2.7 $1
18     elif command -v virtualenv2; then
19         virtualenv2 -p python2.7 $1
20     elif command -v virtualenv; then
21         virtualenv -p python2.7 $1
22     else
23         echo Cannot find virtualenv command.
24         return 1
25     fi
26 }
27
28 # exit when something goes wrong during venv install
29 set -e
30 if [ ! -d "$BASEDIR/venv" ]; then
31     venv_install $BASEDIR/venv
32     echo "Virtualenv created."
33 fi
34
35 if [[ ! $(rpm -qa | grep python-2.7) ]]; then
36     echo "Python 2.7 not found, but required...attempting to install"
37     sudo yum install -y python-2.7*
38 fi
39
40 if [ ! -f "$BASEDIR/venv/updated" -o $BASEDIR/requirements.pip -nt $BASEDIR/venv/updated ]; then
41     source $BASEDIR/venv/bin/activate
42     pip install -r $BASEDIR/requirements.pip
43     touch $BASEDIR/venv/updated
44     echo "Requirements installed."
45     deactivate
46 fi
47 set +e