-
Notifications
You must be signed in to change notification settings - Fork 33
/
install_build_tools.sh
executable file
·760 lines (686 loc) · 18.6 KB
/
install_build_tools.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
#!/bin/bash
#
# Idempotence...
#
# This script was made to run as often as you like; it will only make changes
# the first time it's run.
#
echo "Running install_build_tools.sh."
PLATFORM=$(./scope_env.sh platform)
if [ ${PLATFORM} = "Error" ]; then
echo "Exiting. install_build_tools.sh does not support this platform type."
exit 1
else
echo "Determined platform type is : ${PLATFORM}."
fi
FAILED=0
########################################
## macOS section
########################################
#
# This was originally developed and tested on MacOS with:
# System Version: macOS 10.14.5 (18F203)
# Homebrew 2.1.6
# autoconf (GNU Autoconf) 2.69
# automake (GNU automake) 1.16.1
# glibtool (GNU libtool) 2.4.6
# cmake version 3.14.5
# lcov: LCOV version 1.14
#
macOS_brew_exists() {
if brew --version &>/dev/null; then
echo "homebrew is already installed; doing nothing for homebrew."
else
echo "homebrew is not already installed."
return 1
fi
}
macOS_brew_install() {
echo "Installing homebrew."
# The initial "echo" is to pass the "hit enter to continue" prompt.
echo | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
if [ $? = 0 ]; then
echo "Installation of homebrew successful."
else
echo "Installation of homebrew failed."
FAILED=1
fi
}
macOS_autoconf_exists() {
if autoconf --version &>/dev/null; then
echo "autoconf is already installed; doing nothing for autoconf."
else
echo "autoconf is not already installed."
return 1
fi
}
macOS_autoconf_install() {
echo "Installing autoconf."
brew install autoconf
if [ $? = 0 ]; then
echo "Installation of autoconf successful."
else
echo "Installation of autoconf failed."
FAILED=1
fi
}
macOS_automake_exists() {
if automake --version &>/dev/null; then
echo "automake is already installed; doing nothing for automake."
else
echo "automake is not already installed."
return 1
fi
}
macOS_automake_install() {
echo "Installing automake."
brew install automake
# We had a new failure with macOS 10.14 on azure on 8-dec-2020.
# Work around it by ignoring the return code
if automake --version &>/dev/null; then
echo "Installation of automake successful."
else
echo "Installation of automake failed."
FAILED=1
fi
}
macOS_glibtool_exists() {
if glibtool --version &>/dev/null; then
echo "glibtool is already installed; doing nothing for glibtool."
else
echo "glibtool is not already installed."
return 1
fi
}
macOS_glibtool_install() {
echo "Installing glibtool."
brew install libtool
if [ $? = 0 ]; then
echo "Installation of glibtool successful."
else
echo "Installation of glibtool failed."
FAILED=1
fi
}
macOS_cmake_exists() {
if cmake --version &>/dev/null; then
echo "cmake is already installed; doing nothing for cmake."
else
echo "cmake is not already installed."
return 1
fi
}
macOS_cmake_install() {
echo "Installing cmake."
brew install cmake
if [ $? = 0 ]; then
echo "Installation of cmake successful."
else
echo "Installation of cmake failed."
FAILED=1
fi
}
macOS_lcov_exists() {
if lcov --version &>/dev/null; then
echo "lcov is already installed; doing nothing for lcov."
else
echo "lcov is not already installed."
return 1
fi
}
macOS_lcov_install() {
echo "Installing lcov."
brew install lcov
if [ $? = 0 ]; then
echo "Installation of lcov successful."
else
echo "Installation of lcov failed."
FAILED=1
fi
}
macOS_dump_versions() {
# The crazy sed stuff at the end of each just provides indention.
system_profiler SPSoftwareDataType | grep "System Version" | sed 's/^[ ]*/ /'
brew --version | head -n1 | sed 's/^/ /'
autoconf --version | head -n1 | sed 's/^/ /'
automake --version | head -n1 | sed 's/^/ /'
glibtool --version | head -n1 | sed 's/^/ /'
cmake --version | head -n1 | sed 's/^/ /'
lcov --version | head -n1 | sed 's/^/ /'
}
if [ ${PLATFORM} = "macOS" ]; then
if ! macOS_brew_exists; then
macOS_brew_install
fi
if ! macOS_autoconf_exists; then
macOS_autoconf_install
fi
if ! macOS_automake_exists; then
macOS_automake_install
fi
if ! macOS_glibtool_exists; then
macOS_glibtool_install
fi
if ! macOS_cmake_exists; then
macOS_cmake_install
fi
if ! macOS_lcov_exists; then
macOS_lcov_install
fi
if (( FAILED )); then
echo "Installation failure detected."
echo "Pertinent version info:"
macOS_dump_versions
exit 1
fi
exit 0
fi
########################################
## linux yum section
########################################
#
# This was originally developed and tested on CentOS with:
# CentOS Linux release 7.6.1810 (Core)
# yum 3.4.3
# Sudo version 1.8.23
# autoconf (GNU Autoconf) 2.69
# GNU Make 3.82
# automake (GNU automake) 1.13.4
# libtool (GNU libtool) 2.4.2
# cmake version 3.13.5
# lcov: LCOV version 1.13
# go1.15.5
# upx 4.0.1
#
PKG_MGR="unknown"
linux_determine_pkg_mgr() {
if yum --version &>/dev/null; then
PKG_MGR="yum"
elif apt-get --version &>/dev/null; then
PKG_MGR="apt-get"
else
return 1
fi
return 0
}
yum_sudo_exists() {
if sudo --version &>/dev/null; then
echo "sudo is already installed; doing nothing for sudo."
else
echo "sudo is not already installed."
return 1
fi
}
yum_sudo_install() {
echo "Installing sudo."
yum install sudo
if [ $? = 0 ]; then
echo "Installation of sudo successful."
else
echo "Installation of sudo failed."
FAILED=1
fi
}
yum_curl_exists() {
if curl --version &>/dev/null; then
echo "curl is already installed; doing nothing for curl."
else
echo "curl is not already installed."
return 1
fi
}
yum_curl_install() {
echo "Installing curl."
yum install curl
if [ $? = 0 ]; then
echo "Installation of curl successful."
else
echo "Installation of curl failed."
FAILED=1
fi
}
yum_autoconf_exists() {
if autoconf --version &>/dev/null; then
echo "autoconf is already installed; doing nothing for autoconf."
else
echo "autoconf is not already installed."
return 1
fi
}
yum_autoconf_install() {
echo "Installing autoconf."
sudo yum -y install autoconf
if [ $? = 0 ]; then
echo "Installation of autoconf successful."
else
echo "Installation of autoconf failed."
FAILED=1
fi
}
yum_make_exists() {
if make --version &>/dev/null; then
echo "make is already installed; doing nothing for make."
else
echo "make is not already installed."
return 1
fi
}
yum_make_install() {
echo "Installing make."
sudo yum -y install make
if [ $? = 0 ]; then
echo "Installation of make successful."
else
echo "Installation of make failed."
FAILED=1
fi
}
yum_automake_exists() {
if automake --version &>/dev/null; then
echo "automake is already installed; doing nothing for automake."
else
echo "automake is not already installed."
return 1
fi
}
yum_automake_install() {
echo "Installing automake."
sudo yum -y install automake
if [ $? = 0 ]; then
echo "Installation of automake successful."
else
echo "Installation of automake failed."
FAILED=1
fi
}
yum_libtool_exists() {
if libtool --version &>/dev/null; then
echo "libtool is already installed; doing nothing for libtool."
else
echo "libtool is not already installed."
return 1
fi
}
yum_libtool_install() {
echo "Installing libtool."
sudo yum -y install libtool
if [ $? = 0 ]; then
echo "Installation of libtool successful."
else
echo "Installation of libtool failed."
FAILED=1
fi
}
yum_cmake_exists() {
if cmake --version &>/dev/null; then
echo "cmake is already installed; doing nothing for cmake."
else
echo "cmake is not already installed."
return 1
fi
}
yum_cmake_install() {
echo "Installing cmake."
sudo yum -y install epel-release
sudo yum -y install cmake3
if [ $? = 0 ]; then
sudo alternatives --install /usr/local/bin/cmake cmake /usr/bin/cmake3 10 \
--slave /usr/local/bin/ctest ctest /usr/bin/ctest3 \
--slave /usr/local/bin/cpack cpack /usr/bin/cpack3 \
--slave /usr/local/bin/ccmake ccmake /usr/bin/ccmake3 \
--family cmake
fi
if [ $? = 0 ]; then
echo "Installation of cmake successful."
else
echo "Installation of cmake failed."
FAILED=1
fi
}
yum_lcov_exists() {
if lcov --version &>/dev/null; then
echo "lcov is already installed; doing nothing for lcov."
else
echo "lcov is not already installed."
return 1
fi
}
yum_lcov_install() {
echo "Installing lcov."
sudo yum -y install epel-release
sudo yum -y install lcov
if [ $? = 0 ]; then
echo "Installation of lcov successful."
else
echo "Installation of lcov failed."
FAILED=1
fi
}
yum_go_exists() {
if go version &>/dev/null; then
echo "go is already installed; doing nothing for go."
else
echo "go is not already installed."
return 1
fi
}
yum_go_install() {
echo "Installing go."
sudo yum -y install epel-release
sudo yum -y install golang
if [ $? = 0 ]; then
echo "Installation of go successful."
else
echo "Installation of go failed."
FAILED=1
fi
}
upx_exists() {
if upx --version &>/dev/null; then
echo "upx is already installed; doing nothing for upx."
else
echo "upx is not already installed."
return 1
fi
}
upx_install() {
upxVersion=4.0.1
arch=$(arch | sed s/aarch64/arm64/ | sed s/x86_64/amd64/)
curl -Ls https://github.com/upx/upx/releases/download/v${upxVersion}/upx-${upxVersion}-${arch}_linux.tar.xz -o - | tar xvJf - -C /tmp
cp /tmp/upx-${upxVersion}-${arch}_linux/upx /usr/local/bin/
chmod +x /usr/local/bin/upx
echo "Installation of upx successful."
}
yum_dump_versions() {
# The crazy sed stuff at the end of each just provides indention.
if [ -f /etc/centos-release ]; then
cat /etc/centos-release | head -n1 | sed 's/^[ ]*/ /'
elif [ -f /etc/redhat-release ]; then
cat /etc/redhat-release | head -n1 | sed 's/^[ ]*/ /'
elif [ -f /etc/os-release ]; then
grep PRETTY_NAME /etc/os-release | cut -d \" -f2 | sed 's/^/ /'
fi
yum --version | head -n1 | sed 's/^/ yum /'
sudo --version | head -n1 | sed 's/^/ /'
curl --version | head -n1 | sed 's/^/ /'
autoconf --version | head -n1 | sed 's/^/ /'
make --version | head -n1 | sed 's/^/ /'
automake --version | head -n1 | sed 's/^/ /'
libtool --version | head -n1 | sed 's/^/ /'
cmake --version | head -n1 | sed 's/^/ /'
lcov --version | head -n1 | sed 's/^/ /'
go version | head -n1 | sed 's/^/ /'
upx --version | head -n1 | sed 's/^/ /'
}
yum_install() {
echo "Running the yum install."
if ! yum_sudo_exists; then
yum_sudo_install
fi
if ! yum_curl_exists; then
yum_curl_install
fi
if ! yum_autoconf_exists; then
yum_autoconf_install
fi
if ! yum_make_exists; then
yum_make_install
fi
if ! yum_automake_exists; then
yum_automake_install
fi
if ! yum_libtool_exists; then
yum_libtool_install
fi
if ! yum_cmake_exists; then
yum_cmake_install
fi
if ! yum_lcov_exists; then
yum_lcov_install
fi
if ! yum_go_exists; then
yum_go_install
fi
if ! upx_exists; then
upx_install
fi
if (( FAILED )); then
echo "Installation failure detected."
echo "Pertinent version info:"
yum_dump_versions
exit 1
fi
exit 0
}
########################################
## linux apt section
########################################
#
# This was originally developed and tested on ubuntu with:
# Ubuntu 18.04.2 LTS
# apt 1.6.11 (amd64)
# Sudo version 1.8.21p2
# GNU Make 4.1
# autoconf (GNU Autoconf) 2.69
# libtool (GNU libtool) 2.4.6
# cmake version 3.10.2
# lcov: LCOV version 1.13
#
apt_sudo_exists() {
if sudo --version &>/dev/null; then
echo "sudo is already installed; doing nothing for sudo."
else
echo "sudo is not already installed."
return 1
fi
}
apt_sudo_install() {
echo "Installing sudo."
apt-get update && apt-get install sudo
if [ $? = 0 ]; then
echo "Installation of sudo successful."
else
echo "Installation of sudo failed."
FAILED=1
fi
}
apt_curl_exists() {
if curl --version &>/dev/null; then
echo "curl is already installed; doing nothing for curl."
else
echo "curl is not already installed."
return 1
fi
}
apt_curl_install() {
echo "Installing curl."
apt-get update && apt-get install curl
if [ $? = 0 ]; then
echo "Installation of curl successful."
else
echo "Installation of curl failed."
FAILED=1
fi
}
apt_make_exists() {
if make --version &>/dev/null; then
echo "make is already installed; doing nothing for make."
else
echo "make is not already installed."
return 1
fi
}
apt_make_install() {
echo "Installing make."
sudo apt-get install -y make
if [ $? = 0 ]; then
echo "Installation of make successful."
else
echo "Installation of make failed."
FAILED=1
fi
}
apt_autoconf_exists() {
if autoconf --version &>/dev/null; then
echo "autoconf is already installed; doing nothing for autoconf."
else
echo "autoconf is not already installed."
return 1
fi
}
apt_autoconf_install() {
echo "Installing autoconf."
sudo apt-get install -y autoconf
if [ $? = 0 ]; then
echo "Installation of autoconf successful."
else
echo "Installation of autoconf failed."
FAILED=1
fi
}
apt_libtool_exists() {
if libtool --version &>/dev/null; then
echo "libtool is already installed; doing nothing for libtool."
else
echo "libtool is not already installed."
return 1
fi
}
apt_libtool_install() {
echo "Installing libtool."
sudo apt-get install -y libtool-bin
if [ $? = 0 ]; then
echo "Installation of libtool successful."
else
echo "Installation of libtool failed."
FAILED=1
fi
}
apt_cmake_exists() {
if cmake --version &>/dev/null; then
echo "cmake is already installed; doing nothing for cmake."
else
echo "cmake is not already installed."
return 1
fi
}
apt_cmake_install() {
echo "Installing cmake."
sudo -E DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata
sudo apt-get install -y cmake
if [ $? = 0 ]; then
echo "Installation of cmake successful."
else
echo "Installation of cmake failed."
FAILED=1
fi
}
apt_lcov_exists() {
if lcov --version &>/dev/null; then
echo "lcov is already installed; doing nothing for lcov."
else
echo "lcov is not already installed."
return 1
fi
}
apt_lcov_install() {
echo "Installing lcov."
sudo apt-get install -y lcov
if [ $? = 0 ]; then
echo "Installation of lcov successful."
else
echo "Installation of lcov failed."
FAILED=1
fi
}
apt_go_exists() {
if go version &>/dev/null; then
echo "go is already installed; doing nothing for go."
else
echo "go is not already installed."
return 1
fi
}
apt_go_install() {
echo "Installing go."
sudo -E DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata
sudo apt-get install -y software-properties-common
sudo add-apt-repository -y ppa:longsleep/golang-backports
sudo apt update
sudo apt-get install -y golang-go
if [ $? = 0 ]; then
echo "Installation of go successful."
else
echo "Installation of go failed."
FAILED=1
fi
}
apt_dump_versions() {
# The crazy sed stuff at the end of each just provides indention.
if lsb_release -d &>/dev/null; then
lsb_release -d | sed 's/^Description:\s*/ /'
elif [ -f /etc/lsb-release ]; then
grep DISTRIB_DESCRIPTION /etc/lsb-release | cut -d \" -f2 | sed 's/^/ /'
fi
apt-get --version | head -n1 | sed 's/^/ /'
sudo --version | head -n1 | sed 's/^/ /'
curl --version | head -n1 | sed 's/^/ /'
make --version | head -n1 | sed 's/^/ /'
autoconf --version | head -n1 | sed 's/^/ /'
libtool --version | head -n1 | sed 's/^/ /'
cmake --version | head -n1 | sed 's/^/ /'
lcov --version | head -n1 | sed 's/^/ /'
go version | head -n1 | sed 's/^/ /'
upx --version | head -n1 | sed 's/^/ /'
}
apt_install() {
echo "Running the apt-get install."
if ! apt_sudo_exists; then
apt_sudo_install
fi
if ! apt_curl_exists; then
apt_curl_install
fi
if ! apt_make_exists; then
apt_make_install
fi
if ! apt_autoconf_exists; then
apt_autoconf_install
fi
if ! apt_libtool_exists; then
apt_libtool_install
fi
if ! apt_cmake_exists; then
apt_cmake_install
fi
if ! apt_lcov_exists; then
apt_lcov_install
fi
if ! apt_go_exists; then
apt_go_install
fi
if ! upx_exists; then
upx_install
fi
if (( FAILED )); then
echo "Installation failure detected."
echo "Pertinent version info:"
apt_dump_versions
exit 1
fi
exit 0
}
if [ ${PLATFORM} = "Linux" ]; then
if ! linux_determine_pkg_mgr; then
echo "Exiting. install_build_tools.sh does not support this package manager."
exit 1
else
echo "Determined package manager is : ${PKG_MGR}."
fi
if [ ${PKG_MGR} = "yum" ]; then
yum_install
elif [ ${PKG_MGR} = "apt-get" ]; then
apt_install
fi
exit 1
fi