-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_virtualenv.sh
executable file
·105 lines (89 loc) · 2.87 KB
/
set_virtualenv.sh
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bash
# Copyright 2017 Janos Czentye
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Install script for ESCAPEv2 to setup virtual environment
# Copyright 2016 Janos Czentye <czentye@tmit.bme.hu>
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
# Fail on error
trap on_error ERR
function on_error {
echo -e "${RED}Error during installation!${NC}"
exit 1
}
function info() {
echo -e "${GREEN}$1${NC}"
}
function print_usage {
echo -e "Usage: $0 [-p python_version] [-h]"
echo -e "Install script for ESCAPEv2 to setup virtual environment\n"
echo -e "optional parameters:"
echo -e "\t-p: set Python version (default: $VERSION)"
echo -e "\t-h: show this help message and exit"
echo -e "Example: ./set_virtualenv.sh -p 2.7.13"
echo -e "Based on virtualenv. More information: virtualenv -h"
exit 0
}
# Default variables
VERSION=2.7.13
ENABLE=".use_virtualenv"
# Read initial parameters
while getopts ":p:h" OPTION;
do
case ${OPTION} in
p)
VERSION=${OPTARG};;
h)
print_usage;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1;;
esac
done
info "======================================="
info "== Install virtualenv for ESCAPEv2 =="
info "======================================="
echo "Used Python version: $VERSION"
info "=== Download Python in a separate folder ==="
wget "https://www.python.org/ftp/python/${VERSION}/Python-${VERSION}.tar.xz"
info "=== Installing dependencies ==="
sudo apt-get update && sudo apt-get install -y python-dev python-pip zlib1g-dev \
libxml2-dev libxslt1-dev libssl-dev libffi-dev python-crypto
sudo pip install virtualenv
info "=== Compile and install Python ==="
tar xvJf "Python-${VERSION}.tar.xz"
cd ./"Python-${VERSION}"
PYTHON_DIR=$PWD
./configure --prefix=${PYTHON_DIR}
make altinstall
make install
cd ..
PROJECT_DIR=$PWD
cd ..
info "=== Set up virtualenv ==="
virtualenv --python="${PYTHON_DIR}/bin/python" --no-site-packages ${PROJECT_DIR}
info "=== Install Python dependencies into virtual environment ==="
cd ${PROJECT_DIR}
source ./bin/activate
pip install numpy jinja2 py2neo networkx requests ncclient pyyaml cryptography==1.3.1
deactivate
info "=== Enable virtualenv for 'escape.py' script ==="
echo ${ENABLE} && touch ${ENABLE}
info "============"
info "== Done =="
info "============"