-
Notifications
You must be signed in to change notification settings - Fork 10
/
install.sh
executable file
·858 lines (734 loc) · 25 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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
#!/bin/sh
# Copyright(c) 2022-present, Salvatore Cuzzilla (Swisscom AG)
# Distributed under the MIT License (http://opensource.org/licenses/MIT)
set -o errexit
set -o nounset
#set -o pipefail
grpc_dev_min_version=145
libjsoncpp_dev_min_version=184
librdkafka_dev_min_version=160
libconfig_dev_min_version=150
libspdlog_dev_min_version=150
libzmq3_dev_min_version=432
sysdeb_install_list="libssl-dev libfmt-dev"
sysrpm_install_list="jsoncpp-devel libconfig-devel spdlog-devel cppzmq-devel openssl-devel"
# gRPC install parameters
readonly grpc_url="https://github.com/grpc/grpc"
readonly grpc_version="v1.45.2"
readonly grpc_clone_dir="$HOME/grpc"
readonly grpc_install_dir="$HOME/.local"
# MDT install parameters
readonly mdt_url="https://github.com/network-analytics/mdt-dialout-collector.git"
readonly mdt_install_dir="/opt/mdt-dialout-collector"
# librdkafka parameters
readonly librdkafka_url="https://github.com/edenhill/librdkafka.git"
readonly librdkafka_version="v1.6.0"
readonly librdkafka_clone_dir="/opt/librdkafka"
# libjsoncpp parameters
readonly libjsoncpp_url="https://github.com/open-source-parsers/jsoncpp"
readonly libjsoncpp_version="1.8.4"
readonly libjsoncpp_clone_dir="/opt/libjsoncpp"
work_dir="$(dirname "$(readlink --canonicalize-existing "${0}" 2> /dev/null)")"
readonly epoch=$(date +'%s')
readonly available_vcpu=$(egrep 'processor' /proc/cpuinfo | wc -l)
readonly err_vcpu_failure=67
readonly err_grpc_ver_fail=68
readonly err_libjsoncpp_ver_fail=69
readonly err_librdkafka_ver_fail=70
readonly err_yum_failure=71
readonly err_apt_failure=72
readonly err_run_as_root=73
readonly err_git_clone_failure=74
readonly err_ds_release_undetected=75
readonly err_ds_undetected=76
readonly err_os_undetected=77
readonly err_cmd_notfound=78
readonly err_validating_input=79
readonly err_reading_file=80
readonly err_parsing_options=81
readonly err_missing_options=82
readonly err_unknown_options=83
readonly err_missing_options_arg=84
readonly err_unimplemented_options=85
readonly err_epel_failure=86
readonly err_mdt_ver_fail=87
readonly script_name="${0##*/}"
h_option_flag=0
b_option_flag=0
l_option_flag=0
v_option_flag=0
v_parame_flag=0
trap clean_up EXIT INT HUP
usage() {
cat <<EOF
Usage: ${script_name} [-h] | ([-b] | [-l]) && [-v <VERSION>]
DESCRIPTION:
The install.sh script automates the install process of the mdt-dialout-collector.
Both the binary & the library versions are supported.
OPTIONS:
-h
Print this help and exit.
-b
Install the standalone flavor of the mdt-dialout-collector (binary version).
-l
Install the library flavor of the mdt-dialout-collector (used with pmacct, library version).
-v <VERSION>
Specify the version of the mdt-dialout-collector to install. Use 'current' for the latest (potentially unstable) code.
Use release versions in the format 'vX.Y.Z' (e.g., 'v1.1.3') for stable code. Mandatory when using either -b or -l.
NOTE:
Either -b or -l must be chosen, but not both. Pairing with -v is required.
EOF
}
parse_user_options() {
while getopts "blhv:" opts; do
case "${opts}" in
h)
h_option_flag=1
;;
b)
b_option_flag=1
;;
l)
l_option_flag=1
;;
v)
v_option_flag=1
mdt_version="${OPTARG}"
;;
:)
die "error - mind your options/arguments - [ -h ] to know more" "${err_unknown_options}"
;;
\?)
die "error - mind your options/arguments - [ -h ] to know more" "${err_missing_options_arg}"
;;
*)
die "error - mind your options/arguments - [ -h ] to know more" "${err_unimplemented_options}"
;;
esac
done
}
shift $((OPTIND -1))
clean_up() {
#echo "clean_up()"
#if [ -d ${grpc_clone_dir} ]; then
# rm -rf ${grpc_clone_dir}
#fi
if [ -d "${librdkafka_clone_dir}" ]; then
rm -rf "${librdkafka_clone_dir}"
fi
if [ -d "${libjsoncpp_clone_dir}" ]; then
rm -rf "${libjsoncpp_clone_dir}"
fi
}
die() {
local readonly msg="${1}"
local readonly code="${2:-90}"
echo "${msg}" >&2
exit "${code}"
}
is_valid_mdt_version() {
local detect="${1}"
# supported MDT versions
set -- current v1.1.4 v1.1.3 v1.1.2 v1.1.1 v1.1.0 v1.0.0
for item in "$@";
do
if [ "${item}" = "${detect}" ]; then
v_parame_flag=1
break
fi
done
}
os_release_detect() {
local detect="${1}"
local item_found_flag=0;
case "${detect}" in
os)
# Supported os
set -- BSD Linux
local operating_system="$(uname)"
for item in "$@";
do
if [ "${item}" = "${operating_system}" ]; then
item_found_flag=1
break
fi
done
if [ "${item_found_flag}" -eq 1 ]; then
echo "${operating_system}";
else
die "error - undetected operating system" "${err_os_undetected}"
fi
;;
flavor)
# Supported distro
set -- debian ubuntu pop centos rocky rhel OpenBSD
local linux_distribution="$(egrep '^ID=' /etc/os-release | awk -F "=" '{print $2}' | tr -d "\"")"
local bsd_distribution="none"
for item in "$@";
do
if [ "${item}" = "${linux_distribution}" ]; then
item_found_flag=1
break
fi
done
if [ "${item_found_flag}" -eq 1 ]; then
echo "${linux_distribution}";
else
die "error - undetected linux distribution" "${err_ds_undetected}"
fi
;;
release)
_os=$(os_release_detect "os")
_flavor=$(os_release_detect "flavor")
if [ "${_os}" = "Linux" ]; then
local distro_release="$(egrep '^VERSION_ID=' /etc/os-release | awk -F "=" '{print $2}' | tr -d "\"")"
case "${_flavor}" in
debian)
# Supported debian releases
set -- 11 12
for item in "$@";
do
if [ "${item}" = "${distro_release}" ]; then
item_found_flag=1
break
fi
done
os_release_helper
;;
ubuntu|pop)
# Supported ubuntu/pop releases
set -- 20.04 22.04 22.10 23.04
for item in "$@";
do
if [ "${item}" = "${distro_release}" ]; then
item_found_flag=1
break
fi
done
os_release_helper
;;
centos|rocky|rhel)
# Supported centos/rocky/rhel releases
set -- 8 8.8 8.9 9 9.1 9.2
for item in "$@";
do
if [ "${item}" = "${distro_release}" ]; then
item_found_flag=1
break
fi
done
os_release_helper
;;
*)
# Should never see the sun
die "error - os_release_detect()" "${err_unimplemented_options}"
;;
esac
fi
;;
esac
}
os_release_helper() {
if [ "${item_found_flag}" -eq 1 ]; then
echo "${_os}" "${_flavor}" "${distro_release}";
else
die "error - undetected os release" "${err_ds_release_undetected}"
fi
}
check_if_root() {
local id_chk="$(id -u)"
if [ ! "${id_chk}" -eq 0 ]; then
die "error - run as root" "${err_run_as_root}"
fi
}
detect_sysdeb_lib() {
local lib="${1}"
libjsoncpp_dev=0 # min 184
librdkafka_dev=0 # min 160
libconfig_dev=0 # min 150
libspdlog_dev=0 # min 150
libzmq3_dev=0 # min 434
#libssl_dev=0 #
#libfmt_dev=0 #
grpc_dev=0 # TBD
local apt_cache_show=1
local lib_generic_version=$(apt-cache show ${lib} | \
egrep Version | \
awk -F ":" '{print $2}' | \
tr -d "\" \"|\.|\-" | \
cut -c1-3)
local lib_spdlog_version=$(apt-cache show libspdlog-dev | \
egrep Version | \
awk -F " " '{print $2}' | \
tr -d "\" \"|\.|\-" | \
cut -c1-5 | \
awk -F ":" '{print $2}')
apt_cache_show="$?"
if [ ! "${apt_cache_show}" -eq 0 ]; then
die "error - apt-cache show failure" "${err_apt_failure}"
fi
if [ "${lib}" = "libjsoncpp-dev" ]; then
if [ "${lib_generic_version}" -ge "${libjsoncpp_dev_min_version}" ]; then
sysdeb_install_list="${sysdeb_install_list} ${lib}"
libjsoncpp_dev=1
fi
fi
if [ "${lib}" = "librdkafka-dev" ]; then
if [ "${lib_generic_version}" -ge "${librdkafka_dev_min_version}" ]; then
sysdeb_install_list="${sysdeb_install_list} ${lib}"
librdkafka_dev=1
fi
fi
if [ "${lib}" = "libconfig++-dev" ]; then
if [ "${lib_generic_version}" -ge "${libconfig_dev_min_version}" ]; then
sysdeb_install_list="${sysdeb_install_list} ${lib}"
libconfig_dev=1
fi
fi
if [ "${lib}" = "libspdlog-dev" ]; then
if [ "${lib_spdlog_version}" -ge "${libspdlog_dev_min_version}" ]; then
sysdeb_install_list="${sysdeb_install_list} ${lib}"
libspdlog_dev=1
fi
fi
if [ "${lib}" = "libzmq3-dev" ]; then
if [ "${lib_generic_version}" -ge "${libzmq3_dev_min_version}" ]; then
sysdeb_install_list="${sysdeb_install_list} ${lib}"
libzmq3_dev=1
fi
fi
}
# TBD
# Additional development required
detect_sysrpm_lib() {
#local lib="${1}"
libjsoncpp_dev=0 # min 184
librdkafka_dev=0 # min 160
libconfig_dev=0 # min 150
libspdlog_dev=0 # min 150
libzmq3_dev=0 # min 434
#libssl_dev=0 #
#libfmt_dev=0 #
grpc_dev=0
}
detect_installed_grpc() {
grpc_installed=0
local grpc_pkg_find=$(find /usr -name "grpc\+\+.pc")
if [ ! -z "${grpc_pkg_find}" ]; then
grpc_installed=1
fi
if [ "${grpc_installed}" -eq 1 ]; then
grpc_raw_version=$(egrep "Version" "${grpc_pkg_find}" | awk -F ":" '{print $2}' | tr -d "")
grpc_installed_version=$(egrep "Version" "${grpc_pkg_find}" | awk -F ":" '{print $2}' | tr -d "\" \"|\." | cut -c1-3)
fi
}
detect_installed_librdkafka() {
rdkafka_installed=0
local rdkafka_pkg_find=$(find /usr -name "rdkafka\+\+.pc")
if [ ! -z "${rdkafka_pkg_find}" ]; then
rdkafka_installed=1
fi
if [ "${rdkafka_installed}" -eq 1 ]; then
rdkafka_raw_version=$(egrep "Version" "${rdkafka_pkg_find}" | awk -F ":" '{print $2}' | tr -d "")
rdkafka_version=$(egrep "Version" "${rdkafka_pkg_find}" | awk -F ":" '{print $2}' | tr -d "\" \"|\.")
rdkafka_pkg_find_root=$(echo "${rdkafka_pkg_find}" | sed 's/\/rdkafka++.pc$//g')
fi
}
librdkafka_install_from_src() {
# librdkafka not installed ---> then install
if [ "${rdkafka_installed}" -eq 0 ]; then
local git_clone_rdkafka=1
if [ ! -d "${librdkafka_clone_dir}" ]; then
git clone -b "${librdkafka_version}" "${librdkafka_url}" "${librdkafka_clone_dir}"
git_clone_rdkafka="$?"
else
# assuming that the clone was already performed
git_clone_rdkafka=0
fi
cd "${librdkafka_clone_dir}"
./configure
if [ "${available_vcpu}" -le 1 ]; then
die "error - requires vcpu > 1)" "${err_vcpu_failure}"
else
make -j`echo $((${available_vcpu} - 1))`
make install
fi
else
# inform about the installed *.pc
export PKG_CONFIG_PATH="$rdkafka_pkg_find_root"
fi
}
detect_installed_libjsoncpp() {
jsoncpp_installed=0
local jsoncpp_pkg_find=$(find /usr -name "jsoncpp.pc")
if [ ! -z "${jsoncpp_pkg_find}" ]; then
jsoncpp_installed=1
fi
if [ "${jsoncpp_installed}" -eq 1 ]; then
jsoncpp_raw_version=$(egrep "Version" "${jsoncpp_pkg_find}" | awk -F ":" '{print $2}' | tr -d "")
jsoncpp_version=$(egrep "Version" "${jsoncpp_pkg_find}" | awk -F ":" '{print $2}' | tr -d "\" \"|\.")
jsoncpp_pkg_find_root=$(echo "${jsoncpp_pkg_find}" | sed 's/\/jsoncpp.pc$//g')
fi
}
libjsoncpp_install_from_src() {
# libjsoncpp not installed ---> then install
if [ "${jsoncpp_installed}" -eq 0 ]; then
local git_clone_jsoncpp=1
if [ ! -d "${libjsoncpp_clone_dir}" ]; then
git clone -b "${libjsoncpp_version}" "${libjsoncpp_url}" "${libjsoncpp_clone_dir}"
git_clone_jsoncpp="$?"
else
# assuming that the clone was already performed
git_clone_jsoncpp=0
fi
mkdir -p "${libjsoncpp_clone_dir}/build"
cd "${libjsoncpp_clone_dir}/build"
cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON ../
if [ "${available_vcpu}" -le 1 ]; then
die "error - requires vcpu > 1)" "${err_vcpu_failure}"
else
make -j`echo $((${available_vcpu} - 1))`
make install
fi
else
export PKG_CONFIG_PATH="$jsoncpp_pkg_find_root"
fi
}
grpc_framework_install() {
export PATH="$PATH:${grpc_install_dir}/bin"
if [ ! -d "${grpc_install_dir}" ]; then
mkdir -p "${grpc_install_dir}"
fi
local git_clone=1
if [ ! -d "${grpc_clone_dir}" ]; then
git clone --recurse-submodules -b "${grpc_version}" --depth 1 \
--shallow-submodules "${grpc_url}" "${grpc_clone_dir}"
git_clone="$?"
else
# assuming that the clone was already performed
git_clone=0
fi
if [ ! "${git_clone}" -eq 0 ]; then
die "error - git clone failure" "${err_git_clone_failure}"
fi
cd "${grpc_clone_dir}"
if [ ! -d "cmake/build" ]; then
mkdir -p cmake/build
cd cmake/build
cmake -DgRPC_INSTALL=ON \
-DCMAKE_BUILD_TYPE=Release \
-DgRPC_BUILD_TESTS=OFF \
-DCMAKE_INSTALL_PREFIX="${grpc_install_dir}" \
-DABSL_PROPAGATE_CXX_STD=ON \
-DgRPC_ABSL_PROVIDER=module \
-DgRPC_CARES_PROVIDER=module \
-DgRPC_PROTOBUF_PROVIDER=module \
-DgRPC_RE2_PROVIDER=module \
-DgRPC_SSL_PROVIDER=module \
-DgRPC_ZLIB_PROVIDER=module \
../..
if [ "${available_vcpu}" -le 1 ]; then
die "error - requires vcpu > 1)" "${err_vcpu_failure}"
else
make -j`echo $((${available_vcpu} - 1))`
make install
fi
fi
}
grpc_collector_bin_install_deb() {
#echo "grpc_collector_bin_install_deb()"
local apt_install=1
apt-get install -y $(echo "${sysdeb_install_list}")
apt_install="$?"
if [ ! "${apt_install}" -eq 0 ]; then
die "error - apt install failure" "${err_apt_failure}"
fi
if [ "${librdkafka_dev}" -eq 0 ]; then
detect_installed_librdkafka
fi
if [ "${rdkafka_installed}" -eq 1 ] && [ "${rdkafka_version}" -lt "${librdkafka_dev_min_version}" ]; then
die "error - the installed version of librdkafka (${rdkafka_raw_version}) is too old" "${err_librdkafka_ver_fail}"
else
librdkafka_install_from_src
fi
if [ "${libjsoncpp_dev}" -eq 0 ]; then
detect_installed_libjsoncpp
fi
if [ "${jsoncpp_installed}" -eq 1 ] && [ "${jsoncpp_version}" -lt "${libjsoncpp_dev_min_version}" ]; then
die "error - the installed version of libjsoncpp (${jsoncpp_raw_version}) is too old" "${err_libjsoncpp_ver_fail}"
else
libjsoncpp_install_from_src
fi
local git_clone=1
if [ ! -d "${mdt_install_dir}" ]; then
git clone -b "${mdt_version}" "${mdt_url}" "${mdt_install_dir}"
git_clone="$?"
else
# assuming that the clone was already performed
git_clone=0
fi
if [ ! "${git_clone}" -eq 0 ]; then
die "error - git clone failure" "${err_git_clone_failure}"
fi
if [ ! -d "${mdt_install_dir}/build" ]; then
mkdir -p "${mdt_install_dir}/build"
fi
cd "${mdt_install_dir}/build"
cmake ../
if [ "${available_vcpu}" -le 1 ]; then
die "error - requires vcpu > 1)" "${err_vcpu_failure}"
else
make -j`echo $((${available_vcpu} - 1))`
fi
# deploy a customizable configuration
}
grpc_collector_bin_install_rpm() {
#echo "grpc_collector_bin_install_rpm()"
local yum_install=1
yum install -y $(echo "${sysrpm_install_list}")
yum_install="$?"
sed -i '/SPDLOG_FMT_EXTERNAL/s/^\/\/ //g' /usr/include/spdlog/tweakme.h
if [ ! "${yum_install}" -eq 0 ]; then
die "error - yum install failure" "${err_yum_failure}"
fi
if [ "${librdkafka_dev}" -eq 0 ]; then
detect_installed_librdkafka
fi
# librdkafka installed && version number insuffcient ---> exit!
if [ "${rdkafka_installed}" -eq 1 ] && [ "${rdkafka_version}" -lt "${librdkafka_dev_min_version}" ]; then
die "error - the installed version of librdkafka (${rdkafka_raw_version}) is too old" "${err_librdkafka_ver_fail}"
else
librdkafka_install_from_src
fi
local git_clone=1
if [ ! -d "${mdt_install_dir}" ]; then
git clone -b "${mdt_version}" "${mdt_url}" "${mdt_install_dir}"
git_clone="$?"
else
# assuming that the clone was already performed
git_clone=0
fi
if [ ! "${git_clone}" -eq 0 ]; then
die "error - git clone failure" "${err_git_clone_failure}"
fi
if [ ! -d "${mdt_install_dir}/build" ]; then
mkdir -p "${mdt_install_dir}/build"
fi
cd "${mdt_install_dir}/build"
cmake ../
if [ "${available_vcpu}" -le 1 ]; then
die "error - requires vcpu > 1)" "${err_vcpu_failure}"
else
make -j`echo $((${available_vcpu} - 1))`
fi
# deploy a customizable configuration
}
grpc_collector_lib_install_deb() {
#echo "grpc_collector_lib_install_deb()"
if [ ! -f "/usr/local/bin/grpc_cpp_plugin" ]; then
ln -s "${grpc_install_dir}/bin/grpc_cpp_plugin" "/usr/local/bin/grpc_cpp_plugin"
fi
local apt_install=1
apt-get install -y $(echo "${sysdeb_install_list}")
apt_install="$?"
if [ ! "${apt_install}" -eq 0 ]; then
die "error - apt install failure" "${err_apt_failure}"
fi
if [ "${librdkafka_dev}" -eq 0 ]; then
detect_installed_librdkafka
fi
if [ "${rdkafka_installed}" -eq 1 ] && [ "${rdkafka_version}" -lt "${librdkafka_dev_min_version}" ]; then
die "error - the installed version of librdkafka (${rdkafka_raw_version}) is too old" "${err_librdkafka_ver_fail}"
else
librdkafka_install_from_src
fi
if [ "${libjsoncpp_dev}" -eq 0 ]; then
detect_installed_libjsoncpp
fi
if [ "${jsoncpp_installed}" -eq 1 ] && [ "${jsoncpp_version}" -lt "${libjsoncpp_dev_min_version}" ]; then
die "error - the installed version of libjsoncpp (${jsoncpp_raw_version}) is too old" "${err_libjsoncpp_ver_fail}"
else
libjsoncpp_install_from_src
fi
local git_clone=1
if [ ! -d "${mdt_install_dir}" ]; then
git clone -b "${mdt_version}" "${mdt_url}" "${mdt_install_dir}"
git_clone="$?"
else
# assuming that the clone was already performed
git_clone=0
fi
if [ ! "${git_clone}" -eq 0 ]; then
die "error - git clone failure" "${err_git_clone_failure}"
fi
cd "${mdt_install_dir}"
./autogen.sh
PKG_CONFIG_PATH="$grpc_install_dir/lib/pkgconfig:/usr/local/lib/pkgconfig" \
CPPFLAGS="-I${grpc_install_dir}/include -I/usr/include/jsoncpp" ./configure
if [ "${available_vcpu}" -le 1 ]; then
die "error - requires vcpu > 1)" "${err_vcpu_failure}"
else
make -j`echo $((${available_vcpu} - 1))`
make install
fi
# deploy a customizable configuration
}
grpc_collector_lib_install_rpm() {
#echo "grpc_collector_lib_install_rpm()"
if [ ! -f "/usr/local/bin/grpc_cpp_plugin" ]; then
ln -s "${grpc_install_dir}/bin/grpc_cpp_plugin" "/usr/local/bin/grpc_cpp_plugin"
fi
local yum_install=1
yum install -y $(echo "${sysrpm_install_list}")
yum_install="$?"
sed -i '/SPDLOG_FMT_EXTERNAL/s/^\/\/ //g' /usr/include/spdlog/tweakme.h
if [ ! "${yum_install}" -eq 0 ]; then
die "error - yum install failure" "${err_yum_failure}"
fi
if [ "${librdkafka_dev}" -eq 0 ]; then
detect_installed_librdkafka
fi
# librdkafka installed && version number insuffcient ---> exit!
if [ "${rdkafka_installed}" -eq 1 ] && [ "${rdkafka_version}" -lt "${librdkafka_dev_min_version}" ]; then
die "error - the installed version of librdkafka (${rdkafka_raw_version}) is too old" "${err_librdkafka_ver_fail}"
else
librdkafka_install_from_src
fi
local git_clone=1
if [ ! -d "${mdt_install_dir}" ]; then
git clone -b "${mdt_version}" "${mdt_url}" "${mdt_install_dir}"
git_clone="$?"
else
# assuming that the clone was already performed
git_clone=0
fi
if [ ! "${git_clone}" -eq 0 ]; then
die "error - git clone failure" "${err_git_clone_failure}"
fi
cd "${mdt_install_dir}"
./autogen.sh
PKG_CONFIG_PATH="$grpc_install_dir/lib/pkgconfig:$grpc_install_dir/lib64/pkgconfig:/usr/local/lib/pkgconfig" \
CPPFLAGS="-I${grpc_install_dir}/include" ./configure
if [ "${available_vcpu}" -le 1 ]; then
die "error - requires vcpu > 1)" "${err_vcpu_failure}"
else
make -j`echo $((${available_vcpu} - 1))`
make install
fi
# deploy a customizable configuration
}
grpc_collector_deploy() {
_os_info="$(os_release_detect "release")"
command -v uname >/dev/null 2>&1 || die "error - expected uname command" "${err_cmd_notfound}"
command -v egrep >/dev/null 2>&1 || die "error - expected egrep command" "${err_cmd_notfound}"
command -v awk >/dev/null 2>&1 || die "error - expected awk command" "${err_cmd_notfound}"
command -v git >/dev/null 2>&1 || die "error - expected git command" "${err_cmd_notfound}"
command -v id >/dev/null 2>&1 || die "error - expected id command" "${err_cmd_notfound}"
command -v make >/dev/null 2>&1 || die "error - expected make command" "${err_cmd_notfound}"
command -v cmake >/dev/null 2>&1 || die "error - expected cmake command" "${err_cmd_notfound}"
command -v gcc >/dev/null 2>&1 || die "error - expected gcc command" "${err_cmd_notfound}"
command -v g++ >/dev/null 2>&1 || die "error - expected g++ command" "${err_cmd_notfound}"
command -v autoreconf >/dev/null 2>&1 || die "error - expected autoreconf (autoconf) command" "${err_cmd_notfound}"
command -v libtoolize >/dev/null 2>&1 || die "error - expected libtoolize (libtool) command" "${err_cmd_notfound}"
command -v cut >/dev/null 2>&1 || die "error - expected cut command" "${err_cmd_notfound}"
case "${_os_info}" in
"Linux debian 11" | \
"Linux debian 12" | \
"Linux ubuntu 20.04" | \
"Linux ubuntu 22.04" | \
"Linux ubuntu 22.10" | \
"Linux ubuntu 23.04" | \
"Linux pop 22.04")
#echo "grpc_collector_deploy_deb()"
command -v apt-get >/dev/null 2>&1 || die "error - expected apt command" "${err_cmd_notfound}"
check_if_root
detect_sysdeb_lib "libjsoncpp-dev"
detect_sysdeb_lib "librdkafka-dev"
detect_sysdeb_lib "libconfig++-dev"
detect_sysdeb_lib "libspdlog-dev"
detect_sysdeb_lib "libzmq3-dev"
if [ "${grpc_dev}" -eq 0 ]; then
detect_installed_grpc
fi
if [ "${grpc_installed}" -eq 1 ] && [ "${grpc_installed_version}" -lt "${grpc_dev_min_version}" ]; then
die "error - the installed version of gRPC (${grpc_raw_version}) is too old" "${err_grpc_ver_fail}"
else
grpc_framework_install
fi
if [ "${b_option_flag}" -eq 1 ]; then
grpc_collector_bin_install_deb
fi
if [ "${l_option_flag}" -eq 1 ]; then
grpc_collector_lib_install_deb
fi
;;
"Linux centos 8" | \
"Linux centos 9" | \
"Linux rocky 8.8" | \
"Linux rocky 8.9" | \
"Linux rhel 8" | \
"Linux rhel 9" | \
"Linux rhel 9.1" | \
"Linux rhel 9.2")
#echo "grpc_collector_deploy_rpm()"
if [ "${_os_info}" = "Linux centos 8" ] || [ "${_os_info}" = "Linux centos 9" ]; then
command -v yum >/dev/null 2>&1 || die "error - expected yum command" "${err_cmd_notfound}"
else
command -v dnf >/dev/null 2>&1 || die "error - expected dnf command" "${err_cmd_notfound}"
fi
check_if_root
yum install -y epel-release >/dev/null 2>&1 || die "error - epel-release install failure" "${err_epel_failure}"
# Switch to a recent gcc version (old centos/rocky/rhel release)
if [ "${_os_info}" = "Linux centos 8" ] || [ "${_os_info}" = "Linux rhel 8" ] || [ "${_os_info}" = "Linux rocky 8.8" ] || [ "${_os_info}" = "Linux rocky 8.9" ]; then
yum -y install gcc-toolset-11 >/dev/null 2>&1
source /opt/rh/gcc-toolset-11/enable
fi
detect_sysrpm_lib
if [ "${grpc_dev}" -eq 0 ]; then
detect_installed_grpc
fi
if [ "${grpc_installed}" -eq 1 ] && [ "${grpc_installed_version}" -lt "${grpc_dev_min_version}" ]; then
die "error - the installed version of gRPC (${grpc_raw_version}) is too old" "${err_grpc_ver_fail}"
else
grpc_framework_install
fi
if [ "${b_option_flag}" -eq 1 ]; then
grpc_collector_bin_install_rpm
fi
if [ "${l_option_flag}" -eq 1 ]; then
grpc_collector_lib_install_rpm
fi
;;
*)
# Should never see the sun
die "error - grpc_collector_install(): ${_os_info} offcially not supported" "${err_unimplemented_options}"
;;
esac
}
parse_user_options "${@}"
if [ "${h_option_flag}" -eq 1 ]; then
usage
exit 0
fi
if [ "${v_option_flag}" -eq 0 ]; then
die "error - mind your options/arguments - [ -h ] to know more" "${err_validating_input}"
fi
is_valid_mdt_version "${mdt_version}"
if [ "${v_parame_flag}" -eq 0 ]; then
die "error - invalid MDT release" "${err_mdt_ver_fail}"
fi
if [ "${mdt_version}" = "current" ]; then
mdt_version="main"
fi
# both bin & lib to 1: invalid
if [ "${b_option_flag}" -eq 1 ] && [ "${l_option_flag}" -eq 1 ]; then
die "error - mind your options/arguments - [ -h ] to know more" "${err_validating_input}"
fi
# both bin & lib to 0: invalid
if [ "${b_option_flag}" -eq 0 ] && [ "${l_option_flag}" -eq 0 ]; then
die "error - mind your options/arguments - [ -h ] to know more" "${err_validating_input}"
fi
if [ "${b_option_flag}" -eq 1 ] || [ "${l_option_flag}" -eq 1 ]; then
grpc_collector_deploy
fi
exit 0