summaryrefslogtreecommitdiffstats
path: root/utils/lab-reconfiguration/create_venv.sh
blob: 4e7144c7000552f2b99839f6894ee034d7eb2d4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash -e
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2016 Cisco and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
# Script checks that venv exists. If it doesn't it will be created
# It requires python2.7 and virtualenv packages installed

BASEDIR=`dirname $0`

function venv_install() {
    if command -v virtualenv-2.7; then
        virtualenv-2.7 -p python2.7 $1
    elif command -v virtualenv2; then
        virtualenv2 -p python2.7 $1
    elif command -v virtualenv; then
        virtualenv -p python2.7 $1
    else
        echo Cannot find virtualenv command.
        return 1
    fi
}

# exit when something goes wrong during venv install
set -e
if [ ! -d "$BASEDIR/venv" ]; then
    venv_install $BASEDIR/venv
    echo "Virtualenv created."
fi

if [[ ! $(rpm -qa | grep python-2.7) ]]; then
    echo "Python 2.7 not found, but required...attempting to install"
    sudo yum install -y python-2.7*
fi

if [ ! -f "$BASEDIR/venv/updated" -o $BASEDIR/requirements.pip -nt $BASEDIR/venv/updated ]; then
    source $BASEDIR/venv/bin/activate
    pip install -r $BASEDIR/requirements.pip
    touch $BASEDIR/venv/updated
    echo "Requirements installed."
    deactivate
fi
set +e