@cryptotaxi247 / netdata-1 / commits / 1c257e696

Assorted installer code cleanup. (#14632)

* Consolidate shared options for native packages. This makes the code significantly easier to read and greatly redueces redundancy. * Collapse cases with one-line bodies to single lines. * Consolidate forced install type flags into a single variable. * Clean up binpkg handling in updater. * Assorted updater cleanup. * Use bundled crontab for scheduling updates. Instead of using one embedeed in the updater script. * Fix botched merge. * Fix another merge issue. * Fix missing Amazon Linux support in updater code.

Austin S. Hemmelgarn committed Apr 7, 2023 at 07:19 UTC 1c257e69690f13ee7881f5024c14afd87a167f12
2 files changed +168 -342
packaging/installer/kickstart.sh
+153 -296
@@ -48,9 +48,7 @@ NETDATA_CLAIM_URL="https://api.netdata.cloud"
48 NETDATA_COMMAND="default"
49 NETDATA_DISABLE_CLOUD=0
50 NETDATA_INSTALLER_OPTIONS=""
51 -NETDATA_ONLY_BUILD=0
52 -NETDATA_ONLY_NATIVE=0
53 -NETDATA_ONLY_STATIC=0
51 +NETDATA_FORCE_METHOD=""
52 NETDATA_OFFLINE_INSTALL_SOURCE=""
53 NETDATA_REQUIRE_CLOUD=1
54 NETDATA_WARNINGS=""
@@ -68,7 +66,7 @@ NETDATA_TARBALL_BASEURL="${NETDATA_TARBALL_BASEURL:-https://github.com/netdata/n
66 TELEMETRY_API_KEY="${NETDATA_POSTHOG_API_KEY:-mqkwGT0JNFqO-zX2t0mW6Tec9yooaVu7xCBlXtHnt5Y}"
67
68 if echo "${0}" | grep -q 'kickstart-static64'; then
71 - NETDATA_ONLY_STATIC=1
69 + NETDATA_FORCE_METHOD='static'
70 fi
71
72 if [ ! -t 1 ]; then
@@ -333,9 +331,7 @@ trap_handler() {
331 printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ERROR ${TPUT_RESET} Installer exited unexpectedly (${code}-${lineno})"
332
333 case "${code}" in
336 - 0)
337 - printf >&2 "%s\n" "This is almost certainly the result of a bug. If you have time, please report it at ${AGENT_BUG_REPORT_URL}."
338 - ;;
334 + 0) printf >&2 "%s\n" "This is almost certainly the result of a bug. If you have time, please report it at ${AGENT_BUG_REPORT_URL}." ;;
335 *)
336 printf >&2 "%s\n" "This is probably a result of a transient issue on your system. Things should work correctly if you try again."
337 printf >&2 "%s\n" "If you continue to experience this issue, you can reacn out to us for support on:"
@@ -673,25 +669,15 @@ get_system_info() {
669 DISTRO_COMPAT_NAME="${DISTRO}"
670 else
671 case "${DISTRO}" in
676 - opensuse-leap)
677 - DISTRO_COMPAT_NAME="opensuse"
678 - ;;
679 - cloudlinux|almalinux|rocky|rhel)
680 - DISTRO_COMPAT_NAME="centos"
681 - ;;
682 - artix|manjaro|obarun)
683 - DISTRO_COMPAT_NAME="arch"
684 - ;;
685 - *)
686 - DISTRO_COMPAT_NAME="unknown"
687 - ;;
672 + opensuse-leap) DISTRO_COMPAT_NAME="opensuse" ;;
673 + cloudlinux|almalinux|rocky|rhel) DISTRO_COMPAT_NAME="centos" ;;
674 + artix|manjaro|obarun) DISTRO_COMPAT_NAME="arch" ;;
675 + *) DISTRO_COMPAT_NAME="unknown" ;;
676 esac
677 fi
678
679 case "${DISTRO_COMPAT_NAME}" in
692 - centos|ol)
693 - SYSVERSION=$(echo "$SYSVERSION" | cut -d'.' -f1)
694 - ;;
680 + centos|ol) SYSVERSION=$(echo "$SYSVERSION" | cut -d'.' -f1) ;;
681 esac
682 ;;
683 Darwin)
@@ -702,9 +688,7 @@ get_system_info() {
688 SYSTYPE="FreeBSD"
689 SYSVERSION="$(uname -K)"
690 ;;
705 - *)
706 - fatal "Unsupported system type detected. Netdata cannot be installed on this system using this script." F0200
707 - ;;
691 + *) fatal "Unsupported system type detected. Netdata cannot be installed on this system using this script." F0200 ;;
692 esac
693 }
694
@@ -925,9 +909,9 @@ handle_existing_install() {
909 progress "Found an existing netdata install at ${ndprefix}, but user requested reinstall, continuing."
910
911 case "${INSTALL_TYPE}" in
928 - binpkg-*) NETDATA_ONLY_NATIVE=1 ;;
929 - *-build) NETDATA_ONLY_BUILD=1 ;;
930 - *-static) NETDATA_ONLY_STATIC=1 ;;
912 + binpkg-*) NETDATA_FORCE_METHOD='native' ;;
913 + *-build) NETDATA_FORCE_METHOD='build' ;;
914 + *-static) NETDATA_FORCE_METHOD='static' ;;
915 *)
916 if [ "${ACTION}" = "unsafe-reinstall" ]; then
917 warning "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, but the user has requested we proceed."
@@ -1071,7 +1055,7 @@ EOF
1055 }
1056
1057 confirm_install_prefix() {
1074 - if [ -n "${INSTALL_PREFIX}" ] && [ "${NETDATA_ONLY_BUILD}" -ne 1 ]; then
1058 + if [ -n "${INSTALL_PREFIX}" ] && [ "${NETDATA_FORCE_METHOD}" != 'build' ]; then
1059 fatal "The --install-prefix option is only supported together with the --build-only option." F0204
1060 fi
1061
@@ -1168,52 +1152,24 @@ claim() {
1152 progress "Successfully claimed node"
1153 return 0
1154 ;;
1171 - 1)
1172 - warning "Unable to claim node due to invalid claiming options. If you are seeing this message, you’ve probably found a bug and should open a bug report at ${AGENT_BUG_REPORT_URL}"
1173 - ;;
1174 - 2)
1175 - warning "Unable to claim node due to issues creating the claiming directory or preparing the local claiming key. Make sure you have a working openssl command and that ${INSTALL_PREFIX}/var/lib/netdata/cloud.d exists, then try again."
1176 - ;;
1177 - 3)
1178 - warning "Unable to claim node due to missing dependencies. Usually this means that the Netdata Agent was built without support for Netdata Cloud. If you built the agent from source, please install all needed dependencies for Cloud support. If you used the regular installation script and see this error, please file a bug report at ${AGENT_BUG_REPORT_URL}."
1179 - ;;
1180 - 4)
1181 - warning "Failed to claim node due to inability to connect to ${NETDATA_CLAIM_URL}. Usually this either means that the specified claiming URL is wrong, or that you are having networking problems."
1182 - ;;
1155 + 1) warning "Unable to claim node due to invalid claiming options. If you are seeing this message, you’ve probably found a bug and should open a bug report at ${AGENT_BUG_REPORT_URL}" ;;
1156 + 2) warning "Unable to claim node due to issues creating the claiming directory or preparing the local claiming key. Make sure you have a working openssl command and that ${INSTALL_PREFIX}/var/lib/netdata/cloud.d exists, then try again." ;;
1157 + 3) warning "Unable to claim node due to missing dependencies. Usually this means that the Netdata Agent was built without support for Netdata Cloud. If you built the agent from source, please install all needed dependencies for Cloud support. If you used the regular installation script and see this error, please file a bug report at ${AGENT_BUG_REPORT_URL}." ;;
1158 + 4) warning "Failed to claim node due to inability to connect to ${NETDATA_CLAIM_URL}. Usually this either means that the specified claiming URL is wrong, or that you are having networking problems." ;;
1159 5)
1160 progress "Successfully claimed node, but was not able to notify the Netdata Agent. You will need to restart the Netdata service on this node before it will show up in the Cloud."
1161 return 0
1162 ;;
1187 - 8)
1188 - warning "Failed to claim node due to an invalid agent ID. You can usually resolve this by removing ${INSTALL_PREFIX}/var/lib/netdata/registry/netdata.public.unique.id and restarting the agent. Then try to claim it again using the same options."
1189 - ;;
1190 - 9)
1191 - warning "Failed to claim node due to an invalid node name. This probably means you tried to specify a custom name for this node (for example, using the --claim-hostname option), but the hostname itself was either empty or consisted solely of whitespace. You can resolve this by specifying a valid host name and trying again."
1192 - ;;
1193 - 10)
1194 - warning "Failed to claim node due to an invalid room ID. This issue is most likely caused by a typo. Please check if the room(s) you are trying to add appear on the list of rooms provided to the --claim-rooms option ('${NETDATA_CLAIM_ROOMS}'). Then verify if the rooms are visible in Netdata Cloud and try again."
1195 - ;;
1196 - 11)
1197 - warning "Failed to claim node due to an issue with the generated RSA key pair. You can usually resolve this by removing all files in ${INSTALL_PREFIX}/var/lib/netdata/cloud.d and then trying again."
1198 - ;;
1199 - 12)
1200 - warning "Failed to claim node due to an invalid or expired claiming token. Please check that the token specified with the --claim-token option ('${NETDATA_CLAIM_TOKEN}') matches what you see in the Cloud and try again."
1201 - ;;
1202 - 13)
1203 - warning "Failed to claim node because the Cloud thinks it is already claimed. If this node was created by cloning a VM or as a container from a template, please remove the file ${INSTALL_PREFIX}/var/lib/netdata/registry/netdata.public.unique.id and restart the agent. Then try to claim it again with the same options. Otherwise, if you are certain this node has never been claimed before, you can use the --claim-id option to specify a new node ID to use for claiming, for example by using the uuidgen command like so: --claim-id \"\$(uuidgen)\""
1204 - ;;
1205 - 14)
1206 - warning "Failed to claim node because the node is already in the process of being claimed. You should not need to do anything to resolve this, the node should show up properly in the Cloud soon. If it does not, please report a bug at ${AGENT_BUG_REPORT_URL}."
1207 - ;;
1208 - 15|16|17)
1209 - warning "Failed to claim node due to an internal server error in the Cloud. Please retry claiming this node later, and if you still see this message file a bug report at ${CLOUD_BUG_REPORT_URL}."
1210 - ;;
1211 - 18)
1212 - warning "Unable to claim node because this Netdata installation does not have a unique ID yet. Make sure the agent is running and started up correctly, and then try again."
1213 - ;;
1214 - *)
1215 - warning "Failed to claim node for an unknown reason. This usually means either networking problems or a bug. Please retry claiming later, and if you still see this message file a bug report at ${AGENT_BUG_REPORT_URL}"
1216 - ;;
1163 + 8) warning "Failed to claim node due to an invalid agent ID. You can usually resolve this by removing ${INSTALL_PREFIX}/var/lib/netdata/registry/netdata.public.unique.id and restarting the agent. Then try to claim it again using the same options." ;;
1164 + 9) warning "Failed to claim node due to an invalid node name. This probably means you tried to specify a custom name for this node (for example, using the --claim-hostname option), but the hostname itself was either empty or consisted solely of whitespace. You can resolve this by specifying a valid host name and trying again." ;;
1165 + 10) warning "Failed to claim node due to an invalid room ID. This issue is most likely caused by a typo. Please check if the room(s) you are trying to add appear on the list of rooms provided to the --claim-rooms option ('${NETDATA_CLAIM_ROOMS}'). Then verify if the rooms are visible in Netdata Cloud and try again." ;;
1166 + 11) warning "Failed to claim node due to an issue with the generated RSA key pair. You can usually resolve this by removing all files in ${INSTALL_PREFIX}/var/lib/netdata/cloud.d and then trying again." ;;
1167 + 12) warning "Failed to claim node due to an invalid or expired claiming token. Please check that the token specified with the --claim-token option ('${NETDATA_CLAIM_TOKEN}') matches what you see in the Cloud and try again." ;;
1168 + 13) warning "Failed to claim node because the Cloud thinks it is already claimed. If this node was created by cloning a VM or as a container from a template, please remove the file ${INSTALL_PREFIX}/var/lib/netdata/registry/netdata.public.unique.id and restart the agent. Then try to claim it again with the same options. Otherwise, if you are certain this node has never been claimed before, you can use the --claim-id option to specify a new node ID to use for claiming, for example by using the uuidgen command like so: --claim-id \"\$(uuidgen)\"" ;;
1169 + 14) warning "Failed to claim node because the node is already in the process of being claimed. You should not need to do anything to resolve this, the node should show up properly in the Cloud soon. If it does not, please report a bug at ${AGENT_BUG_REPORT_URL}." ;;
1170 + 15|16|17) warning "Failed to claim node due to an internal server error in the Cloud. Please retry claiming this node later, and if you still see this message file a bug report at ${CLOUD_BUG_REPORT_URL}." ;;
1171 + 18) warning "Unable to claim node because this Netdata installation does not have a unique ID yet. Make sure the agent is running and started up correctly, and then try again." ;;
1172 + *) warning "Failed to claim node for an unknown reason. This usually means either networking problems or a bug. Please retry claiming later, and if you still see this message file a bug report at ${AGENT_BUG_REPORT_URL}" ;;
1173 esac
1174
1175 if [ -z "${NETDATA_NEW_INSTALL}" ]; then
@@ -1281,9 +1237,7 @@ pkg_installed() {
1237 pacman -Qi "${1}" > /dev/null 2>&1
1238 return $?
1239 ;;
1284 - *)
1285 - return 1
1286 - ;;
1240 + *) return 1 ;;
1241 esac
1242 ;;
1243 Darwin)
@@ -1322,9 +1276,7 @@ netdata_avail_check() {
1276 zypper packages -r "$(zypper repos | grep -E 'netdata |netdata-edge ' | cut -f 1 -d '|' | tr -d ' ')" | grep -E 'netdata '
1277 return $?
1278 ;;
1325 - *)
1326 - return 1
1327 - ;;
1279 + *) return 1 ;;
1280 esac
1281 }
1282
@@ -1352,6 +1304,26 @@ check_special_native_deps() {
1304 fi
1305 }
1306
1307 +common_rpm_opts() {
1308 + pkg_type="rpm"
1309 + pkg_suffix=".noarch"
1310 + pkg_vsep="-"
1311 + INSTALL_TYPE="binpkg-rpm"
1312 + NATIVE_VERSION="${INSTALL_VERSION:+"-${INSTALL_VERSION}.${SYSARCH}"}"
1313 +}
1314 +
1315 +common_dnf_opts() {
1316 + if command -v dnf > /dev/null; then
1317 + pm_cmd="dnf"
1318 + repo_subcmd="makecache"
1319 + else
1320 + pm_cmd="yum"
1321 + fi
1322 + pkg_install_opts="${interactive_opts}"
1323 + repo_update_opts="${interactive_opts}"
1324 + uninstall_subcmd="remove"
1325 +}
1326 +
1327 try_package_install() {
1328 failed_refresh_msg="Failed to refresh repository metadata. ${BADNET_MSG} or by misconfiguration of one or more rpackage repositories in the system package manager configuration."
1329
@@ -1390,114 +1362,43 @@ try_package_install() {
1362 fi
1363
1364 case "${DISTRO_COMPAT_NAME}" in
1393 - debian)
1394 - needs_early_refresh=1
1395 - pm_cmd="apt-get"
1396 - repo_subcmd="update"
1397 - repo_prefix="debian/${SYSCODENAME}"
1398 - pkg_type="deb"
1399 - pkg_suffix="+debian${SYSVERSION}_all"
1400 - pkg_vsep="_"
1401 - pkg_install_opts="${interactive_opts}"
1402 - repo_update_opts="${interactive_opts}"
1403 - uninstall_subcmd="purge"
1404 - INSTALL_TYPE="binpkg-deb"
1405 - NATIVE_VERSION="${INSTALL_VERSION:+"=${INSTALL_VERSION}"}"
1406 - ;;
1407 - ubuntu)
1365 + debian|ubuntu)
1366 needs_early_refresh=1
1367 pm_cmd="apt-get"
1368 repo_subcmd="update"
1411 - repo_prefix="ubuntu/${SYSCODENAME}"
1369 pkg_type="deb"
1413 - pkg_suffix="+ubuntu${SYSVERSION}_all"
1370 pkg_vsep="_"
1371 pkg_install_opts="${interactive_opts}"
1372 repo_update_opts="${interactive_opts}"
1373 uninstall_subcmd="purge"
1374 + repo_prefix="${DISTRO_COMPAT_NAME}/${SYSCODENAME}"
1375 + pkg_suffix="+${DISTRO_COMPAT_NAME}${SYSVERSION}_all"
1376 INSTALL_TYPE="binpkg-deb"
1377 NATIVE_VERSION="${INSTALL_VERSION:+"=${INSTALL_VERSION}"}"
1378 ;;
1379 centos)
1422 - if command -v dnf > /dev/null; then
1423 - pm_cmd="dnf"
1424 - repo_subcmd="makecache"
1425 - else
1426 - pm_cmd="yum"
1427 - fi
1380 + common_rpm_opts
1381 + common_dnf_opts
1382 repo_prefix="el/${SYSVERSION}"
1429 - pkg_type="rpm"
1430 - pkg_suffix=".noarch"
1431 - pkg_vsep="-"
1432 - pkg_install_opts="${interactive_opts}"
1433 - repo_update_opts="${interactive_opts}"
1434 - uninstall_subcmd="remove"
1435 - INSTALL_TYPE="binpkg-rpm"
1436 - NATIVE_VERSION="${INSTALL_VERSION:+"-${INSTALL_VERSION}.${SYSARCH}"}"
1383 ;;
1438 - fedora)
1439 - if command -v dnf > /dev/null; then
1440 - pm_cmd="dnf"
1441 - repo_subcmd="makecache"
1442 - else
1443 - pm_cmd="yum"
1444 - fi
1445 - repo_prefix="fedora/${SYSVERSION}"
1446 - pkg_type="rpm"
1447 - pkg_suffix=".noarch"
1448 - pkg_vsep="-"
1449 - pkg_install_opts="${interactive_opts}"
1450 - repo_update_opts="${interactive_opts}"
1451 - uninstall_subcmd="remove"
1452 - INSTALL_TYPE="binpkg-rpm"
1453 - NATIVE_VERSION="${INSTALL_VERSION:+"-${INSTALL_VERSION}.${SYSARCH}"}"
1384 + fedora|ol)
1385 + common_rpm_opts
1386 + common_dnf_opts
1387 + repo_prefix="${DISTRO_COMPAT_NAME}/${SYSVERSION}"
1388 ;;
1389 opensuse)
1390 + common_rpm_opts
1391 pm_cmd="zypper"
1392 repo_subcmd="--gpg-auto-import-keys refresh"
1393 repo_prefix="opensuse/${SYSVERSION}"
1459 - pkg_type="rpm"
1460 - pkg_suffix=".noarch"
1461 - pkg_vsep="-"
1394 pkg_install_opts="${interactive_opts} --allow-unsigned-rpm"
1395 repo_update_opts=""
1396 uninstall_subcmd="remove"
1465 - INSTALL_TYPE="binpkg-rpm"
1466 - NATIVE_VERSION="${INSTALL_VERSION:+"-${INSTALL_VERSION}.${SYSARCH}"}"
1467 - ;;
1468 - ol)
1469 - if command -v dnf > /dev/null; then
1470 - pm_cmd="dnf"
1471 - repo_subcmd="makecache"
1472 - else
1473 - pm_cmd="yum"
1474 - fi
1475 - repo_prefix="ol/${SYSVERSION}"
1476 - pkg_type="rpm"
1477 - pkg_suffix=".noarch"
1478 - pkg_vsep="-"
1479 - pkg_install_opts="${interactive_opts}"
1480 - repo_update_opts="${interactive_opts}"
1481 - uninstall_subcmd="remove"
1482 - INSTALL_TYPE="binpkg-rpm"
1483 - NATIVE_VERSION="${INSTALL_VERSION:+"-${INSTALL_VERSION}.${SYSARCH}"}"
1397 ;;
1398 amzn)
1486 - if command -v dnf > /dev/null; then
1487 - pm_cmd="dnf"
1488 - repo_subcmd="makecache"
1489 - else
1490 - pm_cmd="yum"
1491 - fi
1399 + common_rpm_opts
1400 + common_dnf_opts
1401 repo_prefix="amazonlinux/${SYSVERSION}"
1493 - pkg_type="rpm"
1494 - pkg_suffix=".noarch"
1495 - pkg_vsep="-"
1496 - pkg_install_opts="${interactive_opts}"
1497 - repo_update_opts="${interactive_opts}"
1498 - uninstall_subcmd="remove"
1499 - INSTALL_TYPE="binpkg-rpm"
1500 - NATIVE_VERSION="${INSTALL_VERSION:+"-${INSTALL_VERSION}.${SYSARCH}"}"
1402 ;;
1403 *)
1404 warning "We do not provide native packages for ${DISTRO}."
@@ -1816,9 +1717,7 @@ build_and_install() {
1717 fatal "netdata-installer.sh failed to run: Encountered an unhandled error in the installer code." I0000
1718 fi
1719 ;;
1819 - 2)
1820 - fatal "Insufficient RAM to install netdata." F0008
1821 - ;;
1720 + 2) fatal "Insufficient RAM to install netdata." F0008 ;;
1721 esac
1722 }
1723
@@ -1898,34 +1797,36 @@ prepare_offline_install_source() {
1797
1798 run cd "${1}" || fatal "Failed to switch to target directory for offline install preparation." F0505
1799
1901 - if [ "${NETDATA_ONLY_NATIVE}" -ne 1 ] && [ "${NETDATA_ONLY_BUILD}" -ne 1 ]; then
1902 - set_static_archive_urls "${SELECTED_RELEASE_CHANNEL}" "x86_64"
1800 + case "${NETDATA_FORCE_METHOD}" in
1801 + static|'')
1802 + set_static_archive_urls "${SELECTED_RELEASE_CHANNEL}" "x86_64"
1803
1904 - if check_for_remote_file "${NETDATA_STATIC_ARCHIVE_URL}"; then
1905 - for arch in ${STATIC_INSTALL_ARCHES}; do
1906 - set_static_archive_urls "${SELECTED_RELEASE_CHANNEL}" "${arch}"
1804 + if check_for_remote_file "${NETDATA_STATIC_ARCHIVE_URL}"; then
1805 + for arch in ${STATIC_INSTALL_ARCHES}; do
1806 + set_static_archive_urls "${SELECTED_RELEASE_CHANNEL}" "${arch}"
1807
1908 - progress "Fetching ${NETDATA_STATIC_ARCHIVE_URL}"
1909 - if ! download "${NETDATA_STATIC_ARCHIVE_URL}" "netdata-${arch}-latest.gz.run"; then
1910 - warning "Failed to download static installer archive for ${arch}. ${BADNET_MSG}."
1911 - fi
1912 - done
1913 - legacy=0
1914 - else
1915 - 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."
1916 - progress "Fetching ${NETDATA_STATIC_ARCHIVE_OLD_URL}"
1917 - legacy=1
1808 + progress "Fetching ${NETDATA_STATIC_ARCHIVE_URL}"
1809 + if ! download "${NETDATA_STATIC_ARCHIVE_URL}" "netdata-${arch}-latest.gz.run"; then
1810 + warning "Failed to download static installer archive for ${arch}. ${BADNET_MSG}."
1811 + fi
1812 + done
1813 + legacy=0
1814 + else
1815 + 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."
1816 + progress "Fetching ${NETDATA_STATIC_ARCHIVE_OLD_URL}"
1817 + legacy=1
1818
1919 - if ! download "${NETDATA_STATIC_ARCHIVE_OLD_URL}" "netdata-x86_64-latest.gz.run"; then
1920 - warning "Failed to download static installer archive for x86_64. ${BADNET_MSG}."
1819 + if ! download "${NETDATA_STATIC_ARCHIVE_OLD_URL}" "netdata-x86_64-latest.gz.run"; then
1820 + warning "Failed to download static installer archive for x86_64. ${BADNET_MSG}."
1821 + fi
1822 fi
1922 - fi
1823
1924 - progress "Fetching ${NETDATA_STATIC_ARCHIVE_CHECKSUM_URL}"
1925 - if ! download "${NETDATA_STATIC_ARCHIVE_CHECKSUM_URL}" "sha256sums.txt"; then
1926 - fatal "Failed to download checksum file. ${BADNET_MSG}." F0506
1927 - fi
1928 - fi
1824 + progress "Fetching ${NETDATA_STATIC_ARCHIVE_CHECKSUM_URL}"
1825 + if ! download "${NETDATA_STATIC_ARCHIVE_CHECKSUM_URL}" "sha256sums.txt"; then
1826 + fatal "Failed to download checksum file. ${BADNET_MSG}." F0506
1827 + fi
1828 + ;;
1829 + esac
1830
1831 if [ "${legacy:-0}" -eq 1 ]; then
1832 sed -e 's/netdata-latest.gz.run/netdata-x86_64-latest.gz.run' sha256sums.txt > sha256sums.tmp
@@ -1975,7 +1876,7 @@ prepare_offline_install_source() {
1876 # Per system-type install logic
1877
1878 install_on_linux() {
1978 - if [ "${NETDATA_ONLY_STATIC}" -ne 1 ] && [ "${NETDATA_ONLY_BUILD}" -ne 1 ] && [ -z "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
1879 + if [ "${NETDATA_FORCE_METHOD}" != 'static' ] && [ "${NETDATA_FORCE_METHOD}" != 'build' ] && [ -z "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
1880 SELECTED_INSTALL_METHOD="native"
1881 try_package_install
1882
@@ -1984,20 +1885,17 @@ install_on_linux() {
1885 NETDATA_INSTALL_SUCCESSFUL=1
1886 INSTALL_PREFIX="/"
1887 ;;
1987 - 1)
1988 - fatal "Unable to install on this system." F0300
1989 - ;;
1888 + 1) fatal "Unable to install on this system." F0300 ;;
1889 2)
1991 - if [ "${NETDATA_ONLY_NATIVE}" -eq 1 ]; then
1992 - fatal "Could not install native binary packages." F0301
1993 - else
1994 - warning "Could not install native binary packages, falling back to alternative installation method."
1995 - fi
1890 + case "${NETDATA_FORCE_METHOD}" in
1891 + native) fatal "Could not install native binary packages." F0301 ;;
1892 + *) warning "Could not install native binary packages, falling back to alternative installation method." ;;
1893 + esac
1894 ;;
1895 esac
1896 fi
1897
2000 - if [ "${NETDATA_ONLY_NATIVE}" -ne 1 ] && [ "${NETDATA_ONLY_BUILD}" -ne 1 ] && [ -z "${NETDATA_INSTALL_SUCCESSFUL}" ]; then
1898 + if [ "${NETDATA_FORCE_METHOD}" != 'native' ] && [ "${NETDATA_FORCE_METHOD}" != 'build' ] && [ -z "${NETDATA_INSTALL_SUCCESSFUL}" ]; then
1899 SELECTED_INSTALL_METHOD="static"
1900 INSTALL_TYPE="kickstart-static"
1901 try_static_install
@@ -2007,75 +1905,60 @@ install_on_linux() {
1905 NETDATA_INSTALL_SUCCESSFUL=1
1906 INSTALL_PREFIX="/opt/netdata"
1907 ;;
2010 - 1)
2011 - fatal "Unable to install on this system." F0302
2012 - ;;
1908 + 1) fatal "Unable to install on this system." F0302 ;;
1909 2)
2014 - if [ "${NETDATA_ONLY_STATIC}" -eq 1 ]; then
2015 - fatal "Could not install static build." F0303
2016 - else
2017 - warning "Could not install static build, falling back to alternative installation method."
2018 - fi
1910 + case "${NETDATA_FORCE_METHOD}" in
1911 + static) fatal "Could not install static build." F0303 ;;
1912 + *) warning "Could not install static build, falling back to alternative installation method." ;;
1913 + esac
1914 ;;
1915 esac
1916 fi
1917
2023 - if [ "${NETDATA_ONLY_NATIVE}" -ne 1 ] && [ "${NETDATA_ONLY_STATIC}" -ne 1 ] && [ -z "${NETDATA_INSTALL_SUCCESSFUL}" ]; then
1918 + if [ "${NETDATA_FORCE_METHOD}" != 'native' ] && [ "${NETDATA_FORCE_METHOD}" != 'static' ] && [ -z "${NETDATA_INSTALL_SUCCESSFUL}" ]; then
1919 SELECTED_INSTALL_METHOD="build"
1920 INSTALL_TYPE="kickstart-build"
1921 try_build_install
1922
1923 case "$?" in
2029 - 0)
2030 - NETDATA_INSTALL_SUCCESSFUL=1
2031 - ;;
2032 - *)
2033 - fatal "Unable to install on this system." F0304
2034 - ;;
1924 + 0) NETDATA_INSTALL_SUCCESSFUL=1 ;;
1925 + *) fatal "Unable to install on this system." F0304 ;;
1926 esac
1927 fi
1928 }
1929
1930 install_on_macos() {
2040 - if [ "${NETDATA_ONLY_NATIVE}" -eq 1 ]; then
2041 - fatal "User requested native package, but native packages are not available for macOS. Try installing without \`--only-native\` option." F0305
2042 - elif [ "${NETDATA_ONLY_STATIC}" -eq 1 ]; then
2043 - fatal "User requested static build, but static builds are not available for macOS. Try installing without \`--only-static\` option." F0306
2044 - else
2045 - SELECTED_INSTALL_METHOD="build"
2046 - INSTALL_TYPE="kickstart-build"
2047 - try_build_install
1931 + case "${NETDATA_FORCE_METHOD}" in
1932 + native) fatal "User requested native package, but native packages are not available for macOS. Try installing without \`--only-native\` option." F0305 ;;
1933 + static) fatal "User requested static build, but static builds are not available for macOS. Try installing without \`--only-static\` option." F0306 ;;
1934 + *)
1935 + SELECTED_INSTALL_METHOD="build"
1936 + INSTALL_TYPE="kickstart-build"
1937 + try_build_install
1938
2049 - case "$?" in
2050 - 0)
2051 - NETDATA_INSTALL_SUCCESSFUL=1
2052 - ;;
2053 - *)
2054 - fatal "Unable to install on this system." F0307
2055 - ;;
2056 - esac
2057 - fi
1939 + case "$?" in
1940 + 0) NETDATA_INSTALL_SUCCESSFUL=1 ;;
1941 + *) fatal "Unable to install on this system." F0307 ;;
1942 + esac
1943 + ;;
1944 + esac
1945 }
1946
1947 install_on_freebsd() {
2061 - if [ "${NETDATA_ONLY_NATIVE}" -eq 1 ]; then
2062 - fatal "User requested native package, but native packages are not available for FreeBSD. Try installing without \`--only-native\` option." F0308
2063 - elif [ "${NETDATA_ONLY_STATIC}" -eq 1 ]; then
2064 - fatal "User requested static build, but static builds are not available for FreeBSD. Try installing without \`--only-static\` option." F0309
2065 - else
2066 - SELECTED_INSTALL_METHOD="build"
2067 - INSTALL_TYPE="kickstart-build"
2068 - try_build_install
1948 + case "${NETDATA_FORCE_METHOD}" in
1949 + native) fatal "User requested native package, but native packages are not available for FreeBSD. Try installing without \`--only-native\` option." F0308 ;;
1950 + static) fatal "User requested static build, but static builds are not available for FreeBSD. Try installing without \`--only-static\` option." F0309 ;;
1951 + *)
1952 + SELECTED_INSTALL_METHOD="build"
1953 + INSTALL_TYPE="kickstart-build"
1954 + try_build_install
1955
2070 - case "$?" in
2071 - 0)
2072 - NETDATA_INSTALL_SUCCESSFUL=1
2073 - ;;
2074 - *)
2075 - fatal "Unable to install on this system." F030A
2076 - ;;
2077 - esac
2078 - fi
1956 + case "$?" in
1957 + 0) NETDATA_INSTALL_SUCCESSFUL=1 ;;
1958 + *) fatal "Unable to install on this system." F030A ;;
1959 + esac
1960 + ;;
1961 + esac
1962 }
1963
1964 # ======================================================================
@@ -2084,30 +1967,32 @@ install_on_freebsd() {
1967 validate_args() {
1968 check_claim_opts
1969
2087 - if [ "${ACTION}" = "repositories-only" ] && [ "${NETDATA_ONLY_NATIVE}" -eq 1 ]; then
1970 + if [ -n "${NETDATA_FORCE_METHOD}" ]; then
1971 + SELECTED_INSTALL_METHOD="${NETDATA_FORCE_METHOD}"
1972 + fi
1973 +
1974 + if [ "${ACTION}" = "repositories-only" ] && [ "${NETDATA_FORCE_METHOD}" != "native" ]; then
1975 fatal "Repositories can only be installed for native installs." F050D
1976 fi
1977
1978 if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
2092 - if [ "${NETDATA_ONLY_NATIVE}" -eq 1 ] || [ "${NETDATA_ONLY_BUILD}" -eq 1 ]; then
2093 - fatal "Offline installs are only supported for static builds currently." F0502
2094 - fi
1979 + case "${NETDATA_FORCE_METHOD}" in
1980 + native|build) fatal "Offline installs are only supported for static builds currently." F0502 ;;
1981 + esac
1982 fi
1983
1984 if [ -n "${LOCAL_BUILD_OPTIONS}" ]; then
2098 - if [ "${NETDATA_ONLY_BUILD}" -eq 1 ]; then
2099 - NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} ${LOCAL_BUILD_OPTIONS}"
2100 - else
2101 - fatal "Specifying local build options is only supported when the --build-only option is also specified." F0401
2102 - fi
1985 + case "${NETDATA_FORCE_METHOD}" in
1986 + build) NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} ${LOCAL_BUILD_OPTIONS}" ;;
1987 + *) fatal "Specifying local build options is only supported when the --build-only option is also specified." F0401 ;;
1988 + esac
1989 fi
1990
1991 if [ -n "${STATIC_INSTALL_OPTIONS}" ]; then
2106 - if [ "${NETDATA_ONLY_STATIC}" -eq 1 ]; then
2107 - NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} ${STATIC_INSTALL_OPTIONS}"
2108 - else
2109 - fatal "Specifying installer options options is only supported when the --static-only option is also specified." F0402
2110 - fi
1992 + case "${NETDATA_FORCE_METHOD}" in
1993 + static) NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} ${STATIC_INSTALL_OPTIONS}" ;;
1994 + *) fatal "Specifying installer options options is only supported when the --static-only option is also specified." F0402 ;;
1995 + esac
1996 fi
1997
1998 if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ] && [ -n "${INSTALL_VERSION}" ]; then
@@ -2172,9 +2057,7 @@ parse_args() {
2057 "--release-channel")
2058 RELEASE_CHANNEL="$(echo "${2}" | tr '[:upper:]' '[:lower:]')"
2059 case "${RELEASE_CHANNEL}" in
2175 - nightly|stable|default)
2176 - shift 1
2177 - ;;
2060 + nightly|stable|default) shift 1 ;;
2061 *)
2062 echo "Unrecognized value for --release-channel. Valid release channels are: stable, nightly, default"
2063 exit 1
@@ -2193,9 +2076,7 @@ parse_args() {
2076 "--auto-update-method")
2077 NETDATA_AUTO_UPDATE_TYPE="$(echo "${2}" | tr '[:upper:]' '[:lower:]')"
2078 case "${NETDATA_AUTO_UPDATE_TYPE}" in
2196 - systemd|interval|crontab)
2197 - shift 1
2198 - ;;
2079 + systemd|interval|crontab) shift 1 ;;
2080 *)
2081 echo "Unrecognized value for --auto-update-type. Valid values are: systemd, interval, crontab"
2082 exit 1
@@ -2247,31 +2128,13 @@ parse_args() {
2128 fatal "A distribution name and release must be specified for the --distro-override option." F050F
2129 fi
2130 ;;
2250 - "--native-only")
2251 - NETDATA_ONLY_NATIVE=1
2252 - NETDATA_ONLY_STATIC=0
2253 - NETDATA_ONLY_BUILD=0
2254 - SELECTED_INSTALL_METHOD="native"
2255 - ;;
2131 "--repositories-only")
2132 set_action 'repositories-only'
2258 - NETDATA_ONLY_NATIVE=1
2259 - NETDATA_ONLY_STATIC=0
2260 - NETDATA_ONLY_BUILD=0
2261 - SELECTED_INSTALL_METHOD="native"
2262 - ;;
2263 - "--static-only")
2264 - NETDATA_ONLY_STATIC=1
2265 - NETDATA_ONLY_NATIVE=0
2266 - NETDATA_ONLY_BUILD=0
2267 - SELECTED_INSTALL_METHOD="static"
2268 - ;;
2269 - "--build-only")
2270 - NETDATA_ONLY_BUILD=1
2271 - NETDATA_ONLY_NATIVE=0
2272 - NETDATA_ONLY_STATIC=0
2273 - SELECTED_INSTALL_METHOD="build"
2133 + NETDATA_FORCE_METHOD="native"
2134 ;;
2135 + "--native-only") NETDATA_FORCE_METHOD="native" ;;
2136 + "--static-only") NETDATA_FORCE_METHOD="static" ;;
2137 + "--build-only") NETDATA_FORCE_METHOD="build" ;;
2138 "--claim-token")
2139 NETDATA_CLAIM_TOKEN="${2}"
2140 shift 1
@@ -2291,12 +2154,8 @@ parse_args() {
2154 NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -${optname}=${2}"
2155 shift 1
2156 ;;
2294 - verbose|insecure|noproxy|noreload|daemon-not-running)
2295 - NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -${optname}"
2296 - ;;
2297 - *)
2298 - warning "Ignoring unrecognized claiming option ${optname}"
2299 - ;;
2157 + verbose|insecure|noproxy|noreload|daemon-not-running) NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -${optname}" ;;
2158 + *) warning "Ignoring unrecognized claiming option ${optname}" ;;
2159 esac
2160 ;;
2161 "--local-build-options")
@@ -2324,9 +2183,7 @@ parse_args() {
2183 fatal "A source directory must be specified with the --offline-install-source option." F0501
2184 fi
2185 ;;
2327 - *)
2328 - fatal "Unrecognized option '${1}'. 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." F050E
2329 - ;;
2186 + *) fatal "Unrecognized option '${1}'. 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." F050E ;;
2187 esac
2188 shift 1
2189 done
packaging/installer/netdata-updater.sh
+15 -46
@@ -21,7 +21,7 @@
21 # - TMPDIR (set to a usable temporary directory)
22 # - NETDATA_NIGHTLIES_BASEURL (set the base url for downloading the dist tarball)
23 #
24 -# Copyright: 2018-2020 Netdata Inc.
24 +# Copyright: 2018-2023 Netdata Inc.
25 # SPDX-License-Identifier: GPL-3.0-or-later
26 #
27 # Author: Paweł Krupa <paulfantom@gmail.com>
@@ -225,9 +225,8 @@ enable_netdata_updater() {
225 ;;
226 "crontab")
227 if [ -d "/etc/cron.d" ]; then
228 - cat > "/etc/cron.d/netdata-updater" <<-EOF
229 - 2 57 * * * root ${NETDATA_PREFIX}/netdata-updater.sh
230 - EOF
228 + [ -f "/etc/cron.d/netdata-updater" ] && rm -f "/etc/cron.d/netdata-updater"
229 + install -p -m 0644 -o 0 -g 0 "${NETDATA_PREFIX}/usr/lib/system/cron/netdata-updater-daily" "/etc/cron.d/netdata-updater-daily"
230
231 info "Auto-updating has been ENABLED through cron, using a crontab at /etc/cron.d/netdata-updater\n"
232 info "If the update process fails and you have email notifications set up correctly for cron on this system, you should receive an email notification of the failure."
@@ -262,6 +261,7 @@ disable_netdata_updater() {
261
262 if [ -d /etc/cron.d ]; then
263 rm -f /etc/cron.d/netdata-updater
264 + rm -f /etc/cron.d/netdata-updater-daily
265 fi
266
267 info "Auto-updates have been DISABLED."
@@ -715,7 +715,7 @@ update_binpkg() {
715
716 DISTRO="${ID}"
717
718 - supported_compat_names="debian ubuntu centos fedora opensuse"
718 + supported_compat_names="debian ubuntu centos fedora opensuse ol amzn"
719
720 if str_in_list "${DISTRO}" "${supported_compat_names}"; then
721 DISTRO_COMPAT_NAME="${DISTRO}"
@@ -742,7 +742,7 @@ update_binpkg() {
742 fi
743
744 case "${DISTRO_COMPAT_NAME}" in
745 - debian)
745 + debian|ubuntu)
746 pm_cmd="apt-get"
747 repo_subcmd="update"
748 upgrade_cmd="--only-upgrade install"
@@ -751,29 +751,7 @@ update_binpkg() {
751 pkg_installed_check="dpkg -s"
752 INSTALL_TYPE="binpkg-deb"
753 ;;
754 - ubuntu)
755 - pm_cmd="apt-get"
756 - repo_subcmd="update"
757 - upgrade_cmd="--only-upgrade install"
758 - pkg_install_opts="${interactive_opts}"
759 - repo_update_opts="${interactive_opts}"
760 - pkg_installed_check="dpkg -s"
761 - INSTALL_TYPE="binpkg-deb"
762 - ;;
763 - centos)
764 - if command -v dnf > /dev/null; then
765 - pm_cmd="dnf"
766 - repo_subcmd="makecache"
767 - else
768 - pm_cmd="yum"
769 - fi
770 - upgrade_cmd="upgrade"
771 - pkg_install_opts="${interactive_opts}"
772 - repo_update_opts="${interactive_opts}"
773 - pkg_installed_check="rpm -q"
774 - INSTALL_TYPE="binpkg-rpm"
775 - ;;
776 - fedora)
754 + centos|fedora|ol|amzn)
755 if command -v dnf > /dev/null; then
756 pm_cmd="dnf"
757 repo_subcmd="makecache"
@@ -826,11 +804,10 @@ update_binpkg() {
804 # Simple function to encapsulate original updater behavior.
805 update_legacy() {
806 set_tarball_urls "${RELEASE_CHANNEL}" "${IS_NETDATA_STATIC_BINARY}"
829 - if [ "${IS_NETDATA_STATIC_BINARY}" = "yes" ]; then
830 - update_static && exit 0
831 - else
832 - update_build && exit 0
833 - fi
807 + case "${IS_NETDATA_STATIC_BINARY}" in
808 + yes) update_static && exit 0 ;;
809 + *) update_build && exit 0 ;;
810 + esac
811 }
812
813 logfile=
@@ -901,9 +878,7 @@ while [ -n "${1}" ]; do
878 disable_netdata_updater
879 exit $?
880 ;;
904 - *)
905 - fatal "Unrecognized option ${1}" U001A
906 - ;;
881 + *) fatal "Unrecognized option ${1}" U001A ;;
882 esac
883
884 shift 1
@@ -945,9 +920,7 @@ case "${INSTALL_TYPE}" in
920 set_tarball_urls "${RELEASE_CHANNEL}" "${IS_NETDATA_STATIC_BINARY}"
921 update_static && exit 0
922 ;;
948 - *binpkg*)
949 - update_binpkg && exit 0
950 - ;;
923 + *binpkg*) update_binpkg && exit 0 ;;
924 "") # Fallback case for no `.install-type` file. This just works like the old install type detection.
925 validate_environment_file
926 update_legacy
@@ -961,10 +934,6 @@ case "${INSTALL_TYPE}" in
934 fatal "This script does not support updating custom installations without valid environment files." U0012
935 fi
936 ;;
964 - oci)
965 - fatal "This script does not support updating Netdata inside our official Docker containers, please instead update the container itself." U0013
966 - ;;
967 - *)
968 - fatal "Unrecognized installation type (${INSTALL_TYPE}), unable to update." U0014
969 - ;;
937 + oci) fatal "This script does not support updating Netdata inside our official Docker containers, please instead update the container itself." U0013 ;;
938 + *) fatal "Unrecognized installation type (${INSTALL_TYPE}), unable to update." U0014 ;;
939 esac