Repository navigation
Expand file tree
/
Copy pathinstall_script.sh.template
More file actions
1274 lines (1096 loc) · 45.1 KB
/
Copy pathinstall_script.sh.template
File metadata and controls
1274 lines (1096 loc) · 45.1 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
# (C) Datadog, Inc. 2010-present
# All rights reserved
# Licensed under Apache-2.0 License (see LICENSE)
# Datadog Agent installation script: install and set up the Agent on supported Linux distributions
# using the package manager and Datadog repositories.
set -e
DEPRECATION_MESSAGE_PLACEHOLDER
install_script_version=1.22.0.post
logfile="ddagent-install.log"
support_email=support@datadoghq.com
variant=install_scriptINSTALL_INFO_VERSION_PLACEHOLDER
LEGACY_ETCDIR="/etc/dd-agent"
LEGACY_CONF="$LEGACY_ETCDIR/datadog.conf"
# DATADOG_APT_KEY_CURRENT.public always contains key used to sign current
# repodata and newly released packages
# DATADOG_APT_KEY_382E94DE.public expires in 2022
# DATADOG_APT_KEY_F14F620E.public expires in 2032
# DATADOG_APT_KEY_C0962C7D.public expires in 2028
APT_GPG_KEYS=("DATADOG_APT_KEY_CURRENT.public" "DATADOG_APT_KEY_C0962C7D.public" "DATADOG_APT_KEY_F14F620E.public" "DATADOG_APT_KEY_382E94DE.public")
# DATADOG_RPM_KEY_CURRENT.public always contains key used to sign current
# repodata and newly released packages
# DATADOG_RPM_KEY_E09422B3.public expires in 2022
# DATADOG_RPM_KEY_FD4BF915.public expires in 2024
# DATADOG_RPM_KEY_B01082D3.public expires in 2028
RPM_GPG_KEYS=("DATADOG_RPM_KEY_CURRENT.public" "DATADOG_RPM_KEY_B01082D3.public" "DATADOG_RPM_KEY_FD4BF915.public" "DATADOG_RPM_KEY_E09422B3.public")
# DATADOG_RPM_KEY.public (4172A230) was only useful to install old (< 6.14) Agent packages.
# We no longer add it and we explicitly remove it.
RPM_GPG_KEYS_TO_REMOVE=("gpg-pubkey-4172a230-55dd14f6")
# Error codes for telemetry
GENERAL_ERROR_CODE=1
UNSUPPORTED_PLATFORM_CODE=5
INVALID_PARAMETERS_CODE=6
UNABLE_TO_INSTALL_DEPENDENCY_CODE=7
# Set up a named pipe for logging
npipe=/tmp/$$.tmp
mknod $npipe p
# Log all output to a log for error checking
tee <$npipe $logfile &
exec 1>&-
exec 1>$npipe 2>&1
trap 'rm -f $npipe' EXIT
function fallback_msg(){
printf "
If you are still having problems, please send an email to $support_email
with the contents of $logfile and any information you think would be
useful and we will do our very best to help you solve your problem.\n"
}
function report(){
if curl -f -s \
--data-urlencode "os=${OS}" \
--data-urlencode "version=${agent_major_version}" \
--data-urlencode "log=$(cat $logfile)" \
--data-urlencode "email=${email}" \
--data-urlencode "apikey=${apikey}" \
--data-urlencode "variant=${variant}" \
"$report_failure_url"; then
printf "A notification has been sent to Datadog with the contents of $logfile\n"
else
printf "Unable to send the notification (curl v7.18 or newer is required)"
fi
}
function report_telemetry() {
if [ "$DD_INSTRUMENTATION_TELEMETRY_ENABLED" == "false" ] || \
[ "$site" == "ddog-gov.com" ] || \
[ -z "${apikey}" ] || \
[ -z "$telemetry_url" ]; then
return
fi
if [ -n "$agent_minor_version" ] ; then
safe_agent_version=$(echo -n "$agent_major_version.$agent_minor_version" | tr '\n' ' ' | tr '"' '_')
else
safe_agent_version=$(echo -n "$agent_major_version" | tr '\n' ' ' | tr '"' '_')
fi
APM_TELEMETRY_SAFE_AGENT_VERSION_OVERRIDE_PLACEHOLDER
if [ -z "${ERROR_CODE}" ] ; then
telemetry_event="
{
\"request_type\": \"apm-onboarding-event\",
\"api_version\": \"v1\",
\"payload\": {
\"event_name\": \"agent.installation.success\",
\"tags\": {
\"agent_platform\": \"native\",
\"agent_version\": \"$safe_agent_version\",
\"script_version\": \"$install_script_version\"
}
}
}
"
else
safe_error_message=$(echo -n "$ERROR_MESSAGE" | tr '\n' ' ' | tr '"' '_')
telemetry_event="
{
\"request_type\": \"apm-onboarding-event\",
\"api_version\": \"v1\",
\"payload\": {
\"event_name\": \"agent.installation.error\",
\"tags\": {
\"agent_platform\": \"native\",
\"agent_version\": \"$safe_agent_version\",
\"script_version\": \"$install_script_version\"
},
\"error\": {
\"code\": $ERROR_CODE,
\"message\": \"$safe_error_message\"
}
}
}
"
fi
if ! (cat <<END
$telemetry_event
END
) | curl --fail --silent --output /dev/null \
"$telemetry_url" \
--header 'Content-Type: application/json' \
--header "DD-Api-Key: $apikey" \
--data @-
then
printf "Unable to send telemetry\n"
fi
}
function on_read_error() {
printf "Timed out or input EOF reached, assuming 'No'\n"
yn="n"
}
function get_email() {
emaillocalpart='^[a-zA-Z0-9][a-zA-Z0-9._%+-]{0,63}'
hostnamepart='[a-zA-Z0-9.-]+\.[a-zA-Z]+'
email_regex="$emaillocalpart@$hostnamepart"
cntr=0
until [[ "$cntr" -eq 3 ]]
do
read -p "Enter an email address so we can follow up: " -r email
if [[ "$email" =~ $email_regex ]]; then
isEmailValid=true
break
else
((cntr=cntr+1))
echo -e "\033[33m($cntr/3) Email address invalid: $email\033[0m\n"
fi
done
}
function on_error() {
if [ -z "${ERROR_MESSAGE}" ] ; then
# Save the few lines of the log file for telemetry if the error message is blank
SAVED_ERROR_MESSAGE=$(tail -n 3 $logfile)
fi
printf "\033[31m$ERROR_MESSAGE
It looks like you hit an issue when trying to install the $nice_flavor.
$ERR_SUMMARY
Troubleshooting and basic usage information for the $nice_flavor are available at:
https://docs.datadoghq.com/agent/basic_agent_usage/\n\033[0m\n"
ERROR_MESSAGE=$SAVED_ERROR_MESSAGE
ERROR_CODE=$GENERAL_ERROR_CODE
report_telemetry
if ! tty -s; then
fallback_msg
exit 1;
fi
if [ "$site" == "ddog-gov.com" ]; then
fallback_msg
exit 1;
fi
while true; do
read -t 60 -p "Do you want to send a failure report to Datadog (including $logfile)? (y/[n]) " -r yn || on_read_error
case $yn in
[Yy]* )
get_email
if [[ -n "$isEmailValid" ]]; then
report
fi
fallback_msg
break;;
[Nn]*|"" )
fallback_msg
break;;
* )
printf "Please answer yes or no.\n"
;;
esac
done
}
trap on_error ERR
function verify_agent_version(){
local ver_separator="$1"
if [ -z "$agent_version_custom" ]; then
ERROR_MESSAGE="Specified version not found: $agent_major_version.$agent_minor_version"
ERROR_CODE=$INVALID_PARAMETERS_CODE
echo -e "
\033[33mWarning: $ERROR_MESSAGE
Check available versions at: https://github.com/DataDog/datadog-agent/blob/main/CHANGELOG.rst\033[0m"
fallback_msg
report_telemetry
exit 1;
else
agent_flavor+="$ver_separator$agent_version_custom"
fi
}
function remove_rpm_gpg_keys() {
local sudo_cmd="$1"
shift
local old_keys=("$@")
for key in "${old_keys[@]}"; do
if $sudo_cmd rpm -q "$key" 1>/dev/null 2>/dev/null; then
echo -e "\033[34m\nRemoving old RPM key $key from the RPM database\n\033[0m"
$sudo_cmd rpm --erase "$key"
fi
done
}
function create_config_file() {
local sudo_cmd="$1"
local config_file="$2"
local owner="$3"
if [ ! -e "$config_file" ]; then
$sudo_cmd cp "$config_file.example" "$config_file"
fi
$sudo_cmd chown "$owner:dd-agent" "$config_file"
$sudo_cmd chmod 640 "$config_file"
}
function ensure_config_file_exists() {
local sudo_cmd="$1"
local config_file="$2"
local owner="$3"
if [ -e "$config_file" ]; then
printf "\033[34m\n* Keeping old $config_file configuration file\n\033[0m\n"
else
create_config_file "$sudo_cmd" "$config_file" "$owner"
fi
}
echo -e "\033[34m\n* Datadog INSTALL_SCRIPT_REPORT_VERSION_PLACEHOLDER install script v${install_script_version}\n\033[0m"
hostname=
if [ -n "$DD_HOSTNAME" ]; then
hostname=$DD_HOSTNAME
fi
site=
if [ -n "$DD_SITE" ]; then
site="$DD_SITE"
fi
apikey=
if [ -n "$DD_API_KEY" ]; then
apikey=$DD_API_KEY
fi
no_start=
if [ -n "$DD_INSTALL_ONLY" ]; then
no_start=true
fi
no_agent=
if [ -n "$DD_NO_AGENT_INSTALL" ]; then
no_agent=true
fi
host_tags=
# comma-separated list of tags
if [ -n "$DD_HOST_TAGS" ]; then
host_tags=$DD_HOST_TAGS
fi
if [ -n "$DD_REPO_URL" ]; then
repository_url=$DD_REPO_URL
elif [ -n "$REPO_URL" ]; then
echo -e "\033[33mWarning: REPO_URL is deprecated and might be removed later (use DD_REPO_URL instead).\033[0m"
repository_url=$REPO_URL
else
repository_url="datadoghq.com"
fi
if [ -n "$TESTING_KEYS_URL" ]; then
keys_url=$TESTING_KEYS_URL
else
keys_url="keys.datadoghq.com"
fi
if [ -n "$TESTING_YUM_URL" ]; then
yum_url=$TESTING_YUM_URL
else
yum_url="yum.${repository_url}"
fi
# We turn off `repo_gpgcheck` for custom REPO_URL, unless explicitly turned
# on via DD_RPM_REPO_GPGCHECK.
# There is more logic for redhat/suse in their specific code branches below
rpm_repo_gpgcheck=
if [ -n "$DD_RPM_REPO_GPGCHECK" ]; then
rpm_repo_gpgcheck=$DD_RPM_REPO_GPGCHECK
else
if [ -n "$REPO_URL" ] || [ -n "$DD_REPO_URL" ]; then
rpm_repo_gpgcheck=0
fi
fi
if [ -n "$TESTING_APT_URL" ]; then
apt_url=$TESTING_APT_URL
else
apt_url="apt.${repository_url}"
fi
report_failure_url="https://api.datadoghq.com/agent_stats/report_failure"
if [ -n "$DD_SITE" ]; then
report_failure_url="https://api.${DD_SITE}/agent_stats/report_failure"
fi
telemetry_url="https://instrumentation-telemetry-intake.datadoghq.com/api/v2/apmtelemetry"
if [ -n "$DD_SITE" ]; then
telemetry_url="https://instrumentation-telemetry-intake.${DD_SITE}/api/v2/apmtelemetry"
fi
if [ -n "$TESTING_REPORT_URL" ]; then
report_failure_url=$TESTING_REPORT_URL
telemetry_url=$TESTING_REPORT_URL
fi
upgrade=
if [ -n "$DD_UPGRADE" ]; then
upgrade=$DD_UPGRADE
fi
fips_mode=
if [ -n "$DD_FIPS_MODE" ]; then
fips_mode=$DD_FIPS_MODE
fi
dd_env=
if [ -n "$DD_ENV" ]; then
dd_env=$DD_ENV
fi
declare -a apm_libraries
declare host_injection_enabled
declare docker_injection_enabled
DD_APM_INSTRUMENTATION_ENABLED_DOCKER_PLACEHOLDER
if [ "$DD_APM_INSTRUMENTATION_ENABLED" = "all" ] ; then
host_injection_enabled="true"
docker_injection_enabled="true"
fi
if [ "$DD_APM_INSTRUMENTATION_ENABLED" = "host" ] ; then
host_injection_enabled="true"
fi
if [ "$DD_APM_INSTRUMENTATION_ENABLED" = "docker" ] ; then
docker_injection_enabled="true"
no_agent=true
fi
if [ -n "${host_injection_enabled}${docker_injection_enabled}" ] ; then
apm_libraries=("datadog-apm-inject")
fi
if [ -n "${host_injection_enabled}" ] && [ -n "${no_agent}" ] ; then
ERROR_MESSAGE="Host injection is not supported with the DD_NO_AGENT_INSTALL flag. Unset either DD_APM_INSTRUMENTATION_ENABLED or DD_NO_AGENT_INSTALL"
ERROR_CODE=$INVALID_PARAMETERS_CODE
echo -e "\033[31m$ERROR_MESSAGE\033[0m\n"
report_telemetry
exit 1;
fi
daemon_config_dir="/etc/docker"
if [ -n "$docker_injection_enabled" ]; then
if [ ! -d "$daemon_config_dir" ]; then
ERROR_MESSAGE="$daemon_config_dir does not exist. Please ensure docker is installed"
ERROR_CODE=$INVALID_PARAMETERS_CODE
echo -e "\033[31m$ERROR_MESSAGE\033[0m\n"
report_telemetry
exit 1;
fi
fi
if [ -n "$DD_APM_INSTRUMENTATION_LANGUAGES" ]; then
read -r -a lib_array <<< "$DD_APM_INSTRUMENTATION_LANGUAGES"
for lib in "${lib_array[@]}"
do
case $lib in
all)
apm_libraries+=("datadog-apm-library-all")
;;
java)
apm_libraries+=("datadog-apm-library-java")
;;
js)
apm_libraries+=("datadog-apm-library-js")
;;
python)
apm_libraries+=("datadog-apm-library-python")
;;
dotnet)
apm_libraries+=("datadog-apm-library-dotnet")
;;
ruby)
apm_libraries+=("datadog-apm-library-ruby")
;;
*)
ERROR_MESSAGE="Unknown apm library: $lib. Must be one of: all, java, js, python, dotnet, ruby"
ERROR_CODE=$INVALID_PARAMETERS_CODE
echo "$ERROR_MESSAGE"
report_telemetry
exit 1;
;;
esac
done
elif [ -n "$host_injection_enabled" ] || [ -n "$docker_injection_enabled" ]; then
# Default to all libraries if injection is enabled
apm_libraries+=("datadog-apm-library-all")
fi
no_config_change=
if [ -n "$DD_APM_INSTRUMENTATION_NO_CONFIG_CHANGE" ]; then
no_config_change="--no-config-change"
fi
system_probe_ensure_config=
if [ -n "$DD_SYSTEM_PROBE_ENSURE_CONFIG" ]; then
system_probe_ensure_config=$DD_SYSTEM_PROBE_ENSURE_CONFIG
fi
agent_flavor="datadog-agent"
if [ -n "$DD_AGENT_FLAVOR" ]; then
agent_flavor=$DD_AGENT_FLAVOR #Eg: datadog-iot-agent
fi
# Emulate hashmap with simple switch case
getMapData() {
if [ "$1" = "flavor_to_readable" ]; then
case "$2" in
"datadog-agent")
DATA="Datadog Agent"
;;
"datadog-iot-agent")
DATA="Datadog IoT Agent"
;;
"datadog-dogstatsd")
DATA="Datadog Dogstatsd"
;;
"datadog-fips-proxy")
DATA="Datadog FIPS Proxy"
;;
"datadog-heroku-agent")
DATA="Datadog Heroku Agent"
;;
*)
DATA="Unknown"
;;
esac
fi
printf '%s' "$DATA"
}
nice_flavor=$(getMapData flavor_to_readable "$agent_flavor")
if [ -z "$nice_flavor" ]; then
ERROR_MESSAGE="Unknown DD_AGENT_FLAVOR \"$agent_flavor\""
ERROR_CODE=$INVALID_PARAMETERS_CODE
echo -e "\033[33m$ERROR_MESSAGE\033[0m"
fallback_msg
report_telemetry
exit 1;
fi
if [ "$agent_flavor" = "datadog-dogstatsd" ]; then
system_service="datadog-dogstatsd"
etcdir="/etc/datadog-dogstatsd"
config_file="$etcdir/dogstatsd.yaml"
fi
if [ -z "$system_service" ]; then
system_service="datadog-agent"
fi
declare -a services
if [ -n "$no_agent" ]; then
services=()
else
services=("$system_service")
fi
if [ -n "$fips_mode" ]; then
services+=("datadog-fips-proxy")
fi
if [ -z "$etcdir" ]; then
etcdir="/etc/datadog-agent"
fi
etcdirfips=/etc/datadog-fips-proxy
if [ -z "$config_file" ]; then
config_file="$etcdir/datadog.yaml"
fi
config_file_fips=$etcdirfips/datadog-fips-proxy.cfg
system_probe_config_file=$etcdir/system-probe.yaml
security_agent_config_file=$etcdir/security-agent.yaml
agent_major_version=AGENT_MAJOR_VERSION_PLACEHOLDER
# shellcheck disable=SC2050
# ^ to disable the warning about constant comparison in the elif clause below
if [ -n "$DD_AGENT_MAJOR_VERSION" ]; then
if [ "$DD_AGENT_MAJOR_VERSION" != "6" ] && [ "$DD_AGENT_MAJOR_VERSION" != "7" ]; then
ERROR_MESSAGE="DD_AGENT_MAJOR_VERSION must be either 6 or 7. Current value: $DD_AGENT_MAJOR_VERSION"
ERROR_CODE=$INVALID_PARAMETERS_CODE
echo "$ERROR_MESSAGE"
report_telemetry
exit 1;
fi
agent_major_version=$DD_AGENT_MAJOR_VERSION
elif [ "IS_LEGACY_SCRIPT_PLACEHOLDER" == "true" ]; then
if [ "$agent_flavor" == "datadog-agent" ] ; then
echo -e "\033[33mWarning: DD_AGENT_MAJOR_VERSION not set. Installing $nice_flavor version 6 by default.\033[0m"
else
echo -e "\033[33mWarning: DD_AGENT_MAJOR_VERSION not set. Installing $nice_flavor version 7 by default.\033[0m"
agent_major_version=7
fi
fi
if [ -n "$DD_AGENT_MINOR_VERSION" ]; then
# Examples:
# - 20 = defaults to highest patch version x.20.2
# - 20.0 = sets explicit patch version x.20.0
# Note: Specifying an invalid minor version will terminate the script.
agent_minor_version=${DD_AGENT_MINOR_VERSION}
# Handle pre-release versions like "35.0~rc.5" -> "35.0" or "27.1~viper~conflict~fix" -> "27.1"
# Allow to get a "clean" version number that can be used to compare the version with others (e.g: "35.0~rc.5" < "36.0" because "35.0" < "36.0")
clean_agent_minor_version=$(echo "${DD_AGENT_MINOR_VERSION}" | sed -E 's/~.*//g')
# remove the patch version if the minor version includes it (eg: 33.1 -> 33)
agent_minor_version_without_patch="${clean_agent_minor_version%.*}"
fi
agent_dist_channel=stable
if [ -n "$DD_AGENT_DIST_CHANNEL" ]; then
if [ "$repository_url" == "datadoghq.com" ]; then
if [ "$DD_AGENT_DIST_CHANNEL" != "stable" ] && [ "$DD_AGENT_DIST_CHANNEL" != "beta" ]; then
ERROR_MESSAGE="DD_AGENT_DIST_CHANNEL must be either 'stable' or 'beta'. Current value: $DD_AGENT_DIST_CHANNEL"
ERROR_CODE=$INVALID_PARAMETERS_CODE
echo "$ERROR_MESSAGE"
report_telemetry
exit 1;
fi
elif [ "$DD_AGENT_DIST_CHANNEL" != "stable" ] && [ "$DD_AGENT_DIST_CHANNEL" != "beta" ] && [ "$DD_AGENT_DIST_CHANNEL" != "nightly" ]; then
ERROR_MESSAGE="DD_AGENT_DIST_CHANNEL must be either 'stable', 'beta' or 'nightly' on custom repos. Current value: $DD_AGENT_DIST_CHANNEL"
ERROR_CODE=$INVALID_PARAMETERS_CODE
echo "$ERROR_MESSAGE"
report_telemetry
exit 1;
fi
agent_dist_channel=$DD_AGENT_DIST_CHANNEL
fi
if [ -n "$TESTING_YUM_VERSION_PATH" ]; then
yum_version_path=$TESTING_YUM_VERSION_PATH
else
yum_version_path="${agent_dist_channel}/${agent_major_version}"
fi
if [ -n "$TESTING_APT_REPO_VERSION" ]; then
apt_repo_version=$TESTING_APT_REPO_VERSION
else
apt_repo_version="${agent_dist_channel} ${agent_major_version}"
fi
if [ ! "$apikey" ]; then
# if it's an upgrade, then we will use the transition script
if [ ! "$upgrade" ] && [ ! -e "$config_file" ] && [ ! "$no_agent" ]; then
printf "\033[31mAPI key not available in DD_API_KEY environment variable.\033[0m\n"
exit 1;
fi
fi
if [[ $(uname -m) == "armv7l" ]] && [[ $agent_flavor == "datadog-agent" ]] && [ ! "$no_agent" ]; then
ERROR_MESSAGE="The full $nice_flavor isn't available for your architecture (armv7l).\nInstall the $(getMapData flavor_to_readable datadog-iot-agent) by setting DD_AGENT_FLAVOR='datadog-iot-agent'."
ERROR_CODE=$UNSUPPORTED_PLATFORM_CODE
printf "\033[31m$ERROR_MESSAGE\033[0m\n"
report_telemetry
exit 1;
fi
if [ ${#apm_libraries[@]} -gt 0 ] && [ $agent_major_version = "6" ] ; then
ERROR_MESSAGE="APM library injection is not supported with Agent version 6"
ERROR_CODE=$INVALID_PARAMETERS_CODE
echo -e "\033[31m$ERROR_MESSAGE\033[0m\n"
report_telemetry
exit 1;
fi
# OS/Distro Detection
# Try lsb_release, fallback with /etc/issue then uname command
KNOWN_DISTRIBUTION="(Debian|Ubuntu|RedHat|CentOS|openSUSE|Amazon|Arista|SUSE|Rocky|AlmaLinux)"
DISTRIBUTION=$(lsb_release -d 2>/dev/null | grep -Eo $KNOWN_DISTRIBUTION || grep -Eo $KNOWN_DISTRIBUTION /etc/issue 2>/dev/null || grep -Eo $KNOWN_DISTRIBUTION /etc/Eos-release 2>/dev/null || grep -m1 -Eo $KNOWN_DISTRIBUTION /etc/os-release 2>/dev/null || uname -s)
if [ "$DISTRIBUTION" == "Darwin" ]; then
ERROR_MESSAGE="This script does not support installing on the Mac."
ERROR_CODE=$UNSUPPORTED_PLATFORM_CODE
printf "\033[31m$ERROR_MESSAGE
Please use the 1-step script available at https://app.datadoghq.com/account/settings#agent/mac.\033[0m\n"
report_telemetry
exit 1;
elif [ -f /etc/debian_version ] || [ "$DISTRIBUTION" == "Debian" ] || [ "$DISTRIBUTION" == "Ubuntu" ]; then
OS="Debian"
elif [ -f /etc/redhat-release ] || [ "$DISTRIBUTION" == "RedHat" ] || [ "$DISTRIBUTION" == "CentOS" ] || [ "$DISTRIBUTION" == "Amazon" ] || [ "$DISTRIBUTION" == "Rocky" ] || [ "$DISTRIBUTION" == "AlmaLinux" ]; then
OS="RedHat"
# Some newer distros like Amazon may not have a redhat-release file
elif [ -f /etc/system-release ] || [ "$DISTRIBUTION" == "Amazon" ]; then
OS="RedHat"
# Arista is based off of Fedora14/18 but do not have /etc/redhat-release
elif [ -f /etc/Eos-release ] || [ "$DISTRIBUTION" == "Arista" ]; then
OS="RedHat"
# openSUSE and SUSE use /etc/SuSE-release or /etc/os-release
elif [ -f /etc/SuSE-release ] || [ "$DISTRIBUTION" == "SUSE" ] || [ "$DISTRIBUTION" == "openSUSE" ]; then
OS="SUSE"
fi
if [[ "$agent_flavor" == "datadog-dogstatsd" ]]; then
if [[ $(uname -m) == "armv7l" ]] || { [[ $(uname -m) != "x86_64" ]] && [[ "$OS" != "Debian" ]]; }; then
ERROR_MESSAGE="The $nice_flavor isn't available for your architecture."
ERROR_CODE=$UNSUPPORTED_PLATFORM_CODE
printf "\033[31m$ERROR_MESSAGE\033[0m\n"
report_telemetry
exit 1;
fi
if [[ "$OS" == "Debian" ]] && [[ $(uname -m) == "aarch64" ]] && { [[ -n "$agent_minor_version_without_patch" ]] && [[ "$agent_minor_version_without_patch" -lt 35 ]]; }; then
ERROR_MESSAGE="The $nice_flavor is only available since version 7.35.0 for your architecture."
ERROR_CODE=$UNSUPPORTED_PLATFORM_CODE
printf "\033[31m$ERROR_MESSAGE\033[0m\n"
report_telemetry
exit 1;
fi
fi
if [ -n "$fips_mode" ]; then
UNAME_M=$(uname -m)
if [[ ${UNAME_M} != "x86_64" ]] && [[ ${UNAME_M} != "aarch64" ]]; then
ERROR_MESSAGE="FIPS mode isn't available for your architecture"
ERROR_CODE=$UNSUPPORTED_PLATFORM_CODE
printf "\033[31m$ERROR_MESSAGE\033[0m\n"
report_telemetry
exit 1;
fi
if [[ -n "$agent_minor_version_without_patch" ]] && [[ "${agent_minor_version_without_patch}" -lt 41 ]]; then
ERROR_MESSAGE="FIPS mode is only available since version AGENT_MAJOR_VERSION_PLACEHOLDER.41.0 and requested minor version is $agent_minor_version"
ERROR_CODE=$INVALID_PARAMETERS_CODE
printf "\033[31m$ERROR_MESSAGE\033[0m\n"
report_telemetry
exit 1;
fi
fi
# Root user detection
if [ "$UID" == "0" ]; then
sudo_cmd=''
else
sudo_cmd='sudo'
fi
# Install the necessary package sources
if [ "$OS" == "RedHat" ]; then
remove_rpm_gpg_keys "$sudo_cmd" "${RPM_GPG_KEYS_TO_REMOVE[@]}"
if { [ "$DISTRIBUTION" == "Rocky" ] || [ "$DISTRIBUTION" == "AlmaLinux" ]; } && { [ -n "$agent_minor_version_without_patch" ] && [ "$agent_minor_version_without_patch" -lt 33 ]; } && ! echo "$agent_flavor" | grep '[0-9]' > /dev/null; then
ERROR_MESSAGE="A future version of $nice_flavor will support $DISTRIBUTION"
ERROR_CODE=$UNSUPPORTED_PLATFORM_CODE
echo -e "\033[33m$ERROR_MESSAGE\n\033[0m"
report_telemetry
exit;
fi
echo -e "\033[34m\n* Installing YUM sources for Datadog\n\033[0m"
UNAME_M=$(uname -m)
if [ "$UNAME_M" == "i686" ] || [ "$UNAME_M" == "i386" ] || [ "$UNAME_M" == "x86" ]; then
ARCHI="i386"
elif [ "$UNAME_M" == "aarch64" ]; then
ARCHI="aarch64"
else
ARCHI="x86_64"
fi
# Because of https://bugzilla.redhat.com/show_bug.cgi?id=1792506, we disable
# repo_gpgcheck on RHEL/CentOS 8.1
if [ -z "$rpm_repo_gpgcheck" ]; then
if grep -q "8\.1\(\b\|\.\)" /etc/redhat-release 2>/dev/null; then
rpm_repo_gpgcheck=0
else
rpm_repo_gpgcheck=1
fi
fi
gpgkeys=''
separator='\n '
for key_path in "${RPM_GPG_KEYS[@]}"; do
gpgkeys="${gpgkeys:+"${gpgkeys}${separator}"}https://${keys_url}/${key_path}"
done
$sudo_cmd sh -c "echo -e '[datadog]\nname = Datadog, Inc.\nbaseurl = https://${yum_url}/${yum_version_path}/${ARCHI}/\nenabled=1\ngpgcheck=1\nrepo_gpgcheck=${rpm_repo_gpgcheck}\npriority=1\ngpgkey=${gpgkeys}' > /etc/yum.repos.d/datadog.repo"
$sudo_cmd yum -y clean metadata
dnf_flag=""
if [ -f "/usr/bin/dnf" ] && { [ ! -f "/usr/bin/yum" ] || [ -L "/usr/bin/yum" ]; } ; then
# On modern Red Hat based distros, yum is an alias (symlink) of dnf.
# "dnf install" doesn't upgrade a package if a newer version
# is available, unless the --best flag is set
# NOTE: we assume that sometime in the future "/usr/bin/yum" will
# be removed altogether, so we test for that as well.
dnf_flag="--best"
fi
if [ -n "$agent_minor_version" ]; then
# Example: datadog-agent-7.20.2-1
pkg_pattern="$agent_major_version\.${agent_minor_version%.}(\.[[:digit:]]+){0,1}(-[[:digit:]])?"
agent_version_custom="$(yum -y --disablerepo=* --enablerepo=datadog list --showduplicates datadog-agent | sort -r | grep -E "$pkg_pattern" -om1)" || true
verify_agent_version "-"
fi
declare -a packages
if [ -n "$no_agent" ]; then
packages=()
else
packages=("$agent_flavor")
fi
if [ -n "$fips_mode" ]; then
packages+=("datadog-fips-proxy")
fi
if [ ${#apm_libraries[@]} -gt 0 ]; then
packages+=("${apm_libraries[@]}")
fi
echo -e " \033[33mInstalling package(s): ${packages[*]}\n\033[0m"
$sudo_cmd yum -y --disablerepo='*' --enablerepo='datadog' install $dnf_flag "${packages[@]}" 2> >(tee /tmp/ddog_install_error_msg >&2) || $sudo_cmd yum -y install $dnf_flag "${packages[@]}" 2> >(tee /tmp/ddog_install_error_msg >&2)
ERR_SUMMARY=$(grep "Error Summary" -A3 /tmp/ddog_install_error_msg || true)
elif [ "$OS" == "Debian" ]; then
apt_trusted_d_keyring="/etc/apt/trusted.gpg.d/datadog-archive-keyring.gpg"
apt_usr_share_keyring="/usr/share/keyrings/datadog-archive-keyring.gpg"
DD_APT_INSTALL_ERROR_MSG=/tmp/ddog_install_error_msg
MAX_RETRY_NB=10
for i in $(seq 1 $MAX_RETRY_NB)
do
printf "\033[34m\n* Installing apt-transport-https, curl and gnupg\n\033[0m\n"
$sudo_cmd apt-get update || printf "\033[31m'apt-get update' failed, the script will not install the latest version of apt-transport-https.\033[0m\n"
# installing curl might trigger install of additional version of libssl; this will fail the installation process,
# see https://unix.stackexchange.com/q/146283 for reference - we use DEBIAN_FRONTEND=noninteractive to fix that
apt_exit_code=0
if [ -z "$sudo_cmd" ]; then
# if $sudo_cmd is empty, doing `$sudo_cmd X=Y command` fails with
# `X=Y: command not found`; therefore we don't prefix the command with
# $sudo_cmd at all in this case
DEBIAN_FRONTEND=noninteractive apt-get install -y apt-transport-https curl gnupg 2>$DD_APT_INSTALL_ERROR_MSG || apt_exit_code=$?
else
$sudo_cmd DEBIAN_FRONTEND=noninteractive apt-get install -y apt-transport-https curl gnupg 2>$DD_APT_INSTALL_ERROR_MSG || apt_exit_code=$?
fi
if grep "Could not get lock" $DD_APT_INSTALL_ERROR_MSG; then
RETRY_TIME=$((i*5))
printf "\033[31mInstallation failed: Unable to get lock.\nRetrying in ${RETRY_TIME}s ($i/$MAX_RETRY_NB).\033[0m\n"
sleep $RETRY_TIME
elif [ $apt_exit_code -ne 0 ]; then
cat $DD_APT_INSTALL_ERROR_MSG
exit $apt_exit_code
else
break
fi
done
printf "\033[34m\n* Installing APT package sources for Datadog\n\033[0m\n"
$sudo_cmd sh -c "echo 'deb [signed-by=${apt_usr_share_keyring}] https://${apt_url}/ ${apt_repo_version}' > /etc/apt/sources.list.d/datadog.list"
$sudo_cmd sh -c "chmod a+r /etc/apt/sources.list.d/datadog.list"
if [ ! -f $apt_usr_share_keyring ]; then
$sudo_cmd touch $apt_usr_share_keyring
fi
# ensure that the _apt user used on Ubuntu/Debian systems to read GPG keyrings
# can read our keyring
$sudo_cmd chmod a+r $apt_usr_share_keyring
for key in "${APT_GPG_KEYS[@]}"; do
$sudo_cmd curl --retry 5 -o "/tmp/${key}" "https://${keys_url}/${key}"
$sudo_cmd cat "/tmp/${key}" | $sudo_cmd gpg --import --batch --no-default-keyring --keyring "$apt_usr_share_keyring"
done
release_version="$(grep VERSION_ID /etc/os-release | cut -d = -f 2 | xargs echo | cut -d "." -f 1)"
if { [ "$DISTRIBUTION" == "Debian" ] && [ "$release_version" -lt 9 ]; } || \
{ [ "$DISTRIBUTION" == "Ubuntu" ] && [ "$release_version" -lt 16 ]; }; then
# copy with -a to preserve file permissions
$sudo_cmd cp -a $apt_usr_share_keyring $apt_trusted_d_keyring
fi
if [ "$DISTRIBUTION" == "Debian" ] && [ "$release_version" -lt 8 ]; then
if [ -n "$agent_minor_version_without_patch" ]; then
if [ "$agent_minor_version_without_patch" -ge "36" ]; then
ERROR_MESSAGE="Debian < 8 only supports $nice_flavor $agent_major_version up to $agent_major_version.35."
ERROR_CODE=$UNSUPPORTED_PLATFORM_CODE
printf "\033[31m$ERROR_MESSAGE\033[0m\n"
report_telemetry
exit;
fi
else
if ! echo "$agent_flavor" | grep '[0-9]' > /dev/null; then
echo -e " \033[33m$nice_flavor $agent_major_version.35 is the last supported version on $DISTRIBUTION $release_version. Installing $agent_major_version.35 now.\n\033[0m"
agent_minor_version=35
clean_agent_minor_version=35
fi
fi
fi
ERROR_MESSAGE="ERROR
Failed to update the sources after adding the Datadog repository.
This may be due to any of the configured APT sources failing -
see the logs above to determine the cause.
If the failing repository is Datadog, please contact Datadog support.
*****
"
$sudo_cmd apt-get update -o Dir::Etc::sourcelist="sources.list.d/datadog.list" -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
ERROR_MESSAGE="ERROR
Failed to install one or more packages, sometimes it may be
due to another APT source failing. See the logs above to
determine the cause.
If the cause is unclear, please contact Datadog support.
*****
"
if [ -n "$agent_minor_version" ]; then
# Example: datadog-agent=1:7.20.2-1
pkg_pattern="([[:digit:]]:)?$agent_major_version\.${agent_minor_version%.}(\.[[:digit:]]+){0,1}(-[[:digit:]])?"
agent_version_custom="$(apt-cache madison datadog-agent | grep -E "$pkg_pattern" -om1)" || true
verify_agent_version "="
fi
declare -a packages
if [ -n "$no_agent" ]; then
packages=("datadog-signing-keys")
else
packages=("$agent_flavor" "datadog-signing-keys")
fi
if [ -n "$fips_mode" ]; then
packages+=("datadog-fips-proxy")
fi
if [ ${#apm_libraries[@]} -gt 0 ]; then
packages+=("${apm_libraries[@]}")
fi
echo -e " \033[33mInstalling package(s): ${packages[*]}\n\033[0m"
$sudo_cmd apt-get install -y --force-yes "${packages[@]}" 2> >(tee /tmp/ddog_install_error_msg >&2)
ERR_SUMMARY=$(grep "No space left on device" -C1 /tmp/ddog_install_error_msg || true)
ERROR_MESSAGE=""
elif [ "$OS" == "SUSE" ]; then
remove_rpm_gpg_keys "$sudo_cmd" "${RPM_GPG_KEYS_TO_REMOVE[@]}"
UNAME_M=$(uname -m)
if [ "$UNAME_M" == "i686" ] || [ "$UNAME_M" == "i386" ] || [ "$UNAME_M" == "x86" ]; then
ERROR_MESSAGE="The Datadog Agent installer is only available for 64 bit SUSE Enterprise machines."
ERROR_CODE=$UNSUPPORTED_PLATFORM_CODE
printf "\033[31m$ERROR_MESSAGE\033[0m\n"
report_telemetry
exit;
elif [ "$UNAME_M" == "aarch64" ]; then
ARCHI="aarch64"
else
ARCHI="x86_64"
fi
if [ -z "$rpm_repo_gpgcheck" ]; then
rpm_repo_gpgcheck=1
fi
# Try to guess if we're installing on SUSE 11, as it needs a different flow to work
# Note that SUSE11 doesn't have /etc/os-release file, so we have to use /etc/SuSE-release
if cat /etc/SuSE-release 2>/dev/null | grep VERSION | grep 11; then
SUSE11="yes"
fi
# Doing "rpm --import" requires curl on SUSE/SLES
echo -e "\033[34m\n* Ensuring curl is installed\n\033[0m\n"
if ! rpm -q curl > /dev/null; then
# If zypper fails to refresh a random repo, it installs the package, but then fails
# anyway. Therefore we let it do its thing and then see if curl was installed or not.
if [ -z "$sudo_cmd" ]; then
ZYPP_RPM_DEBUG="${ZYPP_RPM_DEBUG:-0}" zypper --non-interactive install curl ||:
else
$sudo_cmd ZYPP_RPM_DEBUG="${ZYPP_RPM_DEBUG:-0}" zypper --non-interactive install curl ||:
fi
if ! rpm -q curl > /dev/null; then
ERROR_MESSAGE="Failed to install curl."
ERROR_CODE=$UNABLE_TO_INSTALL_DEPENDENCY_CODE
echo -e "\033[31m$ERROR_MESSAGE\033[0m\n"
fallback_msg
report_telemetry
exit 1;
fi
fi
echo -e "\033[34m\n* Importing the Datadog GPG Keys\n\033[0m"
if [ "$SUSE11" == "yes" ]; then
# SUSE 11 special case
for key_path in "${RPM_GPG_KEYS[@]}"; do
$sudo_cmd curl -o "/tmp/${key_path}" "https://${keys_url}/${key_path}"
$sudo_cmd rpm --import "/tmp/${key_path}"
done
else
for key_path in "${RPM_GPG_KEYS[@]}"; do
$sudo_cmd rpm --import "https://${keys_url}/${key_path}"
done
fi
# Parse the major version number out of the distro release info file. xargs is used to trim whitespace.
# NOTE: We use this to find out whether or not release version is >= 15, so we have to use /etc/os-release,
# as /etc/SuSE-release has been deprecated and is no longer present everywhere, e.g. in AWS AMI.
# See https://www.suse.com/releasenotes/x86_64/SUSE-SLES/15/#fate-324409
SUSE_VER=$(cat /etc/os-release 2>/dev/null | grep VERSION_ID | tr -d '"' | tr . = | cut -d = -f 2 | xargs echo)
gpgkeys="https://${keys_url}/DATADOG_RPM_KEY_CURRENT.public"
if [ -n "$SUSE_VER" ] && [ "$SUSE_VER" -ge 15 ] && [ "$SUSE_VER" -ne 42 ]; then
gpgkeys=''
separator='\n '
for key_path in "${RPM_GPG_KEYS[@]}"; do
gpgkeys="${gpgkeys:+"${gpgkeys}${separator}"}https://${keys_url}/${key_path}"
done
fi
echo -e "\033[34m\n* Installing YUM Repository for Datadog\n\033[0m"
$sudo_cmd sh -c "echo -e '[datadog]\nname=datadog\nenabled=1\nbaseurl=https://${yum_url}/suse/${yum_version_path}/${ARCHI}\ntype=rpm-md\ngpgcheck=1\nrepo_gpgcheck=${rpm_repo_gpgcheck}\ngpgkey=${gpgkeys}' > /etc/zypp/repos.d/datadog.repo"
echo -e "\033[34m\n* Refreshing repositories\n\033[0m"
$sudo_cmd zypper --non-interactive --no-gpg-checks refresh datadog
# ".32" is the latest version supported for OpenSUSE < 15 and SLES < 12
# we explicitly test for SUSE11 = "yes", as some SUSE11 don't have /etc/os-release, thus SUSE_VER is empty
if [ "$DISTRIBUTION" == "openSUSE" ] && { [ "$SUSE11" == "yes" ] || [ "$SUSE_VER" -lt 15 ]; }; then
if [ -n "$agent_minor_version_without_patch" ]; then
if [ "$agent_minor_version_without_patch" -ge "33" ]; then
ERROR_MESSAGE="openSUSE < 15 only supports $nice_flavor $agent_major_version up to $agent_major_version.32."
ERROR_CODE=$UNSUPPORTED_PLATFORM_CODE
printf "\033[31m$ERROR_MESSAGE\033[0m\n"
report_telemetry
exit;
fi
else
if ! echo "$agent_flavor" | grep '[0-9]' > /dev/null; then
echo -e " \033[33m$nice_flavor $agent_major_version.32 is the last supported version on $DISTRIBUTION $SUSE_VER\n\033[0m"
agent_minor_version=32
clean_agent_minor_version=32
fi
fi
fi
if [ "$DISTRIBUTION" == "SUSE" ] && { [ "$SUSE11" == "yes" ] || [ "$SUSE_VER" -lt 12 ]; }; then
if [ -n "$agent_minor_version_without_patch" ]; then
if [ "$agent_minor_version_without_patch" -ge "33" ]; then
ERROR_MESSAGE="SLES < 12 only supports $nice_flavor $agent_major_version up to $agent_major_version.32."