5
# ======================================================================
6
# Constants
7
8
+PACKAGES_SCRIPT="https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/install-required-packages.sh"
9
REPOCONFIG_URL_PREFIX="https://packagecloud.io/netdata/netdata-repoconfig/packages"
10
REPOCONFIG_VERSION="1-1"
11
PATH="${PATH}:/usr/local/bin:/usr/local/sbin"
13
# ======================================================================
14
# Defaults for environment variables
15
15
-RELEASE_CHANNEL="nightly"
16
-NETDATA_CLAIM_URL="https://app.netdata.cloud"
17
-NETDATA_CLAIM_ONLY=0
18
-NETDATA_USER_CONFIG_DIR="/etc/netdata"
16
+INSTALL_PREFIX=""
17
NETDATA_AUTO_UPDATES="1"
18
+NETDATA_CLAIM_ONLY=0
19
+NETDATA_CLAIM_URL="https://app.netdata.cloud"
20
+NETDATA_DISABLE_CLOUD=0
21
+NETDATA_ONLY_BUILD=0
22
NETDATA_ONLY_NATIVE=0
23
NETDATA_ONLY_STATIC=0
24
+NETDATA_REQUIRE_CLOUD=1
25
+RELEASE_CHANNEL="nightly"
26
27
NETDATA_DISABLE_TELEMETRY="${DO_NOT_TRACK:-0}"
28
NETDATA_TARBALL_BASEURL="${NETDATA_TARBALL_BASEURL:-https://storage.googleapis.com/netdata-nightlies}"
29
+NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS:-""}"
30
31
if [ ! -t 1 ]; then
32
INTERACTIVE=0
52
--disable-telemetry Opt-out of anonymous statistics.
53
--native-only Only install if native binary packages are available.
54
--static-only Only install if a static build is available.
55
+ --build-only Only install using a local build.
56
--reinstall Explicitly reinstall instead of updating any existing install.
57
+ --reinstall-even-if-unsafe Even try to reinstall if we don't think we can do so safely (implies --reinstall).
58
+ --disable-cloud Disable support for Netdata Cloud (default: detect)
59
+ --require-cloud Only install if Netdata Cloud can be enabled. Overrides --disable-cloud.
60
+ --install <path> Specify an installation prefix for local builds (default: autodetect based on system type).
61
--claim-token Use a specified token for claiming to Netdata Cloud.
62
--claim-rooms When claiming, add the node to the specified rooms.
63
--claim-only If there is an existing install, only try to claim it, not update it.
74
you need special options for one of those to work, or have a different tool to do
75
the same thing on your system, you can specify it here.
76
DO_NOT_TRACK If set to a value other than 0, behave as if \`--disable-telemetry\` was specified.
77
+ NETDATA_INSTALLER_OPTIONS: Specifies extra options to pass to the static installer or local build script.
78
79
HEREDOC
80
}
110
return 0
111
}
112
113
+cleanup() {
114
+ if [ -z "${NO_CLEANUP}" ]; then
115
+ ${ROOTCMD} rm -rf "${tmpdir}"
116
+ fi
117
+}
118
+
119
fatal() {
120
printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${*}"
121
+ cleanup
122
exit 1
123
}
124
234
run curl -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}" || return 1
235
elif command -v wget > /dev/null 2>&1; then
236
run wget -T 15 -O "${dest}" "${url}" || return 1
219
- elif command -v fetch > /dev/null 2>&1; then # Native FreeBSD tool
220
- run fetch -T 15 -a -o "${dest}" "${url}" || return 1
237
else
222
- fatal "I need curl, wget, or fetch to proceed, but none of them are available on this system."
238
+ fatal "I need curl or wget to proceed, but neither of them are available on this system."
239
+ fi
240
+}
241
+
242
+get_redirect() {
243
+ url="${1}"
244
+
245
+ if command -v curl > /dev/null 2>&1; then
246
+ run sh -c "curl ${url} -s -L -I -o /dev/null -w '%{url_effective}' | grep -o '[^/]*$'" || return 1
247
+ elif command -v wget > /dev/null 2>&1; then
248
+ run sh -c "wget --max-redirect=0 ${url} 2>&1 | grep Location | cut -d ' ' -f2 | grep -o '[^/]*$'" || return 1
249
+ else
250
+ fatal "I need curl or wget to proceed, but neither of them are available on this system."
251
fi
252
}
253
344
fi
345
}
346
347
+confirm() {
348
+ prompt="${1} [y/n]"
349
+
350
+ while true; do
351
+ echo "${prompt}"
352
+ read -r yn
353
+
354
+ case "$yn" in
355
+ [Yy]*) return 0;;
356
+ [Nn]*) return 1;;
357
+ *) echo "Please answer yes or no.";;
358
+ esac
359
+ done
360
+}
361
+
362
# ======================================================================
363
# Existing install handling code
364
412
fi
413
414
case "${INSTALL_TYPE}" in
372
- kickstart-*|legacy-*|manual-static)
373
- if [ -n "${NETDATA_REINSTALL}" ]; then
415
+ kickstart-*|legacy-*|binpkg-*|manual-static|unknown)
416
+ if [ "${INSTALL_TYPE}" = "unknown" ]; then
417
+ warning "Found an existing netdata install at ${ndprefix}, but could not determine the install type."
418
+ else
419
+ progress "Found an existing netdata install at ${ndprefix}, with installation type '${INSTALL_TYPE}'."
420
+ fi
421
+
422
+ if [ -n "${NETDATA_REINSTALL}" ] || [ -n "${NETDATA_UNSAFE_REINSTALL}" ]; then
423
progress "Found an existing netdata install at ${ndprefix}, but user requested reinstall, continuing."
424
+
425
+ case "${INSTALL_TYPE}" in
426
+ binpkg-*) NETDATA_ONLY_NATIVE=1 ;;
427
+ *-build) NETDATA_ONLY_BUILD=1 ;;
428
+ *-static) NETDATA_ONLY_STATIC=1 ;;
429
+ *)
430
+ if [ -n "${NETDATA_UNSAFE_REINSTALL}" ]; then
431
+ warning "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, but the user has requested we proceed."
432
+ elif [ "${INTERACTIVE}" -eq 0 ]; then
433
+ fatal "User requested reinstall, but we cannot safely reinstall over top of a ${INSTALL_TYPE} installation, exiting."
434
+ else
435
+ if confirm "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, do you want to continue?"; then
436
+ progress "OK, continuing."
437
+ else
438
+ fatal "Cancelling reinstallation at user request."
439
+ fi
440
+ fi
441
+ ;;
442
+ esac
443
+
444
return 0
445
fi
446
447
ret=0
448
380
- if [ "${NETDATA_CLAIM_ONLY}" -eq 0 ]; then
449
+ if [ "${NETDATA_CLAIM_ONLY}" -eq 0 ] && echo "${INSTALL_TYPE}" | grep -vq "binpkg-*"; then
450
if ! update; then
451
warning "Unable to find usable updater script, not updating existing install at ${ndprefix}."
452
fi
453
+ else
454
+ warning "Not updating existing install at ${ndprefix}."
455
fi
456
457
if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then
458
progress "Attempting to claim existing install at ${ndprefix}."
459
+ INSTALL_PREFIX="${ndprefix}"
460
claim
461
ret=$?
462
elif [ "${NETDATA_CLAIM_ONLY}" -eq 1 ]; then
463
fatal "User asked to claim, but did not proide a claiming token."
464
+ else
465
+ progress "Not attempting to claim existing install at ${ndprefix} (no claiming token provided)."
466
fi
467
394
- exit $ret
395
- ;;
396
- binpkg-*)
397
- ret=0
398
-
399
- if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then
400
- progress "Attempting to claim existing install at ${ndprefix}."
401
- claim
402
- ret=$?
403
- fi
404
-
468
+ cleanup
469
exit $ret
470
;;
471
oci)
472
fatal "This is an OCI container, use the regular image lifecycle management commands in your container instead of this script for managing it."
473
;;
410
- unknown)
411
- warning "Found an existing netdata install at ${ndprefix}, but could not determine the install type."
412
-
413
- if [ -n "${NETDATA_REINSTALL}" ]; then
414
- progress "Found an existing netdata install at ${ndprefix}, but user requested reinstall, continuing."
415
- return 0
474
+ *)
475
+ if [ -n "${NETDATA_REINSTALL}" ] || [ -n "${NETDATA_UNSAFE_REINSTALL}" ]; then
476
+ if [ -n "${NETDATA_UNSAFE_REINSTALL}" ]; then
477
+ warning "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, but the user has requested we proceed."
478
+ elif [ "${INTERACTIVE}" -eq 0 ]; then
479
+ fatal "User requested reinstall, but we cannot safely reinstall over top of a ${INSTALL_TYPE} installation, exiting."
480
+ else
481
+ if confirm "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, do you want to continue?"; then
482
+ progress "OK, continuing."
483
+ else
484
+ fatal "Cancelling reinstallation at user request."
485
+ fi
486
+ fi
487
+ else
488
+ fatal "Found an existing netdata install at ${ndprefix}, but the install type is '${INSTALL_TYPE}', which is not supported, refusing to proceed."
489
fi
490
+ ;;
491
+ esac
492
+}
493
418
- ret=0
419
-
420
- if [ "${NETDATA_CLAIM_ONLY}" -eq 0 ]; then
421
- if ! update; then
422
- warning "Unable to find usable updater script, not updating existing install at ${ndprefix}."
494
+soft_disable_cloud() {
495
+ cloud_prefix="${INSTALL_PREFIX}/var/lib/netdata/cloud.d"
496
+
497
+ run ${ROOTCMD} mkdir -p "${cloud_prefix}"
498
+
499
+ cat > "${tmpdir}/cloud.conf" << EOF
500
+[global]
501
+ enabled = no
502
+EOF
503
+
504
+ run ${ROOTCMD} cp "${tmpdir}/cloud.conf" "${cloud_prefix}/cloud.conf"
505
+
506
+ if [ -z "${NETDATA_NO_START}" ]; then
507
+ case "${SYSTYPE}" in
508
+ Darwin) run ${ROOTCMD} launchctl kickstart -k com.github.netdata ;;
509
+ FreeBSD) run ${ROOTCMD} service netdata restart ;;
510
+ Linux)
511
+ initpath="$(${ROOTCMD} readlink /proc/1/exe)"
512
+
513
+ if command -v service > /dev/null 2>&1; then
514
+ run ${ROOTCMD} service netdata restart
515
+ elif command -v rc-service > /dev/null 2>&1; then
516
+ run ${ROOTCMD} rc-service netdata restart
517
+ elif [ "$(basename "${initpath}" 2> /dev/null)" = "systemd" ]; then
518
+ run ${ROOTCMD} systemctl restart netdata
519
+ elif [ -f /etc/init.d/netdata ]; then
520
+ run ${ROOTCMD} /etc/init.d/netdata restart
521
fi
424
- fi
522
+ ;;
523
+ esac
524
+ fi
525
+}
526
426
- if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then
427
- progress "Attempting to claim existing install at ${ndprefix}."
428
- claim
429
- ret=$?
430
- elif [ "${NETDATA_CLAIM_ONLY}" -eq 1 ]; then
431
- fatal "User asked to claim, but did not proide a claiming token."
432
- fi
527
+confirm_install_prefix() {
528
+ if [ -n "${INSTALL_PREFIX}" ] && [ "${NETDATA_ONLY_BUILD}" -ne 1 ]; then
529
+ fatal "The \`--install\` option is only supported together with the \`--only-build\` option."
530
+ fi
531
434
- exit $ret
435
- ;;
436
- *)
437
- fatal "Found an existing netdata install at ${ndprefix}, but it is not a supported install type, refusing to proceed."
438
- ;;
532
+ case "${SYSTYPE}" in
533
+ Darwin) INSTALL_PREFIX="${INSTALL_PREFIX:-/usr/local/netdata}" ;;
534
+ FreeBSD) INSTALL_PREFIX="${INSTALL_PREFIX:-/usr/local}" ;;
535
esac
536
+
537
+ if [ -n "${INSTALL_PREFIX}" ]; then
538
+ NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --install ${INSTALL_PREFIX}"
539
+ fi
540
}
541
542
# ======================================================================
548
fatal "Invalid claiming options, claim rooms may only be specified when a token and URL are specified."
549
elif [ -z "${NETDATA_CLAIM_TOKEN}" ] && [ -n "${NETDATA_CLAIM_EXTRA}" ]; then
550
fatal "Invalid claiming options, a claiming token must be specified."
551
+ elif [ "${NETDATA_DISABLE_CLOUD}" -eq 1 ] && [ -n "${NETDATA_CLAIM_TOKEN}" ]; then
552
+ fatal "Cloud explicitly disabled, but automatic claiming requested. Either enable Netdata Cloud, or remove the --claim-* options."
553
fi
554
}
555
556
claim() {
557
progress "Attempting to claim agent to ${NETDATA_CLAIM_URL}"
456
- if [ -z "${NETDATA_PREFIX}" ]; then
558
+ if [ -z "${INSTALL_PREFIX}" ]; then
559
NETDATA_CLAIM_PATH=/usr/sbin/netdata-claim.sh
458
- elif [ "${NETDATA_PREFIX}" = "/opt/netdata" ]; then
560
+ elif [ "${INSTALL_PREFIX}" = "/opt/netdata" ]; then
561
NETDATA_CLAIM_PATH="/opt/netdata/bin/netdata-claim.sh"
562
else
461
- NETDATA_CLAIM_PATH="${NETDATA_PREFIX}/netdata/usr/sbin/netdata-claim.sh"
563
+ NETDATA_CLAIM_PATH="${INSTALL_PREFIX}/netdata/usr/sbin/netdata-claim.sh"
564
fi
565
566
if ! pgrep netdata > /dev/null; then
573
else
574
warning "Unable to claim node, you must do so manually."
575
if [ -z "${NETDATA_NEW_INSTALL}" ]; then
576
+ cleanup
577
exit 1
578
fi
579
fi
800
return 2
801
fi
802
803
+ if [ "${NETDATA_DISABLE_TELEMETRY}" -eq 1 ]; then
804
+ run ${ROOTCMD} mkdir -p "/etc/netdata"
805
+ run ${ROOTCMD} touch "/etc/netdata/.opt-out-from-anonymous-statistics"
806
+ fi
807
+
808
progress "Installing Netdata package."
809
# shellcheck disable=SC2086
810
if ! run ${ROOTCMD} env ${env} ${pm_cmd} install ${pkg_install_opts} netdata; then
823
824
set_static_archive_urls() {
825
if [ "${RELEASE_CHANNEL}" = "stable" ]; then
718
- latest="$(download "https://api.github.com/repos/netdata/netdata/releases/latest" /dev/stdout | grep tag_name | cut -d'"' -f4)"
826
+ latest="$(get_redirect "https://github.com/netdata/netdata/releases/latest")"
827
export NETDATA_STATIC_ARCHIVE_URL="https://github.com/netdata/netdata/releases/download/${latest}/netdata-${SYSARCH}-${latest}.gz.run"
828
export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/${latest}/sha256sums.txt"
829
else
846
fi
847
848
if ! grep "netdata-${SYSARCH}-latest.gz.run" "${tmpdir}/sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then
741
- fatal "Static binary checksum validation failed. Stopping Netdata Agent installation and leaving binary in ${tmpdir}. Usually this is a result of an older copy of the file being cached somewhere upstream and can be resolved by retrying in an hour."
849
+ fatal "Static binary checksum validation failed. Usually this is a result of an older copy of the file being cached somewhere upstream and can be resolved by retrying in an hour."
850
fi
851
852
if [ "${INTERACTIVE}" -eq 0 ]; then
874
fi
875
}
876
877
+# ======================================================================
878
+# Local build install code
879
+
880
+set_source_archive_urls() {
881
+ if [ "$1" = "stable" ]; then
882
+ latest="$(get_redirect "https://github.com/netdata/netdata/releases/latest")"
883
+ export NETDATA_SOURCE_ARCHIVE_URL="https://github.com/netdata/netdata/releases/download/${latest}/netdata-${latest}.tar.gz"
884
+ export NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/${latest}/sha256sums.txt"
885
+ else
886
+ export NETDATA_SOURCE_ARCHIVE_URL="${NETDATA_TARBALL_BASEURL}/netdata-latest.tar.gz"
887
+ export NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL="${NETDATA_TARBALL_BASEURL}/sha256sums.txt"
888
+ fi
889
+}
890
+
891
+install_local_build_dependencies() {
892
+ bash="$(command -v bash 2> /dev/null)"
893
+
894
+ if [ -z "${bash}" ] || [ ! -x "${bash}" ]; then
895
+ warning "Unable to find a usable version of \`bash\` (required for local build)."
896
+ return 1
897
+ fi
898
+
899
+ progress "Fetching script to detect required packages..."
900
+ download "${PACKAGES_SCRIPT}" "${tmpdir}/install-required-packages.sh"
901
+
902
+ if [ ! -s "${tmpdir}/install-required-packages.sh" ]; then
903
+ warning "Downloaded dependency installation script is empty."
904
+ else
905
+ progress "Running downloaded script to detect required packages..."
906
+
907
+ if [ "${INTERACTIVE}" -eq 0 ]; then
908
+ opts="--dont-wait --non-interactive"
909
+ fi
910
+
911
+ if [ "${SYSTYPE}" = "Darwin" ]; then
912
+ sudo=""
913
+ else
914
+ sudo="${ROOTCMD}"
915
+ fi
916
+
917
+ # shellcheck disable=SC2086
918
+ if ! run ${sudo} "${bash}" "${tmpdir}/install-required-packages.sh" ${opts} netdata; then
919
+ warning "It failed to install all the required packages, but installation might still be possible."
920
+ fi
921
+ fi
922
+}
923
+
924
+build_and_install() {
925
+ progress "Building netdata"
926
+
927
+ echo "INSTALL_TYPE='kickstart-build'" > system/.install-type
928
+
929
+ opts="${NETDATA_INSTALLER_OPTIONS}"
930
+
931
+ if [ "${INTERACTIVE}" -eq 0 ]; then
932
+ opts="${opts} --dont-wait"
933
+ fi
934
+
935
+ if [ "${NETDATA_AUTO_UPDATES}" -eq 1 ]; then
936
+ opts="${opts} --auto-update"
937
+ fi
938
+
939
+ if [ "${RELEASE_CHANNEL}" = "stable" ]; then
940
+ opts="${opts} --stable-channel"
941
+ fi
942
+
943
+ if [ "${NETDATA_REQUIRE_CLOUD}" -eq 1 ]; then
944
+ opts="${opts} --require-cloud"
945
+ elif [ "${NETDATA_DISABLE_CLOUD}" -eq 1 ]; then
946
+ opts="${opts} --disable-cloud"
947
+ fi
948
+
949
+ # shellcheck disable=SC2086
950
+ run ${ROOTCMD} ./netdata-installer.sh ${opts} || fatal "netdata-installer.sh exited with error"
951
+}
952
+
953
+try_build_install() {
954
+ if ! install_local_build_dependencies; then
955
+ return 1
956
+ fi
957
+
958
+ set_source_archive_urls "${RELEASE_CHANNEL}"
959
+
960
+ download "${NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL}" "${tmpdir}/sha256sum.txt"
961
+ download "${NETDATA_SOURCE_ARCHIVE_URL}" "${tmpdir}/netdata-latest.tar.gz"
962
+
963
+ if ! grep netdata-latest.tar.gz "${tmpdir}/sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then
964
+ fatal "Tarball checksum validation failed. Usually this is a result of an older copy of the file being cached somewhere upstream and can be resolved by retrying in an hour."
965
+ fi
966
+
967
+ run tar -xf "${tmpdir}/netdata-latest.tar.gz" -C "${tmpdir}"
968
+ rm -rf "${tmpdir}/netdata-latest.tar.gz" > /dev/null 2>&1
969
+ cd "$(find "${tmpdir}" -mindepth 1 -maxdepth 1 -type d -name netdata-)" || fatal "Cannot cd to netdata source tree"
970
+
971
+ if [ -x netdata-installer.sh ]; then
972
+ build_and_install || return 1
973
+ else
974
+ # This case is needed because some platforms produce an extra directory on the source tarball extraction.
975
+ if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ] && [ -x "$(find . -mindepth 1 -maxdepth 1 -type d)/netdata-installer.sh" ]; then
976
+ cd "$(find . -mindepth 1 -maxdepth 1 -type d)" && build_and_install || return 1
977
+ else
978
+ fatal "Cannot install netdata from source (the source directory does not include netdata-installer.sh). Leaving all files in ${tmpdir}"
979
+ fi
980
+ fi
981
+}
982
+
983
+# ======================================================================
984
+# Per system-type install logic
985
+
986
+install_on_linux() {
987
+ if [ "${NETDATA_ONLY_STATIC}" -ne 1 ] && [ "${NETDATA_ONLY_BUILD}" -ne 1 ]; then
988
+ try_package_install
989
+
990
+ case "$?" in
991
+ 0)
992
+ NETDATA_INSTALL_SUCCESSFUL=1
993
+ ;;
994
+ 1)
995
+ fatal "Unable to install on this system."
996
+ ;;
997
+ 2)
998
+ if [ "${NETDATA_ONLY_NATIVE}" -eq 1 ]; then
999
+ fatal "Could not install native binary packages."
1000
+ else
1001
+ warning "Could not install native binary packages, falling back to alternative installation method."
1002
+ fi
1003
+ ;;
1004
+ esac
1005
+ fi
1006
+
1007
+ if [ "${NETDATA_ONLY_NATIVE}" -ne 1 ] && [ "${NETDATA_ONLY_BUILD}" -ne 1 ] && [ -z "${NETDATA_INSTALL_SUCCESSFUL}" ]; then
1008
+ try_static_install
1009
+
1010
+ case "$?" in
1011
+ 0)
1012
+ NETDATA_INSTALL_SUCCESSFUL=1
1013
+ INSTALL_PREFIX="/opt/netdata"
1014
+ ;;
1015
+ 1)
1016
+ fatal "Unable to install on this system."
1017
+ ;;
1018
+ 2)
1019
+ if [ "${NETDATA_ONLY_STATIC}" -eq 1 ]; then
1020
+ fatal "Could not install static build."
1021
+ else
1022
+ warning "Could not install static build, falling back to alternative installation method."
1023
+ fi
1024
+ ;;
1025
+ esac
1026
+ fi
1027
+
1028
+ if [ "${NETDATA_ONLY_NATIVE}" -ne 1 ] && [ "${NETDATA_ONLY_STATIC}" -ne 1 ] && [ -z "${NETDATA_INSTALL_SUCCESSFUL}" ]; then
1029
+ try_build_install
1030
+
1031
+ case "$?" in
1032
+ 0)
1033
+ NETDATA_INSTALL_SUCCESSFUL=1
1034
+ ;;
1035
+ *)
1036
+ fatal "Unable to install on this system."
1037
+ ;;
1038
+ esac
1039
+ fi
1040
+}
1041
+
1042
+install_on_macos() {
1043
+ if [ "${NETDATA_ONLY_NATIVE}" -eq 1 ]; then
1044
+ fatal "User requested native package, but native packages are not available for macOS. Try installing without \`--only-native\` option."
1045
+ elif [ "${NETDATA_ONLY_STATIC}" -eq 1 ]; then
1046
+ fatal "User requested static build, but static builds are not available for macOS. Try installing without \`--only-static\` option."
1047
+ else
1048
+ try_build_install
1049
+
1050
+ case "$?" in
1051
+ 0)
1052
+ NETDATA_INSTALL_SUCCESSFUL=1
1053
+ ;;
1054
+ *)
1055
+ fatal "Unable to install on this system."
1056
+ ;;
1057
+ esac
1058
+ fi
1059
+}
1060
+
1061
+install_on_freebsd() {
1062
+ if [ "${NETDATA_ONLY_NATIVE}" -eq 1 ]; then
1063
+ fatal "User requested native package, but native packages are not available for FreeBSD. Try installing without \`--only-native\` option."
1064
+ elif [ "${NETDATA_ONLY_STATIC}" -eq 1 ]; then
1065
+ fatal "User requested static build, but static builds are not available for FreeBSD. Try installing without \`--only-static\` option."
1066
+ else
1067
+ try_build_install
1068
+
1069
+ case "$?" in
1070
+ 0)
1071
+ NETDATA_INSTALL_SUCCESSFUL=1
1072
+ ;;
1073
+ *)
1074
+ fatal "Unable to install on this system."
1075
+ ;;
1076
+ esac
1077
+ fi
1078
+}
1079
+
1080
# ======================================================================
1081
# Main program
1082
1086
case "${1}" in
1087
"--help")
1088
usage
1089
+ cleanup
1090
exit 0
1091
;;
1092
"--no-cleanup") NO_CLEANUP=1 ;;
1093
"--dont-wait"|"--non-interactive") INTERACTIVE=0 ;;
1094
"--interactive") INTERACTIVE=1 ;;
1095
"--stable-channel") RELEASE_CHANNEL="stable" ;;
784
- "--no-updates") NETDATA_AUTO_UPDATES="" ;;
1096
+ "--no-updates") NETDATA_AUTO_UPDATES=0 ;;
1097
"--auto-update") NETDATA_AUTO_UPDATES="1" ;;
786
- "--disable-telemetry") NETDATA_DISABLE_TELEMETRY="1" ;;
1098
"--reinstall") NETDATA_REINSTALL=1 ;;
1099
+ "--reinstall-even-if-unsafe") NETDATA_UNSAFE_REINSTALL=1 ;;
1100
"--claim-only") NETDATA_CLAIM_ONLY=1 ;;
1101
+ "--disable-cloud")
1102
+ NETDATA_DISABLE_CLOUD=1
1103
+ NETDATA_REQUIRE_CLOUD=0
1104
+ ;;
1105
+ "--require-cloud")
1106
+ NETDATA_DISABLE_CLOUD=0
1107
+ NETDATA_REQUIRE_CLOUD=1
1108
+ ;;
1109
+ "--dont-start-it")
1110
+ NETDATA_NO_START=1
1111
+ NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --dont-start-it"
1112
+ ;;
1113
+ "--disable-telemetry")
1114
+ NETDATA_DISABLE_TELEMETRY="0"
1115
+ NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --disable-telemetry"
1116
+ ;;
1117
+ "--install")
1118
+ INSTALL_PREFIX="${2}"
1119
+ shift 1
1120
+ ;;
1121
"--native-only")
1122
NETDATA_ONLY_NATIVE=1
1123
NETDATA_ONLY_STATIC=0
1124
+ NETDATA_ONLY_BUILD=0
1125
;;
1126
"--static-only")
1127
NETDATA_ONLY_STATIC=1
1128
NETDATA_ONLY_NATIVE=0
1129
+ NETDATA_ONLY_BUILD=0
1130
;;
797
- "--dont-start-it")
798
- NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --dont-start-it"
1131
+ "--build-only")
1132
+ NETDATA_ONLY_BUILD=1
1133
+ NETDATA_ONLY_NATIVE=0
1134
+ NETDATA_ONLY_STATIC=0
1135
;;
1136
+
1137
"--claim-token")
1138
NETDATA_CLAIM_TOKEN="${2}"
1139
shift 1
1161
;;
1162
esac
1163
;;
1164
+ *)
1165
+ warning "Passing unrecognized option '${1}' to installer script. If this is intended, please add it to \$NETDATA_INSTALLER_OPTIONS instead."
1166
+ NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} ${1}"
1167
+ ;;
1168
esac
1169
shift 1
1170
done
1172
check_claim_opts
1173
confirm_root_support
1174
get_system_info
1175
+confirm_install_prefix
1176
1177
tmpdir="$(create_tmp_directory)"
1178
progress "Using ${tmpdir} as a temporary directory."
1181
handle_existing_install
1182
1183
case "${SYSTYPE}" in
842
- Linux)
843
- if [ "${NETDATA_ONLY_STATIC}" -ne 1 ]; then
844
- try_package_install
845
-
846
- case "$?" in
847
- 0)
848
- NETDATA_INSTALL_SUCCESSFUL=1
849
- ;;
850
- 1)
851
- fatal "Unable to install on this system."
852
- ;;
853
- 2)
854
- if [ "${NETDATA_ONLY_NATIVE}" -eq 1 ]; then
855
- fatal "Could not install native binary packages."
856
- else
857
- warning "Could not install native binary packages, falling back to alternative installation method."
858
- fi
859
- ;;
860
- esac
861
- fi
862
-
863
- if [ "${NETDATA_ONLY_NATIVE}" -ne 1 ] && [ -z "${NETDATA_INSTALL_SUCCESSFUL}" ]; then
864
- try_static_install
865
-
866
- case "$?" in
867
- 0)
868
- NETDATA_INSTALL_SUCCESSFUL=1
869
- NETDATA_USER_CONFIG_DIR="/opt/netdata/etc/netdata"
870
- ;;
871
- 1)
872
- fatal "Unable to install on this system."
873
- ;;
874
- 2)
875
- if [ "${NETDATA_ONLY_STATIC}" -eq 1 ]; then
876
- fatal "Could not install static build."
877
- else
878
- warning "Could not install static build, falling back to alternative installation method."
879
- fi
880
- ;;
881
- esac
882
- fi
883
- ;;
884
- Darwin)
885
- if [ "${NETDATA_ONLY_NATIVE}" -eq 1 ]; then
886
- fatal "User requested native package, but native packages are not available for macOS. Try installing without \`--only-native\` option."
887
- elif [ "${NETDATA_ONLY_STATIC}" -eq 1 ]; then
888
- fatal "User requested static build, but static builds are not available for macOS. Try installing without \`--only-static\` option."
889
- else
890
- fatal "This script currently does not support installation on macOS."
891
- fi
892
- ;;
893
- FreeBSD)
894
- if [ "${NETDATA_ONLY_NATIVE}" -eq 1 ]; then
895
- fatal "User requested native package, but native packages are not available for FreeBSD. Try installing without \`--only-native\` option."
896
- elif [ "${NETDATA_ONLY_STATIC}" -eq 1 ]; then
897
- fatal "User requested static build, but static builds are not available for FreeBSD. Try installing without \`--only-static\` option."
898
- else
899
- fatal "This script currently does not support installation on FreeBSD."
900
- fi
901
- ;;
1184
+ Linux) install_on_linux ;;
1185
+ Darwin) install_on_macos ;;
1186
+ FreeBSD) install_on_freebsd ;;
1187
esac
1188
904
-if [ "${NETDATA_DISABLE_TELEMETRY}" -eq 1 ]; then
905
- run ${ROOTCMD} touch "${NETDATA_USER_CONFIG_DIR}/.opt-out-from-anonymous-statistics"
906
-fi
907
-
1189
if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then
1190
claim
1191
+elif [ "${NETDATA_DISABLE_CLOUD}" -eq 1 ]; then
1192
+ soft_disable_cloud
1193
fi
1194
912
-if [ -z "${NO_CLEANUP}" ]; then
913
- ${ROOTCMD} rm -rf "${tmpdir}"
914
-fi
1195
+cleanup