1
-#!/usr/bin/env bash
2
-# SPDX-License-Identifier: GPL-3.0-or-later
3
-#
4
-# Run me with:
5
-#
6
-# bash <(curl -Ss https://my-netdata.io/kickstart.sh)
7
-#
8
-# or (to install all netdata dependencies):
9
-#
10
-# bash <(curl -Ss https://my-netdata.io/kickstart.sh) all
11
-#
12
-# Other options:
13
-# --dont-wait do not prompt for user input
14
-# --non-interactive do not prompt for user input
15
-# --no-updates do not install script for daily updates
16
-# --local-files set the full path of the desired tarball to run install with
17
-# --allow-duplicate-install do not bail if we detect a duplicate install
18
-# --reinstall if an existing install would be updated, reinstall instead
19
-# --disable-telemetry opt out of anonymous statistics
20
-# --claim-token specify a token to use for claiming the newly installed instance
21
-# --claim-url specify a URL to use for claiming the newly installed isntance
22
-# --claim-rooms specify a list of rooms to claim the newly installed instance to
23
-# --claim-proxy specify a proxy to use while claiming the newly installed instance
24
-#
25
-# Environment options:
1
+#!/bin/sh
2
#
27
-# TMPDIR specify where to save temporary files
28
-# NETDATA_TARBALL_BASEURL set the base url for downloading the dist tarball
29
-#
30
-# This script will:
31
-#
32
-# 1. install all netdata compilation dependencies
33
-# using the package manager of the system
34
-#
35
-# 2. download netdata nightly package to temporary directory
36
-#
37
-# 3. install netdata
3
+# SPDX-License-Identifier: GPL-3.0-or-later
4
39
-# shellcheck disable=SC2039,SC2059,SC2086
5
+# ======================================================================
6
+# Constants
7
41
-# External files
8
+KICKSTART_OPTIONS="${*}"
9
PACKAGES_SCRIPT="https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/install-required-packages.sh"
43
-
44
-# Netdata Tarball Base URL (defaults to our Google Storage Bucket)
45
-[ -z "$NETDATA_TARBALL_BASEURL" ] && NETDATA_TARBALL_BASEURL=https://storage.googleapis.com/netdata-nightlies
46
-
10
+PATH="${PATH}:/usr/local/bin:/usr/local/sbin"
11
+REPOCONFIG_URL_PREFIX="https://packagecloud.io/netdata/netdata-repoconfig/packages"
12
+REPOCONFIG_VERSION="1-1"
13
TELEMETRY_URL="https://posthog.netdata.cloud/capture/"
48
-TELEMETRY_API_KEY="${NETDATA_POSTHOG_API_KEY:-mqkwGT0JNFqO-zX2t0mW6Tec9yooaVu7xCBlXtHnt5Y}"
49
-KICKSTART_OPTIONS="${*}"
50
-
51
-# ---------------------------------------------------------------------------------------------------------------------
52
-# library functions copied from packaging/installer/functions.sh
14
+START_TIME="$(date +%s)"
15
+
16
+# ======================================================================
17
+# Defaults for environment variables
18
+
19
+SELECTED_INSTALL_METHOD="none"
20
+INSTALL_TYPE="unknown"
21
+INSTALL_PREFIX=""
22
+NETDATA_AUTO_UPDATES="1"
23
+NETDATA_CLAIM_ONLY=0
24
+NETDATA_CLAIM_URL="https://app.netdata.cloud"
25
+NETDATA_DISABLE_CLOUD=0
26
+NETDATA_ONLY_BUILD=0
27
+NETDATA_ONLY_NATIVE=0
28
+NETDATA_ONLY_STATIC=0
29
+NETDATA_REQUIRE_CLOUD=1
30
+RELEASE_CHANNEL="nightly"
31
54
-setup_terminal() {
55
- TPUT_RESET=""
56
- TPUT_YELLOW=""
57
- TPUT_WHITE=""
58
- TPUT_BGRED=""
59
- TPUT_BGGREEN=""
60
- TPUT_BOLD=""
61
- TPUT_DIM=""
32
+NETDATA_DISABLE_TELEMETRY="${DO_NOT_TRACK:-0}"
33
+NETDATA_TARBALL_BASEURL="${NETDATA_TARBALL_BASEURL:-https://storage.googleapis.com/netdata-nightlies}"
34
+NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS:-""}"
35
+TELEMETRY_API_KEY="${NETDATA_POSTHOG_API_KEY:-mqkwGT0JNFqO-zX2t0mW6Tec9yooaVu7xCBlXtHnt5Y}"
36
63
- # Is stderr on the terminal? If not, then fail
64
- test -t 2 || return 1
37
+if echo "${0}" | grep -q 'kickstart-static64'; then
38
+ NETDATA_ONLY_STATIC=1
39
+fi
40
66
- if command -v tput > /dev/null 2>&1; then
67
- if [ $(($(tput colors 2> /dev/null))) -ge 8 ]; then
68
- # Enable colors
69
- TPUT_RESET="$(tput sgr 0)"
70
- TPUT_YELLOW="$(tput setaf 3)"
71
- TPUT_WHITE="$(tput setaf 7)"
72
- TPUT_BGRED="$(tput setab 1)"
73
- TPUT_BGGREEN="$(tput setab 2)"
74
- TPUT_BOLD="$(tput bold)"
75
- TPUT_DIM="$(tput dim)"
76
- fi
77
- fi
41
+if [ ! -t 1 ]; then
42
+ INTERACTIVE=0
43
+else
44
+ INTERACTIVE=1
45
+fi
46
79
- return 0
47
+# ======================================================================
48
+# Usage info
49
+
50
+usage() {
51
+ cat << HEREDOC
52
+USAGE: kickstart.sh [options]
53
+ where options include:
54
+
55
+ --non-interactive Do not prompt for user input. (default: prompt if there is a controlling terminal)
56
+ --interactive Prompt for user input even if there is no controlling terminal.
57
+ --dont-start-it Do not start the agent by default (only for static installs or local builds)
58
+ --stable-channel Install a stable version instead of a nightly build (default: install a nightly build)
59
+ --nightly-channel Install a nightly build instead of a stable version
60
+ --no-updates Do not enable automatic updates (default: enable automatic updates)
61
+ --auto-update Enable automatic updates.
62
+ --disable-telemetry Opt-out of anonymous statistics.
63
+ --native-only Only install if native binary packages are available.
64
+ --static-only Only install if a static build is available.
65
+ --build-only Only install using a local build.
66
+ --reinstall Explicitly reinstall instead of updating any existing install.
67
+ --reinstall-even-if-unsafe Even try to reinstall if we don't think we can do so safely (implies --reinstall).
68
+ --disable-cloud Disable support for Netdata Cloud (default: detect)
69
+ --require-cloud Only install if Netdata Cloud can be enabled. Overrides --disable-cloud.
70
+ --install <path> Specify an installation prefix for local builds (default: autodetect based on system type).
71
+ --claim-token Use a specified token for claiming to Netdata Cloud.
72
+ --claim-rooms When claiming, add the node to the specified rooms.
73
+ --claim-only If there is an existing install, only try to claim it, not update it.
74
+ --claim-* Specify other options for the claiming script.
75
+ --no-cleanup Don't do any cleanup steps. This is intended to help with debugging the installer.
76
+
77
+Additionally, this script may use the following environment variables:
78
+
79
+ TMPDIR: Used to specify where to put temporary files. On most systems, the default we select
80
+ automatically should be fine. The user running the script needs to both be able to
81
+ write files to the temporary directory, and run files from that location.
82
+ ROOTCMD: Used to specify a command to use to run another command with root privileges if needed. By
83
+ default we try to use sudo, doas, or pkexec (in that order of preference), but if
84
+ you need special options for one of those to work, or have a different tool to do
85
+ the same thing on your system, you can specify it here.
86
+ DO_NOT_TRACK If set to a value other than 0, behave as if \`--disable-telemetry\` was specified.
87
+ NETDATA_INSTALLER_OPTIONS: Specifies extra options to pass to the static installer or local build script.
88
+
89
+HEREDOC
90
}
81
-setup_terminal || echo > /dev/null
91
83
-# -----------------------------------------------------------------------------
92
+# ======================================================================
93
+# Telemetry functions
94
+
95
telemetry_event() {
85
- if [ -n "${NETDATA_DISABLE_TELEMETRY}" ]; then
96
+ if [ "${NETDATA_DISABLE_TELEMETRY}" -eq 1 ]; then
97
return 0
98
fi
99
100
+ now="$(date +%s)"
101
+ total_duration="$((now - START_TIME))"
102
+
103
if [ -e "/etc/os-release" ]; then
104
eval "$(grep -E "^(NAME|ID|ID_LIKE|VERSION|VERSION_ID)=" < /etc/os-release | sed 's/^/HOST_/')"
105
fi
129
130
if [ -f /etc/machine-id ]; then
131
DISTINCT_ID="$(cat /etc/machine-id)"
118
- elif command -v uuidgen 2> /dev/null; then
132
+ elif command -v uuidgen > /dev/null 2>&1; then
133
DISTINCT_ID="$(uuidgen)"
134
else
135
DISTINCT_ID="null"
146
"\$pathname": "netdata-installer",
147
"\$host": "installer.netdata.io",
148
"\$ip": "127.0.0.1",
135
- "script_variant": "legacy-kickstart",
136
- "error_code": "${2}",
137
- "error_message": "${3}",
149
+ "script_variant": "kickstart-ng",
150
+ "error_code": "${3}",
151
+ "error_message": "${2}",
152
"install_options": "${KICKSTART_OPTIONS}",
153
+ "total_runtime": "${total_duration}",
154
+ "selected_install_method": "${SELECTED_INSTALL_METHOD}",
155
"netdata_release_channel": "${RELEASE_CHANNEL:-null}",
140
- "netdata_install_type": "kickstart-build",
156
+ "netdata_install_type": "${INSTALL_TYPE}",
157
"host_os_name": "${HOST_NAME:-unknown}",
158
"host_os_id": "${HOST_ID:-unknown}",
159
"host_os_id_like": "${HOST_ID_LIKE:-unknown}",
168
EOF
169
)"
170
155
-if [ -n "$(command -v curl 2> /dev/null)" ]; then
156
- curl --silent -o /dev/null --write-out '%{http_code}' -X POST --max-time 2 --header "Content-Type: application/json" -d "${REQ_BODY}" "${TELEMETRY_URL}"
157
-else
158
- wget -q -O - --no-check-certificate \
159
- --server-response \
160
- --method POST \
161
- --timeout=1 \
162
- --header 'Content-Type: application/json' \
163
- --body-data "${REQ_BODY}" \
164
- "${TELEMETRY_URL}" 2>&1 | awk '/^ HTTP/{print $2}'
165
-fi
171
+ if command -v curl > /dev/null 2>&1; then
172
+ curl --silent -o /dev/null -X POST --max-time 2 --header "Content-Type: application/json" -d "${REQ_BODY}" "${TELEMETRY_URL}" > /dev/null
173
+ elif command -v wget > /dev/null 2>&1; then
174
+ wget -q -O - --no-check-certificate \
175
+ --method POST \
176
+ --timeout=1 \
177
+ --header 'Content-Type: application/json' \
178
+ --body-data "${REQ_BODY}" \
179
+ "${TELEMETRY_URL}" > /dev/null
180
+ fi
181
+}
182
+
183
+trap_handler() {
184
+ code="${1}"
185
+ lineno="${2}"
186
+
187
+ printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ERROR ${TPUT_RESET} Installer exited unexpectedly (${code}-${lineno})"
188
+
189
+ telemetry_event INSTALL_CRASH "Installer exited unexpectedly (${code}-${lineno})" "E${code}-${lineno}"
190
+
191
+ trap - EXIT
192
+
193
+ cleanup
194
+
195
+ exit 1
196
+}
197
+
198
+trap 'trap_handler 0 ${LINENO}' EXIT
199
+trap 'trap_handler 1 0' HUP
200
+trap 'trap_handler 2 0' INT
201
+trap 'trap_handler 3 0' QUIT
202
+trap 'trap_handler 13 0' PIPE
203
+trap 'trap_handler 15 0' TERM
204
+
205
+# ======================================================================
206
+# Utility functions
207
+
208
+setup_terminal() {
209
+ TPUT_RESET=""
210
+ TPUT_WHITE=""
211
+ TPUT_BGRED=""
212
+ TPUT_BGGREEN=""
213
+ TPUT_BOLD=""
214
+ TPUT_DIM=""
215
+
216
+ # Is stderr on the terminal? If not, then fail
217
+ test -t 2 || return 1
218
+
219
+ if command -v tput > /dev/null 2>&1; then
220
+ if [ $(($(tput colors 2> /dev/null))) -ge 8 ]; then
221
+ # Enable colors
222
+ TPUT_RESET="$(tput sgr 0)"
223
+ TPUT_WHITE="$(tput setaf 7)"
224
+ TPUT_BGRED="$(tput setab 1)"
225
+ TPUT_BGGREEN="$(tput setab 2)"
226
+ TPUT_BOLD="$(tput bold)"
227
+ TPUT_DIM="$(tput dim)"
228
+ fi
229
+ fi
230
+
231
+ echo "${TPUT_RESET}"
232
+
233
+ return 0
234
+}
235
+
236
+cleanup() {
237
+ if [ -z "${NO_CLEANUP}" ]; then
238
+ ${ROOTCMD} rm -rf "${tmpdir}"
239
+ fi
240
}
241
242
fatal() {
169
- printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${1} \n\n"
243
+ printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${1}"
244
telemetry_event "INSTALL_FAILED" "${1}" "${2}"
245
+ cleanup
246
+ trap - EXIT
247
exit 1
248
}
249
250
run_ok() {
175
- printf >&2 "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET} \n\n"
251
+ printf >&2 "%s\n\n" "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET}"
252
}
253
254
run_failed() {
179
- printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET} \n\n"
255
+ printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET}"
256
}
257
258
ESCAPED_PRINT_METHOD=
259
+# shellcheck disable=SC3050
260
if printf "%q " test > /dev/null 2>&1; then
261
ESCAPED_PRINT_METHOD="printfq"
262
fi
263
+
264
escaped_print() {
265
if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]; then
266
+ # shellcheck disable=SC3050
267
printf "%q " "${@}"
268
else
269
printf "%s" "${*}"
272
}
273
274
progress() {
196
- echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "
275
+ echo >&2 " --- ${TPUT_BOLD}${*}${TPUT_RESET} --- "
276
}
277
278
run_logfile="/dev/null"
279
run() {
201
- local user="${USER--}" dir="${PWD}" info info_console
280
+ user="${USER--}"
281
+ dir="${PWD}"
282
203
- if [ "${UID}" = "0" ]; then
283
+ if [ "$(id -u)" = "0" ]; then
284
info="[root ${dir}]# "
285
info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
286
else
289
fi
290
291
{
212
- printf "${info}"
292
+ printf "%s" "${info}"
293
escaped_print "${@}"
294
printf " ... "
295
} >> "${run_logfile}"
296
217
- printf >&2 "${info_console}${TPUT_BOLD}${TPUT_YELLOW}"
297
+ printf >&2 "%s" "${info_console}${TPUT_BOLD}"
298
escaped_print >&2 "${@}"
219
- printf >&2 "${TPUT_RESET}"
299
+ printf >&2 "%s\n" "${TPUT_RESET}"
300
301
"${@}"
302
223
- local ret=$?
303
+ ret=$?
304
if [ ${ret} -ne 0 ]; then
305
run_failed
226
- printf >> "${run_logfile}" "FAILED with exit code ${ret}\n"
306
+ printf "%s\n" "FAILED with exit code ${ret}" >> "${run_logfile}"
307
else
308
run_ok
229
- printf >> "${run_logfile}" "OK\n"
309
+ printf "OK\n" >> "${run_logfile}"
310
fi
311
312
return ${ret}
313
}
314
315
warning() {
236
- printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} WARNING ${TPUT_RESET} ${*} \n\n"
237
- if [ "${INTERACTIVE}" = "0" ]; then
238
- fatal "Stopping due to non-interactive mode. Fix the issue or retry installation in an interactive mode." F0001
239
- else
240
- read -r -p "Press ENTER to attempt netdata installation > "
241
- progress "OK, let's give it a try..."
242
- fi
316
+ printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} WARNING ${TPUT_RESET} ${*}"
317
}
318
319
_cannot_use_tmpdir() {
246
- local testfile ret
320
testfile="$(TMPDIR="${1}" mktemp -q -t netdata-test.XXXXXXXXXX)"
321
ret=0
322
250
- if [ -z "${testfile}" ] ; then
323
+ if [ -z "${testfile}" ]; then
324
return "${ret}"
325
fi
326
254
- if printf '#!/bin/sh\necho SUCCESS\n' > "${testfile}" ; then
255
- if chmod +x "${testfile}" ; then
256
- if [ "$("${testfile}")" = "SUCCESS" ] ; then
327
+ if printf '#!/bin/sh\necho SUCCESS\n' > "${testfile}"; then
328
+ if chmod +x "${testfile}"; then
329
+ if [ "$("${testfile}")" = "SUCCESS" ]; then
330
ret=1
331
fi
332
fi
337
}
338
339
create_tmp_directory() {
267
- if [ -z "${TMPDIR}" ] || _cannot_use_tmpdir "${TMPDIR}" ; then
268
- if _cannot_use_tmpdir /tmp ; then
269
- if _cannot_use_tmpdir "${PWD}" ; then
270
- echo >&2
271
- echo >&2 "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."
272
- exit 1
340
+ if [ -z "${TMPDIR}" ] || _cannot_use_tmpdir "${TMPDIR}"; then
341
+ if _cannot_use_tmpdir /tmp; then
342
+ if _cannot_use_tmpdir "${PWD}"; then
343
+ 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
344
else
345
TMPDIR="${PWD}"
346
fi
356
url="${1}"
357
dest="${2}"
358
if command -v curl > /dev/null 2>&1; then
288
- run curl -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}" || fatal "Cannot download ${url}" F0002
359
+ run curl -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}" || return 1
360
elif command -v wget > /dev/null 2>&1; then
290
- run wget -T 15 -O "${dest}" "${url}" || fatal "Cannot download ${url}" F0002
361
+ run wget -T 15 -O "${dest}" "${url}" || return 1
362
else
292
- fatal "I need curl or wget to proceed, but neither is available on this system." F0003
363
+ fatal "I need curl or wget to proceed, but neither of them are available on this system." F0003
364
fi
365
}
366
296
-set_tarball_urls() {
297
- if [ -n "${NETDATA_LOCAL_TARBALL_OVERRIDE}" ]; then
298
- progress "Not fetching remote tarballs, local override was given"
299
- return
300
- fi
367
+get_redirect() {
368
+ url="${1}"
369
302
- if [ "$1" = "stable" ]; then
303
- local latest
304
- # Simple version
305
- latest="$(download "https://api.github.com/repos/netdata/netdata/releases/latest" /dev/stdout | grep tag_name | cut -d'"' -f4)"
306
- export NETDATA_TARBALL_URL="https://github.com/netdata/netdata/releases/download/$latest/netdata-latest.tar.gz"
307
- export NETDATA_TARBALL_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/$latest/sha256sums.txt"
370
+ if command -v curl > /dev/null 2>&1; then
371
+ run sh -c "curl ${url} -s -L -I -o /dev/null -w '%{url_effective}' | grep -o '[^/]*$'" || return 1
372
+ elif command -v wget > /dev/null 2>&1; then
373
+ run sh -c "wget --max-redirect=0 ${url} 2>&1 | grep Location | cut -d ' ' -f2 | grep -o '[^/]*$'" || return 1
374
else
309
- export NETDATA_TARBALL_URL="$NETDATA_TARBALL_BASEURL/netdata-latest.tar.gz"
310
- export NETDATA_TARBALL_CHECKSUM_URL="$NETDATA_TARBALL_BASEURL/sha256sums.txt"
375
+ fatal "I need curl or wget to proceed, but neither of them are available on this system." F0003
376
fi
377
}
378
314
-detect_bash4() {
315
- bash="${1}"
316
- if [ -z "${BASH_VERSION}" ]; then
317
- # we don't run under bash
318
- if [ -n "${bash}" ] && [ -x "${bash}" ]; then
319
- # shellcheck disable=SC2016
320
- BASH_MAJOR_VERSION=$(${bash} -c 'echo "${BASH_VERSINFO[0]}"')
321
- fi
379
+safe_sha256sum() {
380
+ # Within the context of the installer, we only use -c option that is common between the two commands
381
+ # We will have to reconsider if we start using non-common options
382
+ if command -v sha256sum > /dev/null 2>&1; then
383
+ sha256sum "$@"
384
+ elif command -v shasum > /dev/null 2>&1; then
385
+ shasum -a 256 "$@"
386
else
323
- # we run under bash
324
- BASH_MAJOR_VERSION="${BASH_VERSINFO[0]}"
387
+ fatal "I could not find a suitable checksum binary to use" F0004
388
fi
389
+}
390
327
- if [ -z "${BASH_MAJOR_VERSION}" ]; then
328
- echo >&2 "No BASH is available on this system"
329
- return 1
330
- elif [ $((BASH_MAJOR_VERSION)) -lt 4 ]; then
331
- echo >&2 "No BASH v4+ is available on this system (installed bash is v${BASH_MAJOR_VERSION})"
332
- return 1
391
+get_system_info() {
392
+ case "$(uname -s)" in
393
+ Linux)
394
+ SYSTYPE="Linux"
395
+
396
+ os_release_file=
397
+ if [ -s "/etc/os-release" ] && [ -r "/etc/os-release" ]; then
398
+ os_release_file="/etc/os-release"
399
+ elif [ -s "/usr/lib/os-release" ] && [ -r "/usr/lib/os-release" ]; then
400
+ os_release_file="/usr/lib/os-release"
401
+ else
402
+ fatal "Cannot find an os-release file ..." F0401
403
+ fi
404
+
405
+ # shellcheck disable=SC1090
406
+ . "${os_release_file}"
407
+
408
+ DISTRO="${ID}"
409
+ SYSVERSION="${VERSION_ID}"
410
+ SYSCODENAME="${VERSION_CODENAME}"
411
+ SYSARCH="$(uname -m)"
412
+
413
+ supported_compat_names="debian ubuntu centos fedora opensuse"
414
+
415
+ if str_in_list "${DISTRO}" "${supported_compat_names}"; then
416
+ DISTRO_COMPAT_NAME="${DISTRO}"
417
+ else
418
+ case "${DISTRO}" in
419
+ opensuse-leap)
420
+ DISTRO_COMPAT_NAME="opensuse"
421
+ ;;
422
+ rhel)
423
+ DISTRO_COMPAT_NAME="centos"
424
+ ;;
425
+ *)
426
+ DISTRO_COMPAT_NAME="unknown"
427
+ ;;
428
+ esac
429
+ fi
430
+ ;;
431
+ Darwin)
432
+ SYSTYPE="Darwin"
433
+ SYSVERSION="$(sw_vers -buildVersion)"
434
+ SYSARCH="$(uname -m)"
435
+ ;;
436
+ FreeBSD)
437
+ SYSTYPE="FreeBSD"
438
+ SYSVERSION="$(uname -K)"
439
+ SYSARCH="$(uname -m)"
440
+ ;;
441
+ *)
442
+ fatal "Unsupported system type detected. Netdata cannot be installed on this system using this script." F0200
443
+ ;;
444
+ esac
445
+}
446
+
447
+str_in_list() {
448
+ printf "%s\n" "${2}" | tr ' ' "\n" | grep -qE "^${1}\$"
449
+ return $?
450
+}
451
+
452
+confirm_root_support() {
453
+ if [ "$(id -u)" -ne "0" ]; then
454
+ if [ -z "${ROOTCMD}" ] && command -v sudo > /dev/null; then
455
+ ROOTCMD="sudo"
456
+ fi
457
+
458
+ if [ -z "${ROOTCMD}" ] && command -v doas > /dev/null; then
459
+ ROOTCMD="doas"
460
+ fi
461
+
462
+ if [ -z "${ROOTCMD}" ] && command -v pkexec > /dev/null; then
463
+ ROOTCMD="pkexec"
464
+ fi
465
+
466
+ if [ -z "${ROOTCMD}" ]; then
467
+ fatal "We need root privileges to continue, but cannot find a way to gain them. Either re-run this script as root, or set \$ROOTCMD to a command that can be used to gain root privileges" F0201
468
+ fi
469
fi
334
- return 0
470
}
471
337
-dependencies() {
338
- SYSTEM="$(uname -s 2> /dev/null || uname -v)"
339
- OS="$(uname -o 2> /dev/null || uname -rs)"
340
- MACHINE="$(uname -m 2> /dev/null)"
472
+confirm() {
473
+ prompt="${1} [y/n]"
474
342
- echo "System : ${SYSTEM}"
343
- echo "Operating System : ${OS}"
344
- echo "Machine : ${MACHINE}"
345
- echo "BASH major version: ${BASH_MAJOR_VERSION}"
475
+ while true; do
476
+ echo "${prompt}"
477
+ read -r yn
478
347
- bash="$(command -v bash 2> /dev/null)"
348
- if ! detect_bash4 "${bash}"; then
349
- warning "Cannot detect packages to be installed in this system, without BASH v4+."
479
+ case "$yn" in
480
+ [Yy]*) return 0;;
481
+ [Nn]*) return 1;;
482
+ *) echo "Please answer yes or no.";;
483
+ esac
484
+ done
485
+}
486
+
487
+# ======================================================================
488
+# Existing install handling code
489
+
490
+update() {
491
+ updater="${ndprefix}/usr/libexec/netdata/netdata-updater.sh"
492
+
493
+ if [ -x "${updater}" ]; then
494
+ if run ${ROOTCMD} "${updater}" --not-running-from-cron; then
495
+ progress "Updated existing install at ${ndprefix}"
496
+ return 0
497
+ else
498
+ fatal "Failed to update existing Netdata install at ${ndprefix}" F0100
499
+ fi
500
else
351
- progress "Fetching script to detect required packages..."
352
- if [ -n "${NETDATA_LOCAL_TARBALL_OVERRIDE_DEPS_SCRIPT}" ]; then
353
- if [ -f "${NETDATA_LOCAL_TARBALL_OVERRIDE_DEPS_SCRIPT}" ]; then
354
- run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_DEPS_SCRIPT}" "${ndtmpdir}/install-required-packages.sh"
355
- else
356
- fatal "Invalid given dependency file, please check your --local-files parameter options and try again" F1001
357
- fi
501
+ return 1
502
+ fi
503
+}
504
+
505
+handle_existing_install() {
506
+ if pkg_installed netdata; then
507
+ ndprefix="/"
508
+ else
509
+ if [ -n "${INSTALL_PREFIX}" ]; then
510
+ searchpath="${INSTALL_PREFIX}/bin:${INSTALL_PREFIX}/sbin:${INSTALL_PREFIX}/usr/bin:${INSTALL_PREFIX}/usr/sbin:${PATH}"
511
+ searchpath="${INSTALL_PREFIX}/netdata/bin:${INSTALL_PREFIX}/netdata/sbin:${INSTALL_PREFIX}/netdata/usr/bin:${INSTALL_PREFIX}/netdata/usr/sbin:${searchpath}"
512
else
359
- download "${PACKAGES_SCRIPT}" "${ndtmpdir}/install-required-packages.sh"
513
+ searchpath="${PATH}"
514
+ fi
515
+
516
+ ndpath="$(PATH="${searchpath}" command -v netdata 2>/dev/null)"
517
+
518
+ if [ -z "$ndpath" ] && [ -x /opt/netdata/bin/netdata ]; then
519
+ ndpath="/opt/netdata/bin/netdata"
520
+ fi
521
+
522
+ if [ -n "${ndpath}" ]; then
523
+ ndprefix="$(dirname "$(dirname "${ndpath}")")"
524
+ fi
525
+
526
+ if echo "${ndprefix}" | grep -Eq '/usr$'; then
527
+ ndprefix="$(dirname "${ndprefix}")"
528
fi
529
+ fi
530
362
- if [ ! -s "${ndtmpdir}/install-required-packages.sh" ]; then
363
- warning "Downloaded dependency installation script is empty."
531
+ if [ -n "${ndprefix}" ]; then
532
+ typefile="${ndprefix}/etc/netdata/.install-type"
533
+ if [ -r "${typefile}" ]; then
534
+ ${ROOTCMD} sh -c "cat \"${typefile}\" > \"${tmpdir}/install-type\""
535
+ # shellcheck disable=SC1091
536
+ . "${tmpdir}/install-type"
537
else
365
- progress "Running downloaded script to detect required packages..."
366
- run ${sudo} "${bash}" "${ndtmpdir}/install-required-packages.sh" ${PACKAGES_INSTALLER_OPTIONS}
367
- # shellcheck disable=SC2181
368
- if [ $? -ne 0 ]; then
369
- warning "It failed to install all the required packages, but installation might still be possible."
370
- fi
538
+ INSTALL_TYPE="unknown"
539
fi
540
+ fi
541
542
+ if [ -z "${ndprefix}" ]; then
543
+ progress "No existing installations of netdata found, assuming this is a fresh install."
544
+ return 0
545
fi
546
+
547
+ case "${INSTALL_TYPE}" in
548
+ kickstart-*|legacy-*|binpkg-*|manual-static|unknown)
549
+ if [ "${INSTALL_TYPE}" = "unknown" ]; then
550
+ warning "Found an existing netdata install at ${ndprefix}, but could not determine the install type."
551
+ else
552
+ progress "Found an existing netdata install at ${ndprefix}, with installation type '${INSTALL_TYPE}'."
553
+ fi
554
+
555
+ if [ -n "${NETDATA_REINSTALL}" ] || [ -n "${NETDATA_UNSAFE_REINSTALL}" ]; then
556
+ progress "Found an existing netdata install at ${ndprefix}, but user requested reinstall, continuing."
557
+
558
+ case "${INSTALL_TYPE}" in
559
+ binpkg-*) NETDATA_ONLY_NATIVE=1 ;;
560
+ *-build) NETDATA_ONLY_BUILD=1 ;;
561
+ *-static) NETDATA_ONLY_STATIC=1 ;;
562
+ *)
563
+ if [ -n "${NETDATA_UNSAFE_REINSTALL}" ]; then
564
+ warning "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, but the user has requested we proceed."
565
+ elif [ "${INTERACTIVE}" -eq 0 ]; then
566
+ fatal "User requested reinstall, but we cannot safely reinstall over top of a ${INSTALL_TYPE} installation, exiting." F0104
567
+ else
568
+ if confirm "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, do you want to continue?"; then
569
+ progress "OK, continuing."
570
+ else
571
+ fatal "Cancelling reinstallation at user request." F0105
572
+ fi
573
+ fi
574
+ ;;
575
+ esac
576
+
577
+ return 0
578
+ fi
579
+
580
+ ret=0
581
+
582
+ if [ "${NETDATA_CLAIM_ONLY}" -eq 0 ] && echo "${INSTALL_TYPE}" | grep -vq "binpkg-*"; then
583
+ if ! update; then
584
+ warning "Unable to find usable updater script, not updating existing install at ${ndprefix}."
585
+ fi
586
+ else
587
+ warning "Not updating existing install at ${ndprefix}."
588
+ fi
589
+
590
+ if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then
591
+ progress "Attempting to claim existing install at ${ndprefix}."
592
+ INSTALL_PREFIX="${ndprefix}"
593
+ claim
594
+ ret=$?
595
+ elif [ "${NETDATA_CLAIM_ONLY}" -eq 1 ]; then
596
+ fatal "User asked to claim, but did not proide a claiming token." F0202
597
+ else
598
+ progress "Not attempting to claim existing install at ${ndprefix} (no claiming token provided)."
599
+ fi
600
+
601
+ cleanup
602
+ trap - EXIT
603
+ exit $ret
604
+ ;;
605
+ oci)
606
+ fatal "This is an OCI container, use the regular image lifecycle management commands in your container instead of this script for managing it." F0203
607
+ ;;
608
+ *)
609
+ if [ -n "${NETDATA_REINSTALL}" ] || [ -n "${NETDATA_UNSAFE_REINSTALL}" ]; then
610
+ if [ -n "${NETDATA_UNSAFE_REINSTALL}" ]; then
611
+ warning "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, but the user has requested we proceed."
612
+ elif [ "${INTERACTIVE}" -eq 0 ]; then
613
+ fatal "User requested reinstall, but we cannot safely reinstall over top of a ${INSTALL_TYPE} installation, exiting." F0104
614
+ else
615
+ if confirm "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, do you want to continue?"; then
616
+ progress "OK, continuing."
617
+ else
618
+ fatal "Cancelling reinstallation at user request." F0105
619
+ fi
620
+ fi
621
+ else
622
+ fatal "Found an existing netdata install at ${ndprefix}, but the install type is '${INSTALL_TYPE}', which is not supported, refusing to proceed." F0103
623
+ fi
624
+ ;;
625
+ esac
626
}
627
376
-safe_sha256sum() {
377
- # Within the context of the installer, we only use -c option that is common between the two commands
378
- # We will have to reconsider if we start non-common options
379
- if command -v sha256sum > /dev/null 2>&1; then
380
- sha256sum "$@"
381
- elif command -v shasum > /dev/null 2>&1; then
382
- shasum -a 256 "$@"
628
+soft_disable_cloud() {
629
+ cloud_prefix="${INSTALL_PREFIX}/var/lib/netdata/cloud.d"
630
+
631
+ run ${ROOTCMD} mkdir -p "${cloud_prefix}"
632
+
633
+ cat > "${tmpdir}/cloud.conf" << EOF
634
+[global]
635
+ enabled = no
636
+EOF
637
+
638
+ run ${ROOTCMD} cp "${tmpdir}/cloud.conf" "${cloud_prefix}/cloud.conf"
639
+
640
+ if [ -z "${NETDATA_NO_START}" ]; then
641
+ case "${SYSTYPE}" in
642
+ Darwin) run ${ROOTCMD} launchctl kickstart -k com.github.netdata ;;
643
+ FreeBSD) run ${ROOTCMD} service netdata restart ;;
644
+ Linux)
645
+ initpath="$(${ROOTCMD} readlink /proc/1/exe)"
646
+
647
+ if command -v service > /dev/null 2>&1; then
648
+ run ${ROOTCMD} service netdata restart
649
+ elif command -v rc-service > /dev/null 2>&1; then
650
+ run ${ROOTCMD} rc-service netdata restart
651
+ elif [ "$(basename "${initpath}" 2> /dev/null)" = "systemd" ]; then
652
+ run ${ROOTCMD} systemctl restart netdata
653
+ elif [ -f /etc/init.d/netdata ]; then
654
+ run ${ROOTCMD} /etc/init.d/netdata restart
655
+ fi
656
+ ;;
657
+ esac
658
+ fi
659
+}
660
+
661
+confirm_install_prefix() {
662
+ if [ -n "${INSTALL_PREFIX}" ] && [ "${NETDATA_ONLY_BUILD}" -ne 1 ]; then
663
+ fatal "The \`--install\` option is only supported together with the \`--only-build\` option." F0204
664
+ fi
665
+
666
+ if [ -n "${INSTALL_PREFIX}" ]; then
667
+ NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --install ${INSTALL_PREFIX}"
668
else
384
- fatal "I could not find a suitable checksum binary to use" F0004
669
+ case "${SYSTYPE}" in
670
+ Darwin)
671
+ INSTALL_PREFIX="/usr/local/netdata"
672
+ NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --install-no-prefix ${INSTALL_PREFIX}"
673
+ ;;
674
+ FreeBSD)
675
+ INSTALL_PREFIX="/usr/local"
676
+ NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --install-no-prefix ${INSTALL_PREFIX}"
677
+ ;;
678
+ esac
679
+ fi
680
+}
681
+
682
+# ======================================================================
683
+# Claiming support code
684
+
685
+check_claim_opts() {
686
+# shellcheck disable=SC2235,SC2030
687
+ if [ -z "${NETDATA_CLAIM_TOKEN}" ] && [ -n "${NETDATA_CLAIM_ROOMS}" ]; then
688
+ fatal "Invalid claiming options, claim rooms may only be specified when a token and URL are specified." F0204
689
+ elif [ -z "${NETDATA_CLAIM_TOKEN}" ] && [ -n "${NETDATA_CLAIM_EXTRA}" ]; then
690
+ fatal "Invalid claiming options, a claiming token must be specified." F0204
691
+ elif [ "${NETDATA_DISABLE_CLOUD}" -eq 1 ] && [ -n "${NETDATA_CLAIM_TOKEN}" ]; then
692
+ fatal "Cloud explicitly disabled, but automatic claiming requested. Either enable Netdata Cloud, or remove the --claim-* options." F0204
693
+ fi
694
+}
695
+
696
+is_netdata_running() {
697
+ if command -v pgrep > /dev/null 2>&1; then
698
+ if pgrep netdata; then
699
+ return 0
700
+ else
701
+ return 1
702
+ fi
703
+ else
704
+ if [ -z "${INSTALL_PREFIX}" ]; then
705
+ NETDATACLI_PATH=/usr/sbin/netdatacli
706
+ elif [ "${INSTALL_PREFIX}" = "/opt/netdata" ]; then
707
+ NETDATACLI_PATH="/opt/netdata/bin/netdatacli"
708
+ else
709
+ NETDATACLI_PATH="${INSTALL_PREFIX}/netdata/usr/sbin/netdatacli"
710
+ fi
711
+
712
+ if "${NETDATACLI_PATH}" ping > /dev/null 2>&1; then
713
+ return 0
714
+ else
715
+ return 1
716
+ fi
717
fi
718
}
719
720
claim() {
721
progress "Attempting to claim agent to ${NETDATA_CLAIM_URL}"
390
- if [ -z "${NETDATA_PREFIX}" ] ; then
722
+ if [ -z "${INSTALL_PREFIX}" ]; then
723
NETDATA_CLAIM_PATH=/usr/sbin/netdata-claim.sh
724
+ elif [ "${INSTALL_PREFIX}" = "/opt/netdata" ]; then
725
+ NETDATA_CLAIM_PATH="/opt/netdata/bin/netdata-claim.sh"
726
else
393
- NETDATA_CLAIM_PATH="${NETDATA_PREFIX}/netdata/usr/sbin/netdata-claim.sh"
727
+ NETDATA_CLAIM_PATH="${INSTALL_PREFIX}/netdata/usr/sbin/netdata-claim.sh"
728
+ fi
729
+
730
+ if ! is_netdata_running; then
731
+ NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -daemon-not-running"
732
fi
733
396
- if ${sudo} "${NETDATA_CLAIM_PATH}" -token=${NETDATA_CLAIM_TOKEN} -rooms=${NETDATA_CLAIM_ROOMS} -url=${NETDATA_CLAIM_URL} ${NETDATA_CLAIM_EXTRA}; then
734
+ # shellcheck disable=SC2086
735
+ if ${ROOTCMD} "${NETDATA_CLAIM_PATH}" -token="${NETDATA_CLAIM_TOKEN}" -rooms="${NETDATA_CLAIM_ROOMS}" -url="${NETDATA_CLAIM_URL}" ${NETDATA_CLAIM_EXTRA}; then
736
progress "Successfully claimed node"
398
- return 0
737
else
400
- run_failed "Unable to claim node, you must do so manually."
401
- return 1
738
+ warning "Unable to claim node, you must do so manually."
739
+ if [ -z "${NETDATA_NEW_INSTALL}" ]; then
740
+ cleanup
741
+ trap - EXIT
742
+ exit 1
743
+ fi
744
fi
745
}
746
405
-# ---------------------------------------------------------------------------------------------------------------------
406
-umask 022
407
-
408
-sudo=""
409
-[ -z "${UID}" ] && UID="$(id -u)"
410
-[ "${UID}" -ne "0" ] && sudo="sudo"
411
-export PATH="${PATH}:/usr/local/bin:/usr/local/sbin"
747
+# ======================================================================
748
+# Native package install code.
749
413
-
414
-# ---------------------------------------------------------------------------------------------------------------------
415
-
416
-INTERACTIVE=1
417
-PACKAGES_INSTALLER_OPTIONS="netdata"
418
-NETDATA_INSTALLER_OPTIONS=""
419
-NETDATA_UPDATES="--auto-update"
420
-RELEASE_CHANNEL="nightly"
421
-while [ -n "${1}" ]; do
422
- case "${1}" in
423
- "all") PACKAGES_INSTALLER_OPTIONS="netdata-all" ;;
424
- "--dont-wait") INTERACTIVE=0 ;;
425
- "--non-interactive") INTERACTIVE=0 ;;
426
- "--no-updates") NETDATA_UPDATES= ;;
427
- "--stable-channel")
428
- RELEASE_CHANNEL="stable"
429
- NETDATA_INSTALLER_OPTIONS="$NETDATA_INSTALLER_OPTIONS --stable-channel"
430
- ;;
431
- "--allow-duplicate-install") NETDATA_ALLOW_DUPLICATE_INSTALL=1 ;;
432
- "--reinstall") NETDATA_REINSTALL=1 ;;
433
- "--claim-token")
434
- NETDATA_CLAIM_TOKEN="${2}"
435
- shift 1
436
- ;;
437
- "--claim-rooms")
438
- NETDATA_CLAIM_ROOMS="${2}"
439
- shift 1
750
+# Check for an already installed package with a given name.
751
+pkg_installed() {
752
+ case "${DISTRO_COMPAT_NAME}" in
753
+ debian|ubuntu)
754
+ dpkg -l "${1}" > /dev/null 2>&1
755
+ return $?
756
;;
441
- "--claim-url")
442
- NETDATA_CLAIM_URL="${2}"
443
- shift 1
757
+ centos|fedora|opensuse)
758
+ rpm -q "${1}" > /dev/null 2>&1
759
+ return $?
760
;;
445
- "--claim-proxy")
446
- NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -proxy ${2}"
447
- shift 1
761
+ *)
762
+ return 1
763
;;
449
- "--dont-start-it")
450
- NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -daemon-not-running"
451
- NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --dont-start-it"
764
+ esac
765
+}
766
+
767
+# Check for the existence of a usable netdata package in the repo.
768
+netdata_avail_check() {
769
+ case "${DISTRO_COMPAT_NAME}" in
770
+ debian|ubuntu)
771
+ env DEBIAN_FRONTEND=noninteractive apt-cache policy netdata | grep -q packagecloud.io/netdata/netdata;
772
+ return $?
773
;;
453
- "--install")
454
- NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --install ${2}"
455
- NETDATA_PREFIX="${2}"
456
- shift 1
774
+ centos|fedora)
775
+ # shellcheck disable=SC2086
776
+ ${pm_cmd} search -v netdata | grep -qE 'Repo *: netdata(-edge)?$'
777
+ return $?
778
;;
458
- "--disable-cloud")
459
- NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --disable-cloud"
460
- NETDATA_DISABLE_CLOUD=1
779
+ opensuse)
780
+ zypper packages -r "$(zypper repos | grep -E 'netdata |netdata-edge ' | cut -f 1 -d '|' | tr -d ' ')" | grep -E 'netdata '
781
+ return $?
782
;;
462
- "--disable-telemetry")
463
- NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --disable-telemetry"
464
- NETDATA_DISABLE_TELEMETRY=1
783
+ *)
784
+ return 1
785
;;
466
- "--local-files")
467
- if [ -z "${2}" ]; then
468
- fatal "Missing netdata: Option --local-files requires extra information. The desired tarball for netdata, the checksum, the go.d plugin tarball , the go.d plugin config tarball and the dependency management script, in this particular order" F1002
469
- fi
786
+ esac
787
+}
788
471
- export NETDATA_LOCAL_TARBALL_OVERRIDE="${2}"
789
+# Check for any distro-specific dependencies we know we need.
790
+check_special_native_deps() {
791
+ if [ "${DISTRO_COMPAT_NAME}" = "centos" ] && [ "${SYSVERSION}" = "7" ]; then
792
+ progress "Checking for libuv availability."
793
+ # shellcheck disable=SC2086
794
+ if ${pm_cmd} search ${interactive_opts} -v libuv | grep -q "No matches found"; then
795
+ progress "libv not found, checking for EPEL availability."
796
+ # shellcheck disable=SC2086
797
+ if ${pm_cmd} search ${interactive_opts} -v epel-release | grep -q "No matches found"; then
798
+ warning "Unable to find a suitable source for libuv, cannot install on this system."
799
+ return 1
800
+ else
801
+ progress "EPEL is available, attempting to install so that required dependencies are available."
802
473
- if [ -z "${3}" ]; then
474
- fatal "Missing checksum file: Option --local-files requires extra information. The desired tarball for netdata, the checksum, the go.d plugin tarball , the go.d plugin config tarball and the dependency management script, in this particular order" F1003
803
+ # shellcheck disable=SC2086
804
+ if ! run ${ROOTCMD} env ${env} ${pm_cmd} install ${pkg_install_opts} epel-release; then
805
+ warning "Failed to install EPEL."
806
+ return 1
807
+ fi
808
fi
809
+ else
810
+ return 0
811
+ fi
812
+ fi
813
+}
814
477
- export NETDATA_LOCAL_TARBALL_OVERRIDE_CHECKSUM="${3}"
478
-
479
- if [ -z "${4}" ]; then
480
- fatal "Missing go.d tarball: Option --local-files requires extra information. The desired tarball for netdata, the checksum, the go.d plugin tarball , the go.d plugin config tarball and the dependency management script, in this particular order" F1004
481
- fi
815
+try_package_install() {
816
+ if [ -z "${DISTRO}" ]; then
817
+ warning "Unable to determine Linux distribution for native packages."
818
+ return 1
819
+ fi
820
483
- export NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN="${4}"
821
+ progress "Attempting to install using native packages..."
822
485
- if [ -z "${5}" ]; then
486
- fatal "Missing go.d config tarball: Option --local-files requires extra information. The desired tarball for netdata, the checksum, the go.d plugin tarball , the go.d plugin config tarball and the dependency management script, in this particular order" F1005
487
- fi
823
+ if [ "${RELEASE_CHANNEL}" = "nightly" ]; then
824
+ release="-edge"
825
+ else
826
+ release=""
827
+ fi
828
489
- export NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG="${5}"
829
+ if [ "${INTERACTIVE}" = "0" ]; then
830
+ interactive_opts="-y"
831
+ env="DEBIAN_FRONTEND=noninteractive"
832
+ else
833
+ interactive_opts=""
834
+ env=""
835
+ fi
836
491
- if [ -z "${6}" ]; then
492
- fatal "Missing dependencies management scriptlet: Option --local-files requires extra information. The desired tarball for netdata, the checksum, the go.d plugin tarball , the go.d plugin config tarball and the dependency management script, in this particular order" F1006
837
+ case "${DISTRO_COMPAT_NAME}" in
838
+ debian)
839
+ needs_early_refresh=1
840
+ pm_cmd="apt-get"
841
+ repo_subcmd="update"
842
+ repo_prefix="debian/${SYSCODENAME}"
843
+ pkg_type="deb"
844
+ pkg_suffix="_all"
845
+ pkg_vsep="_"
846
+ pkg_install_opts="${interactive_opts}"
847
+ repo_update_opts="${interactive_opts}"
848
+ uninstall_subcmd="uninstall"
849
+ INSTALL_TYPE="binpkg-deb"
850
+ ;;
851
+ ubuntu)
852
+ needs_early_refresh=1
853
+ pm_cmd="apt-get"
854
+ repo_subcmd="update"
855
+ repo_prefix="ubuntu/${SYSCODENAME}"
856
+ pkg_type="deb"
857
+ pkg_suffix="_all"
858
+ pkg_vsep="_"
859
+ pkg_install_opts="${interactive_opts}"
860
+ repo_update_opts="${interactive_opts}"
861
+ uninstall_subcmd="uninstall"
862
+ INSTALL_TYPE="binpkg-deb"
863
+ ;;
864
+ centos)
865
+ if command -v dnf > /dev/null; then
866
+ pm_cmd="dnf"
867
+ repo_subcmd="makecache"
868
+ else
869
+ pm_cmd="yum"
870
fi
494
-
495
- export NETDATA_LOCAL_TARBALL_OVERRIDE_DEPS_SCRIPT="${6}"
496
- shift 5
871
+ repo_prefix="el/${SYSVERSION}"
872
+ pkg_type="rpm"
873
+ pkg_suffix=".noarch"
874
+ pkg_vsep="-"
875
+ pkg_install_opts="${interactive_opts}"
876
+ repo_update_opts="${interactive_opts}"
877
+ uninstall_subcmd="remove"
878
+ INSTALL_TYPE="binpkg-rpm"
879
+ ;;
880
+ fedora)
881
+ if command -v dnf > /dev/null; then
882
+ pm_cmd="dnf"
883
+ repo_subcmd="makecache"
884
+ else
885
+ pm_cmd="yum"
886
+ fi
887
+ repo_prefix="fedora/${SYSVERSION}"
888
+ pkg_type="rpm"
889
+ pkg_suffix=".noarch"
890
+ pkg_vsep="-"
891
+ pkg_install_opts="${interactive_opts}"
892
+ repo_update_opts="${interactive_opts}"
893
+ uninstall_subcmd="remove"
894
+ INSTALL_TYPE="binpkg-rpm"
895
+ ;;
896
+ opensuse)
897
+ pm_cmd="zypper"
898
+ repo_subcmd="--gpg-auto-import-keys refresh"
899
+ repo_prefix="opensuse/${SYSVERSION}"
900
+ pkg_type="rpm"
901
+ pkg_suffix=".noarch"
902
+ pkg_vsep="-"
903
+ pkg_install_opts="${interactive_opts} --allow-unsigned-rpm"
904
+ repo_update_opts=""
905
+ uninstall_subcmd="remove"
906
+ INSTALL_TYPE="binpkg-rpm"
907
;;
908
*)
499
- NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} ${1}"
909
+ warning "We do not provide native packages for ${DISTRO}."
910
+ return 2
911
;;
912
esac
502
- shift 1
503
-done
913
505
-if [ "${INTERACTIVE}" = "0" ]; then
506
- PACKAGES_INSTALLER_OPTIONS="--dont-wait --non-interactive ${PACKAGES_INSTALLER_OPTIONS}"
507
- NETDATA_INSTALLER_OPTIONS="$NETDATA_INSTALLER_OPTIONS --dont-wait"
508
-fi
914
+ repoconfig_name="netdata-repo${release}"
915
+ repoconfig_file="${repoconfig_name}${pkg_vsep}${REPOCONFIG_VERSION}${pkg_suffix}.${pkg_type}"
916
+ repoconfig_url="${REPOCONFIG_URL_PREFIX}/${repo_prefix}/${repoconfig_file}/download.${pkg_type}"
917
+
918
+ if ! pkg_installed "${repoconfig_name}"; then
919
+ progress "Downloading repository configuration package."
920
+ if ! download "${repoconfig_url}" "${tmpdir}/${repoconfig_file}"; then
921
+ warning "Failed to download repository configuration package."
922
+ return 2
923
+ fi
924
+
925
+ if [ -n "${needs_early_refresh}" ]; then
926
+ progress "Updating repository metadata."
927
+ # shellcheck disable=SC2086
928
+ if ! run ${ROOTCMD} env ${env} ${pm_cmd} ${repo_subcmd} ${repo_update_opts}; then
929
+ warning "Failed to refresh repository metadata."
930
+ return 2
931
+ fi
932
+ fi
933
510
-if [ -n "${NETDATA_DISABLE_CLOUD}" ]; then
511
- if [ -n "${NETDATA_CLAIM_TOKEN}" ] || [ -n "${NETDATA_CLAIM_ROOMS}" ] || [ -n "${NETDATA_CLAIM_URL}" ]; then
512
- run_failed "Cloud explicitly disabled but automatic claiming requested."
513
- run_failed "Either enable Netdata Cloud, or remove the --claim-* options."
514
- exit 1
934
+ progress "Installing repository configuration package."
935
+ # shellcheck disable=SC2086
936
+ if ! run ${ROOTCMD} env ${env} ${pm_cmd} install ${pkg_install_opts} "${tmpdir}/${repoconfig_file}"; then
937
+ warning "Failed to install repository configuration package."
938
+ return 2
939
+ fi
940
+
941
+ if [ -n "${repo_subcmd}" ]; then
942
+ progress "Updating repository metadata."
943
+ # shellcheck disable=SC2086
944
+ if ! run ${ROOTCMD} env ${env} ${pm_cmd} ${repo_subcmd} ${repo_update_opts}; then
945
+ fatal "Failed to update repository metadata." F0205
946
+ fi
947
+ fi
948
+ else
949
+ progress "Repository configuration is already present, attempting to install netdata."
950
fi
516
-fi
951
518
-# shellcheck disable=SC2235,SC2030,SC2031
519
-if ( [ -z "${NETDATA_CLAIM_TOKEN}" ] && [ -n "${NETDATA_CLAIM_URL}" ] ) || ( [ -n "${NETDATA_CLAIM_TOKEN}" ] && [ -z "${NETDATA_CLAIM_URL}" ] ); then
520
- run_failed "Invalid claiming options, both a claiming token and URL must be specified."
521
- exit 1
522
-elif [ -z "${NETDATA_CLAIM_TOKEN}" ] && [ -n "${NETDATA_CLAIM_ROOMS}" ]; then
523
- run_failed "Invalid claiming options, claim rooms may only be specified when a token and URL are specified."
524
- exit 1
525
-fi
952
+ if ! check_special_native_deps; then
953
+ warning "Could not find secondary dependencies ${DISTRO} on ${SYSARCH}."
954
+ if [ -z "${NO_CLEANUP}" ]; then
955
+ progress "Attempting to uninstall repository configuration package."
956
+ # shellcheck disable=SC2086
957
+ run ${ROOTCMD} env ${env} ${pm_cmd} ${uninstall_subcmd} ${pkg_install_opts} "${repoconfig_name}"
958
+ fi
959
+ return 2
960
+ fi
961
527
-# ---------------------------------------------------------------------------------------------------------------------
528
-# look for an existing install and try to update that instead if it exists
962
+ progress "Checking for usable Netdata package."
963
+ if ! netdata_avail_check "${DISTRO_COMPAT_NAME}"; then
964
+ warning "Could not find a usable native package for ${DISTRO} on ${SYSARCH}."
965
+ if [ -z "${NO_CLEANUP}" ]; then
966
+ progress "Attempting to uninstall repository configuration package."
967
+ # shellcheck disable=SC2086
968
+ run ${ROOTCMD} env ${env} ${pm_cmd} ${uninstall_subcmd} ${pkg_install_opts} "${repoconfig_name}"
969
+ fi
970
+ return 2
971
+ fi
972
530
-ndpath="$(command -v netdata 2>/dev/null)"
531
-if [ -z "$ndpath" ] && [ -x /opt/netdata/bin/netdata ] ; then
532
- ndpath="/opt/netdata/bin/netdata"
533
-fi
973
+ if [ "${NETDATA_DISABLE_TELEMETRY}" -eq 1 ]; then
974
+ run ${ROOTCMD} mkdir -p "/etc/netdata"
975
+ run ${ROOTCMD} touch "/etc/netdata/.opt-out-from-anonymous-statistics"
976
+ fi
977
535
-if [ -n "$ndpath" ] ; then
536
- ndprefix="$(dirname "$(dirname "${ndpath}")")"
978
+ progress "Installing Netdata package."
979
+ # shellcheck disable=SC2086
980
+ if ! run ${ROOTCMD} env ${env} ${pm_cmd} install ${pkg_install_opts} netdata; then
981
+ warning "Failed to install Netdata package."
982
+ if [ -z "${NO_CLEANUP}" ]; then
983
+ progress "Attempting to uninstall repository configuration package."
984
+ # shellcheck disable=SC2086
985
+ run ${ROOTCMD} env ${env} ${pm_cmd} ${uninstall_subcmd} ${pkg_install_opts} "${repoconfig_name}"
986
+ fi
987
+ return 2
988
+ fi
989
+}
990
538
- if [ "${ndprefix}" = /usr ] ; then
539
- ndprefix="/"
991
+# ======================================================================
992
+# Static build install code
993
+
994
+set_static_archive_urls() {
995
+ if [ "${RELEASE_CHANNEL}" = "stable" ]; then
996
+ latest="$(get_redirect "https://github.com/netdata/netdata/releases/latest")"
997
+ export NETDATA_STATIC_ARCHIVE_URL="https://github.com/netdata/netdata/releases/download/${latest}/netdata-${SYSARCH}-${latest}.gz.run"
998
+ export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/${latest}/sha256sums.txt"
999
+ else
1000
+ export NETDATA_STATIC_ARCHIVE_URL="${NETDATA_TARBALL_BASEURL}/netdata-latest.gz.run"
1001
+ export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="${NETDATA_TARBALL_BASEURL}/sha256sums.txt"
1002
fi
1003
+}
1004
542
- progress "Found existing install of Netdata under: ${ndprefix}"
1005
+try_static_install() {
1006
+ set_static_archive_urls "${RELEASE_CHANNEL}"
1007
+ progress "Downloading static netdata binary: ${NETDATA_STATIC_ARCHIVE_URL}"
1008
544
- if [ -r "${ndprefix}/etc/netdata/.environment" ] ; then
545
- ndstatic="$(grep IS_NETDATA_STATIC_BINARY "${ndprefix}/etc/netdata/.environment" | cut -d "=" -f 2 | tr -d \")"
546
- if [ -z "${NETDATA_REINSTALL}" ] && [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE}" ] ; then
547
- if [ -n "${NETDATA_CLAIM_TOKEN}" ] ; then
548
- if [ "${ndprefix}" != '/' ] ; then
549
- NETDATA_PREFIX="${ndprefix}"
550
- fi
1009
+ if ! download "${NETDATA_STATIC_ARCHIVE_URL}" "${tmpdir}/netdata-${SYSARCH}-latest.gz.run"; then
1010
+ warning "Unable to download static build archive for ${SYSARCH}."
1011
+ return 2
1012
+ fi
1013
552
- claim
553
- exit $?
554
- elif [ -x "${ndprefix}/usr/libexec/netdata/netdata-updater.sh" ] ; then
555
- progress "Attempting to update existing install instead of creating a new one"
556
- if run ${sudo} "${ndprefix}/usr/libexec/netdata/netdata-updater.sh" --not-running-from-cron ; then
557
- progress "Updated existing install at ${ndpath}"
558
- exit 0
559
- else
560
- fatal "Failed to update existing Netdata install" F0100
561
- fi
562
- else
563
- if [ -z "${NETDATA_ALLOW_DUPLICATE_INSTALL}" ] || [ "${ndstatic}" = "yes" ] ; then
564
- fatal "Existing installation detected which cannot be safely updated by this script. Refusing to continue." F0101
565
- else
566
- progress "User explicitly requested duplicate install, proceeding."
567
- fi
568
- fi
569
- else
570
- if [ "${ndstatic}" = "no" ] ; then
571
- progress "User requested reinstall instead of update, proceeding."
572
- else
573
- fatal "Existing install is a static install. Please use kickstart-static64.sh instead." F0102
574
- fi
575
- fi
1014
+ if ! download "${NETDATA_STATIC_ARCHIVE_CHECKSUM_URL}" "${tmpdir}/sha256sum.txt"; then
1015
+ fatal "Unable to fetch checksums to verify static build archive." F0206
1016
+ fi
1017
+
1018
+ if ! grep "netdata-${SYSARCH}-latest.gz.run" "${tmpdir}/sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then
1019
+ fatal "Static binary checksum validation failed. Usually this is a result of an older copy of the file being cached somewhere upstream and can be resolved by retrying in an hour." F0207
1020
+ fi
1021
+
1022
+ if [ "${INTERACTIVE}" -eq 0 ]; then
1023
+ opts="${opts} --accept"
1024
+ fi
1025
+
1026
+ progress "Installing netdata"
1027
+ # shellcheck disable=SC2086
1028
+ if ! run ${ROOTCMD} sh "${tmpdir}/netdata-${SYSARCH}-latest.gz.run" ${opts} -- ${NETDATA_AUTO_UPDATES:+--auto-update} ${NETDATA_INSTALLER_OPTIONS}; then
1029
+ warning "Failed to install static build of Netdata on ${SYSARCH}."
1030
+ run rm -rf /opt/netdata
1031
+ return 2
1032
+ fi
1033
+
1034
+ install_type_file="/opt/netdata/etc/netdata/.install-type"
1035
+ if [ -f "${install_type_file}" ]; then
1036
+ ${ROOTCMD} sh -c "cat \"${install_type_file}\" > \"${tmpdir}/install-type\""
1037
+ ${ROOTCMD} chown "$(id -u)":"$(id -g)" "${tmpdir}/install-type"
1038
+ # shellcheck disable=SC1091
1039
+ . "${tmpdir}/install-type"
1040
+ cat > "${tmpdir}/install-type" <<- EOF
1041
+ INSTALL_TYPE='kickstart-static'
1042
+ PREBUILT_ARCH='${PREBUILT_ARCH}'
1043
+ EOF
1044
+ ${ROOTCMD} chown netdata:netdata "${tmpdir}/install-type"
1045
+ ${ROOTCMD} cp "${tmpdir}/install-type" "${install_type_file}"
1046
+ fi
1047
+}
1048
+
1049
+# ======================================================================
1050
+# Local build install code
1051
+
1052
+set_source_archive_urls() {
1053
+ if [ "$1" = "stable" ]; then
1054
+ latest="$(get_redirect "https://github.com/netdata/netdata/releases/latest")"
1055
+ export NETDATA_SOURCE_ARCHIVE_URL="https://github.com/netdata/netdata/releases/download/${latest}/netdata-${latest}.tar.gz"
1056
+ export NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/${latest}/sha256sums.txt"
1057
else
577
- progress "Existing install appears to be handled manually or through the system package manager."
578
- if [ -n "${NETDATA_CLAIM_TOKEN}" ] ; then
579
- if [ "${ndprefix}" != '/' ] ; then
580
- NETDATA_PREFIX="${ndprefix}"
581
- fi
1058
+ export NETDATA_SOURCE_ARCHIVE_URL="${NETDATA_TARBALL_BASEURL}/netdata-latest.tar.gz"
1059
+ export NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL="${NETDATA_TARBALL_BASEURL}/sha256sums.txt"
1060
+ fi
1061
+}
1062
+
1063
+install_local_build_dependencies() {
1064
+ bash="$(command -v bash 2> /dev/null)"
1065
+
1066
+ if [ -z "${bash}" ] || [ ! -x "${bash}" ]; then
1067
+ warning "Unable to find a usable version of \`bash\` (required for local build)."
1068
+ return 1
1069
+ fi
1070
+
1071
+ progress "Fetching script to detect required packages..."
1072
+ download "${PACKAGES_SCRIPT}" "${tmpdir}/install-required-packages.sh"
1073
+
1074
+ if [ ! -s "${tmpdir}/install-required-packages.sh" ]; then
1075
+ warning "Downloaded dependency installation script is empty."
1076
+ else
1077
+ progress "Running downloaded script to detect required packages..."
1078
583
- claim
584
- exit $?
585
- elif [ -z "${NETDATA_ALLOW_DUPLICATE_INSTALL}" ] ; then
586
- fatal "Existing installation detected which cannot be safely updated by this script. Refusing to continue." F0103
1079
+ if [ "${INTERACTIVE}" -eq 0 ]; then
1080
+ opts="--dont-wait --non-interactive"
1081
+ fi
1082
+
1083
+ if [ "${SYSTYPE}" = "Darwin" ]; then
1084
+ sudo=""
1085
else
588
- progress "User explicitly requested duplicate install, proceeding."
1086
+ sudo="${ROOTCMD}"
1087
+ fi
1088
+
1089
+ # shellcheck disable=SC2086
1090
+ if ! run ${sudo} "${bash}" "${tmpdir}/install-required-packages.sh" ${opts} netdata; then
1091
+ warning "It failed to install all the required packages, but installation might still be possible."
1092
fi
1093
fi
591
-fi
1094
+}
1095
593
-# ---------------------------------------------------------------------------------------------------------------------
594
-# install required system packages
1096
+build_and_install() {
1097
+ progress "Building netdata"
1098
596
-ndtmpdir=$(create_tmp_directory)
597
-cd "${ndtmpdir}" || exit 1
1099
+ echo "INSTALL_TYPE='kickstart-build'" > system/.install-type
1100
599
-dependencies
1101
+ opts="${NETDATA_INSTALLER_OPTIONS}"
1102
601
-# ---------------------------------------------------------------------------------------------------------------------
602
-# download netdata package
1103
+ if [ "${INTERACTIVE}" -eq 0 ]; then
1104
+ opts="${opts} --dont-wait"
1105
+ fi
1106
604
-if [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE}" ]; then
605
- set_tarball_urls "${RELEASE_CHANNEL}"
1107
+ if [ "${NETDATA_AUTO_UPDATES}" -eq 1 ]; then
1108
+ opts="${opts} --auto-update"
1109
+ fi
1110
607
- download "${NETDATA_TARBALL_CHECKSUM_URL}" "${ndtmpdir}/sha256sum.txt"
608
- download "${NETDATA_TARBALL_URL}" "${ndtmpdir}/netdata-latest.tar.gz"
609
-else
610
- progress "Installation sources were given as input, running installation using \"${NETDATA_LOCAL_TARBALL_OVERRIDE}\""
611
- run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_CHECKSUM}" "${ndtmpdir}/sha256sum.txt"
612
- run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE}" "${ndtmpdir}/netdata-latest.tar.gz"
613
-fi
1111
+ if [ "${RELEASE_CHANNEL}" = "stable" ]; then
1112
+ opts="${opts} --stable-channel"
1113
+ fi
1114
615
-if ! grep netdata-latest.tar.gz "${ndtmpdir}/sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then
616
- fatal "Tarball checksum validation failed. Stopping Netdata Agent installation and leaving tarball in ${ndtmpdir}.\nUsually this is a result of an older copy of the file being cached somewhere upstream and can be resolved by retrying in an hour." F0005
617
-fi
618
-run tar -xf netdata-latest.tar.gz
619
-rm -rf netdata-latest.tar.gz > /dev/null 2>&1
620
-cd netdata-* || fatal "Cannot cd to netdata source tree" F0006
1115
+ if [ "${NETDATA_REQUIRE_CLOUD}" -eq 1 ]; then
1116
+ opts="${opts} --require-cloud"
1117
+ elif [ "${NETDATA_DISABLE_CLOUD}" -eq 1 ]; then
1118
+ opts="${opts} --disable-cloud"
1119
+ fi
1120
622
-# ---------------------------------------------------------------------------------------------------------------------
623
-# install netdata from source
1121
+ # shellcheck disable=SC2086
1122
+ run ${ROOTCMD} ./netdata-installer.sh ${opts}
1123
625
-install() {
626
- progress "Installing netdata..."
627
- run ${sudo} ./netdata-installer.sh ${NETDATA_UPDATES} ${NETDATA_INSTALLER_OPTIONS}
1124
case $? in
1125
1)
1126
fatal "netdata-installer.sh exited with error" F0007
1129
fatal "Insufficient RAM to install netdata" F0008
1130
;;
1131
esac
636
- if [ -d "${ndtmpdir}" ] && [ ! "${ndtmpdir}" = "/" ]; then
637
- run ${sudo} rm -rf "${ndtmpdir}" > /dev/null 2>&1
1132
+}
1133
+
1134
+try_build_install() {
1135
+ if ! install_local_build_dependencies; then
1136
+ return 1
1137
+ fi
1138
+
1139
+ set_source_archive_urls "${RELEASE_CHANNEL}"
1140
+
1141
+ download "${NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL}" "${tmpdir}/sha256sum.txt"
1142
+ download "${NETDATA_SOURCE_ARCHIVE_URL}" "${tmpdir}/netdata-latest.tar.gz"
1143
+
1144
+ if ! grep netdata-latest.tar.gz "${tmpdir}/sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then
1145
+ fatal "Tarball checksum validation failed. Usually this is a result of an older copy of the file being cached somewhere upstream and can be resolved by retrying in an hour." F0005
1146
+ fi
1147
+
1148
+ run tar -xf "${tmpdir}/netdata-latest.tar.gz" -C "${tmpdir}"
1149
+ rm -rf "${tmpdir}/netdata-latest.tar.gz" > /dev/null 2>&1
1150
+ cd "$(find "${tmpdir}" -mindepth 1 -maxdepth 1 -type d -name netdata-)" || fatal "Cannot cd to netdata source tree" F0006
1151
+
1152
+ if [ -x netdata-installer.sh ]; then
1153
+ build_and_install || return 1
1154
+ else
1155
+ # This case is needed because some platforms produce an extra directory on the source tarball extraction.
1156
+ if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ] && [ -x "$(find . -mindepth 1 -maxdepth 1 -type d)/netdata-installer.sh" ]; then
1157
+ cd "$(find . -mindepth 1 -maxdepth 1 -type d)" && build_and_install || return 1
1158
+ else
1159
+ fatal "Cannot install netdata from source (the source directory does not include netdata-installer.sh). Leaving all files in ${tmpdir}" F0009
1160
+ fi
1161
fi
1162
}
1163
641
-if [ -x netdata-installer.sh ]; then
642
- echo "INSTALL_TYPE='kickstart-build'" > system/.install-type
643
- install "$@"
644
-else
645
- if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ] && [ -x "$(find . -mindepth 1 -maxdepth 1 -type d)/netdata-installer.sh" ]; then
646
- cd "$(find . -mindepth 1 -maxdepth 1 -type d)" && install "$@"
1164
+# ======================================================================
1165
+# Per system-type install logic
1166
+
1167
+install_on_linux() {
1168
+ if [ "${NETDATA_ONLY_STATIC}" -ne 1 ] && [ "${NETDATA_ONLY_BUILD}" -ne 1 ]; then
1169
+ SELECTED_INSTALL_METHOD="native"
1170
+ try_package_install
1171
+
1172
+ case "$?" in
1173
+ 0)
1174
+ NETDATA_INSTALL_SUCCESSFUL=1
1175
+ ;;
1176
+ 1)
1177
+ fatal "Unable to install on this system." F0300
1178
+ ;;
1179
+ 2)
1180
+ if [ "${NETDATA_ONLY_NATIVE}" -eq 1 ]; then
1181
+ fatal "Could not install native binary packages." F0301
1182
+ else
1183
+ warning "Could not install native binary packages, falling back to alternative installation method."
1184
+ fi
1185
+ ;;
1186
+ esac
1187
+ fi
1188
+
1189
+ if [ "${NETDATA_ONLY_NATIVE}" -ne 1 ] && [ "${NETDATA_ONLY_BUILD}" -ne 1 ] && [ -z "${NETDATA_INSTALL_SUCCESSFUL}" ]; then
1190
+ SELECTED_INSTALL_METHOD="static"
1191
+ INSTALL_TYPE="kickstart-static"
1192
+ try_static_install
1193
+
1194
+ case "$?" in
1195
+ 0)
1196
+ NETDATA_INSTALL_SUCCESSFUL=1
1197
+ INSTALL_PREFIX="/opt/netdata"
1198
+ ;;
1199
+ 1)
1200
+ fatal "Unable to install on this system." F0302
1201
+ ;;
1202
+ 2)
1203
+ if [ "${NETDATA_ONLY_STATIC}" -eq 1 ]; then
1204
+ fatal "Could not install static build." F0303
1205
+ else
1206
+ warning "Could not install static build, falling back to alternative installation method."
1207
+ fi
1208
+ ;;
1209
+ esac
1210
+ fi
1211
+
1212
+ if [ "${NETDATA_ONLY_NATIVE}" -ne 1 ] && [ "${NETDATA_ONLY_STATIC}" -ne 1 ] && [ -z "${NETDATA_INSTALL_SUCCESSFUL}" ]; then
1213
+ SELECTED_INSTALL_METHOD="build"
1214
+ INSTALL_TYPE="kickstart-build"
1215
+ try_build_install
1216
+
1217
+ case "$?" in
1218
+ 0)
1219
+ NETDATA_INSTALL_SUCCESSFUL=1
1220
+ ;;
1221
+ *)
1222
+ fatal "Unable to install on this system." F0304
1223
+ ;;
1224
+ esac
1225
+ fi
1226
+}
1227
+
1228
+install_on_macos() {
1229
+ if [ "${NETDATA_ONLY_NATIVE}" -eq 1 ]; then
1230
+ fatal "User requested native package, but native packages are not available for macOS. Try installing without \`--only-native\` option." F0305
1231
+ elif [ "${NETDATA_ONLY_STATIC}" -eq 1 ]; then
1232
+ fatal "User requested static build, but static builds are not available for macOS. Try installing without \`--only-static\` option." F0306
1233
else
648
- fatal "Cannot install netdata from source (the source directory does not include netdata-installer.sh). Leaving all files in ${ndtmpdir}" F0009
649
- exit 1
1234
+ SELECTED_INSTALL_METHOD="build"
1235
+ INSTALL_TYPE="kickstart-build"
1236
+ try_build_install
1237
+
1238
+ case "$?" in
1239
+ 0)
1240
+ NETDATA_INSTALL_SUCCESSFUL=1
1241
+ ;;
1242
+ *)
1243
+ fatal "Unable to install on this system." F0307
1244
+ ;;
1245
+ esac
1246
fi
651
-fi
1247
+}
1248
+
1249
+install_on_freebsd() {
1250
+ if [ "${NETDATA_ONLY_NATIVE}" -eq 1 ]; then
1251
+ fatal "User requested native package, but native packages are not available for FreeBSD. Try installing without \`--only-native\` option." F0308
1252
+ elif [ "${NETDATA_ONLY_STATIC}" -eq 1 ]; then
1253
+ fatal "User requested static build, but static builds are not available for FreeBSD. Try installing without \`--only-static\` option." F0309
1254
+ else
1255
+ SELECTED_INSTALL_METHOD="build"
1256
+ INSTALL_TYPE="kickstart-build"
1257
+ try_build_install
1258
+
1259
+ case "$?" in
1260
+ 0)
1261
+ NETDATA_INSTALL_SUCCESSFUL=1
1262
+ ;;
1263
+ *)
1264
+ fatal "Unable to install on this system." F030A
1265
+ ;;
1266
+ esac
1267
+ fi
1268
+}
1269
+
1270
+# ======================================================================
1271
+# Main program
1272
653
-# --------------------------------------------------------------------------------------------------------------------
1273
+setup_terminal || echo > /dev/null
1274
+
1275
+while [ -n "${1}" ]; do
1276
+ case "${1}" in
1277
+ "--help")
1278
+ usage
1279
+ cleanup
1280
+ trap - EXIT
1281
+ exit 0
1282
+ ;;
1283
+ "--no-cleanup") NO_CLEANUP=1 ;;
1284
+ "--dont-wait"|"--non-interactive") INTERACTIVE=0 ;;
1285
+ "--interactive") INTERACTIVE=1 ;;
1286
+ "--stable-channel") RELEASE_CHANNEL="stable" ;;
1287
+ "--no-updates") NETDATA_AUTO_UPDATES=0 ;;
1288
+ "--auto-update") NETDATA_AUTO_UPDATES="1" ;;
1289
+ "--reinstall") NETDATA_REINSTALL=1 ;;
1290
+ "--reinstall-even-if-unsafe") NETDATA_UNSAFE_REINSTALL=1 ;;
1291
+ "--claim-only") NETDATA_CLAIM_ONLY=1 ;;
1292
+ "--disable-cloud")
1293
+ NETDATA_DISABLE_CLOUD=1
1294
+ NETDATA_REQUIRE_CLOUD=0
1295
+ ;;
1296
+ "--require-cloud")
1297
+ NETDATA_DISABLE_CLOUD=0
1298
+ NETDATA_REQUIRE_CLOUD=1
1299
+ ;;
1300
+ "--dont-start-it")
1301
+ NETDATA_NO_START=1
1302
+ NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --dont-start-it"
1303
+ ;;
1304
+ "--disable-telemetry")
1305
+ NETDATA_DISABLE_TELEMETRY="1"
1306
+ NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --disable-telemetry"
1307
+ ;;
1308
+ "--install")
1309
+ INSTALL_PREFIX="${2}"
1310
+ shift 1
1311
+ ;;
1312
+ "--native-only")
1313
+ NETDATA_ONLY_NATIVE=1
1314
+ NETDATA_ONLY_STATIC=0
1315
+ NETDATA_ONLY_BUILD=0
1316
+ SELECTED_INSTALL_METHOD="native"
1317
+ ;;
1318
+ "--static-only")
1319
+ NETDATA_ONLY_STATIC=1
1320
+ NETDATA_ONLY_NATIVE=0
1321
+ NETDATA_ONLY_BUILD=0
1322
+ SELECTED_INSTALL_METHOD="static"
1323
+ ;;
1324
+ "--build-only")
1325
+ NETDATA_ONLY_BUILD=1
1326
+ NETDATA_ONLY_NATIVE=0
1327
+ NETDATA_ONLY_STATIC=0
1328
+ SELECTED_INSTALL_METHOD="build"
1329
+ ;;
1330
+ "--claim-token")
1331
+ NETDATA_CLAIM_TOKEN="${2}"
1332
+ shift 1
1333
+ ;;
1334
+ "--claim-rooms")
1335
+ NETDATA_CLAIM_ROOMS="${2}"
1336
+ shift 1
1337
+ ;;
1338
+ "--claim-url")
1339
+ NETDATA_CLAIM_URL="${2}"
1340
+ shift 1
1341
+ ;;
1342
+ "--claim-*")
1343
+ optname="$(echo "${1}" | cut -d '-' -f 4-)"
1344
+ case "${optname}" in
1345
+ id|proxy|user|hostname)
1346
+ NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -${optname} ${2}"
1347
+ shift 1
1348
+ ;;
1349
+ verbose|insecure|noproxy|noreload|daemon-not-running)
1350
+ NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -${optname}"
1351
+ ;;
1352
+ *)
1353
+ warning "Ignoring unrecognized claiming option ${optname}"
1354
+ ;;
1355
+ esac
1356
+ ;;
1357
+ *)
1358
+ warning "Passing unrecognized option '${1}' to installer script. If this is intended, please add it to \$NETDATA_INSTALLER_OPTIONS instead."
1359
+ NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} ${1}"
1360
+ ;;
1361
+ esac
1362
+ shift 1
1363
+done
1364
+
1365
+check_claim_opts
1366
+confirm_root_support
1367
+get_system_info
1368
+confirm_install_prefix
1369
+
1370
+tmpdir="$(create_tmp_directory)"
1371
+progress "Using ${tmpdir} as a temporary directory."
1372
+cd "${tmpdir}" || exit 1
1373
+
1374
+handle_existing_install
1375
+
1376
+case "${SYSTYPE}" in
1377
+ Linux) install_on_linux ;;
1378
+ Darwin) install_on_macos ;;
1379
+ FreeBSD) install_on_freebsd ;;
1380
+esac
1381
1382
if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then
1383
claim
1384
+elif [ "${NETDATA_DISABLE_CLOUD}" -eq 1 ]; then
1385
+ soft_disable_cloud
1386
fi
1387
+
1388
+telemetry_event INSTALL_SUCCESS "" ""
1389
+cleanup
1390
+trap - EXIT