master
sh 2,652 lines 97.3 KB
Raw
1 #!/bin/sh
2 #
3 # SPDX-License-Identifier: GPL-3.0-or-later
4 #
5 # Next unused error code: F0520
6
7 # ======================================================================
8 # Constants
9
10 DEFAULT_RELEASE_CHANNEL="nightly"
11 KICKSTART_OPTIONS="${*}"
12 KICKSTART_SOURCE="$(
13 self=${0}
14 while [ -L "${self}" ]
15 do
16 cd "${self%/*}" || exit 1
17 self=$(readlink "${self}")
18 done
19 cd "${self%/*}" || exit 1
20 echo "$(pwd -P)/${self##*/}"
21 )"
22 DEFAULT_PLUGIN_PACKAGES=""
23 REPOCONFIG_DEB_VERSION="5-5"
24 REPOCONFIG_RPM_VERSION="5-5"
25 START_TIME="$(date +%s)"
26 STATIC_INSTALL_ARCHES="x86_64 armv7l armv6l aarch64"
27
28 # ======================================================================
29 # Properly sort out inconsistencies in `$PATH` across distros
30 #
31 # Debian and Ubuntu still don’t include sbin directories for regular
32 # users (even though the distinction is all but pointless at this point in
33 # time), and a number of distros don’t include the standard paths under
34 # `/usr/local` either.
35
36 for dir in /usr/sbin /sbin /usr/local/bin /usr/local/sbin ; do
37 case ":${PATH}:" in
38 *:${dir}:*) ;;
39 *) PATH="${PATH}:${dir}" ;;
40 esac
41 done
42
43 # ======================================================================
44 # URLs used throughout the script
45
46 AGENT_BUG_REPORT_URL="https://github.com/netdata/netdata/issues/new/choose"
47 CLOUD_BUG_REPORT_URL="https://github.com/netdata/netdata-cloud/issues/new/choose"
48 DISCORD_INVITE="https://discord.gg/5ygS846fR6"
49 DISCUSSIONS_URL="https://github.com/netdata/netdata/discussions"
50 DOCS_URL="https://learn.netdata.cloud/docs/"
51 FORUM_URL="https://community.netdata.cloud/"
52 INSTALL_DOC_URL="https://learn.netdata.cloud/docs/install-the-netdata-agent/one-line-installer-for-all-linux-systems"
53 PACKAGES_SCRIPT="https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/install-required-packages.sh"
54 PUBLIC_CLOUD_URL="https://app.netdata.cloud"
55 RELEASE_INFO_URL="https://repo.netdata.cloud/releases"
56 STABLE_REPO_URL_PREFIX="https://repository.netdata.cloud/repos/stable"
57 NIGHTLY_REPO_URL_PREFIX="https://repository.netdata.cloud/repos/edge"
58 REPOCONFIG_URL_PREFIX="https://repository.netdata.cloud/repos/repoconfig"
59 TELEMETRY_URL="https://us-east1-netdata-analytics-bi.cloudfunctions.net/ingest_agent_events"
60
61 # ======================================================================
62 # Defaults for environment variables
63
64 DRY_RUN=0
65 SELECTED_INSTALL_METHOD="none"
66 INSTALL_TYPE="unknown"
67 INSTALL_PREFIX=""
68 NETDATA_AUTO_UPDATES="default"
69 NETDATA_CLAIM_URL="https://app.netdata.cloud"
70 NETDATA_COMMAND="default"
71 NETDATA_INSTALLER_OPTIONS=""
72 NETDATA_REQUESTED_INSTALL_TYPE="auto"
73 NETDATA_OFFLINE_INSTALL_SOURCE=""
74 NETDATA_WARNINGS=""
75 RELEASE_CHANNEL="default"
76
77 if [ -n "$DISABLE_TELEMETRY" ]; then
78 NETDATA_DISABLE_TELEMETRY="${DISABLE_TELEMETRY}"
79 elif [ -n "$DO_NOT_TRACK" ]; then
80 NETDATA_DISABLE_TELEMETRY="${DO_NOT_TRACK}"
81 else
82 NETDATA_DISABLE_TELEMETRY=0
83 fi
84
85 NETDATA_TARBALL_BASEURL="${NETDATA_TARBALL_BASEURL:-https://github.com/netdata/netdata-nightlies/releases}"
86
87 if echo "${0}" | grep -q 'kickstart-static64'; then
88 NETDATA_REQUESTED_INSTALL_TYPE='static'
89 fi
90
91 if [ ! -t 1 ]; then
92 INTERACTIVE=0
93 else
94 INTERACTIVE=1
95 fi
96
97 CURL="$(PATH="${PATH}:/opt/netdata/bin" command -v curl 2>/dev/null && true)"
98
99 # ======================================================================
100 # Shared messages used in multiple places throughout the script.
101
102 BADCACHE_MSG="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"
103 BADNET_MSG="This is usually a result of a networking issue"
104 ERROR_F0003="Could not find a usable HTTP client. Either curl or wget is required to proceed with installation."
105 BADOPT_MSG="If you are following a third-party guide online, please see ${INSTALL_DOC_URL} for current instructions for using this script. If you are using a local copy of this script instead of fetching it from our servers, consider updating it. If you intended to pass this option to the installer code, please use either --local-build-options or --static-install-options to specify it instead."
106
107 # ======================================================================
108 # Core program logic
109
110 main() {
111 case "${ACTION}" in
112 uninstall)
113 uninstall
114 printf >&2 "Finished uninstalling the Netdata Agent."
115 deferred_warnings
116 cleanup
117 trap - EXIT
118 exit 0
119 ;;
120 reinstall-clean)
121 NEW_INSTALL_PREFIX="${INSTALL_PREFIX}"
122 uninstall
123 cleanup
124
125 ACTION=''
126 INSTALL_PREFIX="${NEW_INSTALL_PREFIX}"
127 # shellcheck disable=SC2086
128 main
129
130 trap - EXIT
131 exit 0
132 ;;
133 prepare-offline)
134 prepare_offline_install_source "${OFFLINE_TARGET}"
135 deferred_warnings
136 trap - EXIT
137 exit 0
138 ;;
139 esac
140
141 handle_existing_install
142 set_tmpdir
143
144 if [ -n "${INSTALL_VERSION}" ]; then
145 if echo "${INSTALL_VERSION}" | grep -E -o "^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$" > /dev/null 2>&1; then
146 NEW_SELECTED_RELEASE_CHANNEL="stable"
147 else
148 NEW_SELECTED_RELEASE_CHANNEL="nightly"
149 fi
150
151 if ! [ "${NEW_SELECTED_RELEASE_CHANNEL}" = "${SELECTED_RELEASE_CHANNEL}" ]; then
152 warning "Selected release channel does not match this version and it will be changed automatically."
153 SELECTED_RELEASE_CHANNEL="${NEW_SELECTED_RELEASE_CHANNEL}"
154 fi
155 fi
156
157 case "${SYSTYPE}" in
158 Linux) install_on_linux ;;
159 Darwin) install_on_macos ;;
160 FreeBSD) install_on_freebsd ;;
161 esac
162
163 if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then
164 claim
165 fi
166
167 set_auto_updates
168
169 printf >&2 "%s\n\n" "Successfully installed the Netdata Agent."
170 deferred_warnings
171 success_banner
172 telemetry_event INSTALL_SUCCESS "" ""
173 cleanup
174 trap - EXIT
175 }
176
177 # ======================================================================
178 # Usage info
179
180 usage() {
181 cat << HEREDOC
182 USAGE: kickstart.sh [options]
183 where options include:
184
185 --non-interactive Do not prompt for user input. (default: prompt if there is a controlling terminal)
186 --interactive Prompt for user input even if there is no controlling terminal.
187 --dont-start-it Do not start the agent by default (only for static installs or local builds)
188 --dry-run Report what we would do with the given options on this system, but don’t actually do anything.
189 --release-channel Specify the release channel to use for the install (default: ${DEFAULT_RELEASE_CHANNEL})
190 --stable-channel Equivalent to "--release-channel stable"
191 --nightly-channel Equivalent to "--release-channel nightly"
192 --no-updates Do not enable automatic updates (default: enable automatic updates using the best supported scheduling method)
193 --auto-update Enable automatic updates.
194 --auto-update-type Specify a particular scheduling type for auto-updates (valid types: systemd, interval, crontab)
195 --disable-telemetry Opt-out of anonymous statistics.
196 --native-only Only install if native binary packages are available.
197 --static-only Only install if a static build is available.
198 --build-only Only install using a local build.
199 --install-type <type> Specify what installation type to use (native, static, build, auto, or any).
200 --install-prefix <path> Specify an installation prefix for local builds (default: autodetect based on system type).
201 --old-install-prefix <path> Specify an old local builds installation prefix for uninstall/reinstall (if it's not default).
202 --install-version <version> Specify the version of Netdata to install.
203 --claim-token Use a specified token for claiming to Netdata Cloud.
204 --claim-rooms When claiming, add the node to the specified rooms.
205 --claim-* Specify other options for the claiming script.
206 --no-cleanup Don't do any cleanup steps. This is intended to help with debugging the installer.
207 --local-build-options Specify additional options to pass to the installer code when building locally. Only valid if --build-only is also specified.
208 --static-install-options Specify additional options to pass to the static installer code. Only valid if --static-only is also specified.
209 --offline-architecture Limit an offline install source being prepared with --prepare-offline-install-source to only include the specified static build architecture.
210 --offline-install-source Specify a folder to use as installation source when working offline. Use --prepare-offline-install-source first to set up this folder.
211
212 The following options are mutually exclusive and specifiy special operations other than trying to install Netdata normally or update an existing install:
213
214 --reinstall If there is an existing install, reinstall it instead of trying to update it. If there is no existing install, install netdata normally.
215 --reinstall-even-if-unsafe If there is an existing install, reinstall it instead of trying to update it, even if doing so is known to potentially break things. If there is no existing install, install Netdata normally.
216 --reinstall-clean If there is an existing install, uninstall it before trying to install Netdata. Fails if there is no existing install.
217 --uninstall Uninstall an existing installation of Netdata. Fails if there is no existing install.
218 --claim-only If there is an existing install, only try to claim it without attempting to update it. If there is no existing install, install and claim Netdata normally.
219 --repositories-only Only install repository configuration packages instead of doing a full install of Netdata. Automatically sets --native-only.
220 --prepare-offline-install-source Instead of installing the agent, prepare a directory that can be used to install on another system without needing to download anything.
221
222 Additionally, this script may use the following environment variables:
223
224 TMPDIR: Used to specify where to put temporary files. On most systems, the default we select
225 automatically should be fine. The user running the script needs to both be able to
226 write files to the temporary directory, and run files from that location.
227 ROOTCMD: Used to specify a command to use to run another command with root privileges if needed. By
228 default we try to use sudo, doas, or pkexec (in that order of preference), but if
229 you need special options for one of those to work, or have a different tool to do
230 the same thing on your system, you can specify it here.
231 DISABLE_TELEMETRY If set to a value other than 0, behave as if \`--disable-telemetry\` was specified.
232
233 HEREDOC
234 }
235
236 # ======================================================================
237 # Telemetry functions
238
239 telemetry_event() {
240 if [ "${NETDATA_DISABLE_TELEMETRY}" -eq 1 ] || [ "${DRY_RUN}" -eq 1 ]; then
241 return 0
242 fi
243
244 now="$(date +%s)"
245 total_duration="$((now - START_TIME))"
246
247 if [ -e "/etc/os-release" ]; then
248 eval "$(grep -E "^(NAME|ID|ID_LIKE|VERSION|VERSION_ID)=" < /etc/os-release | sed 's/^/HOST_/')"
249 fi
250
251 if [ -z "${HOST_NAME}" ] || [ -z "${HOST_VERSION}" ] || [ -z "${HOST_ID}" ]; then
252 if [ -f "/etc/lsb-release" ]; then
253 DISTRIB_ID="unknown"
254 DISTRIB_RELEASE="unknown"
255 DISTRIB_CODENAME="unknown"
256 eval "$(grep -E "^(DISTRIB_ID|DISTRIB_RELEASE|DISTRIB_CODENAME)=" < /etc/lsb-release)"
257 if [ -z "${HOST_NAME}" ]; then HOST_NAME="${DISTRIB_ID}"; fi
258 if [ -z "${HOST_VERSION}" ]; then HOST_VERSION="${DISTRIB_RELEASE}"; fi
259 if [ -z "${HOST_ID}" ]; then HOST_ID="${DISTRIB_CODENAME}"; fi
260 fi
261 fi
262
263 KERNEL_NAME="$(uname -s)"
264
265 if [ "${KERNEL_NAME}" = FreeBSD ]; then
266 TOTAL_RAM="$(sysctl -n hw.physmem)"
267 elif [ "${KERNEL_NAME}" = Darwin ]; then
268 TOTAL_RAM="$(sysctl -n hw.memsize)"
269 elif [ -r /proc/meminfo ]; then
270 TOTAL_RAM="$(grep -F MemTotal /proc/meminfo | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | cut -f 1 -d ' ')"
271 TOTAL_RAM="$((TOTAL_RAM * 1024))"
272 fi
273
274 MD5_PATH="$(exec <&- 2>&-; which md5sum || command -v md5sum || type md5sum)"
275
276 if [ "${KERNEL_NAME}" = Darwin ] && command -v ioreg >/dev/null 2>&1; then
277 DISTINCT_ID="macos-$(ioreg -rd1 -c IOPlatformExpertDevice | awk '/IOPlatformUUID/ { split($0, line, "\""); printf("%s\n", line[4]); }')"
278 elif [ -f /etc/machine-id ] && [ -n "$MD5_PATH" ]; then
279 DISTINCT_ID="machine-$($MD5_PATH < /etc/machine-id | cut -f1 -d" ")"
280 elif [ -f /var/db/dbus/machine-id ] && [ -n "$MD5_PATH" ]; then
281 DISTINCT_ID="dbus-$($MD5_PATH < /var/db/dbus/machine-id | cut -f1 -d" ")"
282 elif [ -f /var/lib/dbus/machine-id ] && [ -n "$MD5_PATH" ]; then
283 DISTINCT_ID="dbus-$($MD5_PATH < /var/lib/dbus/machine-id | cut -f1 -d" ")"
284 elif command -v uuidgen > /dev/null 2>&1; then
285 DISTINCT_ID="uuid-$(uuidgen | tr '[:upper:]' '[:lower:]')"
286 else
287 DISTINCT_ID="null"
288 fi
289
290 REQ_BODY="$(cat << EOF
291 {
292 "event": "${1}",
293 "properties": {
294 "distinct_id": "${DISTINCT_ID}",
295 "event_source": "agent installer",
296 "\$current_url": "agent installer",
297 "\$pathname": "netdata-installer",
298 "\$host": "installer.netdata.io",
299 "\$ip": "127.0.0.1",
300 "script_variant": "kickstart-ng",
301 "error_code": "${3}",
302 "error_message": "${2}",
303 "install_options": "${KICKSTART_OPTIONS}",
304 "install_interactivity": "${INTERACTIVE}",
305 "install_auto_updates": "${NETDATA_AUTO_UPDATES}",
306 "install_command": "${NETDATA_COMMAND}",
307 "total_runtime": "${total_duration}",
308 "selected_install_method": "${SELECTED_INSTALL_METHOD}",
309 "netdata_release_channel": "${RELEASE_CHANNEL:-null}",
310 "netdata_install_type": "${INSTALL_TYPE}",
311 "host_os_name": "${HOST_NAME:-unknown}",
312 "host_os_id": "${HOST_ID:-unknown}",
313 "host_os_id_like": "${HOST_ID_LIKE:-unknown}",
314 "host_os_version": "${HOST_VERSION:-unknown}",
315 "host_os_version_id": "${HOST_VERSION_ID:-unknown}",
316 "system_kernel_name": "${KERNEL_NAME}",
317 "system_kernel_version": "$(uname -r)",
318 "system_architecture": "$(uname -m)",
319 "system_total_ram": "${TOTAL_RAM:-unknown}",
320 "system_distinct_id": "${DISTINCT_ID}"
321 }
322 }
323 EOF
324 )"
325
326 succeeded=0
327
328 if [ -n "${CURL}" ]; then
329 if "${CURL}" --silent -o /dev/null -X POST --max-time 2 --header "Content-Type: application/json" -d "${REQ_BODY}" "${TELEMETRY_URL}" > /dev/null; then
330 succeeded=1
331 fi
332 fi
333
334 if [ "${succeeded}" -eq 0 ]; then
335 if command -v wget > /dev/null 2>&1; then
336 if wget --help 2>&1 | grep BusyBox > /dev/null 2>&1; then
337 # BusyBox-compatible version of wget, there is no --no-check-certificate option
338 wget -q -O - \
339 -T 1 \
340 --header 'Content-Type: application/json' \
341 --post-data "${REQ_BODY}" \
342 "${TELEMETRY_URL}" > /dev/null
343 else
344 wget -q -O - --no-check-certificate \
345 --method POST \
346 --timeout=1 \
347 --header 'Content-Type: application/json' \
348 --body-data "${REQ_BODY}" \
349 "${TELEMETRY_URL}" > /dev/null
350 fi
351 fi
352 fi
353 }
354
355 trap_handler() {
356 code="${1}"
357 lineno="${2}"
358
359 deferred_warnings
360
361 printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ERROR ${TPUT_RESET} Installer exited unexpectedly (${code}-${lineno})"
362
363 case "${code}" in
364 0) printf >&2 "%s\n" "This is almost certainly the result of a bug. If you have time, please report it at ${AGENT_BUG_REPORT_URL}." ;;
365 *)
366 printf >&2 "%s\n" "This is probably a result of a transient issue on your system. Things should work correctly if you try again."
367 printf >&2 "%s\n" "If you continue to experience this issue, you can reach out to us for support on:"
368 support_list
369 ;;
370 esac
371
372 telemetry_event INSTALL_CRASH "Installer exited unexpectedly (${code}-${lineno})" "E${code}-${lineno}"
373
374 trap - EXIT
375
376 cleanup
377
378 exit 1
379 }
380
381 trap 'trap_handler 0 ${LINENO}' EXIT
382 trap 'trap_handler 1 0' HUP
383 trap 'trap_handler 2 0' INT
384 trap 'trap_handler 3 0' QUIT
385 trap 'trap_handler 13 0' PIPE
386 trap 'trap_handler 15 0' TERM
387
388 # ======================================================================
389 # Utility functions
390
391 canonical_path() {
392 OLDPWD="$(pwd)"
393 cd "$(dirname "${1}")" || exit 1
394 case "$(basename "${1}")" in
395 ..) dirname "$(pwd -P)" ;;
396 .) pwd -P ;;
397 *) echo "$(pwd -P)/$(basename "${1}")" ;;
398 esac
399 cd "${OLDPWD}" || exit 1
400 }
401
402 setup_terminal() {
403 TPUT_RESET=""
404 TPUT_WHITE=""
405 TPUT_BGRED=""
406 TPUT_BGGREEN=""
407 TPUT_BOLD=""
408 TPUT_DIM=""
409
410 # Is stderr on the terminal? If not, then fail
411 test -t 2 || return 1
412
413 if command -v tput > /dev/null 2>&1; then
414 if num_colors=$(tput colors 2> /dev/null) && [ "${num_colors:-0}" -ge 8 ]; then
415 # Enable colors
416 TPUT_RESET="$(tput sgr 0)"
417 TPUT_WHITE="$(tput setaf 7)"
418 TPUT_BGRED="$(tput setab 1)"
419 TPUT_BGGREEN="$(tput setab 2)"
420 TPUT_BOLD="$(tput bold)"
421 TPUT_DIM="$(tput dim)"
422 fi
423 fi
424
425 echo "${TPUT_RESET}"
426
427 return 0
428 }
429
430 support_list() {
431 printf >&2 "%s\n" " - GitHub: ${DISCUSSIONS_URL}"
432 printf >&2 "%s\n" " - Discord: ${DISCORD_INVITE}"
433 printf >&2 "%s\n" " - Our community forums: ${FORUM_URL}"
434 }
435
436 success_banner() {
437 printf >&2 "%s\n" "To view the dashboard, open your web browser and enter http://NODE:19999."
438 printf >&2 "%s\n\n" "Replace NODE with the IP address or hostname of your Netdata server."
439
440 printf >&2 "%s\n\n" "Official documentation can be found online at ${DOCS_URL}."
441
442 if [ -z "${CLAIM_TOKEN}" ]; then
443 printf >&2 "%s\n\n" "Looking to monitor all of your infrastructure with Netdata? Check out Netdata Cloud at ${PUBLIC_CLOUD_URL}."
444 fi
445
446 printf >&2 "%s\n" "Join our community and connect with us on:"
447 support_list
448 }
449
450 cleanup() {
451 if [ -z "${NO_CLEANUP}" ] && [ -n "${tmpdir}" ]; then
452 cd || true
453 DRY_RUN=0
454 run_as_root rm -rf "${tmpdir}"
455 fi
456 }
457
458 deferred_warnings() {
459 if [ -n "${NETDATA_WARNINGS}" ]; then
460 printf >&2 "%s\n" "The following non-fatal warnings or errors were encountered:"
461 # shellcheck disable=SC2059
462 printf >&2 "${NETDATA_WARNINGS}"
463 printf >&2 "\n\n"
464 fi
465 }
466
467 fatal() {
468 deferred_warnings
469 printf >&2 "%b\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${1}"
470 printf >&2 "%s\n" "For community support, you can connect with us on:"
471 support_list
472 telemetry_event "INSTALL_FAILED" "${1}" "${2}"
473 cleanup
474 trap - EXIT
475 exit 1
476 }
477
478 ESCAPED_PRINT_METHOD=
479 # shellcheck disable=SC3050
480 if printf "%s " test > /dev/null 2>&1; then
481 ESCAPED_PRINT_METHOD="printfq"
482 fi
483
484 escaped_print() {
485 if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]; then
486 # shellcheck disable=SC3050
487 printf "%s " "${@}"
488 else
489 printf "%s" "${*}"
490 fi
491 return 0
492 }
493
494 progress() {
495 echo >&2 " --- ${TPUT_BOLD}${*}${TPUT_RESET} --- "
496 }
497
498 run_logfile="/dev/null"
499 run() {
500 user="${USER--}"
501 dir="${PWD}"
502
503 if [ "$(id -u)" = "0" ]; then
504 info="[root ${dir}]# "
505 info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
506 else
507 info="[${user} ${dir}]$ "
508 info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ "
509 fi
510
511 if [ "${DRY_RUN}" -eq 1 ]; then
512 printf >&2 "%s" "Would run command:\n"
513 fi
514
515 {
516 printf "%s" "${info}"
517 escaped_print "${@}"
518 printf " ... "
519 } >> "${run_logfile}"
520
521 printf >&2 "%s" "${info_console}${TPUT_BOLD}"
522 escaped_print >&2 "${@}"
523 printf >&2 "%s\n" "${TPUT_RESET}"
524
525 if [ "${DRY_RUN}" -ne 1 ]; then
526 "${@}"
527 ret=$?
528 else
529 ret=0
530 fi
531
532 if [ ${ret} -ne 0 ]; then
533 printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET}"
534 printf "%s\n" "FAILED with exit code ${ret}" >> "${run_logfile}"
535 # shellcheck disable=SC2089
536 NETDATA_WARNINGS="${NETDATA_WARNINGS}\n - Command \"${*}\" failed with exit code ${ret}."
537 else
538 printf >&2 "%s\n\n" "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET}"
539 printf "OK\n" >> "${run_logfile}"
540 fi
541
542 return ${ret}
543 }
544
545 run_as_root() {
546 confirm_root_support
547
548 if [ "$(id -u)" -ne "0" ]; then
549 printf >&2 "Root privileges required to run %s\n" "${*}"
550 fi
551
552 run ${ROOTCMD} "${@}"
553 }
554
555 run_script() {
556 set_tmpdir
557
558 export NETDATA_SCRIPT_STATUS_PATH="${tmpdir}/.script-status"
559
560 export NETDATA_SAVE_WARNINGS=1
561 export NETDATA_PROPAGATE_WARNINGS=1
562 # shellcheck disable=SC2090
563 export NETDATA_WARNINGS="${NETDATA_WARNINGS}"
564
565 # shellcheck disable=SC2086
566 run ${ROOTCMD} "${@}"
567
568 ret="$?"
569
570 if [ -r "${NETDATA_SCRIPT_STATUS_PATH}" ]; then
571 # shellcheck disable=SC1090
572 . "${NETDATA_SCRIPT_STATUS_PATH}"
573 rm -f "${NETDATA_SCRIPT_STATUS_PATH}"
574 fi
575
576 return "${ret}"
577 }
578
579 warning() {
580 printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} WARNING ${TPUT_RESET} ${*}"
581 NETDATA_WARNINGS="${NETDATA_WARNINGS}\n - ${*}"
582 }
583
584 _cannot_use_tmpdir() {
585 testfile="$(TMPDIR="${1}" mktemp -q -t netdata-test.XXXXXXXXXX)"
586 ret=0
587
588 if [ -z "${testfile}" ]; then
589 return "${ret}"
590 fi
591
592 if printf '#!/bin/sh\necho SUCCESS\n' > "${testfile}"; then
593 if chmod +x "${testfile}"; then
594 if [ "$("${testfile}")" = "SUCCESS" ]; then
595 ret=1
596 fi
597 fi
598 fi
599
600 rm -f "${testfile}"
601 return "${ret}"
602 }
603
604 create_tmp_directory() {
605 if [ -z "${TMPDIR}" ] || _cannot_use_tmpdir "${TMPDIR}"; then
606 if _cannot_use_tmpdir /tmp; then
607 if _cannot_use_tmpdir "${PWD}"; then
608 fatal "Unable to find a usable temporary directory. Please set \$TMPDIR to a path that is both writable and allows execution of files and try again." F0400
609 else
610 TMPDIR="${PWD}"
611 fi
612 else
613 TMPDIR="/tmp"
614 fi
615 fi
616
617 mktemp -d -t netdata-kickstart-XXXXXXXXXX
618 }
619
620 set_tmpdir() {
621 if [ -z "${tmpdir}" ] || [ ! -d "${tmpdir}" ]; then
622 tmpdir="$(create_tmp_directory)"
623 progress "Using ${tmpdir} as a temporary directory."
624 cd "${tmpdir}" || fatal "Failed to change current working directory to ${tmpdir}." F000A
625 fi
626 }
627
628 check_for_remote_file() {
629 url="${1}"
630 succeeded=0
631 checked=0
632
633 if echo "${url}" | grep -Eq "^file:///"; then
634 [ -e "${url#file://}" ] || return 1
635 return 0
636 elif [ -n "${NETDATA_ASSUME_REMOTE_FILES_ARE_PRESENT}" ]; then
637 return 0
638 fi
639
640 if [ -n "${CURL}" ]; then
641 checked=1
642
643 if "${CURL}" --output /dev/null --silent --head --fail "${url}"; then
644 succeeded=1
645 fi
646 fi
647
648 if [ "${succeeded}" -eq 0 ]; then
649 if command -v wget > /dev/null 2>&1; then
650 checked=1
651
652 if wget -S --spider "${url}" 2>&1 | grep -q 'HTTP/1.1 200 OK'; then
653 succeeded=1
654 fi
655 fi
656 fi
657
658 if [ "${succeeded}" -eq 1 ]; then
659 return 0
660 elif [ "${checked}" -eq 1 ]; then
661 return 1
662 else
663 fatal "${ERROR_F0003}" F0003
664 fi
665 }
666
667 download() {
668 url="${1}"
669 dest="${2}"
670 succeeded=0
671 checked=0
672
673 if echo "${url}" | grep -Eq "^file:///"; then
674 run cp "${url#file://}" "${dest}" || return 1
675 return 0
676 fi
677
678
679 if [ -n "${CURL}" ]; then
680 checked=1
681
682 if run "${CURL}" --fail -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}"; then
683 succeeded=1
684 else
685 rm -f "${dest}"
686 fi
687 fi
688
689 if [ "${succeeded}" -eq 0 ]; then
690 if command -v wget > /dev/null 2>&1; then
691 checked=1
692
693 if run wget -T 15 -O "${dest}" "${url}"; then
694 succeeded=1
695 fi
696 fi
697 fi
698
699 if [ "${succeeded}" -eq 1 ]; then
700 return 0
701 elif [ "${checked}" -eq 1 ]; then
702 return 1
703 else
704 fatal "${ERROR_F0003}" F0003
705 fi
706 }
707
708 get_actual_version() {
709 major="${1}"
710 channel="${2}"
711 url="${RELEASE_INFO_URL}/${channel}/${major}"
712
713 if check_for_remote_file "${RELEASE_INFO_URL}"; then
714 if check_for_remote_file "${url}"; then
715 download "${url}" -
716 else
717 echo "NONE"
718 fi
719 else
720 echo ""
721 fi
722 }
723
724 get_redirect() {
725 url="${1}"
726 succeeded=0
727 checked=0
728
729 if [ -n "${CURL}" ]; then
730 checked=1
731
732 if run sh -c "${CURL} ${url} -s -L -I -o /dev/null -w '%{url_effective}' | grep -Eo '[^/]+/?$' | grep -Eo '^[^/]+'"; then
733 succeeded=1
734 fi
735 fi
736
737 if [ "${succeeded}" -eq 0 ]; then
738 if command -v wget > /dev/null 2>&1; then
739 checked=1
740
741 if run sh -c "wget -S -O /dev/null ${url} 2>&1 | grep -m 1 Location | grep -Eo '[^/]+/?$' | grep -Eo '^[^/]+'"; then
742 succeeded=1
743 fi
744 fi
745 fi
746
747 if [ "${succeeded}" -eq 1 ]; then
748 return 0
749 elif [ "${checked}" -eq 1 ]; then
750 return 1
751 else
752 fatal "${ERROR_F0003}" F0003
753 fi
754 }
755
756 safe_sha256sum() {
757 if command -v shasum > /dev/null 2>&1; then
758 shasum -a 256 "$@"
759 elif command -v sha256sum > /dev/null 2>&1; then
760 sha256sum "$@"
761 else
762 fatal "Could not find a usable checksum tool. Either sha256sum, or a version of shasum supporting SHA256 checksums is required to proceed with installation." F0004
763 fi
764 }
765
766 report_bad_sha256sum() {
767 file="${1}"
768 sums="${2}"
769
770 actual="$(safe_sha256sum "${file}" | awk '{ print $1 }')"
771 expected="$(grep "${file}" "${sums}" | awk '{ print $1 }')"
772
773 printf "Expected: %s\n" "${expected}"
774 printf "Actual: %s\n" "${actual}"
775 }
776
777 get_system_info() {
778 SYSARCH="$(uname -m)"
779
780 case "$(uname -s)" in
781 Linux)
782 SYSTYPE="Linux"
783
784 if [ -z "${SKIP_DISTRO_DETECTION}" ]; then
785 os_release_file=
786 if [ -s "/etc/os-release" ] && [ -r "/etc/os-release" ]; then
787 os_release_file="/etc/os-release"
788 elif [ -s "/usr/lib/os-release" ] && [ -r "/usr/lib/os-release" ]; then
789 os_release_file="/usr/lib/os-release"
790 else
791 warning "Cannot find usable OS release information. Native packages will not be available for this install."
792 fi
793
794 if [ -n "${os_release_file}" ]; then
795 # shellcheck disable=SC1090
796 . "${os_release_file}"
797
798 DISTRO="${ID}"
799 SYSVERSION="${VERSION_ID}"
800 SYSCODENAME="${VERSION_CODENAME}"
801 else
802 DISTRO="unknown"
803 DISTRO_COMPAT_NAME="unknown"
804 SYSVERSION="unknown"
805 SYSCODENAME="unknown"
806 fi
807 else
808 warning "Distribution auto-detection overridden by user. This is not guaranteed to work, and is not officially supported."
809 fi
810
811 supported_compat_names="debian ubuntu centos fedora opensuse ol amzn arch"
812
813 if str_in_list "${DISTRO}" "${supported_compat_names}"; then
814 DISTRO_COMPAT_NAME="${DISTRO}"
815 else
816 case "${DISTRO}" in
817 raspbian)
818 if [ "$SYSARCH" = "armv7l" ] || [ "$SYSARCH" = "aarch64" ]; then
819 DISTRO_COMPAT_NAME="debian"
820 fi
821 ;;
822 opensuse-leap)
823 DISTRO_COMPAT_NAME="opensuse"
824 ;;
825 opensuse-tumbleweed)
826 DISTRO_COMPAT_NAME="opensuse"
827 SYSVERSION="tumbleweed"
828 ;;
829 cloudlinux|almalinux|centos-stream|rocky|rhel)
830 DISTRO_COMPAT_NAME="centos"
831 ;;
832 artix|manjaro|obarun)
833 DISTRO_COMPAT_NAME="arch"
834 ;;
835 *)
836 DISTRO_COMPAT_NAME="unknown"
837 ;;
838 esac
839 fi
840
841 case "${DISTRO_COMPAT_NAME}" in
842 centos|ol) SYSVERSION=$(echo "$SYSVERSION" | cut -d'.' -f1) ;;
843 esac
844 ;;
845 Darwin)
846 SYSTYPE="Darwin"
847 SYSVERSION="$(sw_vers -buildVersion)"
848 ;;
849 FreeBSD)
850 SYSTYPE="FreeBSD"
851 SYSVERSION="$(uname -K)"
852 ;;
853 *) fatal "Unsupported system type detected. Netdata cannot be installed on this system using this script." F0200 ;;
854 esac
855 }
856
857 str_in_list() {
858 printf "%s\n" "${2}" | tr ' ' "\n" | grep -qE "^${1}\$"
859 return $?
860 }
861
862 confirm_root_support() {
863 if [ "$(id -u)" -ne "0" ]; then
864 if [ -z "${ROOTCMD}" ] && command -v sudo > /dev/null; then
865 if [ "${INTERACTIVE}" -eq 0 ]; then
866 ROOTCMD="sudo -n"
867 else
868 ROOTCMD="sudo"
869 fi
870 fi
871
872 if [ -z "${ROOTCMD}" ] && command -v doas > /dev/null; then
873 if [ "${INTERACTIVE}" -eq 0 ]; then
874 ROOTCMD="doas -n"
875 else
876 ROOTCMD="doas"
877 fi
878 fi
879
880 if [ -z "${ROOTCMD}" ] && command -v pkexec > /dev/null; then
881 ROOTCMD="pkexec"
882 fi
883
884 if [ -z "${ROOTCMD}" ]; then
885 fatal "This script needs root privileges to install Netdata, but cannot find a way to gain them (we support sudo, doas, and pkexec). Either re-run this script as root, or set \$ROOTCMD to a command that can be used to gain root privileges." F0201
886 fi
887 fi
888 }
889
890 confirm() {
891 prompt="${1} [y/n]"
892
893 while true; do
894 echo "${prompt}"
895 read -r yn
896
897 case "$yn" in
898 [Yy]*) return 0;;
899 [Nn]*) return 1;;
900 *) echo "Please answer yes or no.";;
901 esac
902 done
903 }
904
905 # ======================================================================
906 # Existing install handling code
907
908 update() {
909 updater="${ndprefix}/usr/libexec/netdata/netdata-updater.sh"
910
911 if run_as_root test -x "${updater}"; then
912 if [ "${DRY_RUN}" -eq 1 ]; then
913 progress "Would attempt to update existing installation by running the updater script located at: ${updater}"
914 return 0
915 fi
916
917 if [ "${INTERACTIVE}" -eq 0 ]; then
918 opts="--non-interactive"
919 else
920 opts="--interactive"
921 fi
922
923 if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
924 export NETDATA_OFFLINE_INSTALL_SOURCE="${NETDATA_OFFLINE_INSTALL_SOURCE}"
925 fi
926
927 if run_script "${updater}" ${opts} --not-running-from-cron; then
928 progress "Updated existing install at ${ndprefix}"
929 return 0
930 else
931 if [ -n "${EXIT_REASON}" ]; then
932 fatal "Failed to update existing Netdata install at ${ndprefix}: ${EXIT_REASON}" "${EXIT_CODE}"
933 else
934 fatal "Failed to update existing Netdata install at ${ndprefix}: Encountered an unhandled error in the updater. Further information about this error may be displayed above." U0000
935 fi
936 fi
937 else
938 warning "Could not find a usable copy of the updater script. We are unable to update this system in place."
939 return 1
940 fi
941 }
942
943 uninstall() {
944 set_tmpdir
945 get_system_info
946 detect_existing_install
947
948 if [ -n "${OLD_INSTALL_PREFIX}" ]; then
949 INSTALL_PREFIX="$(echo "${OLD_INSTALL_PREFIX}/" | sed 's/$/netdata/g')"
950 else
951 INSTALL_PREFIX="${ndprefix}"
952 fi
953
954 uninstaller="${INSTALL_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh"
955 uninstaller_url="https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/netdata-uninstaller.sh"
956
957 if [ $INTERACTIVE = 0 ]; then
958 FLAGS="--yes --force"
959 else
960 FLAGS="--yes"
961 fi
962
963 if run_as_root test -x "${uninstaller}"; then
964 if [ "${DRY_RUN}" -eq 1 ]; then
965 progress "Would attempt to uninstall existing install with uninstaller script found at: ${uninstaller}"
966 return 0
967 else
968 progress "Found existing netdata-uninstaller. Running it.."
969 # shellcheck disable=SC2086
970 if ! run_script "${uninstaller}" ${FLAGS}; then
971 warning "Uninstaller failed. Some parts of Netdata may still be present on the system."
972 fi
973 fi
974 else
975 if [ "${DRY_RUN}" -eq 1 ]; then
976 progress "Would download installer script from: ${uninstaller_url}"
977 progress "Would attempt to uninstall existing install with downloaded uninstaller script."
978 return 0
979 else
980 progress "Downloading netdata-uninstaller ..."
981 download "${uninstaller_url}" "${tmpdir}/netdata-uninstaller.sh"
982 chmod +x "${tmpdir}/netdata-uninstaller.sh"
983 # shellcheck disable=SC2086
984 if ! run_script "${tmpdir}/netdata-uninstaller.sh" ${FLAGS}; then
985 warning "Uninstaller failed. Some parts of Netdata may still be present on the system."
986 fi
987 fi
988 fi
989 }
990
991 detect_existing_install() {
992 set_tmpdir
993
994 progress "Checking for existing installations of Netdata..."
995 EXISTING_INSTALL_IS_NATIVE="0"
996
997 if [ -n "${INSTALL_PREFIX}" ]; then
998 searchpath="/opt/netdata/bin:${INSTALL_PREFIX}/bin:${INSTALL_PREFIX}/sbin:${INSTALL_PREFIX}/usr/bin:${INSTALL_PREFIX}/usr/sbin:${PATH}"
999 searchpath="${INSTALL_PREFIX}/netdata/bin:${INSTALL_PREFIX}/netdata/sbin:${INSTALL_PREFIX}/netdata/usr/bin:${INSTALL_PREFIX}/netdata/usr/sbin:${searchpath}"
1000 else
1001 searchpath="/opt/netdata/bin:${PATH}"
1002 fi
1003
1004 while [ -n "${searchpath}" ]; do
1005 _ndpath="$(PATH="${searchpath}" command -v netdata 2>/dev/null)"
1006
1007 if [ -n "${_ndpath}" ]; then
1008 _ndpath="$(canonical_path "${_ndpath}")"
1009 fi
1010
1011 if [ -z "${ndpath}" ] && [ -n "${_ndpath}" ]; then
1012 ndpath="${_ndpath}"
1013 elif [ -n "${_ndpath}" ] && [ "${ndpath}" != "${_ndpath}" ]; then
1014 fatal "Multiple installs of Netdata agent detected (located at '${ndpath}' and '${_ndpath}'). Such a setup is not generally supported. If you are certain you want to operate on one of them despite this, use the '--install-prefix' option to specifiy the install you want to operate on." F0517
1015 fi
1016
1017 if [ -n "${INSTALL_PREFIX}" ] && [ -n "${ndpath}" ]; then
1018 break
1019 elif [ -z "${_ndpath}" ]; then
1020 break
1021 elif echo "${searchpath}" | grep -v ':'; then
1022 searchpath=""
1023 else
1024 searchpath="$(echo "${searchpath}" | cut -f 2- -d ':')"
1025 fi
1026 done
1027
1028 if pkg_installed netdata; then
1029 ndprefix="/"
1030 EXISTING_INSTALL_IS_NATIVE="1"
1031 elif [ -n "${ndpath}" ]; then
1032 case "${ndpath}" in
1033 */usr/bin/netdata|*/usr/sbin/netdata) ndprefix="$(dirname "$(dirname "$(dirname "${ndpath}")")")" ;;
1034 *) ndprefix="$(dirname "$(dirname "${ndpath}")")" ;;
1035 esac
1036
1037 if echo "${ndprefix}" | grep -Eq '^/usr$'; then
1038 ndprefix="$(dirname "${ndprefix}")"
1039 fi
1040 fi
1041
1042 if [ -n "${ndprefix}" ]; then
1043 typefile="${ndprefix}/etc/netdata/.install-type"
1044 if [ -r "${typefile}" ]; then
1045 # shellcheck disable=SC1090,SC1091
1046 . "${typefile}"
1047 else
1048 INSTALL_TYPE="unknown"
1049 fi
1050
1051 envfile="${ndprefix}/etc/netdata/.environment"
1052 if [ "${INSTALL_TYPE}" = "unknown" ] || [ "${INSTALL_TYPE}" = "custom" ]; then
1053 if [ -r "${envfile}" ]; then
1054 # shellcheck disable=SC1090,SC1091
1055 . "${envfile}"
1056 if [ -n "${NETDATA_IS_STATIC_INSTALL}" ]; then
1057 if [ "${NETDATA_IS_STATIC_INSTALL}" = "yes" ]; then
1058 INSTALL_TYPE="legacy-static"
1059 else
1060 INSTALL_TYPE="legacy-build"
1061 fi
1062 fi
1063 fi
1064 fi
1065 fi
1066 }
1067
1068 handle_existing_install() {
1069 detect_existing_install
1070
1071 if [ -z "${ndprefix}" ] || [ -z "${INSTALL_TYPE}" ]; then
1072 progress "No existing installations of netdata found, assuming this is a fresh install."
1073 return 0
1074 fi
1075
1076 case "${INSTALL_TYPE}" in
1077 kickstart-*|legacy-*|binpkg-*|manual-static|unknown)
1078 if [ "${INSTALL_TYPE}" = "unknown" ]; then
1079 if [ "${EXISTING_INSTALL_IS_NATIVE}" -eq 1 ]; then
1080 warning "Found an existing netdata install managed by the system package manager, but could not determine the install type. Usually this means you installed an unsupported third-party netdata package. This script supports claiming most such installs, but attempting to update or reinstall them using this script may be dangerous."
1081 else
1082 warning "Found an existing netdata install at ${ndprefix}, but could not determine the install type. Usually this means you installed Netdata through your distribution’s regular package repositories or some other unsupported method."
1083 fi
1084 else
1085 progress "Found an existing netdata install at ${ndprefix}, with installation type '${INSTALL_TYPE}'."
1086 fi
1087
1088 if [ "${ACTION}" = "reinstall" ] || [ "${ACTION}" = "unsafe-reinstall" ]; then
1089 progress "Found an existing netdata install at ${ndprefix}, but user requested reinstall, continuing."
1090
1091 case "${INSTALL_TYPE}" in
1092 binpkg-*) NETDATA_REQUESTED_INSTALL_TYPE='native' ;;
1093 *-build) NETDATA_REQUESTED_INSTALL_TYPE='build' ;;
1094 *-static) NETDATA_REQUESTED_INSTALL_TYPE='static' ;;
1095 *)
1096 if [ "${ACTION}" = "unsafe-reinstall" ]; then
1097 warning "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, but the user has requested we proceed."
1098 elif [ "${INTERACTIVE}" -eq 0 ]; then
1099 fatal "User requested reinstall, but we cannot safely reinstall over top of a ${INSTALL_TYPE} installation, exiting." F0104
1100 else
1101 if [ "${EXISTING_INSTALL_IS_NATIVE}" ]; then
1102 reinstall_prompt="Reinstalling over top of an existing install managed by the system package manager is known to cause things to break, are you sure you want to continue?"
1103 else
1104 reinstall_prompt="Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, do you want to continue?"
1105 fi
1106
1107 if confirm "${reinstall_prompt}"; then
1108 progress "OK, continuing."
1109 else
1110 fatal "Cancelling reinstallation at user request." F0105
1111 fi
1112 fi
1113 ;;
1114 esac
1115
1116 return 0
1117 elif [ "${INSTALL_TYPE}" = "unknown" ]; then
1118 claimonly_notice="If you just want to claim this install, you should re-run this command with the --claim-only option instead."
1119 if [ "${EXISTING_INSTALL_IS_NATIVE}" -eq 1 ]; then
1120 failmsg="Attempting to update an installation managed by the system package manager is known to not work in most cases. If you are trying to install the latest version of Netdata, you will need to manually uninstall it through your system package manager. ${claimonly_notice}"
1121 promptmsg="Attempting to update an installation managed by the system package manager is known to not work in most cases. If you are trying to install the latest version of Netdata, you will need to manually uninstall it through your system package manager. ${claimonly_notice} Are you sure you want to continue?"
1122 else
1123 failmsg="We do not support trying to update or claim installations when we cannot determine the install type. You will need to uninstall the existing install using the same method you used to install it to proceed. ${claimonly_notice}"
1124 promptmsg="Attempting to update an existing install with an unknown installation type is not officially supported. It may work, but it also might break your system. ${claimonly_notice} Are you sure you want to continue?"
1125 fi
1126 if [ "${INTERACTIVE}" -eq 0 ] && [ "${ACTION}" != "claim" ]; then
1127 fatal "${failmsg}" F0106
1128 elif [ "${INTERACTIVE}" -eq 1 ] && [ "${ACTION}" != "claim" ]; then
1129 if confirm "${promptmsg}"; then
1130 progress "OK, continuing"
1131 else
1132 fatal "Cancelling update of unknown installation type at user request." F050C
1133 fi
1134 fi
1135 fi
1136
1137 ret=0
1138
1139 if [ "${ACTION}" != "claim" ]; then
1140 if ! update; then
1141 warning "Failed to update existing Netdata install at ${ndprefix}."
1142 else
1143 progress "Successfully updated existing netdata install at ${ndprefix}."
1144 fi
1145 else
1146 warning "Not updating existing install at ${ndprefix}."
1147 fi
1148
1149 if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then
1150 progress "Attempting to claim existing install at ${ndprefix}."
1151 INSTALL_PREFIX="${ndprefix}"
1152 claim
1153 ret=$?
1154 elif [ "${ACTION}" = "claim" ]; then
1155 fatal "User asked to claim, but did not provide a claiming token." F0202
1156 else
1157 progress "Not attempting to claim existing install at ${ndprefix} (no claiming token provided)."
1158 fi
1159
1160 deferred_warnings
1161 success_banner
1162 cleanup
1163 trap - EXIT
1164 exit $ret
1165 ;;
1166 oci)
1167 fatal "This is an OCI container, use the regular container lifecycle management commands for your container tools instead of this script for managing it." F0203
1168 ;;
1169 *)
1170 if [ "${ACTION}" = "reinstall" ] || [ "${ACTION}" = "unsafe-reinstall" ]; then
1171 if [ "${ACTION}" = "unsafe-reinstall" ]; then
1172 warning "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, but the user has requested we proceed."
1173 elif [ "${INTERACTIVE}" -eq 0 ]; then
1174 fatal "User requested reinstall, but we cannot safely reinstall over top of a ${INSTALL_TYPE} installation, exiting." F0104
1175 else
1176 if confirm "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, do you want to continue?"; then
1177 progress "OK, continuing."
1178 else
1179 fatal "Cancelling reinstallation at user request." F0105
1180 fi
1181 fi
1182 else
1183 if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then
1184 progress "Attempting to claim existing install at ${ndprefix}."
1185 INSTALL_PREFIX="${ndprefix}"
1186 claim
1187 ret=$?
1188
1189 cleanup
1190 trap - EXIT
1191 exit $ret
1192 elif [ "${ACTION}" = "claim" ]; then
1193 fatal "User asked to claim, but did not provide a claiming token." F0202
1194 else
1195 fatal "Found an existing netdata install at ${ndprefix}, but the install type is '${INSTALL_TYPE}', which is not supported by this script, refusing to proceed." F0103
1196 fi
1197 fi
1198 ;;
1199 esac
1200 }
1201
1202 confirm_install_prefix() {
1203 if [ -n "${INSTALL_PREFIX}" ] && [ "${NETDATA_REQUESTED_INSTALL_TYPE}" != 'build' ]; then
1204 fatal "The --install-prefix option is only supported together with the --build-only option." F0204
1205 fi
1206
1207 if [ -n "${INSTALL_PREFIX}" ]; then
1208 NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --install-prefix ${INSTALL_PREFIX}"
1209 else
1210 case "${SYSTYPE}" in
1211 Darwin)
1212 INSTALL_PREFIX="/usr/local/netdata"
1213 NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --install-no-prefix ${INSTALL_PREFIX}"
1214 ;;
1215 FreeBSD)
1216 INSTALL_PREFIX="/usr/local"
1217 NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --install-no-prefix ${INSTALL_PREFIX}"
1218 ;;
1219 esac
1220 fi
1221 }
1222
1223 # ======================================================================
1224 # Claiming support code
1225
1226 check_claim_opts() {
1227 # shellcheck disable=SC2235,SC2030
1228 if [ -z "${NETDATA_CLAIM_TOKEN}" ] && [ -n "${NETDATA_CLAIM_ROOMS}" ]; then
1229 fatal "Invalid claiming options, claim rooms may only be specified when a token is specified." F0204
1230 elif [ -z "${NETDATA_CLAIM_TOKEN}" ] && [ -n "${NETDATA_CLAIM_EXTRA}${NETDATA_CLAIM_PROXY}${NETDATA_CLAIM_NORELOAD}${NETDATA_CLAIM_INSECURE}" ]; then
1231 # The above condition checks if _any_ claiming options other than the rooms have been set when the token is unset.
1232 fatal "Invalid claiming options, a claiming token must be specified." F0204
1233 fi
1234 }
1235
1236 is_netdata_running() {
1237 if command -v pgrep > /dev/null 2>&1; then
1238 if pgrep netdata; then
1239 return 0
1240 else
1241 return 1
1242 fi
1243 else
1244 if [ -z "${INSTALL_PREFIX}" ]; then
1245 NETDATACLI_PATH=/usr/sbin/netdatacli
1246 elif [ "${INSTALL_PREFIX}" = "/opt/netdata" ]; then
1247 NETDATACLI_PATH="/opt/netdata/bin/netdatacli"
1248 else
1249 NETDATACLI_PATH="${INSTALL_PREFIX}/netdata/usr/sbin/netdatacli"
1250 fi
1251
1252 if "${NETDATACLI_PATH}" ping > /dev/null 2>&1; then
1253 return 0
1254 else
1255 return 1
1256 fi
1257 fi
1258 }
1259
1260 write_claim_config() {
1261 if [ -z "${INSTALL_PREFIX}" ] || [ "${INSTALL_PREFIX}" = "/" ]; then
1262 config_path="/etc/netdata"
1263 netdatacli="$(command -v netdatacli)"
1264 elif [ "${INSTALL_PREFIX}" = "/opt/netdata" ]; then
1265 config_path="/opt/netdata/etc/netdata"
1266 netdatacli="/opt/netdata/bin/netdatacli"
1267 elif [ ! -d "${INSTALL_PREFIX}/netdata" ]; then
1268 config_path="${INSTALL_PREFIX}/etc/netdata"
1269 netdatacli="${INSTALL_PREFIX}/usr/sbin/netdatacli"
1270 else
1271 config_path="${INSTALL_PREFIX}/netdata/etc/netdata"
1272 netdatacli="${INSTALL_PREFIX}/netdata/usr/sbin/netdatacli"
1273 fi
1274
1275 claim_config="${config_path}/claim.conf"
1276
1277 if [ "${DRY_RUN}" -eq 1 ]; then
1278 progress "Would attempt to write claiming configuration to ${claim_config}"
1279 return 0
1280 fi
1281
1282 progress "Writing claiming configuration to ${claim_config}"
1283
1284 config="[global]"
1285 config="${config}\n url = ${NETDATA_CLAIM_URL}"
1286 config="${config}\n token = ${NETDATA_CLAIM_TOKEN}"
1287 if [ -n "${NETDATA_CLAIM_ROOMS}" ]; then
1288 config="${config}\n rooms = ${NETDATA_CLAIM_ROOMS}"
1289 fi
1290 if [ -n "${NETDATA_CLAIM_PROXY}" ]; then
1291 config="${config}\n proxy = ${NETDATA_CLAIM_PROXY}"
1292 fi
1293 if [ -n "${NETDATA_CLAIM_INSECURE}" ]; then
1294 config="${config}\n insecure = ${NETDATA_CLAIM_INSECURE}"
1295 fi
1296
1297 run_as_root touch "${claim_config}.tmp" || return 1
1298 run_as_root chmod 0640 "${claim_config}.tmp" || return 1
1299 run_as_root chown ":${NETDATA_CLAIM_GROUP:-netdata}" "${claim_config}.tmp" || return 1
1300 run_as_root sh -c "printf '${config}\\n' > \"${claim_config}.tmp\"" || return 1
1301 run_as_root mv -f "${claim_config}.tmp" "${claim_config}" || return 1
1302
1303 if [ -z "${NETDATA_CLAIM_NORELOAD}" ]; then
1304 if [ -n "${netdatacli}" ]; then
1305 run_as_root "${netdatacli}" reload-claiming-state || return 1
1306 else
1307 warning "Unable to find the netdatacli binary, the agent must be restarted to finish claiming"
1308 fi
1309 fi
1310 }
1311
1312 run_claim_script() {
1313 if [ -n "${NETDATA_CLAIM_NORELOAD}" ]; then
1314 NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -daemon-not-running"
1315 fi
1316
1317 if [ -n "${NETDATA_CLAIM_INSECURE}" ]; then
1318 NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -insecure"
1319 fi
1320
1321 if [ -n "${NETDATA_CLAIM_PROXY}" ]; then
1322 if [ "${NETDATA_CLAIM_PROXY}" = "none" ]; then
1323 NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -noproxy"
1324 else
1325 NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -proxy=${NETDATA_CLAIM_PROXY}"
1326 fi
1327 fi
1328
1329 # shellcheck disable=SC2086
1330 run_as_root "${NETDATA_CLAIM_PATH}" -token="${NETDATA_CLAIM_TOKEN}" -rooms="${NETDATA_CLAIM_ROOMS}" -url="${NETDATA_CLAIM_URL}" ${NETDATA_CLAIM_EXTRA}
1331 case $? in
1332 0) progress "Successfully claimed node" ;;
1333 1) warning "Unable to claim node due to invalid claiming options. If you are seeing this message, you’ve probably found a bug and should open a bug report at ${AGENT_BUG_REPORT_URL}" ;;
1334 2) warning "Unable to claim node due to issues creating the claiming directory or preparing the local claiming key. Make sure you have a working openssl command and that ${INSTALL_PREFIX}/var/lib/netdata/cloud.d exists, then try again." ;;
1335 3) warning "Unable to claim node due to missing dependencies. Usually this means that the Netdata Agent was built without support for Netdata Cloud. If you built the agent from source, please install all needed dependencies for Cloud support. If you used the regular installation script and see this error, please file a bug report at ${AGENT_BUG_REPORT_URL}." ;;
1336 4) warning "Failed to claim node due to inability to connect to ${NETDATA_CLAIM_URL}. Usually this either means that the specified claiming URL is wrong, or that you are having networking problems." ;;
1337 5) progress "Successfully claimed node, but was not able to notify the Netdata Agent. You will need to restart the Netdata service on this node before it will show up in the Cloud." ;;
1338 8) warning "Failed to claim node due to an invalid agent ID. You can usually resolve this by removing ${INSTALL_PREFIX}/var/lib/netdata/registry/netdata.public.unique.id and restarting the agent. Then try to claim it again using the same options." ;;
1339 9) warning "Failed to claim node due to an invalid node name. This probably means you tried to specify a custom name for this node (for example, using the --claim-hostname option), but the hostname itself was either empty or consisted solely of whitespace. You can resolve this by specifying a valid host name and trying again." ;;
1340 10) warning "Failed to claim node due to an invalid room ID. This issue is most likely caused by a typo. Please check if the room(s) you are trying to add appear on the list of rooms provided to the --claim-rooms option ('${NETDATA_CLAIM_ROOMS}'). Then verify if the rooms are visible in Netdata Cloud and try again." ;;
1341 11) warning "Failed to claim node due to an issue with the generated RSA key pair. You can usually resolve this by removing all files in ${INSTALL_PREFIX}/var/lib/netdata/cloud.d and then trying again." ;;
1342 12) warning "Failed to claim node due to an invalid or expired claiming token. Please check that the token specified with the --claim-token option ('${NETDATA_CLAIM_TOKEN}') matches what you see in the Cloud and try again." ;;
1343 13) warning "Failed to claim node because the Cloud thinks it is already claimed. If this node was created by cloning a VM or as a container from a template, please remove the file ${INSTALL_PREFIX}/var/lib/netdata/registry/netdata.public.unique.id and restart the agent. Then try to claim it again with the same options. Otherwise, if you are certain this node has never been claimed before, you can use the --claim-id option to specify a new node ID to use for claiming, for example by using the uuidgen command like so: --claim-id \"\$(uuidgen)\"" ;;
1344 14) warning "Failed to claim node because the node is already in the process of being claimed. You should not need to do anything to resolve this, the node should show up properly in the Cloud soon. If it does not, please report a bug at ${AGENT_BUG_REPORT_URL}." ;;
1345 15|16|17) warning "Failed to claim node due to an internal server error in the Cloud. Please retry claiming this node later, and if you still see this message file a bug report at ${CLOUD_BUG_REPORT_URL}." ;;
1346 18) warning "Unable to claim node because this Netdata installation does not have a unique ID yet. Make sure the agent is running and started up correctly, and then try again." ;;
1347 *) warning "Failed to claim node for an unknown reason. This usually means either networking problems or a bug. Please retry claiming later, and if you still see this message file a bug report at ${AGENT_BUG_REPORT_URL}" ;;
1348 esac
1349 }
1350
1351 claim() {
1352 if [ "${DRY_RUN}" -eq 1 ]; then
1353 progress "Would attempt to claim agent to ${NETDATA_CLAIM_URL}"
1354 else
1355 progress "Attempting to claim agent to ${NETDATA_CLAIM_URL}"
1356 fi
1357
1358 if command -v netdata-claim.sh > /dev/null 2>&1; then
1359 NETDATA_CLAIM_PATH="$(command -v netdata-claim.sh)"
1360 elif [ -z "${INSTALL_PREFIX}" ] || [ "${INSTALL_PREFIX}" = "/" ]; then
1361 NETDATA_CLAIM_PATH=/usr/sbin/netdata-claim.sh
1362 elif [ "${INSTALL_PREFIX}" = "/opt/netdata" ]; then
1363 NETDATA_CLAIM_PATH="/opt/netdata/bin/netdata-claim.sh"
1364 elif [ ! -d "${INSTALL_PREFIX}/netdata" ]; then
1365 if [ -d "${INSTALL_PREFIX}/usr" ]; then
1366 NETDATA_CLAIM_PATH="${INSTALL_PREFIX}/usr/sbin/netdata-claim.sh"
1367 else
1368 NETDATA_CLAIM_PATH="${INSTALL_PREFIX}/sbin/netdata-claim.sh"
1369 fi
1370 else
1371 NETDATA_CLAIM_PATH="${INSTALL_PREFIX}/netdata/usr/sbin/netdata-claim.sh"
1372 fi
1373
1374 method="script"
1375 err_msg=
1376 err_code=
1377 if [ -z "${NETDATA_CLAIM_PATH}" ]; then
1378 method="config"
1379 elif [ ! -e "${NETDATA_CLAIM_PATH}" ]; then
1380 method="config"
1381 elif [ ! -f "${NETDATA_CLAIM_PATH}" ]; then
1382 err_msg="Unable to claim node: ${NETDATA_CLAIM_PATH} is not a file."
1383 err_code=F0513
1384 elif grep -q '%%NEW_CLAIMING_METHOD%%' "${NETDATA_CLAIM_PATH}"; then
1385 method="config"
1386 elif [ ! -x "${NETDATA_CLAIM_PATH}" ]; then
1387 err_msg="Unable to claim node: claiming script at ${NETDATA_CLAIM_PATH} is not executable. Reinstalling Netdata may resolve this."
1388 err_code=F0514
1389 fi
1390
1391 if [ -n "$err_msg" ]; then
1392 if [ "${ACTION}" = "claim" ]; then
1393 fatal "$err_msg" "$err_code"
1394 else
1395 warning "$err_msg"
1396 return 1
1397 fi
1398 fi
1399
1400 if ! is_netdata_running; then
1401 NETDATA_CLAIM_NORELOAD=1
1402 fi
1403
1404 case ${method} in
1405 script) run_claim_script ;;
1406 config)
1407 if ! write_claim_config; then
1408 warning "Failed to write claiming configuration. This usually means you do not have permissions to access the configuration directory."
1409 fi
1410 ;;
1411 esac
1412
1413 if [ "${ACTION}" = "claim" ]; then
1414 deferred_warnings
1415 printf >&2 "%s\n" "For community support, you can connect with us on:"
1416 support_list
1417 cleanup
1418 trap - EXIT
1419 exit 1
1420 fi
1421 }
1422
1423 # ======================================================================
1424 # Auto-update handling code.
1425 set_auto_updates() {
1426 if run_as_root test -x "${INSTALL_PREFIX}/usr/libexec/netdata/netdata-updater.sh"; then
1427 updater="${INSTALL_PREFIX}/usr/libexec/netdata/netdata-updater.sh"
1428 elif run_as_root test -x "${INSTALL_PREFIX}/netdata/usr/libexec/netdata/netdata-updater.sh"; then
1429 updater="${INSTALL_PREFIX}/netdata/usr/libexec/netdata/netdata-updater.sh"
1430 else
1431 warning "Could not find netdata-updater.sh. This means that auto-updates cannot (currently) be enabled on this system. See https://learn.netdata.cloud/docs/agent/packaging/installer/update for more information about updating Netdata."
1432 return 0
1433 fi
1434
1435 if [ "${AUTO_UPDATE}" -eq 1 ]; then
1436 if [ "${DRY_RUN}" -eq 1 ]; then
1437 progress "Would have attempted to enable automatic updates."
1438 # This first case is for catching using a new kickstart script with an old build. It can be safely removed after v1.34.0 is released.
1439 elif ! run_as_root grep -q '\--enable-auto-updates' "${updater}"; then
1440 echo
1441 elif ! run_as_root "${updater}" --enable-auto-updates "${NETDATA_AUTO_UPDATE_TYPE}"; then
1442 warning "Failed to enable auto updates. Netdata will still work, but you will need to update manually."
1443 fi
1444 else
1445 if [ "${DRY_RUN}" -eq 1 ]; then
1446 progress "Would have attempted to disable automatic updates."
1447 else
1448 run_as_root "${updater}" --disable-auto-updates
1449 fi
1450 fi
1451 }
1452
1453 # ======================================================================
1454 # Native package install code.
1455
1456 # Check for an already installed package with a given name.
1457 pkg_installed() {
1458 case "${SYSTYPE}" in
1459 Linux)
1460 case "${DISTRO_COMPAT_NAME}" in
1461 debian|ubuntu)
1462 # shellcheck disable=SC2016
1463 dpkg-query --show --showformat '${Status}' "${1}" 2>&1 | cut -f 1 -d ' ' | grep -q '^install$'
1464 return $?
1465 ;;
1466 centos|fedora|opensuse|ol|amzn)
1467 rpm -q "${1}" > /dev/null 2>&1
1468 return $?
1469 ;;
1470 alpine)
1471 apk -e info "${1}" > /dev/null 2>&1
1472 return $?
1473 ;;
1474 arch)
1475 pacman -Qi "${1}" > /dev/null 2>&1
1476 return $?
1477 ;;
1478 *) return 1 ;;
1479 esac
1480 ;;
1481 Darwin)
1482 if command -v brew > /dev/null 2>&1; then
1483 brew list "${1}" > /dev/null 2>&1
1484 return $?
1485 else
1486 return 1
1487 fi
1488 ;;
1489 FreeBSD)
1490 if pkg -N > /dev/null 2>&1; then
1491 pkg info "${1}" > /dev/null 2>&1
1492 return $?
1493 else
1494 return 1
1495 fi
1496 ;;
1497 *) return 1 ;;
1498 esac
1499 }
1500
1501 # Check for the existence of a usable netdata package in the repo.
1502 netdata_avail_check() {
1503 case "${DISTRO_COMPAT_NAME}" in
1504 debian|ubuntu)
1505 env DEBIAN_FRONTEND=noninteractive apt-cache policy netdata | grep -q "repo.*.netdata.cloud/repos/";
1506 return $?
1507 ;;
1508 centos|fedora|ol|amzn)
1509 # shellcheck disable=SC2086
1510 LC_ALL=C ${pm_cmd} info --nogpgcheck netdata | grep -qE '^(Repo(sitory)?|From repo) *: *netdata(-edge)?(/.*)?$'
1511 return $?
1512 ;;
1513 opensuse)
1514 zypper packages -r "$(zypper repos | grep -E 'netdata |netdata-edge ' | cut -f 1 -d '|' | tr -d ' ')" | grep -E 'netdata '
1515 return $?
1516 ;;
1517 *) return 1 ;;
1518 esac
1519 }
1520
1521 # Check for any distro-specific dependencies we know we need.
1522 check_special_native_deps() {
1523 if [ "${DISTRO_COMPAT_NAME}" = "centos" ] && [ "${SYSVERSION}" -gt 6 ]; then
1524 progress "EPEL is required on this system, checking if it’s available."
1525
1526 if [ "${SYSVERSION}" -ge 9 ]; then
1527 progress "EPEL support requires CodeReady Builder repo on this system, attempting to enable it."
1528
1529 case "${DISTRO}" in
1530 rhel) run_as_root subscription-manager repos --enable "codeready-builder-for-rhel-${SYSVERSION}-$(arch)-rpms" ;;
1531 *) run_as_root dnf config-manager --set-enabled crb ;;
1532 esac
1533 fi
1534
1535 if [ "${DISTRO}" = "rhel" ]; then
1536 # shellcheck disable=SC2086
1537 if ! run_as_root env ${env} ${pm_cmd} ${install_subcmd} ${pkg_install_opts} "https://dl.fedoraproject.org/pub/epel/epel-release-latest-${SYSVERSION}.noarch.rpm"; then
1538 warning "Failed to install EPEL, even though it is required to install native packages on this system."
1539 return 1
1540 fi
1541 elif LC_ALL=C ${pm_cmd} search --nogpgcheck -v epel-release | grep -q "No matches found"; then
1542 warning "Unable to find a suitable source for libuv, cannot install using native packages on this system."
1543 return 1
1544 else
1545 progress "EPEL is available, attempting to install so that required dependencies are available."
1546
1547 # shellcheck disable=SC2086
1548 if ! run_as_root env ${env} ${pm_cmd} ${install_subcmd} ${pkg_install_opts} epel-release; then
1549 warning "Failed to install EPEL, even though it is required to install native packages on this system."
1550 return 1
1551 fi
1552 fi
1553 fi
1554 }
1555
1556 cleanup_apt_state() {
1557 cache_dir="/var/cache/apt/archives"
1558
1559 if [ -d "${cache_dir}" ]; then
1560 run_as_root find "${cache_dir}" -type f -name 'netdata*.deb' -delete
1561 fi
1562
1563 for p in netdata-repo netdata-repo-edge; do
1564 if pkg_installed "${p}" ; then
1565 warning "Detected already installed repository configuration ${p}, attempting to remove it."
1566 # shellcheck disable=SC2086
1567 run_as_root env ${env} ${pm_cmd} ${uninstall_subcmd} ${pkg_install_opts} "${p}"
1568 fi
1569 done
1570 }
1571
1572 cleanup_dnf_state() {
1573 for p in "" "-edge"; do
1574 if pkg_installed "netdata-repo${p}"; then
1575 warning "Detected already installed repository configuration netdata-repo${p}, attempting to remove it."
1576 run_as_root "${pm_cmd}" clean all --disablerepo "*" --enablerepo "netdata${p}"
1577 run_as_root "${pm_cmd}" "${uninstall_subcmd}" -y "netdata-repo${p}"
1578 fi
1579 done
1580 }
1581
1582 cleanup_zypper_state() {
1583 for p in netdata-repo netdata-repo-edge; do
1584 if pkg_installed "${p}" ; then
1585 warning "Detected already installed repository configuration ${p}, attempting to remove it."
1586 # shellcheck disable=SC2086
1587 run_as_root env ${env} ${pm_cmd} ${uninstall_subcmd} ${pkg_install_opts} "${p}"
1588 fi
1589 done
1590 }
1591
1592 common_rpm_opts() {
1593 pkg_type="rpm"
1594 pkg_suffix=".noarch"
1595 pkg_vsep="-"
1596 INSTALL_TYPE="binpkg-rpm"
1597 NATIVE_VERSION="${INSTALL_VERSION:+"-${INSTALL_VERSION}.${SYSARCH}"}"
1598 }
1599
1600 common_dnf_opts() {
1601 if [ "${INTERACTIVE}" = "0" ]; then
1602 interactive_opts="-y"
1603 fi
1604 if command -v dnf > /dev/null; then
1605 pm_cmd="dnf"
1606 else
1607 pm_cmd="yum"
1608 fi
1609 repo_subcmd="makecache"
1610 install_subcmd="install"
1611 pkg_install_opts="${interactive_opts}"
1612 repo_update_opts="${interactive_opts}"
1613 uninstall_subcmd="remove"
1614 }
1615
1616 try_package_install() {
1617 failed_refresh_msg="Failed to refresh repository metadata. ${BADNET_MSG} or incompatibilities with one or more third-party package repositories in the system package manager configuration."
1618
1619 if [ -z "${DISTRO_COMPAT_NAME}" ] || [ "${DISTRO_COMPAT_NAME}" = "unknown" ]; then
1620 warning "Unable to determine Linux distribution for native packages."
1621 return 3
1622 elif [ -z "${SYSCODENAME}" ]; then
1623 case "${DISTRO_COMPAT_NAME}" in
1624 debian|ubuntu)
1625 warning "Release codename not set. Unable to check availability of native packages for this system."
1626 return 3
1627 ;;
1628 esac
1629 fi
1630
1631 set_tmpdir
1632
1633 if [ "${DRY_RUN}" -eq 1 ]; then
1634 progress "Would attempt to install using native packages..."
1635 else
1636 progress "Attempting to install using native packages..."
1637 fi
1638
1639 if [ "${SELECTED_RELEASE_CHANNEL}" = "nightly" ]; then
1640 release="-edge"
1641 else
1642 release=""
1643 fi
1644
1645 interactive_opts=""
1646 env=""
1647
1648 if [ -n "${SKIP_DISTRO_DETECTION}" ]; then
1649 warning "Attempting to use native packages with a distro override. This is not officially supported, but may work in some cases. If your system requires a distro override to use native packages, please open a feature request at ${AGENT_BUG_REPORT_URL} about it so that we can update the installer to auto-detect this."
1650 fi
1651
1652 case "${DISTRO_COMPAT_NAME}" in
1653 debian|ubuntu)
1654 if [ "${INTERACTIVE}" = "0" ]; then
1655 install_subcmd="-o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold install"
1656 interactive_opts="-y"
1657 env="DEBIAN_FRONTEND=noninteractive"
1658 else
1659 install_subcmd="install"
1660 fi
1661 needs_early_refresh=1
1662 pm_cmd="apt-get"
1663 repo_subcmd="update"
1664 pkg_type="deb"
1665 pkg_vsep="_"
1666 pkg_install_opts="${interactive_opts}"
1667 repo_update_opts="${interactive_opts}"
1668 uninstall_subcmd="purge"
1669 repo_prefix="${DISTRO_COMPAT_NAME}/${SYSCODENAME}"
1670 pkg_suffix="+${DISTRO_COMPAT_NAME}${SYSVERSION}_all"
1671 INSTALL_TYPE="binpkg-deb"
1672 NATIVE_VERSION="${INSTALL_VERSION:+"=${INSTALL_VERSION}"}"
1673 ;;
1674 centos)
1675 common_rpm_opts
1676 common_dnf_opts
1677 repo_prefix="el/${SYSVERSION}"
1678 # if [ "${SYSVERSION}" -lt 8 ]; then
1679 # explicitly_install_native_plugins=1
1680 # fi
1681 ;;
1682 fedora|ol)
1683 common_rpm_opts
1684 common_dnf_opts
1685 repo_prefix="${DISTRO_COMPAT_NAME}/${SYSVERSION}"
1686 ;;
1687 opensuse)
1688 if [ "${INTERACTIVE}" = "0" ]; then
1689 install_subcmd="--non-interactive --no-gpg-checks install"
1690 else
1691 install_subcmd="--no-gpg-checks install"
1692 fi
1693 common_rpm_opts
1694 pm_cmd="zypper"
1695 repo_subcmd="--gpg-auto-import-keys refresh"
1696 repo_prefix="opensuse/${SYSVERSION}"
1697 pkg_install_opts="${interactive_opts} --allow-unsigned-rpm"
1698 repo_update_opts=""
1699 uninstall_subcmd="remove"
1700 ;;
1701 amzn)
1702 common_rpm_opts
1703 common_dnf_opts
1704 repo_prefix="amazonlinux/${SYSVERSION}"
1705 ;;
1706 *)
1707 warning "We do not provide native packages for ${DISTRO}."
1708 return 3
1709 ;;
1710 esac
1711
1712 if [ -n "${INSTALL_VERSION}" ]; then
1713 if echo "${INSTALL_VERSION}" | grep -q "nightly"; then
1714 new_release="-edge"
1715 else
1716 new_release=
1717 fi
1718
1719 if { [ -n "${new_release}" ] && [ -z "${release}" ]; } || { [ -z "${new_release}" ] && [ -n "${release}" ]; }; then
1720 warning "Selected release channel does not match this version and it will be changed automatically."
1721 fi
1722
1723 release="${new_release}"
1724 fi
1725
1726 repoconfig_name="netdata-repo${release}"
1727
1728 case "${SELECTED_RELEASE_CHANNEL}" in
1729 stable) REPO_URL_PREFIX="${STABLE_REPO_URL_PREFIX}" ;;
1730 nightly) REPO_URL_PREFIX="${NIGHTLY_REPO_URL_PREFIX}" ;;
1731 esac
1732
1733 case "${pkg_type}" in
1734 deb)
1735 repoconfig_file="${repoconfig_name}${pkg_vsep}${REPOCONFIG_DEB_VERSION}${pkg_suffix}.${pkg_type}"
1736 repoconfig_url="${REPOCONFIG_URL_PREFIX}/${repo_prefix}/${repoconfig_file}"
1737 ref_check_url="${REPOCONFIG_URL_PREFIX}"
1738 pub_check_url="${REPO_URL_PREFIX}/${repo_prefix}/.currently.published"
1739 pkg_meta_url="${REPO_URL_PREFIX}/${repo_prefix}/InRelease"
1740 ;;
1741 rpm)
1742 repoconfig_file="${repoconfig_name}${pkg_vsep}${REPOCONFIG_RPM_VERSION}${pkg_suffix}.${pkg_type}"
1743 repoconfig_url="${REPOCONFIG_URL_PREFIX}/${repo_prefix}/${SYSARCH}/${repoconfig_file}"
1744 ref_check_url="${REPOCONFIG_URL_PREFIX}"
1745 pub_check_url="${REPO_URL_PREFIX}/${repo_prefix}/${SYSARCH}/.currently.published"
1746 pkg_meta_url="${REPO_URL_PREFIX}/${repo_prefix}/${SYSARCH}/repodata/repomd.xml"
1747 ;;
1748 esac
1749
1750 if ! check_for_remote_file "${ref_check_url}"; then
1751 NETDATA_ASSUME_REMOTE_FILES_ARE_PRESENT=1
1752 fi
1753
1754 progress "Checking if native packages are being published for this platform."
1755 if ! check_for_remote_file "${pub_check_url}"; then
1756 warning "Native packages are not being published for this system."
1757 return 3
1758 fi
1759
1760 if ! check_for_remote_file "${pkg_meta_url}"; then
1761 warning "Native packages have not yet been published for this system."
1762 return 4
1763 fi
1764
1765 progress "Checking for availability of repository configuration package."
1766 if ! check_for_remote_file "${repoconfig_url}"; then
1767 warning "No repository configuration package available for ${DISTRO} ${SYSVERSION}. Cannot install native packages on this system."
1768 return 3
1769 fi
1770
1771 if ! download "${repoconfig_url}" "${tmpdir}/${repoconfig_file}"; then
1772 fatal "Failed to download repository configuration package. ${BADNET_MSG}." F0209
1773 fi
1774
1775 case "${pm_cmd}" in
1776 apt-get) cleanup_apt_state ;;
1777 yum|dnf) cleanup_dnf_state ;;
1778 zypper) cleanup_zypper_state ;;
1779 *) warning "I don’t know how to clean up package manager state for ${pm_cmd}. Please report this as a bug at ${AGENT_BUG_REPORT_URL}."
1780 esac
1781
1782 if [ -n "${needs_early_refresh}" ]; then
1783 # shellcheck disable=SC2086
1784 if ! run_as_root env ${env} ${pm_cmd} ${repo_subcmd} ${repo_update_opts}; then
1785 warning "${failed_refresh_msg}"
1786 return 2
1787 fi
1788 fi
1789
1790 if ! check_special_native_deps; then
1791 warning "Could not find secondary dependencies for ${DISTRO} on ${SYSARCH}."
1792 return 2
1793 fi
1794
1795 # shellcheck disable=SC2086
1796 if ! run_as_root env ${env} ${pm_cmd} ${install_subcmd} ${pkg_install_opts} "${tmpdir}/${repoconfig_file}"; then
1797 warning "Failed to install repository configuration package."
1798 return 2
1799 fi
1800
1801 if [ -n "${repo_subcmd}" ]; then
1802 # shellcheck disable=SC2086
1803 if ! run_as_root env ${env} ${pm_cmd} ${repo_subcmd} ${repo_update_opts}; then
1804 fatal "${failed_refresh_msg} In most cases, disabling any third-party repositories on the system and re-running the installer with the same options should work. If that does not work, consider using a static build with the --static-only option instead of native packages." F0205
1805 fi
1806 fi
1807
1808 if [ "${ACTION}" = "repositories-only" ]; then
1809 progress "Successfully installed repository configuraion package."
1810 deferred_warnings
1811 cleanup
1812 trap - EXIT
1813 exit 0
1814 fi
1815
1816 if ! netdata_avail_check "${DISTRO_COMPAT_NAME}"; then
1817 warning "Could not find a usable native package for ${DISTRO} on ${SYSARCH}."
1818 if [ -z "${NO_CLEANUP}" ]; then
1819 progress "Attempting to uninstall repository configuration package."
1820 # shellcheck disable=SC2086
1821 run_as_root env ${env} ${pm_cmd} ${uninstall_subcmd} ${pkg_install_opts} "${repoconfig_name}"
1822 fi
1823 return 2
1824 fi
1825
1826 if [ "${NETDATA_DISABLE_TELEMETRY}" -eq 1 ]; then
1827 run_as_root mkdir -p "/etc/netdata"
1828 run_as_root touch "/etc/netdata/.opt-out-from-anonymous-statistics"
1829 fi
1830
1831 # shellcheck disable=SC2086
1832 if ! run_as_root env ${env} ${pm_cmd} ${install_subcmd} ${pkg_install_opts} "netdata${NATIVE_VERSION}"; then
1833 warning "Failed to install Netdata package."
1834 if [ -z "${NO_CLEANUP}" ]; then
1835 progress "Attempting to uninstall repository configuration package."
1836 # shellcheck disable=SC2086
1837 run_as_root env ${env} ${pm_cmd} ${uninstall_subcmd} ${pkg_install_opts} "${repoconfig_name}"
1838 fi
1839 return 2
1840 fi
1841
1842 if [ -n "${explicitly_install_native_plugins}" ]; then
1843 progress "Installing external plugins."
1844 # shellcheck disable=SC2086
1845 if ! run_as_root env ${env} ${pm_cmd} ${install_subcmd} ${DEFAULT_PLUGIN_PACKAGES}; then
1846 warning "Failed to install external plugin packages. Some collectors may not be available."
1847 fi
1848 fi
1849 }
1850
1851 # ======================================================================
1852 # Static build install code
1853 # shellcheck disable=SC2034,SC2086,SC2126
1854 set_static_archive_urls() {
1855 if [ -z "${2}" ]; then
1856 arch="${SYSARCH}"
1857 else
1858 arch="${2}"
1859 fi
1860
1861 if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
1862 path="$(cd "${NETDATA_OFFLINE_INSTALL_SOURCE}" || exit 1; pwd)"
1863 export NETDATA_STATIC_ARCHIVE_URL="file://${path}/netdata-${arch}-latest.gz.run"
1864 export NETDATA_STATIC_ARCHIVE_NAME="netdata-${arch}-latest.gz.run"
1865 export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="file://${path}/sha256sums.txt"
1866 elif [ "${1}" = "stable" ]; then
1867 if [ -n "${INSTALL_VERSION}" ]; then
1868 export NETDATA_STATIC_ARCHIVE_URL="https://github.com/netdata/netdata/releases/download/v${INSTALL_VERSION}/netdata-${arch}-v${INSTALL_VERSION}.gz.run"
1869 export NETDATA_STATIC_ARCHIVE_OLD_URL="https://github.com/netdata/netdata/releases/download/v${INSTALL_VERSION}/netdata-v${INSTALL_VERSION}.gz.run"
1870 export NETDATA_STATIC_ARCHIVE_NAME="netdata-${arch}-v${INSTALL_VERSION}.gz.run"
1871 export NETDATA_STATIC_ARCHIVE_OLD_NAME="netdata-v${INSTALL_VERSION}.gz.run"
1872 export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/v${INSTALL_VERSION}/sha256sums.txt"
1873 else
1874 latest="$(get_redirect "https://github.com/netdata/netdata/releases/latest")"
1875 export NETDATA_STATIC_ARCHIVE_URL="https://github.com/netdata/netdata/releases/download/${latest}/netdata-${arch}-latest.gz.run"
1876 export NETDATA_STATIC_ARCHIVE_NAME="netdata-${arch}-latest.gz.run"
1877 export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/${latest}/sha256sums.txt"
1878 fi
1879 else
1880 if [ -n "${INSTALL_VERSION}" ]; then
1881 export NETDATA_STATIC_ARCHIVE_URL="${NETDATA_TARBALL_BASEURL}/download/v${INSTALL_VERSION}/netdata-${arch}-v${INSTALL_VERSION}.gz.run"
1882 export NETDATA_STATIC_ARCHIVE_OLD_URL="${NETDATA_TARBALL_BASEURL}/download/v${INSTALL_VERSION}/netdata-v${INSTALL_VERSION}.gz.run"
1883 export NETDATA_STATIC_ARCHIVE_NAME="netdata-${arch}-v${INSTALL_VERSION}.gz.run"
1884 export NETDATA_STATIC_ARCHIVE_OLD_NAME="netdata-v${INSTALL_VERSION}.gz.run"
1885 export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="${NETDATA_TARBALL_BASEURL}/download/v${INSTALL_VERSION}/sha256sums.txt"
1886 else
1887 tag="$(get_redirect "${NETDATA_TARBALL_BASEURL}/latest")"
1888 export NETDATA_STATIC_ARCHIVE_URL="${NETDATA_TARBALL_BASEURL}/download/${tag}/netdata-${arch}-latest.gz.run"
1889 export NETDATA_STATIC_ARCHIVE_NAME="netdata-${arch}-latest.gz.run"
1890 export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="${NETDATA_TARBALL_BASEURL}/download/${tag}/sha256sums.txt"
1891 fi
1892 fi
1893 }
1894
1895 try_static_install() {
1896 set_static_archive_urls "${SELECTED_RELEASE_CHANNEL}"
1897 if [ "${DRY_RUN}" -eq 1 ]; then
1898 progress "Would attempt to install using static build..."
1899 else
1900 progress "Attempting to install using static build..."
1901 fi
1902
1903 if ! check_for_remote_file "${NETDATA_TARBALL_BASEURL}"; then
1904 NETDATA_ASSUME_REMOTE_FILES_ARE_PRESENT=1
1905 fi
1906
1907 # Check status code first, so that we can provide nicer fallback for dry runs.
1908 if check_for_remote_file "${NETDATA_STATIC_ARCHIVE_URL}"; then
1909 netdata_agent="${NETDATA_STATIC_ARCHIVE_NAME}"
1910 elif [ "${SYSARCH}" = "x86_64" ] && check_for_remote_file "${NETDATA_STATIC_ARCHIVE_OLD_URL}"; then
1911 netdata_agent="${NETDATA_STATIC_ARCHIVE_OLD_NAME}"
1912 export NETDATA_STATIC_ARCHIVE_URL="${NETDATA_STATIC_ARCHIVE_OLD_URL}"
1913 else
1914 warning "Could not find a ${SELECTED_RELEASE_CHANNEL} static build for ${SYSARCH} CPUs. This usually means there is some networking issue preventing access to https://github.com/ from this system."
1915 return 2
1916 fi
1917
1918 if ! download "${NETDATA_STATIC_ARCHIVE_URL}" "./${netdata_agent}"; then
1919 fatal "Unable to download static build archive for ${SYSARCH}. ${BADNET_MSG}." F0208
1920 fi
1921
1922 if ! download "${NETDATA_STATIC_ARCHIVE_CHECKSUM_URL}" "./sha256sum.txt"; then
1923 fatal "Unable to fetch checksums to verify static build archive. ${BADNET_MSG}." F0206
1924 fi
1925
1926 if [ "${DRY_RUN}" -eq 1 ]; then
1927 progress "Would validate SHA256 checksum of downloaded static build archive."
1928 else
1929 if [ -z "${INSTALL_VERSION}" ]; then
1930 if ! grep "${netdata_agent}" ./sha256sum.txt | safe_sha256sum -c - > /dev/null 2>&1; then
1931 bad_sums_report="$(report_bad_sha256sum "${netdata_agent}" "./sha256sum.txt")"
1932 fatal "Static binary checksum validation failed.\n${bad_sums_report}\n${BADCACHE_MSG}." F0207
1933 fi
1934 fi
1935 fi
1936
1937 if [ "${INTERACTIVE}" -eq 0 ]; then
1938 opts="${opts} --accept"
1939 fi
1940
1941 env_cmd="env NETDATA_CERT_TEST_URL=${NETDATA_CLAIM_URL} NETDATA_CERT_MODE=check"
1942
1943 if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
1944 env_cmd="env NETDATA_CERT_TEST_URL=${NETDATA_CLAIM_URL} NETDATA_CERT_MODE=auto"
1945 fi
1946
1947 progress "Installing netdata"
1948 # shellcheck disable=SC2086
1949 if ! run_as_root ${env_cmd} /bin/sh "./${netdata_agent}" ${opts} -- ${NETDATA_INSTALLER_OPTIONS}; then
1950 warning "Failed to install static build of Netdata on ${SYSARCH}."
1951 run rm -rf /opt/netdata
1952 return 2
1953 fi
1954
1955 if [ "${DRY_RUN}" -ne 1 ]; then
1956 install_type_file="/opt/netdata/etc/netdata/.install-type"
1957 if [ -f "${install_type_file}" ]; then
1958 run_as_root sh -c "cat \"${install_type_file}\" > \"${tmpdir}/install-type\""
1959 run_as_root chown "$(id -u)":"$(id -g)" "${tmpdir}/install-type"
1960 # shellcheck disable=SC1090,SC1091
1961 . "${tmpdir}/install-type"
1962 cat > "${tmpdir}/install-type" <<- EOF
1963 INSTALL_TYPE='kickstart-static'
1964 PREBUILT_ARCH='${PREBUILT_ARCH}'
1965 EOF
1966 run_as_root chown netdata:netdata "${tmpdir}/install-type"
1967 run_as_root cp "${tmpdir}/install-type" "${install_type_file}"
1968 fi
1969 fi
1970 }
1971
1972 # ======================================================================
1973 # Local build install code
1974
1975 set_source_archive_urls() {
1976 if [ "$1" = "stable" ]; then
1977 if [ -n "${INSTALL_VERSION}" ]; then
1978 export NETDATA_SOURCE_ARCHIVE_URL="https://github.com/netdata/netdata/releases/download/v${INSTALL_VERSION}/netdata-v${INSTALL_VERSION}.tar.gz"
1979 export NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/v${INSTALL_VERSION}/sha256sums.txt"
1980 else
1981 latest="$(get_redirect "https://github.com/netdata/netdata/releases/latest")"
1982 export NETDATA_SOURCE_ARCHIVE_URL="https://github.com/netdata/netdata/releases/download/${latest}/netdata-${latest}.tar.gz"
1983 export NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/${latest}/sha256sums.txt"
1984 fi
1985 else
1986 if [ -n "${INSTALL_VERSION}" ]; then
1987 export NETDATA_SOURCE_ARCHIVE_URL="${NETDATA_TARBALL_BASEURL}/download/v${INSTALL_VERSION}/netdata-latest.tar.gz"
1988 export NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL="${NETDATA_TARBALL_BASEURL}/download/v${INSTALL_VERSION}/sha256sums.txt"
1989 else
1990 tag="$(get_redirect "${NETDATA_TARBALL_BASEURL}/latest")"
1991 export NETDATA_SOURCE_ARCHIVE_URL="${NETDATA_TARBALL_BASEURL}/download/${tag}/netdata-latest.tar.gz"
1992 export NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL="${NETDATA_TARBALL_BASEURL}/download/${tag}/sha256sums.txt"
1993 fi
1994 fi
1995 }
1996
1997 install_local_build_dependencies() {
1998 set_tmpdir
1999 bash="$(command -v bash 2> /dev/null)"
2000
2001 if [ -z "${bash}" ] || [ ! -x "${bash}" ]; then
2002 warning "Unable to find a usable version of \`bash\` (required for local build)."
2003 return 1
2004 fi
2005
2006 if ! download "${PACKAGES_SCRIPT}" "${tmpdir}/install-required-packages.sh"; then
2007 fatal "Failed to download dependency handling script for local build. ${BADNET_MSG}." F000D
2008 fi
2009
2010 if [ "${DRY_RUN}" -eq 1 ]; then
2011 progress "Would run downloaded script to install required build dependencies..."
2012 else
2013 progress "Running downloaded script to install required build dependencies..."
2014 fi
2015
2016 if [ "${INTERACTIVE}" -eq 0 ]; then
2017 opts="--dont-wait --non-interactive"
2018 fi
2019
2020 # shellcheck disable=SC2086
2021 if [ "$(uname -s)" = "Darwin" ]; then
2022 if ! run "${bash}" "${tmpdir}/install-required-packages.sh" ${opts} netdata; then
2023 warning "Failed to install all required packages, but installation might still be possible."
2024 fi
2025 else
2026 if ! run_as_root "${bash}" "${tmpdir}/install-required-packages.sh" ${opts} netdata; then
2027 warning "Failed to install all required packages, but installation might still be possible."
2028 fi
2029 fi
2030 }
2031
2032 build_and_install() {
2033 if [ "${DRY_RUN}" -eq 1 ]; then
2034 progress "Would attempt to build netdata..."
2035 else
2036 progress "Building netdata..."
2037 fi
2038
2039 echo "INSTALL_TYPE='kickstart-build'" > system/.install-type
2040
2041 opts="${NETDATA_INSTALLER_OPTIONS}"
2042
2043 if [ "${INTERACTIVE}" -eq 0 ]; then
2044 opts="${opts} --dont-wait"
2045 fi
2046
2047 if [ "${SELECTED_RELEASE_CHANNEL}" = "stable" ]; then
2048 opts="${opts} --stable-channel"
2049 fi
2050
2051 # shellcheck disable=SC2086
2052 run_script ./netdata-installer.sh ${opts}
2053
2054 case $? in
2055 0) ;;
2056 1)
2057 if [ -n "${EXIT_REASON}" ]; then
2058 fatal "netdata-installer.sh failed to run: ${EXIT_REASON}" "${EXIT_CODE}"
2059 else
2060 fatal "netdata-installer.sh failed to run: Encountered an unhandled error in the installer code." I0000
2061 fi
2062 ;;
2063 2) fatal "Insufficient RAM to install netdata." F0008 ;;
2064 *) fatal "netdata-installer.sh failed to run: Encountered an unhandled error in the installer code." F051A ;;
2065 esac
2066 }
2067
2068 try_build_install() {
2069 set_tmpdir
2070
2071 if [ "${DRY_RUN}" -eq 1 ]; then
2072 progress "Would attempt to install by building locally..."
2073 else
2074 progress "Attempting to install by building locally..."
2075 fi
2076
2077 if ! install_local_build_dependencies; then
2078 return 1
2079 fi
2080
2081 set_source_archive_urls "${SELECTED_RELEASE_CHANNEL}"
2082
2083 if [ -n "${INSTALL_VERSION}" ]; then
2084 if ! download "${NETDATA_SOURCE_ARCHIVE_URL}" "./netdata-v${INSTALL_VERSION}.tar.gz"; then
2085 fatal "Failed to download source tarball for local build. ${BADNET_MSG}." F000B
2086 fi
2087 elif ! download "${NETDATA_SOURCE_ARCHIVE_URL}" "./netdata-latest.tar.gz"; then
2088 fatal "Failed to download source tarball for local build. ${BADNET_MSG}." F000B
2089 fi
2090
2091 if ! download "${NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL}" "./sha256sum.txt"; then
2092 fatal "Failed to download checksums for source tarball verification. ${BADNET_MSG}." F000C
2093 fi
2094
2095 if [ "${DRY_RUN}" -eq 1 ]; then
2096 progress "Would validate SHA256 checksum of downloaded source archive."
2097 else
2098 if [ -z "${INSTALL_VERSION}" ]; then
2099 # shellcheck disable=SC2086
2100 if ! grep netdata-latest.tar.gz "./sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then
2101 bad_sums_report="$(report_bad_sha256sum netdata-latest.tar.gz "./sha256sum.txt")"
2102 fatal "Tarball checksum validation failed.\n${bad_sums_report}\n${BADCACHE_MSG}." F0005
2103 fi
2104 fi
2105 fi
2106
2107 if [ -n "${INSTALL_VERSION}" ]; then
2108 run tar -xf "./netdata-v${INSTALL_VERSION}.tar.gz" -C "${tmpdir}"
2109 rm -rf "./netdata-v${INSTALL_VERSION}.tar.gz" > /dev/null 2>&1
2110 else
2111 run tar -xf "./netdata-latest.tar.gz" -C "${tmpdir}"
2112 rm -rf "./netdata-latest.tar.gz" > /dev/null 2>&1
2113 fi
2114
2115 if [ "${DRY_RUN}" -ne 1 ]; then
2116 netdata_src_dir="$(find "${tmpdir}" -mindepth 1 -maxdepth 1 -type d -name 'netdata-*' | head -n 1)"
2117 [ -z "${netdata_src_dir}" ] && fatal "Cannot find netdata source directory in ${tmpdir}" F0006
2118 cd "${netdata_src_dir}" || fatal "Cannot change directory to netdata source tree" F0006
2119 fi
2120
2121 if [ -x netdata-installer.sh ] || [ "${DRY_RUN}" -eq 1 ]; then
2122 build_and_install || return 1
2123 else
2124 # This case is needed because some platforms produce an extra directory on the source tarball extraction.
2125 if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ] && [ -x "$(find . -mindepth 1 -maxdepth 1 -type d)/netdata-installer.sh" ]; then
2126 cd "$(find . -mindepth 1 -maxdepth 1 -type d)" && build_and_install || return 1
2127 else
2128 fatal "Cannot install netdata from source (the source directory does not include netdata-installer.sh)." F0009
2129 fi
2130 fi
2131 }
2132
2133 # ======================================================================
2134 # Offline install support code
2135
2136 prepare_offline_install_source() {
2137 if [ -e "${1}" ]; then
2138 if [ ! -d "${1}" ]; then
2139 fatal "${1} is not a directory, unable to prepare offline install source." F0503
2140 fi
2141 else
2142 run mkdir -p "${1}" || fatal "Unable to create target directory for offline install preparation." F0504
2143 fi
2144
2145 run cd "${1}" || fatal "Failed to switch to target directory for offline install preparation." F0505
2146
2147 case "${NETDATA_REQUESTED_INSTALL_TYPE}" in
2148 static|auto|any)
2149 set_static_archive_urls "${SELECTED_RELEASE_CHANNEL}" "x86_64"
2150
2151 if ! check_for_remote_file "${NETDATA_TARBALL_BASEURL}"; then
2152 NETDATA_ASSUME_REMOTE_FILES_ARE_PRESENT=1
2153 fi
2154
2155 if check_for_remote_file "${NETDATA_STATIC_ARCHIVE_URL}"; then
2156 for arch in $(echo "${NETDATA_OFFLINE_ARCHES:-${STATIC_INSTALL_ARCHES}}" | awk '{for (i=1;i<=NF;i++) if (!a[$i]++) printf("%s%s",$i,FS)}{printf("\n")}'); do
2157 set_static_archive_urls "${SELECTED_RELEASE_CHANNEL}" "${arch}"
2158
2159 if check_for_remote_file "${NETDATA_STATIC_ARCHIVE_URL}"; then
2160 progress "Fetching ${NETDATA_STATIC_ARCHIVE_URL}"
2161 if ! download "${NETDATA_STATIC_ARCHIVE_URL}" "netdata-${arch}-latest.gz.run"; then
2162 warning "Failed to download static installer archive for ${arch}. ${BADNET_MSG}."
2163 fi
2164 else
2165 progress "Skipping ${NETDATA_STATIC_ARCHIVE_URL} as it does not exist on the server."
2166 fi
2167 done
2168 legacy=0
2169 else
2170 warning "Selected version of Netdata only provides static builds for x86_64. You will only be able to install on x86_64 systems with this offline install source."
2171 progress "Fetching ${NETDATA_STATIC_ARCHIVE_OLD_URL}"
2172 legacy=1
2173
2174 if ! download "${NETDATA_STATIC_ARCHIVE_OLD_URL}" "netdata-x86_64-latest.gz.run"; then
2175 warning "Failed to download static installer archive for x86_64. ${BADNET_MSG}."
2176 fi
2177 fi
2178
2179 if [ -z "$(find . -name '*.gz.run')" ]; then
2180 fatal "Did not actually download any static installer archives, cannot continue. ${BADNET_MSG}." F0516
2181 fi
2182
2183 progress "Fetching ${NETDATA_STATIC_ARCHIVE_CHECKSUM_URL}"
2184 if ! download "${NETDATA_STATIC_ARCHIVE_CHECKSUM_URL}" "sha256sums.txt"; then
2185 fatal "Failed to download checksum file. ${BADNET_MSG}." F0506
2186 fi
2187 ;;
2188 *) fatal "Install type ${NETDATA_REQUESTED_INSTALL_TYPE} is not supported for offline installs." F051B
2189 esac
2190
2191 if [ "${legacy:-0}" -eq 1 ]; then
2192 sed -e 's/netdata-latest.gz.run/netdata-x86_64-latest.gz.run' sha256sums.txt > sha256sums.tmp
2193 mv sha256sums.tmp sha256sums.txt
2194 fi
2195
2196 if [ "${DRY_RUN}" -ne 1 ]; then
2197 progress "Verifying checksums."
2198
2199 failed_files=""
2200 for file in $(find . -name '*.gz.run'); do
2201 if ! grep -e "${file}" sha256sums.txt | safe_sha256sum -c -; then
2202 failed_files="${failed_files}\n${file}\n$(report_bad_sha256sum "${file}" sha256sums.txt)"
2203 fi
2204 done
2205
2206 if [ -n "${failed_files}" ]; then
2207 fatal "Checksums for offline install files are incorrect.\n${failed_files}\n${BADCACHE_MSG}." F0507
2208 fi
2209 else
2210 progress "Would verify SHA256 checksums of downloaded installation files."
2211 fi
2212
2213 if [ "${DRY_RUN}" -ne 1 ]; then
2214 progress "Preparing install script."
2215 cat > "install.sh" <<-EOF
2216 #!/bin/sh
2217 dir=\$(CDPATH= cd -- "\$(dirname -- "\$0")" && pwd)
2218 "\${dir}/kickstart.sh" --offline-install-source "\${dir}" \${@}
2219 EOF
2220 chmod +x "install.sh"
2221 else
2222 progress "Would create install script"
2223 fi
2224
2225 if [ "${DRY_RUN}" -ne 1 ]; then
2226 progress "Copying kickstart script."
2227 cp "${KICKSTART_SOURCE}" "kickstart.sh"
2228 chmod +x "kickstart.sh"
2229 else
2230 progress "Would copy kickstart.sh to offline install source directory"
2231 fi
2232
2233 if [ "${DRY_RUN}" -ne 1 ]; then
2234 progress "Saving release channel information."
2235 echo "${SELECTED_RELEASE_CHANNEL}" > "channel"
2236 else
2237 progress "Would save release channel information to offline install source directory"
2238 fi
2239
2240 progress "Finished preparing offline install source directory at ${1}. You can now copy this directory to a target system and then run the script ‘install.sh’ from it to install on that system."
2241 }
2242
2243 # ======================================================================
2244 # Per system-type install logic
2245
2246 install_on_linux() {
2247 if [ "${NETDATA_REQUESTED_INSTALL_TYPE}" != 'static' ] && [ "${NETDATA_REQUESTED_INSTALL_TYPE}" != 'build' ] && [ -z "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
2248 SELECTED_INSTALL_METHOD="native"
2249 try_package_install
2250
2251 case "$?" in
2252 0)
2253 NETDATA_INSTALL_SUCCESSFUL=1
2254 INSTALL_PREFIX="/"
2255 ;;
2256 1) fatal "Unable to install on this system." F0300 ;;
2257 2)
2258 case "${NETDATA_REQUESTED_INSTALL_TYPE}" in
2259 native|auto) fatal "Could not install using native binary packages even though they appear to be available. This usually means something is wrong with your system package manager that requires manual intervention to fix. If you want to install anyway without using native packages, re-run this script with the option '--install-type any'" F0301 ;;
2260 *) warning "Could not install using native binary packages, falling back to alternative installation method." ;;
2261 esac
2262 ;;
2263 3)
2264 case "${NETDATA_REQUESTED_INSTALL_TYPE}" in
2265 native) fatal "Native packages are not available for this system, unable to install." F051C ;;
2266 *) warning "Native packages are not available for this system, falling back to alternative installation method." ;;
2267 esac
2268 ;;
2269 4)
2270 case "${NETDATA_REQUESTED_INSTALL_TYPE}" in
2271 native|auto)
2272 case "${SELECTED_RELEASE_CHANNEL}" in
2273 stable) fatal "A stable build with native packages has not yet been published for this system, but is expected to be published within the next few weeks. If you need to install now, you should be able to do so either by using a nightly build (add --release-channel=nightly to the options passed to this script) or by using a static build (add --install-type=static to the options passed to this script). Note that if you use a static build, you may have to reinstall once a stable build is published with native packages for this system to get full support." F051D ;;
2274 nightly) fatal "A nightly build with native packages has not yet been published for this system, but is expected to be published at 01:00 UTC tomorrow. Please try again tomorrow." F051E ;;
2275 esac
2276 ;;
2277 *) warning "Native packages are not available for this system, falling back to alternative installation method." ;;
2278 esac
2279 esac
2280 fi
2281
2282 if [ "${NETDATA_REQUESTED_INSTALL_TYPE}" != 'native' ] && [ "${NETDATA_REQUESTED_INSTALL_TYPE}" != 'build' ] && [ -z "${NETDATA_INSTALL_SUCCESSFUL}" ]; then
2283 SELECTED_INSTALL_METHOD="static"
2284 INSTALL_TYPE="kickstart-static"
2285 try_static_install
2286
2287 case "$?" in
2288 0)
2289 NETDATA_INSTALL_SUCCESSFUL=1
2290 INSTALL_PREFIX="/opt/netdata"
2291 ;;
2292 1) fatal "Unable to install on this system." F0302 ;;
2293 2)
2294 case "${NETDATA_REQUESTED_INSTALL_TYPE}" in
2295 static) fatal "Could not install static build." F0303 ;;
2296 *) warning "Could not install static build, falling back to alternative installation method." ;;
2297 esac
2298 ;;
2299 esac
2300 fi
2301
2302 if [ "${NETDATA_REQUESTED_INSTALL_TYPE}" != 'native' ] && [ "${NETDATA_REQUESTED_INSTALL_TYPE}" != 'static' ] && [ -z "${NETDATA_INSTALL_SUCCESSFUL}" ]; then
2303 SELECTED_INSTALL_METHOD="build"
2304 INSTALL_TYPE="kickstart-build"
2305 try_build_install
2306
2307 case "$?" in
2308 0) NETDATA_INSTALL_SUCCESSFUL=1 ;;
2309 *) fatal "Unable to install on this system." F0304 ;;
2310 esac
2311 fi
2312 }
2313
2314 install_on_macos() {
2315 case "${NETDATA_REQUESTED_INSTALL_TYPE}" in
2316 native) fatal "User requested native package, but native packages are not available for macOS. Try installing without \`--native-only\` option." F0305 ;;
2317 static) fatal "User requested static build, but static builds are not available for macOS. Try installing without \`--static-only\` option." F0306 ;;
2318 *)
2319 SELECTED_INSTALL_METHOD="build"
2320 INSTALL_TYPE="kickstart-build"
2321 try_build_install
2322
2323 case "$?" in
2324 0) NETDATA_INSTALL_SUCCESSFUL=1 ;;
2325 *) fatal "Unable to install on this system." F0307 ;;
2326 esac
2327 ;;
2328 esac
2329 }
2330
2331 install_on_freebsd() {
2332 case "${NETDATA_REQUESTED_INSTALL_TYPE}" in
2333 native) fatal "User requested native package, but native packages are not available for FreeBSD. Try installing without \`--native-only\` option." F0308 ;;
2334 static) fatal "User requested static build, but static builds are not available for FreeBSD. Try installing without \`--static-only\` option." F0309 ;;
2335 *)
2336 SELECTED_INSTALL_METHOD="build"
2337 INSTALL_TYPE="kickstart-build"
2338 try_build_install
2339
2340 case "$?" in
2341 0) NETDATA_INSTALL_SUCCESSFUL=1 ;;
2342 *) fatal "Unable to install on this system." F030A ;;
2343 esac
2344 ;;
2345 esac
2346 }
2347
2348 # ======================================================================
2349 # Argument parsing code
2350
2351 handle_major_version() {
2352 CONTINUE_INSTALL_PROMPT="Attempting to install will use the latest version available overall. Do you wish to continue the install?"
2353
2354 if [ -z "${INSTALL_MAJOR_VERSION}" ]; then
2355 return
2356 fi
2357
2358 actual_version="$(get_actual_version "v${INSTALL_MAJOR_VERSION}" "${RELEASE_CHANNEL}")"
2359
2360 if [ -z "${actual_version}" ]; then
2361 if [ "${INTERACTIVE}" -eq 0 ]; then
2362 fatal "Could not determine the lastest releaase in channel '${RELEASE_CHANNEL}' with major version '${INSTALL_MAJOR_VERSION}'" F0517
2363 else
2364 if confirm "Unable to determine the correct version to install for major version '${INSTALL_MAJOR_VERSION}'. ${CONTINUE_INSTALL_PROMPT}"; then
2365 progress "User requested continuing the install with the latest version."
2366 else
2367 fatal "Cancelling installation at user request." F0518
2368 fi
2369 fi
2370 elif [ "${actual_version}" = 'NONE' ]; then
2371 if [ "${INTERACTIVE}" -eq 0 ]; then
2372 warning "No releases with major version '${INSTALL_MAJOR_VERSION}' have been published. Continuing the install with the latest version instead."
2373 else
2374 if confirm "No releases with major version '${INSTALL_MAJOR_VERSION}' have been published. ${CONTINUE_INSTALL_PROMPT}"; then
2375 progress "User requested continuing the install with the latest version."
2376 else
2377 fatal "Cancelling installation at user request." F0519
2378 fi
2379 fi
2380 else
2381 INSTALL_VERSION="${actual_version}"
2382 fi
2383 }
2384
2385 validate_args() {
2386 check_claim_opts
2387
2388 if [ -n "${NETDATA_REQUESTED_INSTALL_TYPE}" ]; then
2389 SELECTED_INSTALL_METHOD="${NETDATA_REQUESTED_INSTALL_TYPE}"
2390 fi
2391
2392 if [ "${ACTION}" = "repositories-only" ] && [ "${NETDATA_REQUESTED_INSTALL_TYPE}" != "native" ]; then
2393 fatal "Repositories can only be installed for native installs." F050D
2394 fi
2395
2396 if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
2397 case "${NETDATA_REQUESTED_INSTALL_TYPE}" in
2398 native|build) fatal "Offline installs are only supported for static builds currently." F0502 ;;
2399 esac
2400
2401 if [ ! -d "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
2402 fatal "Offline install source must be a directory." F0519
2403 fi
2404 fi
2405
2406 if [ -n "${LOCAL_BUILD_OPTIONS}" ]; then
2407 case "${NETDATA_REQUESTED_INSTALL_TYPE}" in
2408 build) NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} ${LOCAL_BUILD_OPTIONS}" ;;
2409 *) fatal "Specifying local build options is only supported when the --build-only option is also specified." F0401 ;;
2410 esac
2411 fi
2412
2413 if [ -n "${STATIC_INSTALL_OPTIONS}" ]; then
2414 case "${NETDATA_REQUESTED_INSTALL_TYPE}" in
2415 static) NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} ${STATIC_INSTALL_OPTIONS}" ;;
2416 *) fatal "Specifying installer options options is only supported when the --static-only option is also specified." F0402 ;;
2417 esac
2418 fi
2419
2420 if [ "${RELEASE_CHANNEL}" = "default" ]; then
2421 if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
2422 SELECTED_RELEASE_CHANNEL="$(cat "${NETDATA_OFFLINE_INSTALL_SOURCE}/channel")"
2423
2424 if [ -z "${SELECTED_RELEASE_CHANNEL}" ]; then
2425 fatal "Could not find a release channel indicator in ${NETDATA_OFFLINE_INSTALL_SOURCE}." F0508
2426 fi
2427 else
2428 SELECTED_RELEASE_CHANNEL="${DEFAULT_RELEASE_CHANNEL}"
2429 fi
2430 else
2431 if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ] && [ "${RELEASE_CHANNEL}" != "$(cat "${NETDATA_OFFLINE_INSTALL_SOURCE}/channel")" ]; then
2432 fatal "Release channal '${RELEASE_CHANNEL}' requested, but indicated offline installation source release channel is '$(cat "${NETDATA_OFFLINE_INSTALL_SOURCE}/channel")'." F0509
2433 fi
2434
2435 SELECTED_RELEASE_CHANNEL="${RELEASE_CHANNEL}"
2436 fi
2437
2438 if [ -n "${INSTALL_MAJOR_VERSION}" ] && [ -n "${INSTALL_VERSION}" ]; then
2439 fatal "Only one of --install-version or --install-major-version may be specified." F0515
2440 fi
2441
2442 handle_major_version # Appropriately updates INSTALL_VERSION if INSTALL_MAJOR_VERSION is set.
2443
2444 if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ] && [ -n "${INSTALL_VERSION}" ]; then
2445 fatal "Specifying an install version alongside an offline install source is not supported." F050A
2446 fi
2447
2448 if [ "${NETDATA_AUTO_UPDATES}" = "default" ]; then
2449 if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ] || [ -n "${INSTALL_VERSION}" ]; then
2450 AUTO_UPDATE=0
2451 else
2452 AUTO_UPDATE=1
2453 fi
2454 elif [ "${NETDATA_INSTALL_MAJOR_VERSION}" ]; then
2455 warning "Forcibly disabling auto updates as a specific major version was requested."
2456 AUTO_UPDATE=0
2457 elif [ "${NETDATA_AUTO_UPDATES}" = 1 ]; then
2458 AUTO_UPDATE=1
2459 else
2460 AUTO_UPDATE=0
2461 fi
2462 }
2463
2464 set_action() {
2465 new_action="${1}"
2466
2467 if [ -n "${ACTION}" ]; then
2468 warning "Ignoring previously specified '${ACTION}' operation in favor of '${new_action}' specified later on the command line."
2469 fi
2470
2471 ACTION="${new_action}"
2472 NETDATA_COMMAND="${new_action}"
2473 }
2474
2475 parse_args() {
2476 while [ -n "${1}" ]; do
2477 case "${1}" in
2478 "--help")
2479 usage
2480 cleanup
2481 trap - EXIT
2482 exit 0
2483 ;;
2484 "--no-cleanup") NO_CLEANUP=1 ;;
2485 "--dont-wait"|"--non-interactive") INTERACTIVE=0 ;;
2486 "--interactive") INTERACTIVE=1 ;;
2487 "--dry-run") DRY_RUN=1 ;;
2488 "--release-channel")
2489 RELEASE_CHANNEL="$(echo "${2}" | tr '[:upper:]' '[:lower:]')"
2490 case "${RELEASE_CHANNEL}" in
2491 nightly|stable|default) shift 1 ;;
2492 *)
2493 echo "Unrecognized value for --release-channel. Valid release channels are: stable, nightly, default"
2494 exit 1
2495 ;;
2496 esac
2497 ;;
2498 "--stable-channel") RELEASE_CHANNEL="stable" ;;
2499 "--nightly-channel") RELEASE_CHANNEL="nightly" ;;
2500 "--reinstall") set_action 'reinstall' ;;
2501 "--reinstall-even-if-unsafe") set_action 'unsafe-reinstall' ;;
2502 "--reinstall-clean") set_action 'reinstall-clean' ;;
2503 "--uninstall") set_action 'uninstall' ;;
2504 "--claim-only") set_action 'claim' ;;
2505 "--no-updates") NETDATA_AUTO_UPDATES=0 ;;
2506 "--auto-update") NETDATA_AUTO_UPDATES="1" ;;
2507 "--auto-update-type"|"--auto-update-method")
2508 NETDATA_AUTO_UPDATE_TYPE="$(echo "${2}" | tr '[:upper:]' '[:lower:]')"
2509 case "${NETDATA_AUTO_UPDATE_TYPE}" in
2510 systemd|interval|crontab) shift 1 ;;
2511 *)
2512 echo "Unrecognized value for --auto-update-type. Valid values are: systemd, interval, crontab"
2513 exit 1
2514 ;;
2515 esac
2516 ;;
2517 "--disable-cloud")
2518 warning "Cloud cannot be disabled"
2519 ;;
2520 "--require-cloud")
2521 warning "Cloud is always required"
2522 ;;
2523 "--dont-start-it")
2524 NETDATA_NO_START=1
2525 NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --dont-start-it"
2526 ;;
2527 "--disable-telemetry")
2528 NETDATA_DISABLE_TELEMETRY="1"
2529 NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --disable-telemetry"
2530 ;;
2531 "--install-prefix")
2532 INSTALL_PREFIX="${2}"
2533 shift 1
2534 ;;
2535 "--old-install-prefix")
2536 OLD_INSTALL_PREFIX="${2}"
2537 shift 1
2538 ;;
2539 "--install-major-version")
2540 INSTALL_MAJOR_VERSION="${2}"
2541 shift 1
2542 ;;
2543 "--install-version")
2544 INSTALL_VERSION="${2}"
2545 AUTO_UPDATE=0
2546 shift 1
2547 ;;
2548 "--distro-override")
2549 if [ -n "${2}" ]; then
2550 SKIP_DISTRO_DETECTION=1
2551 DISTRO="$(echo "${2}" | cut -f 1 -d ':' | tr '[:upper:]' '[:lower:]')"
2552 SYSVERSION="$(echo "${2}" | cut -f 2 -d ':')"
2553 SYSCODENAME="$(echo "${2}" | cut -f 3 -d ':' | tr '[:upper:]' '[:lower:]')"
2554
2555 if [ -z "${SYSVERSION}" ]; then
2556 fatal "You must specify a release as well as a distribution name." F0510
2557 fi
2558
2559 shift 1
2560 else
2561 fatal "A distribution name and release must be specified for the --distro-override option." F050F
2562 fi
2563 ;;
2564 "--repositories-only")
2565 set_action 'repositories-only'
2566 NETDATA_REQUESTED_INSTALL_TYPE="native"
2567 ;;
2568 "--native-only") NETDATA_REQUESTED_INSTALL_TYPE="native" ;;
2569 "--static-only") NETDATA_REQUESTED_INSTALL_TYPE="static" ;;
2570 "--build-only") NETDATA_REQUESTED_INSTALL_TYPE="build" ;;
2571 "--install-type")
2572 case "${2}" in
2573 native|static|build|auto|any) NETDATA_REQUESTED_INSTALL_TYPE="${2}" ;;
2574 *) fatal "${2} is not a recognized install type. Please specify one of native, static, build, auto, or any." F051F ;;
2575 esac
2576 shift 1
2577 ;;
2578 "--claim-"*)
2579 optname="$(echo "${1}" | cut -d '-' -f 4-)"
2580 case "${optname}" in
2581 token) NETDATA_CLAIM_TOKEN="${2}"; shift 1 ;;
2582 rooms) NETDATA_CLAIM_ROOMS="${2}"; shift 1 ;;
2583 url) NETDATA_CLAIM_URL="${2}"; shift 1 ;;
2584 proxy) NETDATA_CLAIM_PROXY="${2}"; shift 1 ;;
2585 noproxy) NETDATA_CLAIM_PROXY="none" ;;
2586 insecure) NETDATA_CLAIM_INSECURE=yes ;;
2587 noreload) NETDATA_CLAIM_NORELOAD=1 ;;
2588 id|user|hostname)
2589 NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -${optname}=${2}"
2590 shift 1
2591 ;;
2592 verbose|daemon-not-running) NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -${optname}" ;;
2593 *) warning "Ignoring unrecognized claiming option ${optname}" ;;
2594 esac
2595 ;;
2596 "--local-build-options")
2597 LOCAL_BUILD_OPTIONS="${LOCAL_BUILD_OPTIONS} ${2}"
2598 shift 1
2599 ;;
2600 "--static-install-options")
2601 STATIC_INSTALL_OPTIONS="${STATIC_INSTALL_OPTIONS} ${2}"
2602 shift 1
2603 ;;
2604 "--prepare-offline-install-source")
2605 if [ -n "${2}" ]; then
2606 set_action 'prepare-offline'
2607 OFFLINE_TARGET="${2}"
2608 shift 1
2609 else
2610 fatal "A target directory must be specified with the --prepare-offline-install-source option." F0500
2611 fi
2612 ;;
2613 "--offline-architecture")
2614 if echo "${STATIC_INSTALL_ARCHES}" | grep -qw "${2}"; then
2615 NETDATA_OFFLINE_ARCHES="${NETDATA_OFFLINE_ARCHES} ${2}"
2616 else
2617 fatal "${2} is not a recognized static build architecture (supported architectures are ${STATIC_INSTALL_ARCHES})" F0518
2618 fi
2619 shift 1
2620 ;;
2621 "--offline-install-source")
2622 if [ -d "${2}" ]; then
2623 NETDATA_OFFLINE_INSTALL_SOURCE="${2}"
2624 # shellcheck disable=SC2164
2625 NETDATA_TARBALL_BASEURL="file://$(cd "${2}"; pwd)"
2626 shift 1
2627 else
2628 fatal "A source directory must be specified with the --offline-install-source option." F0501
2629 fi
2630 ;;
2631 "--"|"all"|"--yes"|"-y"|"--force"|"--accept") warning "Option '${1}' is not recognized, ignoring it. ${BADOPT_MSG}" ;;
2632 *) fatal "Unrecognized option '${1}'. ${BADOPT_MSG}" F050E ;;
2633 esac
2634 shift 1
2635 done
2636
2637 validate_args
2638 }
2639
2640 # ======================================================================
2641 # Main program
2642
2643 setup_terminal || echo > /dev/null
2644
2645 # shellcheck disable=SC2068
2646 parse_args $@
2647
2648 confirm_root_support
2649 get_system_info
2650 confirm_install_prefix
2651
2652 main