-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
169 lines (146 loc) · 4.26 KB
/
setup.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# Setup virtual environment and set environment
# to use this framework
# Just execute `source setup.sh`
FAIL=1
SUCCESS=0
CURRENT_DIR=`pwd`
TEMP=/tmp
VENV=$CURRENT_DIR/v_env
function usage {
echo -n "
Usage:
source setup.sh
"
}
function print_echo {
echo
echo "==> $@"
}
function execute_cmd {
echo "Executing: $@"
eval $@
rc=$?
echo "Done"
echo
return $rc
}
function test_setup {
print_echo "Setting up environment variables"
PYTHONPATH=$CURRENT_DIR:$PYTHONPATH
PATH=$CURRENT_DIR:$PATH
export CURRENT_DIR PYTHONPATH PATH
echo "Done"
echo
# Remove all *.pyc files
print_echo "Removing all *.pyc files"
execute_cmd "find $CURRENT_DIR -name \"*.pyc\" -exec rm -f {} \;"
# If already in virtual environment, deactivate
print_echo "Attempting to deactivating current virutal environment, if any"
execute_cmd "deactivate 2>/dev/null"
# Create virtual environment
print_echo "Creating virtual environment at $VENV"
cmd_suffix=""
python_to_use=$(which python2.7)
if [ "$python_to_use" != "" ]; then
cmd_suffix="-p $python_to_use"
fi
execute_cmd "virtualenv $cmd_suffix $VENV"
if [ $? -ne $SUCCESS ]; then
print_echo "Could not create virtual environment"
return $FAIL
fi
# Activate virtual environment
print_echo "Activating virtual environment"
execute_cmd "source $VENV/bin/activate"
# Upgrading the pip and setuptools
print_echo "Upgrading the pip and setuptools"
execute_cmd "pip install --upgrade pip setuptools"
print_echo "Installing requirements,setting up environment"
execute_cmd "pip install -r $CURRENT_DIR/requirements.txt"
if [ $? -ne $SUCCESS ]; then
print_echo "Could not install all the requirements"
return $FAIL
fi
}
function install_virtualenv {
print_echo "Installing virtualenv using sudo (please type password if prompted)"
execute_cmd "sudo pip install -U virtualenv"
if [ $? -ne $SUCCESS ]; then
print_echo "Could not install virtualenv"
return $FAIL
fi
return $SUCCESS
}
function check_cmd_installed {
print_echo "Checking if $1 is installed or not"
execute_cmd "type $1 &> /dev/null"
if [ $? -ne $SUCCESS ]; then
print_echo "$1 is not installed"
return $FAIL
fi
print_echo "$1 is already installed"
return $SUCCESS
}
function install_pip {
print_echo "Installing PIP"
check_cmd_installed curl
if [ $? -ne $SUCCESS ]; then
print_echo "$1 is not installed"
return $FAIL
fi
print_echo "Installing pip..............."
print_echo "Downloading get-pip.py"
execute_cmd \
"curl https://bootstrap.pypa.io/get-pip.py -o $TEMP/get-pip.py"
print_echo "Installing pip using sudo (please type password if prompted)"
execute_cmd "sudo python $TEMP/get-pip.py"
if [ $? -ne $SUCCESS ]; then
print_echo "Could not install pip"
return $FAIL
fi
return $SUCCESS
}
function install_virtualenv {
print_echo "Installing Virtualenv module................."
execute_cmd "sudo pip install -U virtualenv"
if [ $? -ne $SUCCESS ]; then
print_echo "virtualenv is not installed"
return $FAIL
fi
print_echo "virtualenv is installed"
return $SUCCESS
}
function check_requirements {
print_echo "Checking if requirements are met"
requirements_met=$SUCCESS
# Check if pip is installed and install if necessary
check_cmd_installed pip || install_pip
if [ $? -ne $SUCCESS ]; then
requirements_met=$FAIL
fi
# Check if virtualenv is installed and install if necessary
check_cmd_installed virtualenv || install_virtualenv
if [ $? -ne $SUCCESS ]; then
requirements_met=$FAIL
fi
if [ $requirements_met -ne $SUCCESS ]; then
echo "Requirements are not met."
echo
return $FAIL
else
echo "Requirements are met."
echo
return $SUCCESS
fi
}
check_requirements
if [ $? -ne $SUCCESS ]; then
print_echo "Requirements are not met!!!!!!!!!! :("
fi
print_echo "Requirements are okay............ :)"
test_setup
if [ $? -ne $SUCCESS ]; then
echo "Test setup Failed!!!!!!!!!! :("
return 1
fi
print_echo "Test Setup successful............ :)"