-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathinstall-deps.sh
More file actions
executable file
·1712 lines (1468 loc) · 62.5 KB
/
Copy pathinstall-deps.sh
File metadata and controls
executable file
·1712 lines (1468 loc) · 62.5 KB
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
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# install-deps.sh makes it more convenient to install
# dependencies for ADU Agent and Delivery Optimization.
# Some dependencies are installed via packages and
# others are installed from source code.
# Ensure that getopt starts from first option if ". <script.sh>" was used.
OPTIND=1
ret=""
# Ensure we dont end the user's terminal session if invoked from source (".").
if [[ $0 != "${BASH_SOURCE[0]}" ]]; then
ret='return'
else
ret='exit'
fi
# Use sudo if user is not root
SUDO=""
if [ "$(id -u)" != "0" ]; then
SUDO="sudo"
fi
warn() { echo -e "\033[1;33mWarning:\033[0m $*" >&2; }
error() { echo -e "\033[1;31mError:\033[0m $*" >&2; }
# Determine the git root directory
GITROOT="$(git rev-parse --show-toplevel 2> /dev/null)"
if [ -z "$GITROOT" ]; then
# If not in a git repo, use the script's parent directory
GITROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
fi
# Setup defaults
install_all_deps=false
install_packages=false
install_packages_only=false
# The folder where source code will be placed
# for building and installing from source.
# Use parent directory of git root to avoid vcpkg manifest conflicts
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)"
repo_root="$(cd "$script_dir/.." > /dev/null 2>&1 && pwd)"
DEFAULT_WORKFOLDER="$repo_root/.workspace"
work_folder=$DEFAULT_WORKFOLDER
keep_source_code=false
use_ssh=false
# ADUC Deps
install_aduc_deps=false
install_azure_iot_sdk=false
azure_sdk_ref=LTS_03_2025
# ADUC Diagnostics Deps
azure_storage_sdk_branch_ref=main
azure_storage_sdk_tag_ref=azure-core_1.6.0
install_azure_storage_sdk=false
# ADUC Test Deps
install_catch2=false
default_catch2_ref=v3.8.0
catch2_ref=$default_catch2_ref
install_swupdate=false
default_swupdate_ref=2021.11
swupdate_ref=$default_swupdate_ref
install_cmake=false
supported_cmake_version='3.23.2'
install_cmake_version="$supported_cmake_version"
cmake_force_source=false
cmake_prefix="$work_folder"
cmake_installer_dir=""
cmake_bin="cmake"
install_shellcheck=false
supported_shellcheck_version='0.8.0'
install_valgrind=false
valgrind_install_method="apt" # apt or source
supported_valgrind_version='3.23.0'
valgrind_ref="VALGRIND_3_23_0"
install_githooks=false
du_test_data_dir_path="/tmp/adu/"
# DO Deps
default_do_ref=develop
install_do=false
do_ref=$default_do_ref
# Default delta ref uses GCC 12+ compatible branch
default_delta_ref=feature/vnext-delta
install_delta=false
delta_ref=$default_delta_ref
# CMake symlink location
cmake_dir_symlink="$repo_root/.workspace/deviceupdate-cmake"
# catch2 build
#
# used for dependencies like catch2 that will find system default
# (e.g. g++-9) despite g++-10 installed, so use CC and CXX env
# vars that CMake will honor.
catch2_cc=""
catch2_cxx=""
# Check if a dependency is already installed at the expected version.
# Usage: is_dep_installed <name> <version>
# Returns 0 (true) if the stamp file exists and matches the version.
is_dep_installed() {
local name="$1" version="$2"
local stamp="$deps_stamp_dir/$name"
if [[ -f $stamp ]] && [[ "$(cat "$stamp" 2> /dev/null)" == "$version" ]]; then
return 0
fi
return 1
}
# Record that a dependency was successfully installed.
# Usage: mark_dep_installed <name> <version>
mark_dep_installed() {
local name="$1" version="$2"
mkdir -p "$deps_stamp_dir"
echo "$version" > "$deps_stamp_dir/$name"
}
# Dependencies packages
aduc_packages=('git' 'make' 'build-essential' 'cmake' 'ninja-build' 'libcurl4-openssl-dev' 'libssl-dev' 'uuid-dev' 'lsb-release' 'curl' 'wget' 'pkg-config' 'libxml2-dev' 'file')
static_analysis_packages=('clang' 'clang-tidy' 'cppcheck')
compiler_packages=('gcc' 'g++')
# Distro and arch info
OS=""
VER=""
is_amd64=false
is_arm64=false
is_arm32=false
print_help() {
echo "Usage: install-deps.sh [options...]"
echo "-a, --install-all-deps Install all dependencies."
echo " Implies --install-aduc-deps, --install-do, --install-packages, --install-cmake, and --install-shellcheck."
echo " Can be used with --install-packages-only."
echo " This is the default if no options are specified."
echo ""
echo "--install-aduc-deps Install dependencies for ADU Agent."
echo " Implies --install-azure-iot-sdk and --install-catch2."
echo " When used with --install-packages will also install the package dependencies."
echo "--install-azure-iot-sdk Install the Azure IoT C SDK from source."
echo "--install-azure-storage-sdk Install the Azure SDK for CPP from source."
echo "--azure-iot-sdk-ref <ref> Install the Azure IoT C SDK from a specific branch or tag."
echo " Default is public-preview."
echo "--install-catch2 Install Catch2 from source."
echo "--install-cmake Installs supported version of cmake from installer if on ubuntu, else installs it from source."
echo "--install-shellcheck Installs supported version of shellcheck."
echo "--install-valgrind [method] Install Valgrind for memory leak detection."
echo " method can be: apt or source."
echo " 'apt' installs from package manager."
echo " 'source' builds from source (version $supported_valgrind_version)."
echo "--cmake-prefix Set the install path prefix when --install-cmake is used. Default is [git-root]/.tmp."
echo "--cmake-version Override the version of CMake. e.g. 3.23.2 that will be installed if --install-cmake is used."
echo "--cmake-force-source Force building cmake from source when --install-cmake is used."
echo "--install-githooks Install githooks required by the repository."
echo "--catch2-ref Install Catch2 from a specific branch or tag."
echo " This value is passed to git clone as the --branch argument."
echo " Default is $default_catch2_ref."
echo ""
echo "--install-swupdate Build and install the SWUpdate project. (required for SWUpdate unit tests on Ubuntu)"
echo "--swupdate-ref <ref> Clone the SWUpdate project from a specific branch or tag."
echo " Default is $default_swupdate_ref."
echo ""
echo "--install-do Install Delivery Optimization from source."
echo " In order to install the correct dependencies, "
echo "--do-ref <ref> Install the DO source from this branch or tag."
echo " This value is passed to git clone as the --branch argument."
echo " Default is $default_do_ref."
echo "--do-commit <commit_sha> Specific commit to fetch."
echo " Default is the latest commit in that branch."
echo ""
echo "--install-delta Install iot-hub-device-update-delta library from source."
echo "--delta-ref <ref> Install the delta library from this branch or tag."
echo " This value is passed to git clone as the --branch argument."
echo " Default is $default_delta_ref."
echo ""
echo "-p, --install-packages Indicates that packages should be installed."
echo "--install-packages-only Indicates that only packages should be installed and that dependencies should not be installed from source."
echo ""
echo "-f, --work-folder <work_folder> Specifies the folder where temp artifacts will be stored."
echo " This folder contains temporary build artifacts for dependencies,"
echo " CMake/shellcheck installations, and test data."
echo " Default is [git-root]/.tmp."
echo "-k, --keep-source-code Indicates that source code should not be deleted after install from work_folder."
echo ""
echo "--use-ssh Use ssh URLs to clone instead of https URLs."
echo ""
echo "--list-deps List the states of the dependencies."
echo "-h, --help Show this help message."
echo ""
echo "Example: ${BASH_SOURCE[0]} --install-all-deps --work-folder ~/adu-linux-client-deps --keep-source-code"
}
do_install_valgrind_from_apt() {
echo "Installing Valgrind from apt..."
$SUDO apt-get install --yes valgrind || return
echo "Valgrind installed from apt successfully."
}
do_install_valgrind_from_source() {
echo "Installing Valgrind from source..."
local valgrind_dir=$work_folder/valgrind
if [[ -d $valgrind_dir ]]; then
$SUDO rm -rf "$valgrind_dir" || return
fi
local valgrind_url
if [[ $use_ssh == "true" ]]; then
valgrind_url=git@github.com:valgrind/valgrind.git
else
valgrind_url=https://github.com/valgrind/valgrind.git
fi
echo -e "Building Valgrind from source...\n\tTag: $valgrind_ref\n\tFolder: $valgrind_dir"
mkdir -p "$valgrind_dir" || return
pushd "$valgrind_dir" > /dev/null || return
git clone --branch "$valgrind_ref" --depth 1 "$valgrind_url" . || return
./autogen.sh || return
./configure --prefix=/usr/local || return
make -j"$(nproc)" || return
$SUDO make install || return
popd > /dev/null || return
if [[ $keep_source_code != "true" ]]; then
echo "Removing Valgrind source code..."
$SUDO rm -rf "$valgrind_dir"
fi
# Create symlink if not already exists
if [[ ! -L /usr/bin/valgrind ]]; then
$SUDO ln -sf /usr/local/bin/valgrind /usr/bin/valgrind || return
fi
echo "Valgrind installed from source successfully."
}
do_install_githooks() {
echo "Installing githooks..."
GITROOT="$(git rev-parse --show-toplevel 2> /dev/null)"
if [ -z "$GITROOT" ]; then
echo 'Unable to determine git root.' >&2
$ret 1
fi
if ! $SUDO ln -sf "$GITROOT/scripts/githooks/pre-commit.sh" "$GITROOT/.git/hooks/pre-commit"; then
echo "Unable to symlink pre-commit. exit code: $?"
$ret 1
fi
}
do_install_aduc_packages() {
echo "Installing dependency packages for ADU Agent..."
$SUDO apt-get install --yes "${aduc_packages[@]}" || return
# For Ubuntu 24.04+, ensure the 'file' utility is installed (may be needed by CPack)
OS=$(lsb_release --short --id)
if [[ $OS == "Ubuntu" ]]; then
# Parse version to check if 24.04 or later
VER_MAJOR=$(echo "$VER" | cut -d. -f1)
VER_MINOR=$(echo "$VER" | cut -d. -f2)
if [[ $VER_MAJOR -gt 24 ]] || [[ $VER_MAJOR -eq 24 && $VER_MINOR -ge 4 ]]; then
echo "Ensuring 'file' utility is available for Ubuntu 24.04+"
$SUDO apt-get install --yes file || echo "Warning: Could not install 'file' package"
fi
fi
# The latest version of gcc available on Debian is gcc-6. We install that version if we are
# building for Debian, otherwise we install gcc-8 for Ubuntu.
if [[ $OS == "Debian" && $VER == "9" ]]; then
$SUDO apt-get install --yes gcc-6 g++-6 || return
catch2_cc=/usr/bin/gcc-6
catch2_cxx=/usr/bin/g++-6
elif [[ ($OS == "Debian" && $VER == "11") || (\
$OS == "Ubuntu" && $VER == "20.04") || (\
$OS == "Ubuntu" && $VER == "22.04") ]] \
; then
$SUDO apt-get install --yes gcc-10 g++-10 || return
catch2_cc=/usr/bin/gcc-10
catch2_cxx=/usr/bin/g++-10
elif [[ $OS == "Debian" && $VER == "12" ]]; then
$SUDO apt-get install --yes gcc-12 g++-12 || return
catch2_cc=/usr/bin/gcc-12
catch2_cxx=/usr/bin/g++-12
elif [[ $OS == "Debian" && $VER == "13" ]]; then
# Debian 13 (trixie) - use gcc-12 for consistency with Debian 12
$SUDO apt-get install --yes gcc-12 g++-12 || return
catch2_cc=/usr/bin/gcc-12
catch2_cxx=/usr/bin/g++-12
elif [[ $OS == "Ubuntu" && $VER == "24.04" ]]; then
# Ubuntu 24.04 and newer have a recent enough default gcc, so we don't need to install a specific version
echo "Using system default gcc for Ubuntu 24.04+"
catch2_cc=/usr/bin/gcc
catch2_cxx=/usr/bin/g++
else
$SUDO apt-get install --yes gcc-8 g++-8 || return
catch2_cc=/usr/bin/gcc-8
catch2_cxx=/usr/bin/g++-8
fi
echo "Installing packages required for static analysis..."
# The following is a workaround as IoT SDK references the following paths which don't exist
# on our target platforms, and without these folders existing, static analysis will report:
# (information) Couldn't find path given by -I '/usr/local/inc/'
# (information) Couldn't find path given by -I '/usr/local/pal/linux/'
$SUDO mkdir --parents /usr/local/inc /usr/local/pal/linux
# Note that clang-tidy requires clang to be installed so that it can find clang headers.
$SUDO apt-get install --yes "${static_analysis_packages[@]}" || return
}
do_install_azure_iot_sdk() {
echo "Installing Azure IoT C SDK ..."
if is_dep_installed "azure-iot-sdk-c" "$azure_sdk_ref"; then
echo "Azure IoT C SDK ($azure_sdk_ref) already installed. Skipping..."
return 0
fi
local azure_sdk_dir=$work_folder/azure-iot-sdk-c
if [[ -d $azure_sdk_dir ]]; then
$SUDO rm -rf "$azure_sdk_dir" || return
fi
local azure_sdk_url
if [[ $use_ssh == "true" ]]; then
azure_sdk_url=git@github.com:Azure/azure-iot-sdk-c.git
else
azure_sdk_url=https://github.com/Azure/azure-iot-sdk-c.git
fi
echo -e "Building azure-iot-sdk-c ...\n\tBranch: $azure_sdk_ref\n\tFolder: $azure_sdk_dir"
mkdir -p "$azure_sdk_dir" || return
pushd "$azure_sdk_dir" > /dev/null || return
git clone --branch "$azure_sdk_ref" "$azure_sdk_url" . || return
git submodule update --init || return
mkdir cmake || return
pushd cmake > /dev/null || return
# use_http is required for uHTTP support.
local azureiotsdkc_cmake_options=(
"-Duse_amqp:BOOL=OFF"
"-Duse_http:BOOL=ON"
"-Duse_mqtt:BOOL=ON"
"-Duse_wsio:BOOL=ON"
"-Dskip_samples:BOOL=ON"
"-Dbuild_service_client:BOOL=OFF"
"-Dbuild_provisioning_service_client:BOOL=OFF"
"-Duse_prov_client:BOOL=OFF"
)
if [[ $keep_source_code == "true" ]]; then
# If source is wanted, presumably samples and symbols are useful as well.
azureiotsdkc_cmake_options+=("-DCMAKE_BUILD_TYPE:STRING=Debug")
else
azureiotsdkc_cmake_options+=("-Dskip_samples=ON")
fi
cmake "${azureiotsdkc_cmake_options[@]}" .. || return
cmake --build . || return
$SUDO cmake --build . --target install || return
popd > /dev/null || return
popd > /dev/null || return
mark_dep_installed "azure-iot-sdk-c" "$azure_sdk_ref"
if [[ $keep_source_code != "true" ]]; then
$SUDO rm -rf "$azure_sdk_dir" || return
fi
}
do_install_catch2() {
echo "Installing Catch2 ..."
if is_dep_installed "catch2" "$catch2_ref"; then
echo "Catch2 ($catch2_ref) already installed. Skipping..."
return 0
fi
local catch2_dir=$work_folder/catch2
if [[ -d $catch2_dir ]]; then
$SUDO rm -rf "$catch2_dir" || return
fi
local catch2_url
if [[ $use_ssh == "true" ]]; then
catch2_url=git@github.com:catchorg/Catch2.git
else
catch2_url=https://github.com/catchorg/Catch2.git
fi
echo -e "Building Catch2 ...\n\tBranch: $catch2_ref\n\tFolder: $catch2_dir"
mkdir -p "$catch2_dir" || return
pushd "$catch2_dir" > /dev/null || return
git clone --recursive --single-branch --branch "$catch2_ref" --depth 1 "$catch2_url" . || return
mkdir cmake || return
pushd cmake > /dev/null || return
CC="$catch2_cc" CXX="$catch2_cxx" "$cmake_bin" .. || return
CC="$catch2_cc" CXX="$catch2_cxx" "$cmake_bin" --build . || return
$SUDO "$cmake_bin" --build . --target install || return
popd > /dev/null || return
popd > /dev/null || return
mark_dep_installed "catch2" "$catch2_ref"
if [[ $keep_source_code != "true" ]]; then
$SUDO rm -rf "$catch2_dir" || return
fi
}
do_install_swupdate() {
echo "Installing SWupdate ($swupdate_ref) ..."
# Currently only support building SWUpdate on following distros:
# - Ubuntu 18.04
# - Ubuntu 20.04
lsb_release -a | grep -e 'Ubuntu 18.04' -e 'Ubuntu 20.04'
local grep_res=$?
if [[ $grep_res -ne "0" ]]; then
echo "Only need to build SWUpdate for Ubuntu 18.04 and Ubuntu 20.04. Skipping..."
return 0
fi
local swupdate_dir=$work_folder/swupdate
if [[ -d $swupdate_dir ]]; then
$SUDO rm -rf "$swupdate_dir" || return 1
fi
local swupdate_url
if [[ $use_ssh == "true" ]]; then
swupdate_url=git@github.com:sbabic/swupdate.git
else
swupdate_url=https://github.com/sbabic/swupdate.git
fi
echo -e "Building SWUpdate ...\n\tBranch: $swupdate_ref\n\tFolder: $swupdate_dir"
mkdir -p "$swupdate_dir" || return
pushd "$swupdate_dir" > /dev/null || return
git clone --recursive --single-branch --branch "$swupdate_ref" --depth 1 "$swupdate_url" . || return
popd > /dev/null || return
echo -e "Customizing SWUpdate build configurations..."
cp src/deps/swupdate/.config "$swupdate_dir" || return
pushd "$swupdate_dir" > /dev/null || return
echo -r "Building SWUpdate..."
make || return
echo -e "Installing SWUpdate..."
$SUDO make install || return
popd > /dev/null || return
if [[ $keep_source_code != "true" ]]; then
$SUDO rm -rf "$swupdate_dir" || return 1
fi
}
do_install_do_release_tarball() {
local ret=0
local dist=''
local arch=''
local do_release_tarball_url=''
local tarball_filename=''
local do_dir="$work_folder/do"
echo -e "Attempting to install libdeliveryoptimization from release tarball...\n"
local os_lowercase="${OS,,}"
echo "os_lowercase => $os_lowercase"
echo "VER => $VER"
echo "is_arm32 => $is_arm32"
echo "is_arm64 => $is_arm64"
echo "is_amd64 => $is_amd64"
if [[ $os_lowercase == "debian" && $VER == "9" ]]; then
echo "evaluating debian9 for supported DO tarball ..."
dist='debian9'
if [[ $is_arm32 == "true" ]]; then
arch='arm32'
else
warn "unsupported arch for DO release asset on Debian9. Supported: arm32"
return 1
fi
elif [[ $os_lowercase == "debian" && $VER == "10" ]]; then
echo "evaluating debian10 for supported DO tarball ..."
dist='debian10'
if [[ $is_amd64 == "true" ]]; then
arch='x64'
elif [[ $is_arm64 == "true" ]]; then
arch='arm64'
elif [[ $is_arm32 == "true" ]]; then
arch='arm32'
else
warn "unsupported arch for DO release asset on Debian10. Supported: amd64 arm64 arm32"
return 1
fi
elif [[ $os_lowercase == "ubuntu" ]]; then
echo "evaluating ubuntu for supported DO tarball ..."
if [[ $VER == "18.04" ]]; then
dist='ubuntu1804'
elif [[ $VER == "20.04" ]]; then
dist='ubuntu2004'
else
warn "unsupported ubuntu version: $VER. Supported: 18.04 20.04"
return 1
fi
if [[ $dist != '' ]]; then
if [[ $is_amd64 == "true" ]]; then
arch='x64'
elif [[ $is_arm64 == "true" ]]; then
arch='arm64'
else
warn "unsupported arch for DO release asset on ${dist}. Supported: amd64 arm64"
return 1
fi
fi
fi
if [[ $dist != '' && $arch != '' ]]; then
tarball_filename="${dist}_${arch}-packages.tar"
do_release_tarball_url="https://github.com/microsoft/do-client/releases/download/${do_ref}/${tarball_filename}"
if [[ ! -e $do_dir ]]; then
echo "creating $do_dir dir..."
mkdir -p "$do_dir" || return
fi
# v0.9.0 DO has libboost-filesystem and libboost-system deps
echo "Installing libboost-filesystem-dev and libboost-system-dev DO deps for ${dist} ..."
$SUDO apt-get install -y libboost-filesystem-dev libboost-system-dev || return
echo "wget DO release tarball from $do_release_tarball_url ..."
wget -P "$do_dir" "${do_release_tarball_url}" || return
echo "extracting $tarball_filename tarball ..."
pushd "$do_dir" || return
ls -latr || return
tar -xf "$tarball_filename" || return
echo "apt-get installing DO .deb ..."
$SUDO apt-get install -y ./deliveryoptimization-agent_*.deb ./libdeliveryoptimization_*.deb ./libdeliveryoptimization-dev*.deb || return
popd || return
fi
return 0
}
do_install_do() {
echo "Installing DO ..."
# Skip DO installation on Ubuntu 24.04 and newer
if [[ $OS == "Ubuntu" && $VER == "24.04" ]]; then
echo "Skipping DO installation on Ubuntu 24.04 (not supported)"
return 0
fi
# Skip DO installation on Debian 13 (trixie) - not yet supported by DO
if [[ $OS == "Debian" && $VER == "13" ]]; then
echo "Skipping DO installation on Debian 13 (not yet supported)"
return 0
fi
local do_dir=$work_folder/do
if [[ -d $do_dir ]]; then
$SUDO rm -rf "$do_dir" || return
fi
if [[ $install_packages == "true" || $install_packages_only == "true" ]]; then
if do_install_do_release_tarball; then
echo "Install libdeliveryoptimization from tarball succeeded!"
return 0
fi
fi
if [[ $keep_source_code != "true" ]]; then
$SUDO rm -rf "$do_dir" || return
elif [[ -d $do_dir ]]; then
warn "$do_dir already exists! Skipping DO."
return 0
fi
echo -e "Building DO ...\n\tBranch: $do_ref\n\tFolder: $do_dir"
mkdir -p "$do_dir" || return
pushd "$do_dir" > /dev/null || return
local do_url
if [[ $use_ssh == "true" ]]; then
do_url=git@github.com:Microsoft/do-client.git
else
do_url=https://github.com/Microsoft/do-client.git
fi
git clone --recursive --single-branch --branch "$do_ref" --depth 1 "$do_url" . || return
bootstrap_file=$do_dir/build/scripts/bootstrap.sh
chmod +x "$bootstrap_file" || return
$SUDO "$bootstrap_file" --install build || return
mkdir cmake || return
pushd cmake > /dev/null || return
local do_cmake_options=(
"-DDO_BUILD_TESTS:BOOL=OFF"
"-DDO_INCLUDE_SDK=ON"
)
if [[ $keep_source_code == "true" ]]; then
do_cmake_options+=("-DCMAKE_BUILD_TYPE=Debug")
else
do_cmake_options+=("-DCMAKE_BUILD_TYPE=Release")
fi
cmake "${do_cmake_options[@]}" .. || return
cmake --build . || return
$SUDO cmake --build . --target install || return
popd > /dev/null || return
popd > /dev/null || return
}
do_install_azure_storage_sdk() {
echo "Installing azure-storage-sdk"
if is_dep_installed "azure-storage-sdk" "$azure_storage_sdk_tag_ref"; then
echo "Azure Storage SDK ($azure_storage_sdk_tag_ref) already installed. Skipping..."
return 0
fi
local azure_storage_sdk_dir=$work_folder/azure_storage_sdk_dir
if [[ -d $azure_storage_sdk_dir ]]; then
$SUDO rm -rf "$azure_storage_sdk_dir" || return
fi
local azure_storage_sdk_url
if [[ $use_ssh == "true" ]]; then
azure_storage_sdk_url=git@github.com:Azure/azure-sdk-for-cpp.git
else
azure_storage_sdk_url=https://github.com/Azure/azure-sdk-for-cpp.git
fi
echo -e "Building Azure Storage SDK ...\n\tBranch: $azure_storage_sdk_branch_ref\n\t Folder: $azure_storage_sdk_dir"
mkdir -p "$azure_storage_sdk_dir" || return
pushd "$azure_storage_sdk_dir" > /dev/null || return
git clone --recursive --single-branch --branch "$azure_storage_sdk_branch_ref" "$azure_storage_sdk_url" . || return
git checkout tags/"$azure_storage_sdk_tag_ref"
# Pin the vcpkg baseline used to resolve this SDK's manifest dependencies.
#
# The azure-sdk-for-cpp manifest at tag azure-core_1.6.0 does not declare a
# "builtin-baseline" in its vcpkg.json, so vcpkg falls back to whatever
# commit happens to be checked out in $VCPKG_ROOT (or HEAD when bootstrapped
# fresh). Newer vcpkg baselines ship libxml2 >= 2.13, which marks
# _xmlBuffer::content and _xmlBuffer::use as XML_DEPRECATED_MEMBER. The
# SDK's sdk/storage/azure-storage-common/src/xml_wrapper.cpp still accesses
# those fields directly and is built with -Werror, breaking the build.
#
# Pin the default registry to vcpkg release 2024.05.24, which still ships
# libxml2 2.11.7 (and is contemporaneous with azure-core_1.6.0).
cat > vcpkg-configuration.json <<'EOF'
{
"default-registry": {
"kind": "builtin",
"baseline": "f7423ee180c4b7f40d43402c2feb3859161ef625"
}
}
EOF
# Apply patch to fix missing cstdint include for GCC 12+ (Ubuntu 24.04, Debian 12)
# Check GCC version and apply patch only if GCC >= 12
local gcc_version
gcc_version=$(gcc -dumpversion | cut -d. -f1)
if [[ $gcc_version -ge 12 ]]; then
local patch_file="$script_dir/patches/azure-storage-sdk-base64-cstdint.patch"
if [[ -f $patch_file ]]; then
echo "Detected GCC $gcc_version (>= 12), applying patch to fix base64.cpp compilation issue..."
git apply "$patch_file" || {
warn "Failed to apply patch, build may fail on GCC $gcc_version"
}
else
warn "Patch file not found at $patch_file, build may fail on GCC $gcc_version"
fi
else
echo "GCC $gcc_version detected, patch not needed (only required for GCC >= 12)"
fi
local azure_storage_sdk_cmake_options=""
if [[ $keep_source_code == "true" ]]; then
# If source is wanted, presumably samples and symbols are useful as well.
azure_storage_sdk_cmake_options+=("-DCMAKE_BUILD_TYPE:STRING=Debug")
else
azure_storage_sdk_cmake_options+=("-DCMAKE_BUILD_TYPE:STRING=Release")
fi
cmake "${azure_storage_sdk_cmake_options[@]}" . || return
cmake --build . || return
$SUDO cmake --build . --target install || return
popd > /dev/null || return
mark_dep_installed "azure-storage-sdk" "$azure_storage_sdk_tag_ref"
}
do_install_delta() {
echo "Installing iot-hub-device-update-delta library ..."
# Compute effective_delta_ref early so we can check the stamp.
local OS VER
OS=$(lsb_release --short --id 2> /dev/null || echo "Unknown")
VER=$(lsb_release --short --release 2> /dev/null || echo "0")
local effective_delta_ref=$delta_ref
if [[ $delta_ref == "main" ]]; then
effective_delta_ref="feature/vnext-delta"
fi
if is_dep_installed "delta" "$effective_delta_ref"; then
echo "Delta library ($effective_delta_ref) already installed. Skipping..."
return 0
fi
local delta_dir=$work_folder/iot-hub-device-update-delta
if [[ -d $delta_dir ]]; then
$SUDO rm -rf "$delta_dir" || return
fi
local delta_url
if [[ $use_ssh == "true" ]]; then
delta_url=git@github.com:Azure/iot-hub-device-update-delta.git
else
delta_url=https://github.com/Azure/iot-hub-device-update-delta.git
fi
# Override delta_ref for distros with strict GCC that rejects the 'main' branch code.
# The 'main' branch uses 'enum class algorithm : uint32_t' which fails on GCC 12+.
# The feature/vnext-delta and adu/debian/12/amd64 branches use 'enum adu_algorithm' instead.
if [[ $delta_ref == "main" ]]; then
echo "Overriding delta_ref from 'main' to '$effective_delta_ref' for GCC compatibility"
fi
echo -e "Building iot-hub-device-update-delta library ...\n\tBranch: $effective_delta_ref\n\tFolder: $delta_dir"
mkdir -p "$delta_dir" || return
pushd "$delta_dir" > /dev/null || return
git clone --recursive --single-branch --branch "$effective_delta_ref" --depth 1 "$delta_url" . || return
# Patch dumpextfs CMakeLists.txt to link com_err (required by libext2fs static lib)
local dumpextfs_cmake="$delta_dir/src/native/tools/dumpextfs/CMakeLists.txt"
if [[ -f $dumpextfs_cmake ]] && ! grep -q "com_err" "$dumpextfs_cmake"; then
echo "Patching dumpextfs CMakeLists.txt to add com_err linkage..."
sed -i 's/pkg_check_modules(E2FSPROGS REQUIRED ext2fs)/pkg_check_modules(E2FSPROGS REQUIRED ext2fs)\npkg_check_modules(COM_ERR REQUIRED com_err)/' "$dumpextfs_cmake"
# shellcheck disable=SC2016 # CMake variables, not shell
sed -i 's/target_include_directories(dumpextfs PRIVATE ${E2FSPROGS_INCLUDE_DIRS})/target_include_directories(dumpextfs PRIVATE ${E2FSPROGS_INCLUDE_DIRS} ${COM_ERR_INCLUDE_DIRS})/' "$dumpextfs_cmake"
# shellcheck disable=SC2016 # CMake variables, not shell
sed -i 's/target_link_libraries(dumpextfs PRIVATE ${E2FSPROGS_LIBRARIES})/target_link_libraries(dumpextfs PRIVATE ${E2FSPROGS_LIBRARIES} ${COM_ERR_LIBRARIES})/' "$dumpextfs_cmake"
fi
# Patch the delta build.sh so it honors CC/CXX env overrides as fallback
# defaults instead of always passing the hard-coded triplet compiler paths
# to CMake. This lets us pin a newer GCC (below) on distros whose
# triplet-prefixed compiler is too old for C++20 (e.g. Ubuntu 20.04 arm64
# ships /usr/bin/aarch64-linux-gnu-g++ at GCC 9, which lacks <span>).
# When CC/CXX are unset, the ${CC:-...} fallback evaluates to the original
# hard-coded path, so this patch is a no-op on healthy distros.
local delta_build_sh="$delta_dir/src/native/build.sh"
if [[ -f $delta_build_sh ]] && grep -q '^\s*C_COMPILER="/usr/bin/' "$delta_build_sh"; then
echo "Patching delta build.sh to honor CC/CXX env overrides..."
# shellcheck disable=SC2016 # Intentional: writing literal ${CC:-...} into the patched script
sed -i \
-e 's|^\(\s*\)C_COMPILER="\(/usr/bin/[^"]*\)"|\1C_COMPILER="${CC:-\2}"|' \
-e 's|^\(\s*\)CXX_COMPILER="\(/usr/bin/[^"]*\)"|\1CXX_COMPILER="${CXX:-\2}"|' \
"$delta_build_sh" || return
fi
# Patch recompress CMakeLists.txt to link libconfig (required by libconfig++ static lib)
local recompress_cmake="$delta_dir/src/native/tools/recompress/CMakeLists.txt"
if [[ -f $recompress_cmake ]] && ! grep -q 'LIBCONFIG_C' "$recompress_cmake"; then
echo "Patching recompress CMakeLists.txt to add libconfig C linkage..."
sed -i 's/pkg_check_modules(LIBCONFIG REQUIRED libconfig++)/pkg_check_modules(LIBCONFIG REQUIRED libconfig++)\npkg_check_modules(LIBCONFIG_C REQUIRED libconfig)/' "$recompress_cmake"
# shellcheck disable=SC2016 # CMake variables, not shell
sed -i 's/target_link_libraries(recompress PRIVATE ${LIBCONFIG_LIBRARIES} config++)/target_link_libraries(recompress PRIVATE ${LIBCONFIG_LIBRARIES} ${LIBCONFIG_C_LIBRARIES} config++ config)/' "$recompress_cmake"
fi
# Install system dependencies required by delta library
echo "Installing delta library system dependencies..."
$SUDO apt-get update || return
# Determine the appropriate GCC version based on distro
local OS VER gcc_ver
OS=$(lsb_release --short --id)
VER=$(lsb_release --short --release)
if [[ $OS == "Debian" && $VER == "12" ]]; then
gcc_ver="12"
elif [[ ($OS == "Debian" && $VER == "11") || ($OS == "Ubuntu" && $VER == "20.04") || ($OS == "Ubuntu" && $VER == "22.04") ]]; then
gcc_ver="10"
else
# Default to system GCC (no specific version suffix)
gcc_ver=""
fi
echo "Using GCC version: ${gcc_ver:-system default}"
if [[ -n $gcc_ver ]]; then
# shellcheck disable=SC2086
$SUDO apt-get install --yes curl zip unzip tar gcc "gcc-${gcc_ver}" g++ "g++-${gcc_ver}" autoconf autopoint ninja-build pkg-config build-essential libtool cmake zlib1g-dev || return
else
$SUDO apt-get install --yes curl zip unzip tar gcc g++ autoconf autopoint ninja-build pkg-config build-essential libtool cmake zlib1g-dev || return
fi
# Setup gcc/g++ alternatives (only if specific version was installed)
if [[ -n $gcc_ver ]]; then
echo "Setting up gcc/g++ alternatives..."
$SUDO update-alternatives --install /usr/bin/gcc gcc "/usr/bin/gcc-${gcc_ver}" 20 || true
$SUDO update-alternatives --install /usr/bin/g++ g++ "/usr/bin/g++-${gcc_ver}" 20 || true
fi
# Setup VCPKG for delta library dependencies
echo "Setting up VCPKG for delta library..."
local vcpkg_root=$work_folder/vcpkg
local build_type="Release"
# Auto-detect architecture for vcpkg triplet
local arch
arch=$(uname -m)
local vcpkg_triplet
local vcpkg_arch
case "$arch" in
x86_64 | amd64)
vcpkg_triplet="x64-linux"
vcpkg_arch="x64"
;;
aarch64 | arm64)
vcpkg_triplet="arm64-linux"
vcpkg_arch="arm64"
;;
armv7l | armhf)
vcpkg_triplet="arm-linux"
vcpkg_arch="arm"
;;
*)
echo "Warning: Unknown architecture '$arch', defaulting to x64-linux"
vcpkg_triplet="x64-linux"
vcpkg_arch="x64"
;;
esac
echo "Detected architecture: $arch -> using triplet: $vcpkg_triplet"
# Decide whether the delta build needs an explicit compiler pin.
# The delta build.sh selects /usr/bin/{x64,arm-linux-gnueabihf,aarch64-linux-gnu}-g++
# per triplet. The unprefixed `update-alternatives` we set above does NOT
# affect the triplet-prefixed binaries. On distros where the triplet g++
# is older than the gcc_ver we just installed (notably Ubuntu 20.04 arm64:
# default aarch64-linux-gnu-g++ is GCC 9, no <span>), pass CC/CXX to the
# patched delta build.sh so CMake picks the newer compiler.
# delta_cc / delta_cxx stay empty when no pin is needed; the patched
# build.sh then falls back to its original hard-coded triplet path.
local triplet_cxx="" delta_cc="" delta_cxx=""
case "$vcpkg_triplet" in
x64-linux) triplet_cxx="/usr/bin/g++" ;;
arm-linux) triplet_cxx="/usr/bin/arm-linux-gnueabihf-g++" ;;
arm64-linux) triplet_cxx="/usr/bin/aarch64-linux-gnu-g++" ;;
esac
if [[ -n $gcc_ver && -x $triplet_cxx ]]; then
local triplet_major
triplet_major=$("$triplet_cxx" -dumpversion 2> /dev/null | cut -d. -f1)
if [[ -n $triplet_major && $triplet_major -lt $gcc_ver ]]; then
if [[ -x "/usr/bin/g++-${gcc_ver}" && -x "/usr/bin/gcc-${gcc_ver}" ]]; then
echo "Triplet compiler $triplet_cxx is GCC ${triplet_major}; pinning delta build to gcc-${gcc_ver}/g++-${gcc_ver} for C++20 support"
delta_cc="/usr/bin/gcc-${gcc_ver}"
delta_cxx="/usr/bin/g++-${gcc_ver}"
else
echo "Warning: triplet compiler $triplet_cxx is GCC ${triplet_major} but /usr/bin/g++-${gcc_ver} is missing; delta build may fail on C++20 sources"
fi
fi
fi
if [[ $keep_source_code == "true" ]]; then
build_type="Debug"
fi
# Pin to a known-good vcpkg release to avoid breakage from HEAD changes.
local vcpkg_commit="e0edebd1dc2d03cf7d02349df91de74ef4d0c00e" # 2026.02.27
# Clone and bootstrap vcpkg if needed
if [ ! -d "$vcpkg_root" ]; then
echo "Cloning vcpkg (pinned to $vcpkg_commit)..."
git clone https://github.com/microsoft/vcpkg "$vcpkg_root" || return
fi
pushd "$vcpkg_root" > /dev/null || return
git fetch origin || true
git checkout "$vcpkg_commit" || return
./bootstrap-vcpkg.sh || return
popd > /dev/null || return
# Create triplet if it doesn't exist (community triplet may not be present)
local triplet_file="$vcpkg_root/triplets/community/$vcpkg_triplet.cmake"
if [ ! -f "$triplet_file" ]; then
echo "Creating $vcpkg_triplet triplet..."
mkdir -p "$vcpkg_root/triplets/community" || return
cat > "$triplet_file" << EOF
set(VCPKG_TARGET_ARCHITECTURE $vcpkg_arch)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_CMAKE_SYSTEM_NAME Linux)
EOF
fi
# Set environment variables to force classic mode and avoid conflicts with ADU's vcpkg.json
export VCPKG_ROOT="$vcpkg_root"
export VCPKG_FEATURE_FLAGS="-manifests"
# Install dependencies using classic mode with --classic flag
echo "Installing vcpkg dependencies for delta library..."
local overlay_ports="$delta_dir/vcpkg/ports"
# Helper function for vcpkg install with classic mode
vcpkg_install_classic() {
local pkg=$1
echo "Installing $pkg:$vcpkg_triplet..."
"$vcpkg_root/vcpkg" install "$pkg:$vcpkg_triplet" \
--classic \
--overlay-ports="$overlay_ports" \
--overlay-triplets="$vcpkg_root/triplets/community" \
--x-install-root="$vcpkg_root/installed" || return 1
}
# ---------------------------------------------------------------------
# Network-isolation workaround: pre-seed the bzip2 source archive.
#
# Every vcpkg port installed below fetches its sources from github.com
# EXCEPT bzip2, whose port downloads bzip2-<ver>.tar.gz from sourceware.org
# (with a www.mirrorservice.org fallback). Under 1ES network isolation the
# amd64 build pool only reaches an allowlist of mirrors; neither sourceware
# host is on it, so the fetch times out and "vcpkg install bzip2" fails with
# BUILD_FAILED, breaking the whole dependency install.
#
# Drop the byte-for-byte identical tarball into vcpkg's download cache under
# the exact name the port expects. The distro archive pools carry it as
# bzip2_<ver>.orig.tar.gz and are on the isolation allowlist -- deb.debian.org
# for Debian containers, azure.archive.ubuntu.com for Ubuntu containers -- so
# one of the mirrors below is always reachable. vcpkg then validates the
# SHA512 and skips its upstream download. If no mirror is reachable or the
# hash mismatches we leave the cache untouched and let vcpkg try upstream
# (no worse than before).
#
# bzip2 1.0.8 has been the latest release since 2019; if the pinned vcpkg
# baseline ever bumps the version, update bzip2_ver / bzip2_sha512.
# ---------------------------------------------------------------------
local bzip2_ver="1.0.8"
local bzip2_sha512="083f5e675d73f3233c7930ebe20425a533feedeaaa9d8cc86831312a6581cefbe6ed0d08d2fa89be81082f2a5abdabca8b3c080bf97218a1bd59dc118a30b9f3"
local vcpkg_downloads="$vcpkg_root/downloads"
local bzip2_cache="$vcpkg_downloads/bzip2-${bzip2_ver}.tar.gz"
if [[ -f $bzip2_cache ]] && echo "${bzip2_sha512} ${bzip2_cache}" | sha512sum --check --status; then
echo "bzip2-${bzip2_ver}.tar.gz already cached for vcpkg; skipping pre-seed."
else
echo "Pre-seeding vcpkg download cache with bzip2-${bzip2_ver}.tar.gz from an allowlisted distro mirror..."
mkdir -p "$vcpkg_downloads"
local bzip2_mirror bzip2_seeded=false
for bzip2_mirror in \
"http://deb.debian.org/debian/pool/main/b/bzip2/bzip2_${bzip2_ver}.orig.tar.gz" \
"http://azure.archive.ubuntu.com/ubuntu/pool/main/b/bzip2/bzip2_${bzip2_ver}.orig.tar.gz" \
"http://archive.ubuntu.com/ubuntu/pool/main/b/bzip2/bzip2_${bzip2_ver}.orig.tar.gz" \
"https://sourceware.org/pub/bzip2/bzip2-${bzip2_ver}.tar.gz"; do
echo " trying ${bzip2_mirror}"
if curl -fsSL --connect-timeout 15 --max-time 180 "$bzip2_mirror" -o "${bzip2_cache}.tmp" \
&& echo "${bzip2_sha512} ${bzip2_cache}.tmp" | sha512sum --check --status; then
mv -f "${bzip2_cache}.tmp" "$bzip2_cache"
echo " pre-seeded ${bzip2_cache} (SHA512 verified)"
bzip2_seeded=true
break
fi
rm -f "${bzip2_cache}.tmp"