-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev_init.sh
executable file
·228 lines (199 loc) · 4.73 KB
/
dev_init.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/bash
#############
# FUNCTIONS #
#############
# the usage of this script
function usage()
{
echo
echo "${0##*/} [-y] [-u] [-h]"
echo
echo "Initializes the virtual environment for the UFDL backend."
echo
echo " -h this help"
echo " -y do not prompt user, assume 'yes'"
echo " -u update any repositories first"
echo " -r skip database reset"
echo
}
function check_executable()
{
echo "Checking $EXEC..."
if [ ! -x "/usr/bin/$EXEC" ]
then
AVAILABLE=false
if [ "$REQUIRED" = "true" ]
then
echo
echo "$EXEC executable not present!"
echo "Install on Debian systems with:"
echo "sudo apt-get install $EXEC $ADDITIONAL"
echo
exit 1
else
echo "...NOT present"
fi
else
echo "...is present"
AVAILABLE=true
fi
}
function check_repository()
{
echo "Checking repo $REPO..."
if [ ! -d "../$REPO" ]
then
echo
echo "Directory ../$REPO does not exist!"
echo "Check out repo as follows:"
echo "cd .."
echo "git clone https://github.com/waikato-ufdl/$REPO.git"
echo
exit 1
else
echo "...is present"
fi
}
function update_repository()
{
echo "Updating repo $REPO..."
CURRENT="`pwd`"
cd "../$REPO"
git pull
cd "$CURRENT"
}
##############
# PARAMETERS #
##############
VENV="venv.dev"
PROMPT="yes"
UPDATE="no"
RESET="yes"
while getopts ":hyur" flag
do
case $flag in
y) PROMPT="no"
;;
u) UPDATE="yes"
;;
h) usage
exit 0
;;
r) RESET="no"
;;
*) usage
exit 1
;;
esac
done
##########
# CHECKS #
##########
echo "Performing checks"
EXEC="virtualenv"
ADDITIONAL=""
REQUIRED=true
check_executable
EXEC="python3.8"
ADDITIONAL="python3.8-dev"
REQUIRED=false
check_executable
PYTHON38_AVAILABLE=$AVAILABLE
EXEC="python3.10"
ADDITIONAL="python3.10-dev"
REQUIRED=false
check_executable
PYTHON310_AVAILABLE=$AVAILABLE
if [ "$PYTHON38_AVAILABLE" = "true" ]
then
PYTHON=python3.8
elif [ "$PYTHON310_AVAILABLE" = "true" ]
then
PYTHON=python3.10
else
echo
echo "Neither Python 3.8 nor Python 3.10 available!"
echo "Install on Debian systems with:"
echo " sudo apt-get install python3.8 python3.8-dev"
echo "or:"
echo " sudo apt-get install python3.10 python3.10-dev"
echo
exit 1
fi
REPO="ufdl-json-messages"
check_repository
REPO="ufdl-job-types"
check_repository
REPO="ufdl-job-contracts"
check_repository
#############
# EXECUTION #
#############
if [ "$PROMPT" = "yes" ]
then
echo
echo "Press any key to start setup of '$VENV' for running UFDL backend (using $PYTHON)..."
read -s -n 1 key
fi
# update repos
if [ "$UPDATE" = "yes" ]
then
REPO="ufdl-json-messages"
update_repository
REPO="ufdl-job-types"
update_repository
REPO="ufdl-job-contracts"
update_repository
echo "Updating this repo..."
git pull
fi
# delete old directory
if [ -d "./$VENV" ]
then
echo "Removing old virtual environment..."
rm -rf ./$VENV
fi
# deleting old "build" directories
echo "Removing old 'build' directories..."
find . -type d -name build -exec rm -R {} \; 2>/dev/null
find ../ufdl-json-messages -type d -name build -exec rm -R {} \; 2>/dev/null
find ../ufdl-job-types -type d -name build -exec rm -R {} \; 2>/dev/null
find ../ufdl-job-contracts -type d -name build -exec rm -R {} \; 2>/dev/null
echo "Creating new virtual environment $VENV..."
virtualenv -p /usr/bin/$PYTHON ./$VENV
echo "Installing dependencies..."
./$VENV/bin/pip install --upgrade pip
./$VENV/bin/pip install --upgrade setuptools==59.4.0
./$VENV/bin/pip install Cython
./$VENV/bin/pip install numpy
./$VENV/bin/pip install "opencv-python<4.2.0"
# check for nvidia-smi and install GPU version
if [ -f "/usr/bin/nvidia-smi" ]
then
./$VENV/bin/pip install tensorflow-gpu
else
./$VENV/bin/pip install tensorflow
fi
echo "Installing UFDL modules..."
./$VENV/bin/pip install ../ufdl-json-messages/
./$VENV/bin/pip install ../ufdl-job-types/
./$VENV/bin/pip install ../ufdl-job-contracts/
./$VENV/bin/pip install ufdl-core-app/
./$VENV/bin/pip install ufdl-image-classification-app/
./$VENV/bin/pip install ufdl-image-segmentation-app/
./$VENV/bin/pip install ufdl-object-detection-app/
./$VENV/bin/pip install ufdl-spectrum-classification-app/
./$VENV/bin/pip install ufdl-speech-app/
./$VENV/bin/pip install ufdl-html-client-app/
./$VENV/bin/pip install ufdl-api-site/
if [ "$RESET" = "yes" ]
then
echo "Configuring backend (admin/admin user)..."
./$VENV/bin/python -m ufdl.api_site.scripts.reset
fi
echo "Start dev server with:"
echo " ./$VENV/bin/python -m ufdl.api_site.scripts.run [BIND]"
echo "Server is then running on:"
echo " localhost:8000"
echo "Using '-b 0.0.0.0' as BIND address will make the server available on"
echo "port 8000 outside of localhost."