1
#!/bin/sh
2
#
3
# SPDX-License-Identifier: GPL-3.0-or-later
4
+#
5
+# Next unused error code: F050A
6
7
# ======================================================================
8
# Constants
10
AGENT_BUG_REPORT_URL="https://github.com/netdata/netdata/issues/new/choose"
11
CLOUD_BUG_REPORT_URL="https://github.com/netdata/netdata-cloud/issues/new/choose"
12
DEFAULT_RELEASE_CHANNEL="nightly"
11
-DISCUSSIONS_URL="https://github.com/netdata/netdata/discussions"
13
DISCORD_INVITE="https://discord.gg/5ygS846fR6"
14
+DISCUSSIONS_URL="https://github.com/netdata/netdata/discussions"
15
+DISCUSSIONS_URL="https://github.com/netdata/netdata/discussions"
16
DOCS_URL="https://learn.netdata.cloud/docs/"
17
FORUM_URL="https://community.netdata.cloud/"
18
KICKSTART_OPTIONS="${*}"
19
+KICKSTART_SOURCE="$(realpath "$0")"
20
PACKAGES_SCRIPT="https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/install-required-packages.sh"
21
PATH="${PATH}:/usr/local/bin:/usr/local/sbin"
22
PUBLIC_CLOUD_URL="https://app.netdata.cloud"
23
REPOCONFIG_URL_PREFIX="https://packagecloud.io/netdata/netdata-repoconfig/packages"
24
REPOCONFIG_VERSION="1-1"
21
-TELEMETRY_URL="https://posthog.netdata.cloud/capture/"
25
START_TIME="$(date +%s)"
26
+STATIC_INSTALL_ARCHES="x86_64 armv7l aarch64 ppc64le"
27
+TELEMETRY_URL="https://posthog.netdata.cloud/capture/"
28
29
# ======================================================================
30
# Defaults for environment variables
40
NETDATA_ONLY_BUILD=0
41
NETDATA_ONLY_NATIVE=0
42
NETDATA_ONLY_STATIC=0
43
+NETDATA_OFFLINE_INSTALL_SOURCE=""
44
NETDATA_REQUIRE_CLOUD=1
45
NETDATA_WARNINGS=""
46
RELEASE_CHANNEL="default"
68
fi
69
70
main() {
65
- if [ "${ACTION}" = "uninstall" ]; then
66
- uninstall
67
- printf >&2 "Finished uninstalling the Netdata Agent."
68
- deferred_warnings
69
- cleanup
70
- trap - EXIT
71
- exit 0
72
- fi
73
-
74
- if [ "${ACTION}" = "reinstall-clean" ]; then
75
- NEW_INSTALL_PREFIX="${INSTALL_PREFIX}"
76
- uninstall
77
- cleanup
71
+ case "${ACTION}" in
72
+ uninstall)
73
+ uninstall
74
+ printf >&2 "Finished uninstalling the Netdata Agent."
75
+ deferred_warnings
76
+ cleanup
77
+ trap - EXIT
78
+ exit 0
79
+ ;;
80
+ reinstall-clean)
81
+ NEW_INSTALL_PREFIX="${INSTALL_PREFIX}"
82
+ uninstall
83
+ cleanup
84
79
- ACTION=
80
- INSTALL_PREFIX="${NEW_INSTALL_PREFIX}"
81
- # shellcheck disable=SC2086
82
- main
85
+ ACTION=
86
+ INSTALL_PREFIX="${NEW_INSTALL_PREFIX}"
87
+ # shellcheck disable=SC2086
88
+ main
89
84
- trap - EXIT
85
- exit 0
86
- fi
90
+ trap - EXIT
91
+ exit 0
92
+ ;;
93
+ prepare-offline)
94
+ prepare_offline_install_source "${OFFLINE_TARGET}"
95
+ deferred_warnings
96
+ trap - EXIT
97
+ exit 0
98
+ ;;
99
+ esac
100
101
tmpdir="$(create_tmp_directory)"
102
progress "Using ${tmpdir} as a temporary directory."
132
USAGE: kickstart.sh [options]
133
where options include:
134
122
- --non-interactive Do not prompt for user input. (default: prompt if there is a controlling terminal)
123
- --interactive Prompt for user input even if there is no controlling terminal.
124
- --dont-start-it Do not start the agent by default (only for static installs or local builds)
125
- --dry-run Report what we would do with the given options on this system, but don’t actually do anything.
126
- --release-channel Specify the release channel to use for the install (default: ${DEFAULT_RELEASE_CHANNEL})
127
- --stable-channel Equivalent to "--release-channel stable"
128
- --nightly-channel Equivalent to "--release-channel nightly"
129
- --no-updates Do not enable automatic updates (default: enable automatic updates using the best supported scheduling method)
130
- --auto-update Enable automatic updates.
131
- --auto-update-type Specify a particular scheduling type for auto-updates (valid types: systemd, interval, crontab)
132
- --disable-telemetry Opt-out of anonymous statistics.
133
- --repositories-only Only install appropriate repository configuration packages (only for native install).
134
- --native-only Only install if native binary packages are available.
135
- --static-only Only install if a static build is available.
136
- --build-only Only install using a local build.
137
- --reinstall Explicitly reinstall instead of updating any existing install.
138
- --reinstall-even-if-unsafe Even try to reinstall if we don't think we can do so safely (implies --reinstall).
139
- --disable-cloud Disable support for Netdata Cloud (default: detect)
140
- --require-cloud Only install if Netdata Cloud can be enabled. Overrides --disable-cloud.
141
- --install <path> This option is deprecated and will be removed in a future version, use --install-prefix instead.
142
- --install-prefix <path> Specify an installation prefix for local builds (default: autodetect based on system type).
143
- --old-install-prefix <path> Specify an old local builds installation prefix for uninstall/reinstall (if it's not default).
144
- --install-version <version> Specify the version of Netdata to install.
145
- --claim-token Use a specified token for claiming to Netdata Cloud.
146
- --claim-rooms When claiming, add the node to the specified rooms.
147
- --claim-only If there is an existing install, only try to claim it, not update it.
148
- --claim-* Specify other options for the claiming script.
149
- --no-cleanup Don't do any cleanup steps. This is intended to help with debugging the installer.
150
- --uninstall Uninstall an existing installation of Netdata.
151
- --reinstall-clean Clean reinstall Netdata.
152
- --local-build-options Specify additional options to pass to the installer code when building locally. Only valid if --build-only is also specified.
153
- --static-install-options Specify additional options to pass to the static installer code. Only valid if --static-only is also specified.
135
+ --non-interactive Do not prompt for user input. (default: prompt if there is a controlling terminal)
136
+ --interactive Prompt for user input even if there is no controlling terminal.
137
+ --dont-start-it Do not start the agent by default (only for static installs or local builds)
138
+ --dry-run Report what we would do with the given options on this system, but don’t actually do anything.
139
+ --release-channel Specify the release channel to use for the install (default: ${DEFAULT_RELEASE_CHANNEL})
140
+ --stable-channel Equivalent to "--release-channel stable"
141
+ --nightly-channel Equivalent to "--release-channel nightly"
142
+ --no-updates Do not enable automatic updates (default: enable automatic updates using the best supported scheduling method)
143
+ --auto-update Enable automatic updates.
144
+ --auto-update-type Specify a particular scheduling type for auto-updates (valid types: systemd, interval, crontab)
145
+ --disable-telemetry Opt-out of anonymous statistics.
146
+ --repositories-only Only install appropriate repository configuration packages (only for native install).
147
+ --native-only Only install if native binary packages are available.
148
+ --static-only Only install if a static build is available.
149
+ --build-only Only install using a local build.
150
+ --reinstall Explicitly reinstall instead of updating any existing install.
151
+ --reinstall-even-if-unsafe Even try to reinstall if we don't think we can do so safely (implies --reinstall).
152
+ --disable-cloud Disable support for Netdata Cloud (default: detect)
153
+ --require-cloud Only install if Netdata Cloud can be enabled. Overrides --disable-cloud.
154
+ --install <path> This option is deprecated and will be removed in a future version, use --install-prefix instead.
155
+ --install-prefix <path> Specify an installation prefix for local builds (default: autodetect based on system type).
156
+ --old-install-prefix <path> Specify an old local builds installation prefix for uninstall/reinstall (if it's not default).
157
+ --install-version <version> Specify the version of Netdata to install.
158
+ --claim-token Use a specified token for claiming to Netdata Cloud.
159
+ --claim-rooms When claiming, add the node to the specified rooms.
160
+ --claim-only If there is an existing install, only try to claim it, not update it.
161
+ --claim-* Specify other options for the claiming script.
162
+ --no-cleanup Don't do any cleanup steps. This is intended to help with debugging the installer.
163
+ --uninstall Uninstall an existing installation of Netdata.
164
+ --reinstall-clean Clean reinstall Netdata.
165
+ --local-build-options Specify additional options to pass to the installer code when building locally. Only valid if --build-only is also specified.
166
+ --static-install-options Specify additional options to pass to the static installer code. Only valid if --static-only is also specified.
167
+ --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.
168
169
Additionally, this script may use the following environment variables:
170
491
492
check_for_remote_file() {
493
url="${1}"
480
- if command -v curl > /dev/null 2>&1; then
494
+
495
+ if echo "${url}" | grep -Eq "^file:///"; then
496
+ [ -e "${url#file://}" ] || return 1
497
+ elif command -v curl > /dev/null 2>&1; then
498
curl --output /dev/null --silent --head --fail "${url}" || return 1
499
elif command -v wget > /dev/null 2>&1; then
500
wget -S --spider "${url}" 2>&1 | grep -q 'HTTP/1.1 200 OK' || return 1
506
download() {
507
url="${1}"
508
dest="${2}"
492
- if command -v curl > /dev/null 2>&1; then
509
+
510
+ if echo "${url}" | grep -Eq "^file:///"; then
511
+ run cp "${url#file://}" "${dest}" || return 1
512
+ elif command -v curl > /dev/null 2>&1; then
513
run curl --fail -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}" || return 1
514
elif command -v wget > /dev/null 2>&1; then
515
run wget -T 15 -O "${dest}" "${url}" || return 1
1409
# Static build install code
1410
# shellcheck disable=SC2034,SC2086,SC2126
1411
set_static_archive_urls() {
1392
- if [ "$1" = "stable" ]; then
1412
+ if [ -z "${2}" ]; then
1413
+ arch="${SYSARCH}"
1414
+ else
1415
+ arch="${2}"
1416
+ fi
1417
+
1418
+ if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
1419
+ path="$(cd "${NETDATA_OFFLINE_INSTALL_SOURCE}" || exit 1; pwd)"
1420
+ export NETDATA_STATIC_ARCHIVE_URL="file://${path}/netdata-${arch}-latest.gz.run"
1421
+ export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="file://${path}/sha256sums.txt"
1422
+ elif [ "${1}" = "stable" ]; then
1423
if [ -n "${INSTALL_VERSION}" ]; then
1424
export NETDATA_STATIC_ARCHIVE_OLD_URL="https://github.com/netdata/netdata/releases/download/v${INSTALL_VERSION}/netdata-v${INSTALL_VERSION}.gz.run"
1395
- export NETDATA_STATIC_ARCHIVE_URL="https://github.com/netdata/netdata/releases/download/v${INSTALL_VERSION}/netdata-${SYSARCH}-v${INSTALL_VERSION}.gz.run"
1425
+ export NETDATA_STATIC_ARCHIVE_URL="https://github.com/netdata/netdata/releases/download/v${INSTALL_VERSION}/netdata-${arch}-v${INSTALL_VERSION}.gz.run"
1426
export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/v${INSTALL_VERSION}/sha256sums.txt"
1427
else
1428
latest="$(get_redirect "https://github.com/netdata/netdata/releases/latest")"
1399
- export NETDATA_STATIC_ARCHIVE_URL="https://github.com/netdata/netdata/releases/download/${latest}/netdata-${SYSARCH}-latest.gz.run"
1429
+ export NETDATA_STATIC_ARCHIVE_URL="https://github.com/netdata/netdata/releases/download/${latest}/netdata-${arch}-latest.gz.run"
1430
export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/${latest}/sha256sums.txt"
1431
fi
1432
else
1433
if [ -n "${INSTALL_VERSION}" ]; then
1404
- export NETDATA_STATIC_ARCHIVE_URL="${NETDATA_TARBALL_BASEURL}/netdata-${SYSARCH}-v${INSTALL_VERSION}.gz.run"
1434
+ export NETDATA_STATIC_ARCHIVE_URL="${NETDATA_TARBALL_BASEURL}/netdata-${arch}-v${INSTALL_VERSION}.gz.run"
1435
export NETDATA_STATIC_ARCHIVE_OLD_URL="${NETDATA_TARBALL_BASEURL}/netdata-v${INSTALL_VERSION}.gz.run"
1436
export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="${NETDATA_TARBALL_BASEURL}/sha256sums.txt"
1437
else
1408
- export NETDATA_STATIC_ARCHIVE_URL="${NETDATA_TARBALL_BASEURL}/netdata-${SYSARCH}-latest.gz.run"
1438
+ export NETDATA_STATIC_ARCHIVE_URL="${NETDATA_TARBALL_BASEURL}/netdata-${arch}-latest.gz.run"
1439
export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="${NETDATA_TARBALL_BASEURL}/sha256sums.txt"
1440
fi
1441
fi
1451
1452
# Check status code first, so that we can provide nicer fallback for dry runs.
1453
if check_for_remote_file "${NETDATA_STATIC_ARCHIVE_URL}"; then
1424
- if [ -n "${INSTALL_VERSION}" ]; then
1454
+ if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
1455
+ netdata_agent="$(basename "${NETDATA_STATIC_ARCHIVE_URL#"file://"}")"
1456
+ elif [ -n "${INSTALL_VERSION}" ]; then
1457
if [ "${SELECTED_RELEASE_CHANNEL}" = "stable" ]; then
1458
netdata_agent="${NETDATA_STATIC_ARCHIVE_URL#"https://github.com/netdata/netdata/releases/download/v${INSTALL_VERSION}/"}"
1459
else
1685
fi
1686
}
1687
1688
+# ======================================================================
1689
+# Offline install support code
1690
+
1691
+prepare_offline_install_source() {
1692
+ if [ -e "${1}" ]; then
1693
+ if [ ! -d "${1}" ]; then
1694
+ fatal "${1} is not a directory, unable to prepare offline install source." F0503
1695
+ fi
1696
+ else
1697
+ run mkdir -p "${1}" || fatal "Unable to create target directory for offline install preparation." F0504
1698
+ fi
1699
+
1700
+ run cd "${1}" || fatal "Failed to swtich to target directory for offline install preparation." F0505
1701
+
1702
+ if [ "${NETDATA_ONLY_NATIVE}" -ne 1 ] && [ "${NETDATA_ONLY_BUILD}" -ne 1 ]; then
1703
+ set_static_archive_urls "${SELECTED_RELEASE_CHANNEL}" "x86_64"
1704
+
1705
+ if check_for_remote_file "${NETDATA_STATIC_ARCHIVE_URL}"; then
1706
+ for arch in ${STATIC_INSTALL_ARCHES}; do
1707
+ set_static_archive_urls "${SELECTED_RELEASE_CHANNEL}" "${arch}"
1708
+
1709
+ progress "Fetching ${NETDATA_STATIC_ARCHIVE_URL}"
1710
+ if ! download "${NETDATA_STATIC_ARCHIVE_URL}" "netdata-${arch}-latest.gz.run"; then
1711
+ warning "Failed to download static installer archive for ${arch}."
1712
+ fi
1713
+ done
1714
+ legacy=0
1715
+ else
1716
+ 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."
1717
+ progress "Fetching ${NETDATA_STATIC_ARCHIVE_OLD_URL}"
1718
+ legacy=1
1719
+
1720
+ if ! download "${NETDATA_STATIC_ARCHIVE_OLD_URL}" "netdata-x86_64-latest.gz.run"; then
1721
+ warning "Failed to download static installer archive for x86_64."
1722
+ fi
1723
+ fi
1724
+
1725
+ progress "Fetching ${NETDATA_STATIC_ARCHIVE_CHECKSUM_URL}"
1726
+ if ! download "${NETDATA_STATIC_ARCHIVE_CHECKSUM_URL}" "sha256sums.txt"; then
1727
+ fatal "Failed to download checksum file." F0506
1728
+ fi
1729
+ fi
1730
+
1731
+ if [ "${legacy:-0}" -eq 1 ]; then
1732
+ sed -e 's/netdata-latest.gz.run/netdata-x86_64-latest.gz.run' sha256sums.txt > sha256sums.tmp
1733
+ mv sha256sums.tmp sha256sums.txt
1734
+ fi
1735
+
1736
+ if [ "${DRY_RUN}" -ne 1 ]; then
1737
+ progress "Verifying checksums."
1738
+ if ! grep -e "$(find . -name '*.gz.run')" sha256sums.txt | safe_sha256sum -c -; then
1739
+ fatal "Checksums for offline install files are incorrect. 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." F0507
1740
+ fi
1741
+ else
1742
+ progress "Would verify SHA256 checksums of downloaded installation files."
1743
+ fi
1744
+
1745
+ if [ "${DRY_RUN}" -ne 1 ]; then
1746
+ progress "Preparing install script."
1747
+ cat > "install.sh" <<-EOF
1748
+ #!/bin/sh
1749
+ dir=\$(CDPATH= cd -- "\$(dirname -- "\$0")" && pwd)
1750
+ "\${dir}/kickstart.sh" --offline-install-source "\${dir}" \${@}
1751
+ EOF
1752
+ chmod +x "install.sh"
1753
+ else
1754
+ progress "Would create install script"
1755
+ fi
1756
+
1757
+ if [ "${DRY_RUN}" -ne 1 ]; then
1758
+ progress "Copying kickstart script."
1759
+ cp "${KICKSTART_SOURCE}" "kickstart.sh"
1760
+ chmod +x "kickstart.sh"
1761
+ else
1762
+ progress "Would copy kickstart.sh to offline install source directory"
1763
+ fi
1764
+
1765
+ if [ "${DRY_RUN}" -ne 1 ]; then
1766
+ progress "Saving release channel information."
1767
+ echo "${SELECTED_RELEASE_CHANNEL}" > "channel"
1768
+ else
1769
+ progress "Would save release channel information to offline install source directory"
1770
+ fi
1771
+
1772
+ 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."
1773
+}
1774
+
1775
# ======================================================================
1776
# Per system-type install logic
1777
1778
install_on_linux() {
1660
- if [ "${NETDATA_ONLY_STATIC}" -ne 1 ] && [ "${NETDATA_ONLY_BUILD}" -ne 1 ]; then
1779
+ if [ "${NETDATA_ONLY_STATIC}" -ne 1 ] && [ "${NETDATA_ONLY_BUILD}" -ne 1 ] && [ -z "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
1780
SELECTED_INSTALL_METHOD="native"
1781
try_package_install
1782
1958
;;
1959
"--install-version")
1960
INSTALL_VERSION="${2}"
1842
- # shellcheck disable=SC2034
1843
- AUTO_UPDATES=0
1961
shift 1
1962
;;
1963
"--old-install-prefix")
2026
STATIC_INSTALL_OPTIONS="${2}"
2027
shift 1
2028
;;
2029
+ "--prepare-offline-install-source")
2030
+ if [ -n "${2}" ]; then
2031
+ ACTION="prepare-offline"
2032
+ OFFLINE_TARGET="${2}"
2033
+ shift 1
2034
+ else
2035
+ fatal "A target directory must be specified with the --prepare-offline-install-source option." F0500
2036
+ fi
2037
+ ;;
2038
+ "--offline-install-source")
2039
+ if [ -d "${2}" ]; then
2040
+ NETDATA_OFFLINE_INSTALL_SOURCE="${2}"
2041
+ shift 1
2042
+ else
2043
+ fatal "A source directory must be specified with the --offline-install-source option." F0501
2044
+ fi
2045
+ ;;
2046
*)
2047
warning "Passing unrecognized option '${1}' to installer script. This behavior is deprecated and will be removed in the near future. 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."
2048
NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} ${1}"
2051
shift 1
2052
done
2053
2054
+if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
2055
+ if [ "${NETDATA_ONLY_NATIVE}" -eq 1 ] || [ "${NETDATA_ONLY_BUILD}" -eq 1 ]; then
2056
+ fatal "Offline installs are only supported for static builds currently." F0502
2057
+ fi
2058
+fi
2059
+
2060
if [ -n "${LOCAL_BUILD_OPTIONS}" ]; then
2061
if [ "${NETDATA_ONLY_BUILD}" -eq 1 ]; then
2062
NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} ${LOCAL_BUILD_OPTIONS}"
2073
fi
2074
fi
2075
1936
-if [ "${NETDATA_AUTO_UPDATES}" = "default" ] || [ "${NETDATA_AUTO_UPDATES}" = "1" ]; then
2076
+if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ] && [ -n "${INSTALL_VERSION}" ]; then
2077
+ fatal "Specifying an install version alongside an offline install source is not supported." F050A
2078
+fi
2079
+
2080
+if [ "${NETDATA_AUTO_UPDATES}" = "default" ]; then
2081
+ if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ] || [ -n "${INSTALL_VERSION}" ]; then
2082
+ AUTO_UPDATE=0
2083
+ else
2084
+ AUTO_UPDATE=1
2085
+ fi
2086
+elif [ "${NETDATA_AUTO_UPDATES}" = 1 ]; then
2087
AUTO_UPDATE=1
2088
else
2089
AUTO_UPDATE=0
2090
fi
2091
2092
if [ "${RELEASE_CHANNEL}" = "default" ]; then
1943
- SELECTED_RELEASE_CHANNEL="${DEFAULT_RELEASE_CHANNEL}"
2093
+ if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
2094
+ SELECTED_RELEASE_CHANNEL="$(cat "${NETDATA_OFFLINE_INSTALL_SOURCE}/channel")"
2095
+
2096
+ if [ -z "${SELECTED_RELEASE_CHANNEL}" ]; then
2097
+ fatal "Could not find a release channel indicator in ${NETDATA_OFFLINE_INSTALL_SOURCE}." F0508
2098
+ fi
2099
+ else
2100
+ SELECTED_RELEASE_CHANNEL="${DEFAULT_RELEASE_CHANNEL}"
2101
+ fi
2102
else
2103
+ if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ] && [ "${RELEASE_CHANNEL}" != "$(cat "${NETDATA_OFFLINE_INSTALL_SOURCE}/channel")" ]; then
2104
+ fatal "Release channal '${RELEASE_CHANNEL}' requested, but indicated offline installation source release channel is '$(cat "${NETDATA_OFFLINE_INSTALL_SOURCE}/channel")'." F0509
2105
+ fi
2106
+
2107
SELECTED_RELEASE_CHANNEL="${RELEASE_CHANNEL}"
2108
fi
2109