-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·329 lines (270 loc) · 8.36 KB
/
bootstrap.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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#!/usr/bin/env bash
export LC_ALL=C
NON_INTERCATIVE="false"
for arg in "$@"; do
if [ "--debug" == "$arg" ]; then
set -x
set -e
fi
if [ "-y" == "$arg" ]; then
NON_INTERCATIVE="true"
fi
done
BASE_URL="https://github.com/softfire-eu"
MANAGERS="experiment-manager physical-device-manager nfv-manager security-manager sdn-manager monitoring-manager"
VENV_NAME="$HOME/.softfire"
SESSION_NAME="softfire"
CODE_LOCATION="/opt/softfire"
CONFIG_LOCATION="/etc/softfire"
CONFIG_FILE_LINKS="https://raw.githubusercontent.com/softfire-eu/experiment-manager/master/etc/experiment-manager.ini \
https://raw.githubusercontent.com/softfire-eu/security-manager/master/etc/template/security-manager.ini \
https://raw.githubusercontent.com/softfire-eu/physical-device-manager/master/etc/physical-device-manager.ini \
https://raw.githubusercontent.com/softfire-eu/physical-device-manager/master/etc/physical-resources.json \
https://raw.githubusercontent.com/softfire-eu/nfv-manager/master/etc/nfv-manager.ini \
https://raw.githubusercontent.com/softfire-eu/nfv-manager/master/etc/available-nsds.json \
https://raw.githubusercontent.com/softfire-eu/experiment-manager/develop/etc/mapping-managers.json \
https://raw.githubusercontent.com/softfire-eu/monitoring-manager/master/etc/monitoring-manager.ini \
https://github.com/softfire-eu/nfv-manager/raw/master/etc/openstack-credentials.json \
https://github.com/softfire-eu/sdn-manager/raw/master/etc/sdn-resources.json \
https://github.com/softfire-eu/sdn-manager/raw/master/etc/sdn-manager.ini"
SECURITY_MANAGER_FOLDER="${CONFIG_LOCATION}/security-manager"
function install_deb_requirements {
sudo apt-get update
sudo apt-get install -y virtualenv tmux python3-pip build-essential libssl-dev libffi-dev python-dev libmysqlclient-dev wget
}
function install_pip_requirements {
pip install -r ./requirements.txt > /dev/null 2>&1
}
function install_manager() {
manager_name=$1
if [ "$2" == "--upgrade" ]; then
pip install --upgrade ${manager_name}
else
pip install ${manager_name}
fi
}
function enable_virtualenv {
echo "Creating virtualenv"
if [ ! -d ${VENV_NAME} ]; then
virtualenv --python=python3 ${VENV_NAME}
fi
echo "created virtual env"
. "$VENV_NAME/bin/activate"
}
function usage {
echo "$0 <action>"
echo ""
echo "actions: [install|update|clean|start|stop|codestart|codeupdate|codeinstall|purge]"
echo ""
echo "install: install the SoftFIRE Middleware python packages"
echo "update: update the SoftFIRE Middleware python packages"
echo "clean: clean the SoftFIRE Middleware"
echo "start: start the SoftFIRE Middleware via python packages"
echo "stop: stop the SoftFIRE Middleware"
echo "codeinstall: install the SoftFIRE Middleware source code"
echo "codeupdate: update the SoftFIRE Middleware source code"
echo "codestart: start the SoftFIRE Middleware via source code"
echo "purge: completely remove the SoftFIRE Middleware"
exit 1
}
function crate_folders {
for dir in ${CONFIG_LOCATION} "/var/log/softfire" "${CONFIG_LOCATION}/users" "${SECURITY_MANAGER_FOLDER}" "${SECURITY_MANAGER_FOLDER}/tmp"; do
if [ ! -d ${dir} ]; then
sudo mkdir -p ${dir}
sudo chown ${USER} ${dir}
fi
done
}
function download_gui {
if [ ! -d "${CONFIG_LOCATION}/views" ]; then
pushd /etc/softfire
git clone https://github.com/softfire-eu/views.git
else
pushd /etc/softfire/views
git pull
fi
popd
}
function copy_config_files {
pushd ${CONFIG_LOCATION}
for url in ${CONFIG_FILE_LINKS}; do
file_name=${url##*/}
echo "Checking $file_name"
if [ ! -f ${file_name} ]; then
wget ${url}
fi
done
popd
}
function check_session {
if tmux has-session -t ${SESSION_NAME} 2>/dev/null; then
tmux a -t ${SESSION_NAME}
exit
else
tmux new -d -s ${SESSION_NAME}
fi
}
function remove_venv {
rm -rf ${VENV_NAME}
}
function remove_databases {
# Works only for sqlite!
db_location=$(awk -F ":///" '/^url/ {print $2}' /etc/softfire/experiment-manager.ini)
rm -rf ${db_location}
db_location=$(awk -F ":///" '/^url/ {print $2}' /etc/softfire/nfv-manager.ini)
rm -rf ${db_location}
echo -n Mysql root Password:
read -s mysql_password
echo
mysql -u root -p${mysql_password} -e "drop database if exists softfire;"
}
function finish_install_message {
echo "Installation was executed. Please configure the system by changing these files:"
echo ""
for url in ${CONFIG_FILE_LINKS}; do
file_name=${url##*/}
echo "* /etc/softfire/$file_name"
done
}
function generate_users {
if [ "true" == "$NON_INTERCATIVE" ]; then
python generate_cork_files.py "${CONFIG_LOCATION}/users/" -y
else
python generate_cork_files.py "${CONFIG_LOCATION}/users/"
fi
}
function main {
if [ "0" == "$#" ]; then
usage
fi
if [ "1" == "$#" -a "--debug" == "$1" ]; then
usage
fi
if [ "--debug" == "$1" ]; then
shift
fi
action=$1
shift
args=$@
case ${action} in
"install")
install_deb_requirements
crate_folders
enable_virtualenv
for m in ${MANAGERS}; do
install_manager ${m}
done
generate_users
copy_config_files
download_gui
finish_install_message
;;
"start")
shift
shift
if [ ! $# -eq 0 ]; then
MANAGERS=$@
fi
check_session
for m in ${MANAGERS}; do
echo "Starting ${m}"
tmux neww -t ${SESSION_NAME} -n "${m}" "source $VENV_NAME/bin/activate && ${m}"
sleep 1
done
;;
"clean")
echo -n Mysql root Password:
read -s mysql_password
echo
mysql -u root -p${mysql_password} -e "drop database if exists softfire; create database softfire;"
generate_users
;;
"update")
enable_virtualenv
for m in ${MANAGERS}; do
install_manager ${m} "--upgrade"
done
download_gui
;;
"codeupdate")
pushd ${CODE_LOCATION}
for x in `ls`; do
pushd $x && git checkout . && git pull && popd;
done
popd
download_gui
;;
"codeinstall")
install_deb_requirements
crate_folders
enable_virtualenv
install_pip_requirements
if [ ! -d ${CODE_LOCATION} ]; then
sudo mkdir ${CODE_LOCATION}
sudo chown -R ${USER} ${CODE_LOCATION}
else
echo "Folder '/opt/softfire' exists already, delete it before code install"
exit 1
fi
pushd /opt/softfire
for m in ${MANAGERS}; do
git clone "${BASE_URL}/${m}.git"
pushd ${m}
exist_develop=$(git ls-remote --heads "${BASE_URL}/${m}.git" develop | wc -l)
if [ ${x}x == "1x" ]; then
git checkout develop
fi
popd
done
popd
download_gui
copy_config_files
generate_users
finish_install_message
;;
"codestart")
enable_virtualenv
install_pip_requirements
shift
shift
check_session
if [ ! $# -eq 0 ]; then
MANAGERS=$@
fi
for m in ${MANAGERS}; do
pip uninstall ${m} -y > /dev/null 2>&1
done
deactivate
tmux new -d -s ${SESSION_NAME}
for m in ${MANAGERS}; do
echo "Starting ${m}"
tmux neww -t ${SESSION_NAME} -n "${m}" "source $VENV_NAME/bin/activate && cd ${CODE_LOCATION}/${m} && ./${m}; bash; source $VENV_NAME/bin/activate "
sleep 1
done
;;
"stop")
tmux kill-session -t ${SESSION_NAME}
;;
"clean")
remove_venv
;;
"purge")
read -p "Are you sure you want to purge all (y/n)?" choice
case "$choice" in
y|Y )
remove_venv
rm -rf ${CODE_LOCATION}
# remove_databases
echo "To complete the purging, delete the folder ${CONFIG_LOCATION}"
;;
n|N )
echo "ah ok..."
;;
* )
echo "invalid choice"
;;
esac
;;
esac
}
main $@