-
Notifications
You must be signed in to change notification settings - Fork 31
/
install.sh
executable file
·411 lines (353 loc) · 9.35 KB
/
install.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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
#! /bin/bash
# Copyright 2019-present Open Networking Foundation
#Copyright (c) 2017 Sprint
#
# SPDX-License-Identifier: Apache-2.0
cd $(dirname ${BASH_SOURCE[0]})
export C3PO_DIR=$PWD
echo "------------------------------------------------------------------------------"
echo " C3PO_DIR exported as $C3PO_DIR"
echo "------------------------------------------------------------------------------"
OSDIST=`lsb_release -is`
OSVER=`lsb_release -rs`
#
# Sets QUIT variable so script will finish.
#
quit()
{
QUIT=$1
}
# Shortcut for quit.
q()
{
quit
}
################################################################################
step_1()
{
TITLE="Environment setup."
CONFIG_NUM=1
TEXT[1]="Check OS and network connection"
FUNC[1]="setup_env"
CPLT[1]=$SETUP_ENV_COMPLETE
}
setup_env()
{
# a. Check for OS and version dependencies
case "$OSDIST" in
Ubuntu)
case "$OSVER" in
14.04|16.04) echo "$OSDIST version $OSVER is supported." ;;
*) echo "$OSDIST version $OSVER is unsupported." ; exit;;
esac
;;
*) echo "ERROR: Unsupported operating system distribution: $OSDIST"; exit;;
esac
echo
echo "Checking network connectivity..."
# b. Check for internet connections
wget -T 3 -t 3 --spider http://www.google.com 2>/dev/null
if [ "$?" != 0 ]; then
while true; do
read -p "No Internet connection. Are you behind a proxy (y/n)? " yn
case $yn in
[Yy]* ) $SETUP_PROXY ; return;;
[Nn]* ) echo "Please check your internet connection..." ; exit;;
* ) "Please answer yes or no.";;
esac
done
fi
SETUP_ENV_COMPLETE="- COMPLETE"
}
################################################################################
step_2()
{
TITLE="Download and Install"
CONFIG_NUM=1
TEXT[1]="Agree to download"
FUNC[1]="get_agreement_download"
CPLT[1]=$GET_AGREEMENT_DOWNLOAD_COMPLETE
case $OSDIST in
Ubuntu)
case "$OSVER" in
14.04)
TEXT[2]="Download and install Cmake 3.5.1"
FUNC[2]="install_cmake"
CPLT[2]=$INSTALL_CMAKE_COMPLETE
TEXT[3]="Download and install libtool 2.4.6"
FUNC[3]="install_libtool"
CPLT[3]=$INSTALL_LIBTOOL_COMPLETE
TEXT[4]="Download packages"
FUNC[4]="install_libs"
CPLT[4]=$INSTALL_LIBS_COMPLETE
;;
16.04)
TEXT[2]="Download packages"
FUNC[2]="install_libs"
CPLT[2]=$INSTALL_LIBS_COMPLETE
;;
*) echo "$OSDIST version $OSVER is unsupported." ; exit;;
esac
;;
*) echo "ERROR: Unsupported operating system distribution: $OSDIST"; exit;;
esac
}
get_agreement_download()
{
echo
echo "List of packages needed for C3PO build and installation:"
echo "-------------------------------------------------------"
case $OSDIST in
Ubuntu)
case $OSVER in
14.04)
echo "1. Cmake version 3.5.1"
echo "2. libtool version 2.4.6"
echo "3. Other libraries including :"
echo " gcc g++ libuv-dev libssl-dev automake libmemcached-dev memcached bison"
echo " flex libsctp-dev libgnutls-dev libgcrypt-dev libidn11-dev nettle-dev"
;;
16.04)
echo "gcc g++ make cmake libuv-dev libssl-dev autotools-dev libtool-bin"
echo "m4 automake libmemcached-dev memcached cmake-curses-gui gcc bison"
echo "flex libsctp-dev libgnutls-dev libgcrypt-dev libidn11-dev nettle-dev"
;;
*) echo "$OSDIST version $OSVER is unsupported." ; exit;;
esac
;;
*) echo "ERROR: Unsupported operating system distribution: $OSDIST"; exit;;
esac
while true; do
echo
read -p "We need to download and install the above mentioned packages. Press (y/n) to continue? " yn
case $yn in
[Yy]* )
touch .agree
break;;
[Nn]* ) exit;;
* ) "Please answer yes or no.";;
esac
done
GET_AGREEMENT_DOWNLOAD_COMPLETE="- COMPLETE"
}
install_cmake()
{
file_name=".agree"
if [ ! -e "$file_name" ]; then
echo "Please choose option '2.Agree to download' first"
return
fi
sudo apt-get purge cmake cmake-curses-gui
sudo apt-get install g++ make autotools-dev m4 libncurses-dev
pushd modules
rm -rf cmake-3.5.1
rm -rf cmake-3.5.1.tar.gz
wget https://cmake.org/files/v3.5/cmake-3.5.1.tar.gz
tar -xvf cmake-3.5.1.tar.gz
cd cmake-3.5.1
./bootstrap && make -j4 && sudo make install
popd
INSTALL_CMAKE_COMPLETE="-COMPLETE"
}
install_libtool()
{
file_name=".agree"
if [ ! -e "$file_name" ]; then
echo "Please choose option '2.Agree to download' first"
return
fi
pushd modules
rm -rf libtool-2.4.6
rm -rf libtool-2.4.6.tar.gz
wget http://ftp.gnu.org/gnu/libtool/libtool-2.4.6.tar.gz
tar -xvf libtool-2.4.6.tar.gz
cd libtool-2.4.6
./configure && make && sudo make install
popd
INSTALL_LIBTOOL_COMPLETE="- COMPLETE"
}
install_libs()
{
echo "Install packages needed to build and run the C3PO components..."
file_name=".agree"
if [ ! -e "$file_name" ]; then
echo "Please choose option '2.Agree to download' first"
return
fi
file_name=".download"
if [ -e "$file_name" ]; then
clear
INSTALL_LIBS_COMPLETE="- COMPLETE"
return
fi
sudo apt-get update > /dev/null
case $OSDIST in
Ubuntu)
case "$OSVER" in
14.04) sudo apt-get install libuv-dev libssl-dev automake libmemcached-dev memcached gcc bison flex libsctp-dev libgnutls-dev libgcrypt-dev libidn11-dev nettle-dev ;;
16.04) sudo apt-get install g++ make cmake libuv-dev libssl-dev autotools-dev libtool-bin m4 automake libmemcached-dev memcached cmake-curses-gui gcc bison flex libsctp-dev libgnutls-dev libgcrypt-dev libidn11-dev nettle-dev ;;
*) echo "$OSDIST version $OSVER is unsupported." ; exit;;
esac
;;
*) echo "ERROR: Unsupported operating system distribution: $OSDIST"; exit;;
esac
touch .download
INSTALL_LIBS_COMPLETE="- COMPLETE"
}
################################################################################
step_3()
{
TITLE="Build and Install Project Submodules"
CONFIG_NUM=1
TEXT[1]="Build and install the submodules"
FUNC[1]="init_submodules"
CPLT[1]=$INIT_SUBMODULES_COMPLETE
# TEXT[2]="Build and install freeDiameter"
# FUNC[2]="build_freeDiameter"
# CPLT[2]=$BUILD_FREEDIAMETER_COMPLETE
# TEXT[3]="Build and install c-ares"
# FUNC[3]="build_c_ares"
# CPLT[3]=$BUILD_C_ARES_COMPLETE
# TEXT[4]="Build and install cpp-driver"
# FUNC[4]="build_cpp_driver"
# CPLT[4]=$BUILD_CPP_DRIVER_COMPLETE
# TEXT[5]="Build and install pistache"
# FUNC[5]="build_pistache"
# CPLT[5]=$BUILD_PISTACHE_COMPLETE
}
init_submodules()
{
git submodule init
git submodule update
build_freeDiameter
build_c_ares
build_cpp_driver
build_pistache
build_rapidjson
sudo ldconfig
INIT_SUBMODULES_COMPLETE="- COMPLETE"
}
build_freeDiameter()
{
pushd modules/freeDiameter
rm -rf build
mkdir -p build
cd build
cmake ..
awk '{if (/^DISABLE_SCTP/) gsub(/OFF/, "ON"); print}' CMakeCache.txt > tmp && mv tmp CMakeCache.txt
make
sudo make install
popd
BUILD_FREEDIAMETER_COMPLETE="- COMPLETE"
}
build_c_ares()
{
pushd modules/c-ares
./buildconf
./configure
make
sudo make install
popd
BUILD_C_ARES_COMPLETE="- COMPLETE"
}
build_cpp_driver()
{
pushd modules/cpp-driver
rm -rf build
mkdir -p build
cd build
cmake ..
make
sudo make install
popd
BUILD_CPP_DRIVER_COMPLETE="- COMPLETE"
}
build_pistache()
{
pushd modules/pistache
rm -rf build
mkdir -p build
cd build
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release ..
make
sudo make install
popd
BUILD_PISTACHE_COMPLETE="- COMPLETE"
}
build_rapidjson() {
echo "Installing rapidjson"
pushd modules/rapidjson
rm -rf build
mkdir -p build
cd build
cmake ..
make
sudo make install
popd
}
################################################################################
step_4()
{
TITLE="Build all C3PO components"
CONFIG_NUM=1
TEXT[1]="Build all C3PO components"
FUNC[1]="build_c3po"
CPLT[1]=$BUILD_C3PO_COMPLETE
}
build_c3po()
{
make clean
make
BUILD_C3PO_COMPLETE="- COMPLETE"
}
################################################################################
SETUP_PROXY="setup_http_proxy"
STEPS[1]="step_1"
STEPS[2]="step_2"
STEPS[3]="step_3"
STEPS[4]="step_4"
QUIT=0
# clear the .argee file
rm -rf .agree
clear
#echo -n "Checking for user permission.. "
#sudo -n true
#if [ $? -ne 0 ]; then
# echo "Password-less sudo user must run this script" 1>&2
# exit 1
#fi
#echo "Done"
#clear
while [ "$QUIT" == "0" ]; do
OPTION_NUM=1
for s in $(seq ${#STEPS[@]}) ; do
${STEPS[s]}
echo "----------------------------------------------------------"
echo " Step $s: ${TITLE}"
echo "----------------------------------------------------------"
for i in $(seq ${#TEXT[@]}) ; do
echo "[$OPTION_NUM] ${TEXT[i]} ${CPLT[i]}"
OPTIONS[$OPTION_NUM]=${FUNC[i]}
let "OPTION_NUM+=1"
done
# Clear TEXT and FUNC arrays before next step
unset TEXT
unset FUNC
unset CPLT
echo ""
done
echo "[$OPTION_NUM] Exit Script"
OPTIONS[$OPTION_NUM]="quit"
echo ""
echo -n "Option: "
read our_entry
${OPTIONS[our_entry]} ${our_entry}
if [ "$QUIT" == "0" ] ; then
echo
echo -n "Press enter to continue ..."; read
clear
continue
exit
fi
echo "Installation complete. Please refer to README.md for more information"
done