netdata-updater.sh 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091
  1. #!/bin/sh
  2. # Netdata updater utility
  3. #
  4. # Variables needed by script:
  5. # - PATH
  6. # - CFLAGS
  7. # - LDFLAGS
  8. # - MAKEOPTS
  9. # - IS_NETDATA_STATIC_BINARY
  10. # - NETDATA_CONFIGURE_OPTIONS
  11. # - REINSTALL_OPTIONS
  12. # - NETDATA_TARBALL_URL
  13. # - NETDATA_TARBALL_CHECKSUM_URL
  14. # - NETDATA_TARBALL_CHECKSUM
  15. # - NETDATA_PREFIX
  16. # - NETDATA_LIB_DIR
  17. #
  18. # Optional environment options:
  19. #
  20. # - TMPDIR (set to a usable temporary directory)
  21. # - NETDATA_NIGHTLIES_BASEURL (set the base url for downloading the dist tarball)
  22. #
  23. # Copyright: 2018-2023 Netdata Inc.
  24. # SPDX-License-Identifier: GPL-3.0-or-later
  25. #
  26. # Author: Paweł Krupa <paulfantom@gmail.com>
  27. # Author: Pavlos Emm. Katsoulakis <paul@netdata.cloud>
  28. # Author: Austin S. Hemmelgarn <austin@netdata.cloud>
  29. # Next unused error code: U001D
  30. set -e
  31. PACKAGES_SCRIPT="https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/install-required-packages.sh"
  32. NETDATA_STABLE_BASE_URL="${NETDATA_BASE_URL:-https://github.com/netdata/netdata/releases}"
  33. NETDATA_NIGHTLY_BASE_URL="${NETDATA_BASE_URL:-https://github.com/netdata/netdata-nightlies/releases}"
  34. NETDATA_DEFAULT_ACCEPT_MAJOR_VERSIONS="1 2"
  35. # Following variables are intended to be overridden by the updater config file.
  36. NETDATA_UPDATER_JITTER=3600
  37. NETDATA_NO_SYSTEMD_JOURNAL=0
  38. NETDATA_ACCEPT_MAJOR_VERSIONS=''
  39. script_dir="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)"
  40. if [ -x "${script_dir}/netdata-updater" ]; then
  41. script_source="${script_dir}/netdata-updater"
  42. else
  43. script_source="${script_dir}/netdata-updater.sh"
  44. fi
  45. PATH="${PATH}:/usr/local/bin:/usr/local/sbin"
  46. if [ ! -t 1 ]; then
  47. INTERACTIVE=0
  48. else
  49. INTERACTIVE=1
  50. fi
  51. if [ -n "${script_source}" ]; then
  52. script_name="$(basename "${script_source}")"
  53. else
  54. script_name="netdata-updater.sh"
  55. fi
  56. info() {
  57. echo >&3 "$(date) : INFO: ${script_name}: " "${1}"
  58. }
  59. warning() {
  60. echo >&3 "$(date) : WARNING: ${script_name}: " "${@}"
  61. }
  62. error() {
  63. echo >&3 "$(date) : ERROR: ${script_name}: " "${1}"
  64. if [ -n "${NETDATA_SAVE_WARNINGS}" ]; then
  65. NETDATA_WARNINGS="${NETDATA_WARNINGS}\n - ${1}"
  66. fi
  67. }
  68. fatal() {
  69. echo >&3 "$(date) : FATAL: ${script_name}: FAILED TO UPDATE NETDATA: " "${1}"
  70. if [ -n "${NETDATA_SAVE_WARNINGS}" ]; then
  71. NETDATA_WARNINGS="${NETDATA_WARNINGS}\n - ${1}"
  72. fi
  73. exit_reason "${1}" "${2}"
  74. exit 1
  75. }
  76. exit_reason() {
  77. if [ -n "${NETDATA_SAVE_WARNINGS}" ]; then
  78. EXIT_REASON="${1}"
  79. EXIT_CODE="${2}"
  80. if [ -n "${NETDATA_PROPAGATE_WARNINGS}" ]; then
  81. if [ -n "${NETDATA_SCRIPT_STATUS_PATH}" ]; then
  82. {
  83. echo "EXIT_REASON=\"${EXIT_REASON}\""
  84. echo "EXIT_CODE=\"${EXIT_CODE}\""
  85. echo "NETDATA_WARNINGS=\"${NETDATA_WARNINGS}\""
  86. } >> "${NETDATA_SCRIPT_STATUS_PATH}"
  87. else
  88. export EXIT_REASON
  89. export EXIT_CODE
  90. export NETDATA_WARNINGS
  91. fi
  92. fi
  93. fi
  94. }
  95. is_integer () {
  96. case "${1#[+-]}" in
  97. *[!0123456789]*) return 1 ;;
  98. '') return 1 ;;
  99. *) return 0 ;;
  100. esac
  101. }
  102. issystemd() {
  103. # if the directory /lib/systemd/system OR /usr/lib/systemd/system (SLES 12.x) does not exit, it is not systemd
  104. if [ ! -d /lib/systemd/system ] && [ ! -d /usr/lib/systemd/system ]; then
  105. return 1
  106. fi
  107. # if there is no systemctl command, it is not systemd
  108. systemctl=$(command -v systemctl 2> /dev/null)
  109. if [ -z "${systemctl}" ] || [ ! -x "${systemctl}" ]; then
  110. return 1
  111. fi
  112. # if pid 1 is systemd, it is systemd
  113. [ "$(basename "$(readlink /proc/1/exe)" 2> /dev/null)" = "systemd" ] && return 0
  114. # if systemd is not running, it is not systemd
  115. pids=$(safe_pidof systemd 2> /dev/null)
  116. [ -z "${pids}" ] && return 1
  117. # check if the running systemd processes are not in our namespace
  118. myns="$(readlink /proc/self/ns/pid 2> /dev/null)"
  119. for p in ${pids}; do
  120. ns="$(readlink "/proc/${p}/ns/pid" 2> /dev/null)"
  121. # if pid of systemd is in our namespace, it is systemd
  122. [ -n "${myns}" ] && [ "${myns}" = "${ns}" ] && return 0
  123. done
  124. # else, it is not systemd
  125. return 1
  126. }
  127. _get_intervaldir() {
  128. if [ -d /etc/cron.daily ]; then
  129. echo /etc/cron.daily
  130. elif [ -d /etc/periodic/daily ]; then
  131. echo /etc/periodic/daily
  132. else
  133. return 1
  134. fi
  135. return 0
  136. }
  137. _get_scheduler_type() {
  138. if _get_intervaldir > /dev/null ; then
  139. echo 'interval'
  140. elif issystemd ; then
  141. echo 'systemd'
  142. elif [ -d /etc/cron.d ] ; then
  143. echo 'crontab'
  144. else
  145. echo 'none'
  146. fi
  147. }
  148. confirm() {
  149. prompt="${1} [y/n]"
  150. while true; do
  151. echo "${prompt}"
  152. read -r yn
  153. case "$yn" in
  154. [Yy]*) return 0;;
  155. [Nn]*) return 1;;
  156. *) echo "Please answer yes or no.";;
  157. esac
  158. done
  159. }
  160. warn_major_update() {
  161. nmv_suffix="New major versions generally involve breaking changes, and may not work in the same way as older versions."
  162. if [ "${INTERACTIVE}" -eq 0 ]; then
  163. warning "Would update to a new major version of Netdata. ${nmv_suffix}"
  164. warning "To install the new major version anyway, either run the updater interactively, or include the new major version number in the NETDATA_ACCEPT_MAJOR_VERSIONS variable in ${UPDATER_CONFIG_PATH}."
  165. fatal "Aborting update to new major version to avoid breaking things." U001B
  166. else
  167. warning "This update will install a new major version of Netdata. ${nmv_suffix}"
  168. if confirm "Are you sure you want to update to a new major version of Netdata?"; then
  169. notice "User accepted update to new major version of Netdata."
  170. else
  171. fatal "Aborting update to new major version at user request." U001C
  172. fi
  173. fi
  174. }
  175. install_build_dependencies() {
  176. bash="$(command -v bash 2> /dev/null)"
  177. if [ -z "${bash}" ] || [ ! -x "${bash}" ]; then
  178. error "Unable to find a usable version of \`bash\` (required for local build)."
  179. return 1
  180. fi
  181. info "Fetching dependency handling script..."
  182. download "${PACKAGES_SCRIPT}" "./install-required-packages.sh" || true
  183. if [ ! -s "./install-required-packages.sh" ]; then
  184. error "Downloaded dependency installation script is empty."
  185. else
  186. info "Running dependency handling script..."
  187. opts="--dont-wait --non-interactive"
  188. # shellcheck disable=SC2086
  189. if ! "${bash}" "./install-required-packages.sh" ${opts} netdata >&3 2>&3; then
  190. error "Installing build dependencies failed. The update should still work, but you might be missing some features."
  191. fi
  192. fi
  193. }
  194. enable_netdata_updater() {
  195. updater_type="$(echo "${1}" | tr '[:upper:]' '[:lower:]')"
  196. case "${updater_type}" in
  197. systemd|interval|crontab)
  198. updater_type="${1}"
  199. ;;
  200. "")
  201. updater_type="$(_get_scheduler_type)"
  202. ;;
  203. *)
  204. fatal "Unrecognized updater type ${updater_type} requested. Supported types are 'systemd', 'interval', and 'crontab'." U0001
  205. ;;
  206. esac
  207. case "${updater_type}" in
  208. "systemd")
  209. if issystemd; then
  210. systemctl enable netdata-updater.timer
  211. info "Auto-updating has been ENABLED using a systemd timer unit.\n"
  212. info "If the update process fails, the failure will be logged to the systemd journal just like a regular service failure."
  213. info "Successful updates should produce empty logs."
  214. else
  215. error "Systemd-based auto-update scheduling requested, but this does not appear to be a systemd system. Auto-updates have NOT been enabled."
  216. return 1
  217. fi
  218. ;;
  219. "interval")
  220. if _get_intervaldir > /dev/null; then
  221. ln -sf "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" "$(_get_intervaldir)/netdata-updater"
  222. info "Auto-updating has been ENABLED through cron, updater script linked to $(_get_intervaldir)/netdata-updater\n"
  223. 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."
  224. info "Successful updates will not send an email."
  225. else
  226. error "Interval-based auto-update scheduling requested, but I could not find an interval scheduling directory. Auto-updates have NOT been enabled."
  227. return 1
  228. fi
  229. ;;
  230. "crontab")
  231. if [ -d "/etc/cron.d" ]; then
  232. [ -f "/etc/cron.d/netdata-updater" ] && rm -f "/etc/cron.d/netdata-updater"
  233. install -p -m 0644 -o 0 -g 0 "${NETDATA_PREFIX}/usr/lib/system/cron/netdata-updater-daily" "/etc/cron.d/netdata-updater-daily"
  234. info "Auto-updating has been ENABLED through cron, using a crontab at /etc/cron.d/netdata-updater\n"
  235. 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."
  236. info "Successful updates will not send an email."
  237. else
  238. error "Crontab-based auto-update scheduling requested, but there is no '/etc/cron.d'. Auto-updates have NOT been enabled."
  239. return 1
  240. fi
  241. ;;
  242. *)
  243. error "Unable to determine what type of auto-update scheduling to use. Auto-updates have NOT been enabled."
  244. return 1
  245. esac
  246. return 0
  247. }
  248. disable_netdata_updater() {
  249. if issystemd && ( systemctl list-units --full -all | grep -Fq "netdata-updater.timer" ) ; then
  250. systemctl disable netdata-updater.timer
  251. fi
  252. if [ -d /etc/cron.daily ]; then
  253. rm -f /etc/cron.daily/netdata-updater.sh
  254. rm -f /etc/cron.daily/netdata-updater
  255. fi
  256. if [ -d /etc/periodic/daily ]; then
  257. rm -f /etc/periodic/daily/netdata-updater.sh
  258. rm -f /etc/periodic/daily/netdata-updater
  259. fi
  260. if [ -d /etc/cron.d ]; then
  261. rm -f /etc/cron.d/netdata-updater
  262. rm -f /etc/cron.d/netdata-updater-daily
  263. fi
  264. info "Auto-updates have been DISABLED."
  265. return 0
  266. }
  267. str_in_list() {
  268. printf "%s\n" "${2}" | tr ' ' "\n" | grep -qE "^${1}\$"
  269. return $?
  270. }
  271. safe_sha256sum() {
  272. # Within the context of the installer, we only use -c option that is common between the two commands
  273. # We will have to reconsider if we start non-common options
  274. if command -v shasum > /dev/null 2>&1; then
  275. shasum -a 256 "$@"
  276. elif command -v sha256sum > /dev/null 2>&1; then
  277. sha256sum "$@"
  278. else
  279. fatal "I could not find a suitable checksum binary to use" U0002
  280. fi
  281. }
  282. cleanup() {
  283. if [ -n "${logfile}" ]; then
  284. cat >&2 "${logfile}"
  285. rm "${logfile}"
  286. fi
  287. if [ -n "$ndtmpdir" ] && [ -d "$ndtmpdir" ]; then
  288. rm -rf "$ndtmpdir"
  289. fi
  290. }
  291. _cannot_use_tmpdir() {
  292. testfile="$(TMPDIR="${1}" mktemp -q -t netdata-test.XXXXXXXXXX)"
  293. ret=0
  294. if [ -z "${testfile}" ] ; then
  295. return "${ret}"
  296. fi
  297. if printf '#!/bin/sh\necho SUCCESS\n' > "${testfile}" ; then
  298. if chmod +x "${testfile}" ; then
  299. if [ "$("${testfile}" 2>/dev/null)" = "SUCCESS" ] ; then
  300. ret=1
  301. fi
  302. fi
  303. fi
  304. rm -f "${testfile}"
  305. return "${ret}"
  306. }
  307. create_tmp_directory() {
  308. if [ -n "${NETDATA_TMPDIR_PATH}" ]; then
  309. echo "${NETDATA_TMPDIR_PATH}"
  310. else
  311. if [ -z "${NETDATA_TMPDIR}" ] || _cannot_use_tmpdir "${NETDATA_TMPDIR}" ; then
  312. if [ -z "${TMPDIR}" ] || _cannot_use_tmpdir "${TMPDIR}" ; then
  313. if _cannot_use_tmpdir /tmp ; then
  314. if _cannot_use_tmpdir "${PWD}" ; then
  315. 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." U0003
  316. else
  317. TMPDIR="${PWD}"
  318. fi
  319. else
  320. TMPDIR="/tmp"
  321. fi
  322. fi
  323. else
  324. TMPDIR="${NETDATA_TMPDIR}"
  325. fi
  326. mktemp -d -t netdata-updater-XXXXXXXXXX
  327. fi
  328. }
  329. check_for_curl() {
  330. if [ -z "${curl}" ]; then
  331. curl="$(PATH="${PATH}:/opt/netdata/bin" command -v curl 2>/dev/null && true)"
  332. fi
  333. }
  334. _safe_download() {
  335. url="${1}"
  336. dest="${2}"
  337. check_for_curl
  338. if [ -n "${curl}" ]; then
  339. "${curl}" -fsSL --connect-timeout 10 --retry 3 "${url}" > "${dest}"
  340. return $?
  341. elif command -v wget > /dev/null 2>&1; then
  342. wget -T 15 -O - "${url}" > "${dest}"
  343. return $?
  344. else
  345. return 255
  346. fi
  347. }
  348. download() {
  349. url="${1}"
  350. dest="${2}"
  351. _safe_download "${url}" "${dest}"
  352. ret=$?
  353. if [ ${ret} -eq 0 ]; then
  354. return 0
  355. elif [ ${ret} -eq 255 ]; then
  356. fatal "I need curl or wget to proceed, but neither is available on this system." U0004
  357. else
  358. fatal "Cannot download ${url}" U0005
  359. fi
  360. }
  361. get_netdata_latest_tag() {
  362. url="${1}/latest"
  363. check_for_curl
  364. if [ -n "${curl}" ]; then
  365. tag=$("${curl}" "${url}" -s -L -I -o /dev/null -w '%{url_effective}' | grep -Eom 1 '[^/]*/?$')
  366. elif command -v wget >/dev/null 2>&1; then
  367. tag=$(wget -S -O /dev/null "${url}" 2>&1 | grep -m 1 Location | grep -Eo '[^/]*/?$')
  368. else
  369. fatal "I need curl or wget to proceed, but neither of them are available on this system." U0006
  370. fi
  371. # Fallback case for simpler local testing.
  372. if echo "${tag}" | grep -Eq 'latest/?$'; then
  373. if _safe_download "${url}/latest-version.txt" ./ndupdate-version.txt; then
  374. tag="$(cat ./ndupdate-version.txt)"
  375. if grep -q 'Not Found' ./ndupdate-version.txt; then
  376. tag="latest"
  377. fi
  378. rm -f ./ndupdate-version.txt
  379. else
  380. tag="latest"
  381. fi
  382. fi
  383. echo "${tag}"
  384. }
  385. newer_commit_date() {
  386. info "Checking if a newer version of the updater script is available."
  387. commit_check_url="https://api.github.com/repos/netdata/netdata/commits?path=packaging%2Finstaller%2Fnetdata-updater.sh&page=1&per_page=1"
  388. python_version_check="from __future__ import print_function;import sys,json;data = json.load(sys.stdin);print(data[0]['commit']['committer']['date'] if isinstance(data, list) else '')"
  389. if command -v jq > /dev/null 2>&1; then
  390. commit_date="$(_safe_download "${commit_check_url}" /dev/stdout | jq '.[0].commit.committer.date' 2>/dev/null | tr -d '"')"
  391. elif command -v python > /dev/null 2>&1;then
  392. commit_date="$(_safe_download "${commit_check_url}" /dev/stdout | python -c "${python_version_check}")"
  393. elif command -v python3 > /dev/null 2>&1;then
  394. commit_date="$(_safe_download "${commit_check_url}" /dev/stdout | python3 -c "${python_version_check}")"
  395. fi
  396. if [ -z "${commit_date}" ] ; then
  397. return 0
  398. elif [ "$(uname)" = "Linux" ]; then
  399. commit_date="$(date -d "${commit_date}" +%s)"
  400. else # assume BSD-style `date` if we are not on Linux
  401. commit_date="$(/bin/date -j -f "%Y-%m-%dT%H:%M:%SZ" "${commit_date}" +%s 2>/dev/null)"
  402. if [ -z "${commit_date}" ]; then
  403. return 0
  404. fi
  405. fi
  406. if [ -e "${script_source}" ]; then
  407. script_date="$(date -r "${script_source}" +%s)"
  408. else
  409. script_date="$(date +%s)"
  410. fi
  411. [ "${commit_date}" -ge "${script_date}" ]
  412. }
  413. self_update() {
  414. if [ -z "${NETDATA_NO_UPDATER_SELF_UPDATE}" ] && newer_commit_date; then
  415. info "Downloading newest version of updater script."
  416. ndtmpdir=$(create_tmp_directory)
  417. cd "$ndtmpdir" || exit 1
  418. if _safe_download "https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/netdata-updater.sh" ./netdata-updater.sh; then
  419. chmod +x ./netdata-updater.sh || exit 1
  420. export ENVIRONMENT_FILE="${ENVIRONMENT_FILE}"
  421. force_update=""
  422. [ "$NETDATA_FORCE_UPDATE" = "1" ] && force_update="--force-update"
  423. exec ./netdata-updater.sh --not-running-from-cron --no-updater-self-update "$force_update" --tmpdir-path "$(pwd)"
  424. else
  425. error "Failed to download newest version of updater script, continuing with current version."
  426. fi
  427. fi
  428. }
  429. parse_version() {
  430. r="${1}"
  431. if [ "${r}" = "latest" ]; then
  432. # If we get ‘latest’ as a version, return the largest possible
  433. # version value.
  434. printf "99999999999999"
  435. return 0
  436. elif echo "${r}" | grep -q '^v.*'; then
  437. # shellcheck disable=SC2001
  438. # XXX: Need a regex group substitution here.
  439. r="$(echo "${r}" | sed -e 's/^v\(.*\)/\1/')"
  440. fi
  441. tmpfile="$(mktemp)"
  442. echo "${r}" | tr '-' ' ' > "${tmpfile}"
  443. read -r v b _ < "${tmpfile}"
  444. if echo "${b}" | grep -vEq "^[0-9]+$"; then
  445. b="0"
  446. fi
  447. echo "${v}" | tr '.' ' ' > "${tmpfile}"
  448. read -r maj min patch _ < "${tmpfile}"
  449. rm -f "${tmpfile}"
  450. printf "%03d%03d%03d%05d" "${maj}" "${min}" "${patch}" "${b}"
  451. }
  452. get_latest_version() {
  453. if [ "${RELEASE_CHANNEL}" = "stable" ]; then
  454. get_netdata_latest_tag "${NETDATA_STABLE_BASE_URL}"
  455. else
  456. get_netdata_latest_tag "${NETDATA_NIGHTLY_BASE_URL}"
  457. fi
  458. }
  459. validate_environment_file() {
  460. if [ -n "${NETDATA_PREFIX+SET_BUT_NULL}" ] && [ -n "${REINSTALL_OPTIONS+SET_BUT_NULL}" ]; then
  461. return 0
  462. else
  463. fatal "Environment file located at ${ENVIRONMENT_FILE} is not valid, unable to update." U0007
  464. fi
  465. }
  466. update_available() {
  467. if [ "$NETDATA_FORCE_UPDATE" = "1" ]; then
  468. info "Force update requested"
  469. return 0
  470. fi
  471. basepath="$(dirname "$(dirname "$(dirname "${NETDATA_LIB_DIR}")")")"
  472. searchpath="${basepath}/bin:${basepath}/sbin:${basepath}/usr/bin:${basepath}/usr/sbin:${PATH}"
  473. searchpath="${basepath}/netdata/bin:${basepath}/netdata/sbin:${basepath}/netdata/usr/bin:${basepath}/netdata/usr/sbin:${searchpath}"
  474. ndbinary="$(PATH="${searchpath}" command -v netdata 2>/dev/null)"
  475. if [ -z "${ndbinary}" ]; then
  476. current_version=0
  477. else
  478. current_version="$(parse_version "$(${ndbinary} -v | cut -f 2 -d ' ')")"
  479. fi
  480. latest_tag="$(get_latest_version)"
  481. latest_version="$(parse_version "${latest_tag}")"
  482. path_version="$(echo "${latest_tag}" | cut -f 1 -d "-")"
  483. # If we can't get the current version for some reason assume `0`
  484. current_version="${current_version:-0}"
  485. # If we can't get the latest version for some reason assume `0`
  486. latest_version="${latest_version:-0}"
  487. info "Current Version: ${current_version}"
  488. info "Latest Version: ${latest_version}"
  489. if [ "${latest_version}" -gt 0 ] && [ "${current_version}" -gt 0 ] && [ "${current_version}" -ge "${latest_version}" ]; then
  490. info "Newest version (current=${current_version} >= latest=${latest_version}) is already installed"
  491. return 1
  492. else
  493. info "Update available"
  494. if [ "${current_version}" -ne 0 ] && [ "${latest_version}" -ne 0 ]; then
  495. current_major="$(${ndbinary} -v | cut -f 2 -d ' ' | cut -f 1 -d '.' | tr -d 'v')"
  496. latest_major="$(echo "${latest_tag}" | cut -f 1 -d '.' | tr -d 'v')"
  497. if [ "${current_major}" -ne "${latest_major}" ]; then
  498. update_safe=0
  499. for v in ${NETDATA_ACCEPT_MAJOR_VERSIONS}; do
  500. if [ "${latest_major}" -eq "${v}" ]; then
  501. update_safe=1
  502. break
  503. fi
  504. done
  505. if [ "${update_safe}" -eq 0 ]; then
  506. warn_major_update
  507. fi
  508. fi
  509. fi
  510. return 0
  511. fi
  512. }
  513. set_tarball_urls() {
  514. filename="netdata-latest.tar.gz"
  515. if [ "$2" = "yes" ]; then
  516. if [ -e /opt/netdata/etc/netdata/.install-type ]; then
  517. # shellcheck disable=SC1091
  518. . /opt/netdata/etc/netdata/.install-type
  519. [ -z "${PREBUILT_ARCH:-}" ] && PREBUILT_ARCH="$(uname -m)"
  520. filename="netdata-${PREBUILT_ARCH}-latest.gz.run"
  521. else
  522. filename="netdata-x86_64-latest.gz.run"
  523. fi
  524. fi
  525. if [ "$1" = "stable" ]; then
  526. latest="$(get_netdata_latest_tag "${NETDATA_STABLE_BASE_URL}")"
  527. export NETDATA_TARBALL_URL="${NETDATA_STABLE_BASE_URL}/download/$latest/${filename}"
  528. export NETDATA_TARBALL_CHECKSUM_URL="${NETDATA_STABLE_BASE_URL}/download/$latest/sha256sums.txt"
  529. else
  530. tag="$(get_netdata_latest_tag "${NETDATA_NIGHTLY_BASE_URL}")"
  531. export NETDATA_TARBALL_URL="${NETDATA_NIGHTLY_BASE_URL}/download/${tag}/${filename}"
  532. export NETDATA_TARBALL_CHECKSUM_URL="${NETDATA_NIGHTLY_BASE_URL}/download/${tag}/sha256sums.txt"
  533. fi
  534. }
  535. update_build() {
  536. [ -z "${logfile}" ] && info "Running on a terminal - (this script also supports running headless from crontab)"
  537. RUN_INSTALLER=0
  538. ndtmpdir=$(create_tmp_directory)
  539. cd "$ndtmpdir" || fatal "Failed to change current working directory to ${ndtmpdir}" U0016
  540. install_build_dependencies
  541. if update_available; then
  542. download "${NETDATA_TARBALL_CHECKSUM_URL}" "${ndtmpdir}/sha256sum.txt" >&3 2>&3
  543. download "${NETDATA_TARBALL_URL}" "${ndtmpdir}/netdata-latest.tar.gz"
  544. if [ -n "${NETDATA_TARBALL_CHECKSUM}" ] &&
  545. grep "${NETDATA_TARBALL_CHECKSUM}" sha256sum.txt >&3 2>&3 &&
  546. [ "$NETDATA_FORCE_UPDATE" != "1" ]; then
  547. info "Newest version is already installed"
  548. else
  549. if ! grep netdata-latest.tar.gz sha256sum.txt | safe_sha256sum -c - >&3 2>&3; then
  550. fatal "Tarball checksum validation failed. Stopping netdata upgrade and leaving tarball in ${ndtmpdir}\nUsually this is a result of an older copy of the tarball or checksum file being cached somewhere upstream and can be resolved by retrying in an hour." U0008
  551. fi
  552. NEW_CHECKSUM="$(safe_sha256sum netdata-latest.tar.gz 2> /dev/null | cut -d' ' -f1)"
  553. tar -xf netdata-latest.tar.gz >&3 2>&3
  554. rm netdata-latest.tar.gz >&3 2>&3
  555. if [ -z "$path_version" ]; then
  556. latest_tag="$(get_latest_version)"
  557. path_version="$(echo "${latest_tag}" | cut -f 1 -d "-")"
  558. fi
  559. cd "$(find . -maxdepth 1 -type d -name "netdata-${path_version}*" | head -n 1)" || fatal "Failed to switch to build directory" U0017
  560. RUN_INSTALLER=1
  561. fi
  562. fi
  563. # We got the sources, run the update now
  564. if [ ${RUN_INSTALLER} -eq 1 ]; then
  565. # signal netdata to start saving its database
  566. # this is handy if your database is big
  567. possible_pids=$(pidof netdata)
  568. do_not_start=
  569. if [ -n "${possible_pids}" ]; then
  570. # shellcheck disable=SC2086
  571. kill -USR1 ${possible_pids}
  572. else
  573. # netdata is currently not running, so do not start it after updating
  574. do_not_start="--dont-start-it"
  575. fi
  576. env="env TMPDIR=${TMPDIR}"
  577. if [ -n "${NETDATA_SELECTED_DASHBOARD}" ]; then
  578. env="${env} NETDATA_SELECTED_DASHBOARD=${NETDATA_SELECTED_DASHBOARD}"
  579. fi
  580. if [ ! -x ./netdata-installer.sh ]; then
  581. if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ] && [ -x "$(find . -mindepth 1 -maxdepth 1 -type d)/netdata-installer.sh" ]; then
  582. cd "$(find . -mindepth 1 -maxdepth 1 -type d)" || fatal "Failed to switch to build directory" U0018
  583. fi
  584. fi
  585. if [ -e "${NETDATA_PREFIX}/etc/netdata/.install-type" ] ; then
  586. install_type="$(cat "${NETDATA_PREFIX}"/etc/netdata/.install-type)"
  587. else
  588. install_type="INSTALL_TYPE='legacy-build'"
  589. fi
  590. if [ "${INSTALL_TYPE}" = "custom" ] && [ -f "${NETDATA_PREFIX}" ]; then
  591. install_type="INSTALL_TYPE='legacy-build'"
  592. fi
  593. info "Re-installing netdata..."
  594. export NETDATA_SAVE_WARNINGS=1
  595. export NETDATA_PROPAGATE_WARNINGS=1
  596. export NETDATA_WARNINGS="${NETDATA_WARNINGS}"
  597. export NETDATA_SCRIPT_STATUS_PATH="${NETDATA_SCRIPT_STATUS_PATH}"
  598. # shellcheck disable=SC2086
  599. if ! ${env} ./netdata-installer.sh ${REINSTALL_OPTIONS} --dont-wait ${do_not_start} >&3 2>&3; then
  600. if [ -r "${NETDATA_SCRIPT_STATUS_PATH}" ]; then
  601. # shellcheck disable=SC1090
  602. . "${NETDATA_SCRIPT_STATUS_PATH}"
  603. rm -f "${NETDATA_SCRIPT_STATUS_PATH}"
  604. fi
  605. if [ -n "${EXIT_REASON}" ]; then
  606. fatal "Failed to rebuild existing netdata install: ${EXIT_REASON}" "U${EXIT_CODE}"
  607. else
  608. fatal "Failed to rebuild existing netdata reinstall." UI0000
  609. fi
  610. fi
  611. # We no longer store checksum info here. but leave this so that we clean up all environment files upon next update.
  612. sed -i '/NETDATA_TARBALL/d' "${ENVIRONMENT_FILE}"
  613. info "Updating tarball checksum info"
  614. echo "${NEW_CHECKSUM}" > "${NETDATA_LIB_DIR}/netdata.tarball.checksum"
  615. echo "${install_type}" > "${NETDATA_PREFIX}/etc/netdata/.install-type"
  616. fi
  617. rm -rf "${ndtmpdir}" >&3 2>&3
  618. [ -n "${logfile}" ] && rm "${logfile}" && logfile=
  619. return 0
  620. }
  621. update_static() {
  622. ndtmpdir="$(create_tmp_directory)"
  623. PREVDIR="$(pwd)"
  624. info "Entering ${ndtmpdir}"
  625. cd "${ndtmpdir}" || fatal "Failed to change current working directory to ${ndtmpdir}" U0019
  626. if update_available; then
  627. sysarch="${PREBUILT_ARCH}"
  628. [ -z "$sysarch" ] && sysarch="$(uname -m)"
  629. download "${NETDATA_TARBALL_CHECKSUM_URL}" "${ndtmpdir}/sha256sum.txt"
  630. download "${NETDATA_TARBALL_URL}" "${ndtmpdir}/netdata-${sysarch}-latest.gz.run"
  631. if ! grep "netdata-${sysarch}-latest.gz.run" "${ndtmpdir}/sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then
  632. fatal "Static binary checksum validation failed. Stopping netdata installation and leaving binary in ${ndtmpdir}\nUsually this is a result of an older copy of the file being cached somewhere and can be resolved by simply retrying in an hour." U000A
  633. fi
  634. if [ -e /opt/netdata/etc/netdata/.install-type ] ; then
  635. install_type="$(cat /opt/netdata/etc/netdata/.install-type)"
  636. else
  637. install_type="INSTALL_TYPE='legacy-static'"
  638. fi
  639. # Do not pass any options other than the accept, for now
  640. # shellcheck disable=SC2086
  641. if sh "${ndtmpdir}/netdata-${sysarch}-latest.gz.run" --accept -- ${REINSTALL_OPTIONS} >&3 2>&3; then
  642. rm -r "${ndtmpdir}"
  643. else
  644. info "NOTE: did not remove: ${ndtmpdir}"
  645. fi
  646. echo "${install_type}" > /opt/netdata/etc/netdata/.install-type
  647. fi
  648. if [ -e "${PREVDIR}" ]; then
  649. info "Switching back to ${PREVDIR}"
  650. cd "${PREVDIR}"
  651. fi
  652. [ -n "${logfile}" ] && rm "${logfile}" && logfile=
  653. exit 0
  654. }
  655. get_new_binpkg_major() {
  656. case "${pm_cmd}" in
  657. apt-get) apt-get --just-print upgrade 2>&1 | grep Inst | grep ' netdata ' | cut -f 3 -d ' ' | tr -d '[]' | cut -f 1 -d '.' ;;
  658. yum) yum check-update netdata | grep -E '^netdata ' | awk '{print $2}' | cut -f 1 -d '.' ;;
  659. dnf) dnf check-update netdata | grep -E '^netdata ' | awk '{print $2}' | cut -f 1 -d '.' ;;
  660. zypper) zypper list-updates | grep '| netdata |' | cut -f 5 -d '|' | tr -d ' ' | cut -f 1 -d '.' ;;
  661. esac
  662. }
  663. update_binpkg() {
  664. os_release_file=
  665. if [ -s "/etc/os-release" ] && [ -r "/etc/os-release" ]; then
  666. os_release_file="/etc/os-release"
  667. elif [ -s "/usr/lib/os-release" ] && [ -r "/usr/lib/os-release" ]; then
  668. os_release_file="/usr/lib/os-release"
  669. else
  670. fatal "Cannot find an os-release file ..." U000B
  671. fi
  672. # shellcheck disable=SC1090
  673. . "${os_release_file}"
  674. DISTRO="${ID}"
  675. supported_compat_names="debian ubuntu centos fedora opensuse ol amzn"
  676. if str_in_list "${DISTRO}" "${supported_compat_names}"; then
  677. DISTRO_COMPAT_NAME="${DISTRO}"
  678. else
  679. case "${DISTRO}" in
  680. opensuse-leap|opensuse-tumbleweed)
  681. DISTRO_COMPAT_NAME="opensuse"
  682. ;;
  683. cloudlinux|almalinux|centos-stream|rocky|rhel)
  684. DISTRO_COMPAT_NAME="centos"
  685. ;;
  686. *)
  687. DISTRO_COMPAT_NAME="unknown"
  688. ;;
  689. esac
  690. fi
  691. interactive_opts=""
  692. env=""
  693. case "${DISTRO_COMPAT_NAME}" in
  694. debian|ubuntu)
  695. if [ "${INTERACTIVE}" = "0" ]; then
  696. upgrade_subcmd="-o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold --only-upgrade install"
  697. interactive_opts="-y"
  698. env="DEBIAN_FRONTEND=noninteractive"
  699. else
  700. upgrade_subcmd="--only-upgrade install"
  701. fi
  702. pm_cmd="apt-get"
  703. repo_subcmd="update"
  704. install_subcmd="install"
  705. mark_auto_cmd="apt-mark auto"
  706. pkg_install_opts="${interactive_opts}"
  707. repo_update_opts="${interactive_opts}"
  708. pkg_installed_check="dpkg-query -s"
  709. INSTALL_TYPE="binpkg-deb"
  710. ;;
  711. centos|fedora|ol|amzn)
  712. if [ "${INTERACTIVE}" = "0" ]; then
  713. interactive_opts="-y"
  714. fi
  715. if command -v dnf > /dev/null; then
  716. pm_cmd="dnf"
  717. repo_subcmd="makecache"
  718. mark_auto_cmd="dnf mark remove"
  719. else
  720. pm_cmd="yum"
  721. mark_auto_cmd="yumdb set reason dep"
  722. fi
  723. upgrade_subcmd="upgrade"
  724. install_subcmd="install"
  725. pkg_install_opts="${interactive_opts}"
  726. repo_update_opts="${interactive_opts}"
  727. pkg_installed_check="rpm -q"
  728. INSTALL_TYPE="binpkg-rpm"
  729. ;;
  730. opensuse)
  731. if [ "${INTERACTIVE}" = "0" ]; then
  732. upgrade_subcmd="--non-interactive update"
  733. else
  734. upgrade_subcmd="update"
  735. fi
  736. pm_cmd="zypper"
  737. repo_subcmd="--gpg-auto-import-keys refresh"
  738. install_subcmd="install"
  739. mark_auto_cmd=""
  740. pkg_install_opts=""
  741. repo_update_opts=""
  742. pkg_installed_check="rpm -q"
  743. INSTALL_TYPE="binpkg-rpm"
  744. ;;
  745. *)
  746. warning "We do not provide native packages for ${DISTRO}."
  747. return 2
  748. ;;
  749. esac
  750. if [ -n "${repo_subcmd}" ]; then
  751. # shellcheck disable=SC2086
  752. env ${env} ${pm_cmd} ${repo_subcmd} ${repo_update_opts} >&3 2>&3 || fatal "Failed to update repository metadata." U000C
  753. fi
  754. for repopkg in netdata-repo netdata-repo-edge; do
  755. if ${pkg_installed_check} ${repopkg} > /dev/null 2>&1; then
  756. # shellcheck disable=SC2086
  757. env ${env} ${pm_cmd} ${upgrade_subcmd} ${pkg_install_opts} ${repopkg} >&3 2>&3 || fatal "Failed to update Netdata repository config." U000D
  758. # shellcheck disable=SC2086
  759. if [ -n "${repo_subcmd}" ]; then
  760. env ${env} ${pm_cmd} ${repo_subcmd} ${repo_update_opts} >&3 2>&3 || fatal "Failed to update repository metadata." U000E
  761. fi
  762. fi
  763. done
  764. current_major="$(netdata -v | cut -f 2 -d ' ' | cut -f 1 -d '.' | tr -d 'v')"
  765. latest_major="$(get_new_binpkg_major)"
  766. if [ -n "${latest_major}" ] && [ "${latest_major}" -ne "${current_major}" ]; then
  767. update_safe=0
  768. for v in ${NETDATA_ACCEPT_MAJOR_VERSIONS}; do
  769. if [ "${latest_major}" -eq "${v}" ]; then
  770. update_safe=1
  771. break
  772. fi
  773. done
  774. if [ "${update_safe}" -eq 0 ]; then
  775. warn_major_update
  776. fi
  777. fi
  778. # shellcheck disable=SC2086
  779. env ${env} ${pm_cmd} ${upgrade_subcmd} ${pkg_install_opts} netdata >&3 2>&3 || fatal "Failed to update Netdata package." U000F
  780. if ${pkg_installed_check} systemd > /dev/null 2>&1; then
  781. if [ "${NETDATA_NO_SYSTEMD_JOURNAL}" -eq 0 ]; then
  782. if ! ${pkg_installed_check} netdata-plugin-systemd-journal > /dev/null 2>&1; then
  783. env ${env} ${pm_cmd} ${install_subcmd} ${pkg_install_opts} netdata-plugin-systemd-journal >&3 2>&3
  784. if [ -n "${mark_auto_cmd}" ]; then
  785. # shellcheck disable=SC2086
  786. env ${env} ${mark_auto_cmd} netdata-plugin-systemd-journal >&3 2>&3
  787. fi
  788. fi
  789. fi
  790. fi
  791. [ -n "${logfile}" ] && rm "${logfile}" && logfile=
  792. return 0
  793. }
  794. # Simple function to encapsulate original updater behavior.
  795. update_legacy() {
  796. set_tarball_urls "${RELEASE_CHANNEL}" "${IS_NETDATA_STATIC_BINARY}"
  797. case "${IS_NETDATA_STATIC_BINARY}" in
  798. yes) update_static && exit 0 ;;
  799. *) update_build && exit 0 ;;
  800. esac
  801. }
  802. logfile=
  803. ndtmpdir=
  804. trap cleanup EXIT
  805. if [ -t 2 ] || [ "${GITHUB_ACTIONS}" ]; then
  806. # we are running on a terminal or under CI
  807. # open fd 3 and send it to stderr
  808. exec 3>&2
  809. else
  810. # we are headless
  811. # create a temporary file for the log
  812. logfile="$(mktemp -t netdata-updater.log.XXXXXX)"
  813. # open fd 3 and send it to logfile
  814. exec 3> "${logfile}"
  815. fi
  816. : "${ENVIRONMENT_FILE:=THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT}"
  817. if [ "${ENVIRONMENT_FILE}" = "THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT" ]; then
  818. if [ -r "${script_dir}/../../../etc/netdata/.environment" ] || [ -r "${script_dir}/../../../etc/netdata/.install-type" ]; then
  819. ENVIRONMENT_FILE="${script_dir}/../../../etc/netdata/.environment"
  820. elif [ -r "/etc/netdata/.environment" ] || [ -r "/etc/netdata/.install-type" ]; then
  821. ENVIRONMENT_FILE="/etc/netdata/.environment"
  822. elif [ -r "/opt/netdata/etc/netdata/.environment" ] || [ -r "/opt/netdata/etc/netdata/.install-type" ]; then
  823. ENVIRONMENT_FILE="/opt/netdata/etc/netdata/.environment"
  824. else
  825. envpath="$(find / -type d \( -path /sys -o -path /proc -o -path /dev \) -prune -false -o -path '*netdata/.environment' -type f 2> /dev/null | head -n 1)"
  826. itpath="$(find / -type d \( -path /sys -o -path /proc -o -path /dev \) -prune -false -o -path '*netdata/.install-type' -type f 2> /dev/null | head -n 1)"
  827. if [ -r "${envpath}" ]; then
  828. ENVIRONMENT_FILE="${envpath}"
  829. elif [ -r "${itpath}" ]; then
  830. ENVIRONMENT_FILE="$(dirname "${itpath}")/.environment"
  831. else
  832. fatal "Cannot find environment file or install type file, unable to update." U0010
  833. fi
  834. fi
  835. fi
  836. if [ -r "${ENVIRONMENT_FILE}" ] ; then
  837. # shellcheck source=/dev/null
  838. . "${ENVIRONMENT_FILE}" || fatal "Failed to source ${ENVIRONMENT_FILE}" U0014
  839. fi
  840. if [ -r "$(dirname "${ENVIRONMENT_FILE}")/.install-type" ]; then
  841. # shellcheck source=/dev/null
  842. . "$(dirname "${ENVIRONMENT_FILE}")/.install-type" || fatal "Failed to source $(dirname "${ENVIRONMENT_FILE}")/.install-type" U0015
  843. fi
  844. UPDATER_CONFIG_PATH="$(dirname "${ENVIRONMENT_FILE}")/netdata-updater.conf"
  845. if [ -r "${UPDATER_CONFIG_PATH}" ]; then
  846. # shellcheck source=/dev/null
  847. . "${UPDATER_CONFIG_PATH}"
  848. fi
  849. [ -z "${NETDATA_ACCEPT_MAJOR_VERSIONS}" ] && NETDATA_ACCEPT_MAJOR_VERSIONS="${NETDATA_DEFAULT_ACCEPT_MAJOR_VERSIONS}"
  850. while [ -n "${1}" ]; do
  851. case "${1}" in
  852. --not-running-from-cron) NETDATA_NOT_RUNNING_FROM_CRON=1 ;;
  853. --no-updater-self-update) NETDATA_NO_UPDATER_SELF_UPDATE=1 ;;
  854. --force-update) NETDATA_FORCE_UPDATE=1 ;;
  855. --non-interactive) INTERACTIVE=0 ;;
  856. --interactive) INTERACTIVE=1 ;;
  857. --tmpdir-path)
  858. NETDATA_TMPDIR_PATH="${2}"
  859. shift 1
  860. ;;
  861. --enable-auto-updates)
  862. enable_netdata_updater "${2}"
  863. exit $?
  864. ;;
  865. --disable-auto-updates)
  866. disable_netdata_updater
  867. exit $?
  868. ;;
  869. *) fatal "Unrecognized option ${1}" U001A ;;
  870. esac
  871. shift 1
  872. done
  873. # Random sleep to alleviate stampede effect of Agents upgrading
  874. # and disconnecting/reconnecting at the same time (or near to).
  875. # But only we're not a controlling terminal (tty)
  876. # Randomly sleep between 1s and 60m
  877. if [ ! -t 1 ] && \
  878. [ -z "${GITHUB_ACTIONS}" ] && \
  879. [ -z "${NETDATA_NOT_RUNNING_FROM_CRON}" ] && \
  880. is_integer "${NETDATA_UPDATER_JITTER}" && \
  881. [ "${NETDATA_UPDATER_JITTER}" -gt 1 ]; then
  882. rnd="$(awk "
  883. BEGIN { srand()
  884. printf(\"%d\\n\", ${NETDATA_UPDATER_JITTER} * rand())
  885. }")"
  886. sleep $(((rnd % NETDATA_UPDATER_JITTER) + 1))
  887. fi
  888. # We dont expect to find lib dir variable on older installations, so load this path if none found
  889. export NETDATA_LIB_DIR="${NETDATA_LIB_DIR:-${NETDATA_PREFIX}/var/lib/netdata}"
  890. # Source the tarball checksum, if not already available from environment (for existing installations with the old logic)
  891. [ -z "${NETDATA_TARBALL_CHECKSUM}" ] && [ -f "${NETDATA_LIB_DIR}/netdata.tarball.checksum" ] && NETDATA_TARBALL_CHECKSUM="$(cat "${NETDATA_LIB_DIR}/netdata.tarball.checksum")"
  892. if echo "$INSTALL_TYPE" | grep -qv ^binpkg && [ "${INSTALL_UID}" != "$(id -u)" ]; then
  893. fatal "You are running this script as user with uid $(id -u). We recommend to run this script as root (user with uid 0)" U0011
  894. fi
  895. self_update
  896. # shellcheck disable=SC2153
  897. case "${INSTALL_TYPE}" in
  898. *-build)
  899. validate_environment_file
  900. set_tarball_urls "${RELEASE_CHANNEL}" "${IS_NETDATA_STATIC_BINARY}"
  901. update_build && exit 0
  902. ;;
  903. *-static*)
  904. validate_environment_file
  905. set_tarball_urls "${RELEASE_CHANNEL}" "${IS_NETDATA_STATIC_BINARY}"
  906. update_static && exit 0
  907. ;;
  908. *binpkg*) update_binpkg && exit 0 ;;
  909. "") # Fallback case for no `.install-type` file. This just works like the old install type detection.
  910. validate_environment_file
  911. update_legacy
  912. ;;
  913. custom)
  914. # At this point, we _should_ have a valid `.environment` file, but it's best to just check.
  915. # If we do, then behave like the legacy updater.
  916. if validate_environment_file && [ -n "${IS_NETDATA_STATIC_BINARY}" ]; then
  917. update_legacy
  918. else
  919. fatal "This script does not support updating custom installations without valid environment files." U0012
  920. fi
  921. ;;
  922. oci) fatal "This script does not support updating Netdata inside our official Docker containers, please instead update the container itself." U0013 ;;
  923. *) fatal "Unrecognized installation type (${INSTALL_TYPE}), unable to update." U0014 ;;
  924. esac