1
-#!/usr/bin/env sh
1
+#!/usr/bin/env bash
2
# SPDX-License-Identifier: GPL-3.0-or-later
3
#
4
# Run me with:
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
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
47
+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
53
81
setup_terminal || echo > /dev/null
82
83
# -----------------------------------------------------------------------------
84
+telemetry_event() {
85
+ if [ -n "${NETDATA_DISABLE_TELEMETRY}" ]; then
86
+ return 0
87
+ fi
88
+
89
+ if [ -e "/etc/os-release" ]; then
90
+ eval "$(grep -E "^(NAME|ID|ID_LIKE|VERSION|VERSION_ID)=" < /etc/os-release | sed 's/^/HOST_/')"
91
+ fi
92
+
93
+ if [ -z "${HOST_NAME}" ] || [ -z "${HOST_VERSION}" ] || [ -z "${HOST_ID}" ]; then
94
+ if [ -f "/etc/lsb-release" ]; then
95
+ DISTRIB_ID="unknown"
96
+ DISTRIB_RELEASE="unknown"
97
+ DISTRIB_CODENAME="unknown"
98
+ eval "$(grep -E "^(DISTRIB_ID|DISTRIB_RELEASE|DISTRIB_CODENAME)=" < /etc/lsb-release)"
99
+ if [ -z "${HOST_NAME}" ]; then HOST_NAME="${DISTRIB_ID}"; fi
100
+ if [ -z "${HOST_VERSION}" ]; then HOST_VERSION="${DISTRIB_RELEASE}"; fi
101
+ if [ -z "${HOST_ID}" ]; then HOST_ID="${DISTRIB_CODENAME}"; fi
102
+ fi
103
+ fi
104
+
105
+ KERNEL_NAME="$(uname -s)"
106
+
107
+ if [ "${KERNEL_NAME}" = FreeBSD ]; then
108
+ TOTAL_RAM="$(sysctl -n hw.physmem)"
109
+ elif [ "${KERNEL_NAME}" = Darwin ]; then
110
+ TOTAL_RAM="$(sysctl -n hw.memsize)"
111
+ elif [ -r /proc/meminfo ]; then
112
+ TOTAL_RAM="$(grep -F MemTotal /proc/meminfo | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | cut -f 1 -d ' ')"
113
+ TOTAL_RAM="$((TOTAL_RAM * 1024))"
114
+ fi
115
+
116
+ if [ -f /etc/machine-id ]; then
117
+ DISTINCT_ID="$(cat /etc/machine-id)"
118
+ elif command -v uuidgen 2> /dev/null; then
119
+ DISTINCT_ID="$(uuidgen)"
120
+ else
121
+ DISTINCT_ID="null"
122
+ fi
123
+
124
+ REQ_BODY="$(cat << EOF
125
+{
126
+ "api_key": "${TELEMETRY_API_KEY}",
127
+ "event": "${1}",
128
+ "properties": {
129
+ "distinct_id": "${DISTINCT_ID}",
130
+ "event_source": "agent installer",
131
+ "\$current_url": "agent installer",
132
+ "\$pathname": "netdata-installer",
133
+ "\$host": "installer.netdata.io",
134
+ "\$ip": "127.0.0.1",
135
+ "script_variant": "legacy-kickstart",
136
+ "error_code": "${2}",
137
+ "error_message": "${3}",
138
+ "install_options": "${KICKSTART_OPTIONS}",
139
+ "netdata_release_channel": "${RELEASE_CHANNEL:-null}",
140
+ "netdata_install_type": "kickstart-build",
141
+ "host_os_name": "${HOST_NAME:-unknown}",
142
+ "host_os_id": "${HOST_ID:-unknown}",
143
+ "host_os_id_like": "${HOST_ID_LIKE:-unknown}",
144
+ "host_os_version": "${HOST_VERSION:-unknown}",
145
+ "host_os_version_id": "${HOST_VERSION_ID:-unknown}",
146
+ "system_kernel_name": "${KERNEL_NAME}",
147
+ "system_kernel_version": "$(uname -r)",
148
+ "system_architecture": "$(uname -m)",
149
+ "system_total_ram": "${TOTAL_RAM:-unknown}"
150
+ }
151
+}
152
+EOF
153
+)"
154
+
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
166
+}
167
+
168
fatal() {
80
- printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${*} \n\n"
169
+ printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${1} \n\n"
170
+ telemetry_event "INSTALL_FAILED" "${1}" "${2}"
171
exit 1
172
}
173
232
return ${ret}
233
}
234
145
-fatal() {
146
- printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${*} \n\n"
147
- exit 1
148
-}
149
-
235
warning() {
236
printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} WARNING ${TPUT_RESET} ${*} \n\n"
237
if [ "${INTERACTIVE}" = "0" ]; then
153
- fatal "Stopping due to non-interactive mode. Fix the issue or retry installation in an interactive mode."
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..."
285
url="${1}"
286
dest="${2}"
287
if command -v curl > /dev/null 2>&1; then
203
- run curl -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}"
288
+ run curl -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}" || fatal "Cannot download ${url}" F0002
289
elif command -v wget > /dev/null 2>&1; then
205
- run wget -T 15 -O "${dest}" "${url}" || fatal "Cannot download ${url}"
290
+ run wget -T 15 -O "${dest}" "${url}" || fatal "Cannot download ${url}" F0002
291
else
207
- fatal "I need curl or wget to proceed, but neither is available on this system."
292
+ fatal "I need curl or wget to proceed, but neither is available on this system." F0003
293
fi
294
}
295
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
271
- fatal "Invalid given dependency file, please check your --local-files parameter options and try again"
356
+ fatal "Invalid given dependency file, please check your --local-files parameter options and try again" F1001
357
fi
358
else
359
download "${PACKAGES_SCRIPT}" "${ndtmpdir}/install-required-packages.sh"
381
elif command -v shasum > /dev/null 2>&1; then
382
shasum -a 256 "$@"
383
else
299
- fatal "I could not find a suitable checksum binary to use"
384
+ fatal "I could not find a suitable checksum binary to use" F0004
385
fi
386
}
387
459
NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --disable-cloud"
460
NETDATA_DISABLE_CLOUD=1
461
;;
462
+ "--disable-telemetry")
463
+ NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --disable-telemetry"
464
+ NETDATA_DISABLE_TELEMETRY=1
465
+ ;;
466
"--local-files")
467
if [ -z "${2}" ]; then
379
- 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"
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
470
471
export NETDATA_LOCAL_TARBALL_OVERRIDE="${2}"
472
473
if [ -z "${3}" ]; then
385
- 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"
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
475
fi
476
477
export NETDATA_LOCAL_TARBALL_OVERRIDE_CHECKSUM="${3}"
478
479
if [ -z "${4}" ]; then
391
- 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"
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
482
483
export NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN="${4}"
484
485
if [ -z "${5}" ]; then
397
- 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"
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
488
489
export NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG="${5}"
490
491
if [ -z "${6}" ]; then
403
- 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"
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
493
fi
494
495
export NETDATA_LOCAL_TARBALL_OVERRIDE_DEPS_SCRIPT="${6}"
515
fi
516
fi
517
429
-# shellcheck disable=SC2235,SC2030
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
557
progress "Updated existing install at ${ndpath}"
558
exit 0
559
else
471
- fatal "Failed to update existing Netdata install"
472
- exit 1
560
+ fatal "Failed to update existing Netdata install" F0100
561
fi
562
else
563
if [ -z "${NETDATA_ALLOW_DUPLICATE_INSTALL}" ] || [ "${ndstatic}" = "yes" ] ; then
476
- fatal "Existing installation detected which cannot be safely updated by this script, refusing to continue."
477
- exit 1
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
570
if [ "${ndstatic}" = "no" ] ; then
571
progress "User requested reinstall instead of update, proceeding."
572
else
486
- fatal "Existing install is a static install, please use kickstart-static64.sh instead."
487
- exit 1
573
+ fatal "Existing install is a static install. Please use kickstart-static64.sh instead." F0102
574
fi
575
fi
576
else
583
claim
584
exit $?
585
elif [ -z "${NETDATA_ALLOW_DUPLICATE_INSTALL}" ] ; then
500
- fatal "Existing installation detected which cannot be safely updated by this script, refusing to continue."
501
- exit 1
586
+ fatal "Existing installation detected which cannot be safely updated by this script. Refusing to continue." F0103
587
else
588
progress "User explicitly requested duplicate install, proceeding."
589
fi
613
fi
614
615
if ! grep netdata-latest.tar.gz "${ndtmpdir}/sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then
531
- 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."
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
535
-cd netdata-* || fatal "Cannot cd to netdata source tree"
620
+cd netdata-* || fatal "Cannot cd to netdata source tree" F0006
621
622
# ---------------------------------------------------------------------------------------------------------------------
623
# install netdata from source
624
625
install() {
626
progress "Installing netdata..."
542
- run ${sudo} ./netdata-installer.sh ${NETDATA_UPDATES} ${NETDATA_INSTALLER_OPTIONS} || fatal "netdata-installer.sh exited with error"
627
+ run ${sudo} ./netdata-installer.sh ${NETDATA_UPDATES} ${NETDATA_INSTALLER_OPTIONS}
628
+ case $? in
629
+ 1)
630
+ fatal "netdata-installer.sh exited with error" F0007
631
+ ;;
632
+ 2)
633
+ fatal "Insufficient RAM to install netdata" F0008
634
+ ;;
635
+ esac
636
if [ -d "${ndtmpdir}" ] && [ ! "${ndtmpdir}" = "/" ]; then
637
run ${sudo} rm -rf "${ndtmpdir}" > /dev/null 2>&1
638
fi
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 "$@"
647
else
555
- fatal "Cannot install netdata from source (the source directory does not include netdata-installer.sh). Leaving all files in ${ndtmpdir}"
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
650
fi
651
fi