netdata-updater.sh 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121
  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. succeeded=0
  338. checked=0
  339. check_for_curl
  340. if [ -n "${curl}" ]; then
  341. checked=1
  342. if "${curl}" -fsSL --connect-timeout 10 --retry 3 "${url}" > "${dest}"; then
  343. succeeded=1
  344. else
  345. rm -f "${dest}"
  346. fi
  347. fi
  348. if [ "${succeeded}" -eq 0 ]; then
  349. if command -v wget > /dev/null 2>&1; then
  350. checked=1
  351. if wget -T 15 -O - "${url}" > "${dest}"; then
  352. succeeded=1
  353. else
  354. rm -f "${dest}"
  355. fi
  356. fi
  357. fi
  358. if [ "${succeeded}" -eq 1 ]; then
  359. return 0
  360. elif [ "${checked}" -eq 1 ]; then
  361. return 1
  362. else
  363. return 255
  364. fi
  365. }
  366. download() {
  367. url="${1}"
  368. dest="${2}"
  369. _safe_download "${url}" "${dest}"
  370. ret=$?
  371. if [ ${ret} -eq 0 ]; then
  372. return 0
  373. elif [ ${ret} -eq 255 ]; then
  374. fatal "I need curl or wget to proceed, but neither is available on this system." U0004
  375. else
  376. fatal "Cannot download ${url}" U0005
  377. fi
  378. }
  379. get_netdata_latest_tag() {
  380. url="${1}/latest"
  381. check_for_curl
  382. if [ -n "${curl}" ]; then
  383. tag=$("${curl}" "${url}" -s -L -I -o /dev/null -w '%{url_effective}')
  384. fi
  385. if [ -z "${tag}" ]; then
  386. if command -v wget >/dev/null 2>&1; then
  387. tag=$(wget -S -O /dev/null "${url}" 2>&1 | grep Location)
  388. fi
  389. fi
  390. if [ -z "${tag}" ]; then
  391. fatal "I need curl or wget to proceed, but neither of them are available on this system." U0006
  392. fi
  393. tag="$(echo "${tag}" | grep -Eom 1 '[^/]*/?$')"
  394. # Fallback case for simpler local testing.
  395. if echo "${tag}" | grep -Eq 'latest/?$'; then
  396. if _safe_download "${url}/latest-version.txt" ./ndupdate-version.txt; then
  397. tag="$(cat ./ndupdate-version.txt)"
  398. if grep -q 'Not Found' ./ndupdate-version.txt; then
  399. tag="latest"
  400. fi
  401. rm -f ./ndupdate-version.txt
  402. else
  403. tag="latest"
  404. fi
  405. fi
  406. echo "${tag}"
  407. }
  408. newer_commit_date() {
  409. info "Checking if a newer version of the updater script is available."
  410. commit_check_url="https://api.github.com/repos/netdata/netdata/commits?path=packaging%2Finstaller%2Fnetdata-updater.sh&page=1&per_page=1"
  411. 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 '')"
  412. if command -v jq > /dev/null 2>&1; then
  413. commit_date="$(_safe_download "${commit_check_url}" /dev/stdout | jq '.[0].commit.committer.date' 2>/dev/null | tr -d '"')"
  414. elif command -v python > /dev/null 2>&1;then
  415. commit_date="$(_safe_download "${commit_check_url}" /dev/stdout | python -c "${python_version_check}")"
  416. elif command -v python3 > /dev/null 2>&1;then
  417. commit_date="$(_safe_download "${commit_check_url}" /dev/stdout | python3 -c "${python_version_check}")"
  418. fi
  419. if [ -z "${commit_date}" ] ; then
  420. return 0
  421. elif [ "$(uname)" = "Linux" ]; then
  422. commit_date="$(date -d "${commit_date}" +%s)"
  423. else # assume BSD-style `date` if we are not on Linux
  424. commit_date="$(/bin/date -j -f "%Y-%m-%dT%H:%M:%SZ" "${commit_date}" +%s 2>/dev/null)"
  425. if [ -z "${commit_date}" ]; then
  426. return 0
  427. fi
  428. fi
  429. if [ -e "${script_source}" ]; then
  430. script_date="$(date -r "${script_source}" +%s)"
  431. else
  432. script_date="$(date +%s)"
  433. fi
  434. [ "${commit_date}" -ge "${script_date}" ]
  435. }
  436. self_update() {
  437. if [ -z "${NETDATA_NO_UPDATER_SELF_UPDATE}" ] && newer_commit_date; then
  438. info "Downloading newest version of updater script."
  439. ndtmpdir=$(create_tmp_directory)
  440. cd "$ndtmpdir" || exit 1
  441. if _safe_download "https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/netdata-updater.sh" ./netdata-updater.sh; then
  442. chmod +x ./netdata-updater.sh || exit 1
  443. export ENVIRONMENT_FILE="${ENVIRONMENT_FILE}"
  444. force_update=""
  445. [ "$NETDATA_FORCE_UPDATE" = "1" ] && force_update="--force-update"
  446. exec ./netdata-updater.sh --not-running-from-cron --no-updater-self-update "$force_update" --tmpdir-path "$(pwd)"
  447. else
  448. error "Failed to download newest version of updater script, continuing with current version."
  449. fi
  450. fi
  451. }
  452. parse_version() {
  453. r="${1}"
  454. if [ "${r}" = "latest" ]; then
  455. # If we get ‘latest’ as a version, return the largest possible
  456. # version value.
  457. printf "99999999999999"
  458. return 0
  459. elif echo "${r}" | grep -q '^v.*'; then
  460. # shellcheck disable=SC2001
  461. # XXX: Need a regex group substitution here.
  462. r="$(echo "${r}" | sed -e 's/^v\(.*\)/\1/')"
  463. fi
  464. tmpfile="$(mktemp)"
  465. echo "${r}" | tr '-' ' ' > "${tmpfile}"
  466. read -r v b _ < "${tmpfile}"
  467. if echo "${b}" | grep -vEq "^[0-9]+$"; then
  468. b="0"
  469. fi
  470. echo "${v}" | tr '.' ' ' > "${tmpfile}"
  471. read -r maj min patch _ < "${tmpfile}"
  472. rm -f "${tmpfile}"
  473. printf "%03d%03d%03d%05d" "${maj}" "${min}" "${patch}" "${b}"
  474. }
  475. get_latest_version() {
  476. if [ "${RELEASE_CHANNEL}" = "stable" ]; then
  477. get_netdata_latest_tag "${NETDATA_STABLE_BASE_URL}"
  478. else
  479. get_netdata_latest_tag "${NETDATA_NIGHTLY_BASE_URL}"
  480. fi
  481. }
  482. validate_environment_file() {
  483. if [ -n "${NETDATA_PREFIX+SET_BUT_NULL}" ] && [ -n "${REINSTALL_OPTIONS+SET_BUT_NULL}" ]; then
  484. return 0
  485. else
  486. fatal "Environment file located at ${ENVIRONMENT_FILE} is not valid, unable to update." U0007
  487. fi
  488. }
  489. update_available() {
  490. if [ "$NETDATA_FORCE_UPDATE" = "1" ]; then
  491. info "Force update requested"
  492. return 0
  493. fi
  494. basepath="$(dirname "$(dirname "$(dirname "${NETDATA_LIB_DIR}")")")"
  495. searchpath="${basepath}/bin:${basepath}/sbin:${basepath}/usr/bin:${basepath}/usr/sbin:${PATH}"
  496. searchpath="${basepath}/netdata/bin:${basepath}/netdata/sbin:${basepath}/netdata/usr/bin:${basepath}/netdata/usr/sbin:${searchpath}"
  497. ndbinary="$(PATH="${searchpath}" command -v netdata 2>/dev/null)"
  498. if [ -z "${ndbinary}" ]; then
  499. current_version=0
  500. else
  501. current_version="$(parse_version "$(${ndbinary} -v | cut -f 2 -d ' ')")"
  502. fi
  503. latest_tag="$(get_latest_version)"
  504. latest_version="$(parse_version "${latest_tag}")"
  505. path_version="$(echo "${latest_tag}" | cut -f 1 -d "-")"
  506. # If we can't get the current version for some reason assume `0`
  507. current_version="${current_version:-0}"
  508. # If we can't get the latest version for some reason assume `0`
  509. latest_version="${latest_version:-0}"
  510. info "Current Version: ${current_version}"
  511. info "Latest Version: ${latest_version}"
  512. if [ "${latest_version}" -gt 0 ] && [ "${current_version}" -gt 0 ] && [ "${current_version}" -ge "${latest_version}" ]; then
  513. info "Newest version (current=${current_version} >= latest=${latest_version}) is already installed"
  514. return 1
  515. else
  516. info "Update available"
  517. if [ "${current_version}" -ne 0 ] && [ "${latest_version}" -ne 0 ]; then
  518. current_major="$(${ndbinary} -v | cut -f 2 -d ' ' | cut -f 1 -d '.' | tr -d 'v')"
  519. latest_major="$(echo "${latest_tag}" | cut -f 1 -d '.' | tr -d 'v')"
  520. if [ "${current_major}" -ne "${latest_major}" ]; then
  521. update_safe=0
  522. for v in ${NETDATA_ACCEPT_MAJOR_VERSIONS}; do
  523. if [ "${latest_major}" -eq "${v}" ]; then
  524. update_safe=1
  525. break
  526. fi
  527. done
  528. if [ "${update_safe}" -eq 0 ]; then
  529. warn_major_update
  530. fi
  531. fi
  532. fi
  533. return 0
  534. fi
  535. }
  536. set_tarball_urls() {
  537. filename="netdata-latest.tar.gz"
  538. if [ "$2" = "yes" ]; then
  539. if [ -e /opt/netdata/etc/netdata/.install-type ]; then
  540. # shellcheck disable=SC1091
  541. . /opt/netdata/etc/netdata/.install-type
  542. [ -z "${PREBUILT_ARCH:-}" ] && PREBUILT_ARCH="$(uname -m)"
  543. filename="netdata-${PREBUILT_ARCH}-latest.gz.run"
  544. else
  545. filename="netdata-x86_64-latest.gz.run"
  546. fi
  547. fi
  548. if [ "$1" = "stable" ]; then
  549. latest="$(get_netdata_latest_tag "${NETDATA_STABLE_BASE_URL}")"
  550. export NETDATA_TARBALL_URL="${NETDATA_STABLE_BASE_URL}/download/$latest/${filename}"
  551. export NETDATA_TARBALL_CHECKSUM_URL="${NETDATA_STABLE_BASE_URL}/download/$latest/sha256sums.txt"
  552. else
  553. tag="$(get_netdata_latest_tag "${NETDATA_NIGHTLY_BASE_URL}")"
  554. export NETDATA_TARBALL_URL="${NETDATA_NIGHTLY_BASE_URL}/download/${tag}/${filename}"
  555. export NETDATA_TARBALL_CHECKSUM_URL="${NETDATA_NIGHTLY_BASE_URL}/download/${tag}/sha256sums.txt"
  556. fi
  557. }
  558. update_build() {
  559. [ -z "${logfile}" ] && info "Running on a terminal - (this script also supports running headless from crontab)"
  560. RUN_INSTALLER=0
  561. ndtmpdir=$(create_tmp_directory)
  562. cd "$ndtmpdir" || fatal "Failed to change current working directory to ${ndtmpdir}" U0016
  563. install_build_dependencies
  564. if update_available; then
  565. download "${NETDATA_TARBALL_CHECKSUM_URL}" "${ndtmpdir}/sha256sum.txt" >&3 2>&3
  566. download "${NETDATA_TARBALL_URL}" "${ndtmpdir}/netdata-latest.tar.gz"
  567. if [ -n "${NETDATA_TARBALL_CHECKSUM}" ] &&
  568. grep "${NETDATA_TARBALL_CHECKSUM}" sha256sum.txt >&3 2>&3 &&
  569. [ "$NETDATA_FORCE_UPDATE" != "1" ]; then
  570. info "Newest version is already installed"
  571. else
  572. if ! grep netdata-latest.tar.gz sha256sum.txt | safe_sha256sum -c - >&3 2>&3; then
  573. 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
  574. fi
  575. NEW_CHECKSUM="$(safe_sha256sum netdata-latest.tar.gz 2> /dev/null | cut -d' ' -f1)"
  576. tar -xf netdata-latest.tar.gz >&3 2>&3
  577. rm netdata-latest.tar.gz >&3 2>&3
  578. if [ -z "$path_version" ]; then
  579. latest_tag="$(get_latest_version)"
  580. path_version="$(echo "${latest_tag}" | cut -f 1 -d "-")"
  581. fi
  582. cd "$(find . -maxdepth 1 -type d -name "netdata-${path_version}*" | head -n 1)" || fatal "Failed to switch to build directory" U0017
  583. RUN_INSTALLER=1
  584. fi
  585. fi
  586. # We got the sources, run the update now
  587. if [ ${RUN_INSTALLER} -eq 1 ]; then
  588. # signal netdata to start saving its database
  589. # this is handy if your database is big
  590. possible_pids=$(pidof netdata)
  591. do_not_start=
  592. if [ -n "${possible_pids}" ]; then
  593. # shellcheck disable=SC2086
  594. kill -USR1 ${possible_pids}
  595. else
  596. # netdata is currently not running, so do not start it after updating
  597. do_not_start="--dont-start-it"
  598. fi
  599. env="env TMPDIR=${TMPDIR}"
  600. if [ -n "${NETDATA_SELECTED_DASHBOARD}" ]; then
  601. env="${env} NETDATA_SELECTED_DASHBOARD=${NETDATA_SELECTED_DASHBOARD}"
  602. fi
  603. if [ ! -x ./netdata-installer.sh ]; then
  604. if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ] && [ -x "$(find . -mindepth 1 -maxdepth 1 -type d)/netdata-installer.sh" ]; then
  605. cd "$(find . -mindepth 1 -maxdepth 1 -type d)" || fatal "Failed to switch to build directory" U0018
  606. fi
  607. fi
  608. if [ -e "${NETDATA_PREFIX}/etc/netdata/.install-type" ] ; then
  609. install_type="$(cat "${NETDATA_PREFIX}"/etc/netdata/.install-type)"
  610. else
  611. install_type="INSTALL_TYPE='legacy-build'"
  612. fi
  613. if [ "${INSTALL_TYPE}" = "custom" ] && [ -f "${NETDATA_PREFIX}" ]; then
  614. install_type="INSTALL_TYPE='legacy-build'"
  615. fi
  616. info "Re-installing netdata..."
  617. export NETDATA_SAVE_WARNINGS=1
  618. export NETDATA_PROPAGATE_WARNINGS=1
  619. export NETDATA_WARNINGS="${NETDATA_WARNINGS}"
  620. export NETDATA_SCRIPT_STATUS_PATH="${NETDATA_SCRIPT_STATUS_PATH}"
  621. # shellcheck disable=SC2086
  622. if ! ${env} ./netdata-installer.sh ${REINSTALL_OPTIONS} --dont-wait ${do_not_start} >&3 2>&3; then
  623. if [ -r "${NETDATA_SCRIPT_STATUS_PATH}" ]; then
  624. # shellcheck disable=SC1090
  625. . "${NETDATA_SCRIPT_STATUS_PATH}"
  626. rm -f "${NETDATA_SCRIPT_STATUS_PATH}"
  627. fi
  628. if [ -n "${EXIT_REASON}" ]; then
  629. fatal "Failed to rebuild existing netdata install: ${EXIT_REASON}" "U${EXIT_CODE}"
  630. else
  631. fatal "Failed to rebuild existing netdata reinstall." UI0000
  632. fi
  633. fi
  634. # We no longer store checksum info here. but leave this so that we clean up all environment files upon next update.
  635. sed -i '/NETDATA_TARBALL/d' "${ENVIRONMENT_FILE}"
  636. info "Updating tarball checksum info"
  637. echo "${NEW_CHECKSUM}" > "${NETDATA_LIB_DIR}/netdata.tarball.checksum"
  638. echo "${install_type}" > "${NETDATA_PREFIX}/etc/netdata/.install-type"
  639. fi
  640. rm -rf "${ndtmpdir}" >&3 2>&3
  641. [ -n "${logfile}" ] && rm "${logfile}" && logfile=
  642. return 0
  643. }
  644. update_static() {
  645. ndtmpdir="$(create_tmp_directory)"
  646. PREVDIR="$(pwd)"
  647. info "Entering ${ndtmpdir}"
  648. cd "${ndtmpdir}" || fatal "Failed to change current working directory to ${ndtmpdir}" U0019
  649. if update_available; then
  650. sysarch="${PREBUILT_ARCH}"
  651. [ -z "$sysarch" ] && sysarch="$(uname -m)"
  652. download "${NETDATA_TARBALL_CHECKSUM_URL}" "${ndtmpdir}/sha256sum.txt"
  653. download "${NETDATA_TARBALL_URL}" "${ndtmpdir}/netdata-${sysarch}-latest.gz.run"
  654. if ! grep "netdata-${sysarch}-latest.gz.run" "${ndtmpdir}/sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then
  655. 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
  656. fi
  657. if [ -e /opt/netdata/etc/netdata/.install-type ] ; then
  658. install_type="$(cat /opt/netdata/etc/netdata/.install-type)"
  659. else
  660. install_type="INSTALL_TYPE='legacy-static'"
  661. fi
  662. # Do not pass any options other than the accept, for now
  663. # shellcheck disable=SC2086
  664. if sh "${ndtmpdir}/netdata-${sysarch}-latest.gz.run" --accept -- ${REINSTALL_OPTIONS} >&3 2>&3; then
  665. rm -r "${ndtmpdir}"
  666. else
  667. info "NOTE: did not remove: ${ndtmpdir}"
  668. fi
  669. echo "${install_type}" > /opt/netdata/etc/netdata/.install-type
  670. fi
  671. if [ -e "${PREVDIR}" ]; then
  672. info "Switching back to ${PREVDIR}"
  673. cd "${PREVDIR}"
  674. fi
  675. [ -n "${logfile}" ] && rm "${logfile}" && logfile=
  676. exit 0
  677. }
  678. get_new_binpkg_major() {
  679. case "${pm_cmd}" in
  680. apt-get) apt-get --just-print upgrade 2>&1 | grep Inst | grep ' netdata ' | cut -f 3 -d ' ' | tr -d '[]' | cut -f 1 -d '.' ;;
  681. yum) yum check-update netdata | grep -E '^netdata ' | awk '{print $2}' | cut -f 1 -d '.' ;;
  682. dnf) dnf check-update netdata | grep -E '^netdata ' | awk '{print $2}' | cut -f 1 -d '.' ;;
  683. zypper) zypper list-updates | grep '| netdata |' | cut -f 5 -d '|' | tr -d ' ' | cut -f 1 -d '.' ;;
  684. esac
  685. }
  686. update_binpkg() {
  687. os_release_file=
  688. if [ -s "/etc/os-release" ] && [ -r "/etc/os-release" ]; then
  689. os_release_file="/etc/os-release"
  690. elif [ -s "/usr/lib/os-release" ] && [ -r "/usr/lib/os-release" ]; then
  691. os_release_file="/usr/lib/os-release"
  692. else
  693. fatal "Cannot find an os-release file ..." U000B
  694. fi
  695. # shellcheck disable=SC1090
  696. . "${os_release_file}"
  697. DISTRO="${ID}"
  698. supported_compat_names="debian ubuntu centos fedora opensuse ol amzn"
  699. if str_in_list "${DISTRO}" "${supported_compat_names}"; then
  700. DISTRO_COMPAT_NAME="${DISTRO}"
  701. else
  702. case "${DISTRO}" in
  703. opensuse-leap|opensuse-tumbleweed)
  704. DISTRO_COMPAT_NAME="opensuse"
  705. ;;
  706. cloudlinux|almalinux|centos-stream|rocky|rhel)
  707. DISTRO_COMPAT_NAME="centos"
  708. ;;
  709. *)
  710. DISTRO_COMPAT_NAME="unknown"
  711. ;;
  712. esac
  713. fi
  714. interactive_opts=""
  715. env=""
  716. case "${DISTRO_COMPAT_NAME}" in
  717. debian|ubuntu)
  718. if [ "${INTERACTIVE}" = "0" ]; then
  719. upgrade_subcmd="-o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold --only-upgrade install"
  720. interactive_opts="-y"
  721. env="DEBIAN_FRONTEND=noninteractive"
  722. else
  723. upgrade_subcmd="--only-upgrade install"
  724. fi
  725. pm_cmd="apt-get"
  726. repo_subcmd="update"
  727. install_subcmd="install"
  728. mark_auto_cmd="apt-mark auto"
  729. pkg_install_opts="${interactive_opts}"
  730. repo_update_opts="${interactive_opts}"
  731. pkg_installed_check="dpkg-query -s"
  732. INSTALL_TYPE="binpkg-deb"
  733. ;;
  734. centos|fedora|ol|amzn)
  735. if [ "${INTERACTIVE}" = "0" ]; then
  736. interactive_opts="-y"
  737. fi
  738. if command -v dnf > /dev/null; then
  739. pm_cmd="dnf"
  740. repo_subcmd="makecache"
  741. mark_auto_cmd="dnf mark remove"
  742. else
  743. pm_cmd="yum"
  744. mark_auto_cmd="yumdb set reason dep"
  745. fi
  746. upgrade_subcmd="upgrade"
  747. install_subcmd="install"
  748. pkg_install_opts="${interactive_opts}"
  749. repo_update_opts="${interactive_opts}"
  750. pkg_installed_check="rpm -q"
  751. INSTALL_TYPE="binpkg-rpm"
  752. ;;
  753. opensuse)
  754. if [ "${INTERACTIVE}" = "0" ]; then
  755. upgrade_subcmd="--non-interactive update"
  756. else
  757. upgrade_subcmd="update"
  758. fi
  759. pm_cmd="zypper"
  760. repo_subcmd="--gpg-auto-import-keys refresh"
  761. install_subcmd="install"
  762. mark_auto_cmd=""
  763. pkg_install_opts=""
  764. repo_update_opts=""
  765. pkg_installed_check="rpm -q"
  766. INSTALL_TYPE="binpkg-rpm"
  767. ;;
  768. *)
  769. warning "We do not provide native packages for ${DISTRO}."
  770. return 2
  771. ;;
  772. esac
  773. if [ -n "${repo_subcmd}" ]; then
  774. # shellcheck disable=SC2086
  775. env ${env} ${pm_cmd} ${repo_subcmd} ${repo_update_opts} >&3 2>&3 || fatal "Failed to update repository metadata." U000C
  776. fi
  777. for repopkg in netdata-repo netdata-repo-edge; do
  778. if ${pkg_installed_check} ${repopkg} > /dev/null 2>&1; then
  779. # shellcheck disable=SC2086
  780. env ${env} ${pm_cmd} ${upgrade_subcmd} ${pkg_install_opts} ${repopkg} >&3 2>&3 || fatal "Failed to update Netdata repository config." U000D
  781. # shellcheck disable=SC2086
  782. if [ -n "${repo_subcmd}" ]; then
  783. env ${env} ${pm_cmd} ${repo_subcmd} ${repo_update_opts} >&3 2>&3 || fatal "Failed to update repository metadata." U000E
  784. fi
  785. fi
  786. done
  787. current_major="$(netdata -v | cut -f 2 -d ' ' | cut -f 1 -d '.' | tr -d 'v')"
  788. latest_major="$(get_new_binpkg_major)"
  789. if [ -n "${latest_major}" ] && [ "${latest_major}" -ne "${current_major}" ]; then
  790. update_safe=0
  791. for v in ${NETDATA_ACCEPT_MAJOR_VERSIONS}; do
  792. if [ "${latest_major}" -eq "${v}" ]; then
  793. update_safe=1
  794. break
  795. fi
  796. done
  797. if [ "${update_safe}" -eq 0 ]; then
  798. warn_major_update
  799. fi
  800. fi
  801. # shellcheck disable=SC2086
  802. env ${env} ${pm_cmd} ${upgrade_subcmd} ${pkg_install_opts} netdata >&3 2>&3 || fatal "Failed to update Netdata package." U000F
  803. if ${pkg_installed_check} systemd > /dev/null 2>&1; then
  804. if [ "${NETDATA_NO_SYSTEMD_JOURNAL}" -eq 0 ]; then
  805. if ! ${pkg_installed_check} netdata-plugin-systemd-journal > /dev/null 2>&1; then
  806. env ${env} ${pm_cmd} ${install_subcmd} ${pkg_install_opts} netdata-plugin-systemd-journal >&3 2>&3
  807. if [ -n "${mark_auto_cmd}" ]; then
  808. # shellcheck disable=SC2086
  809. env ${env} ${mark_auto_cmd} netdata-plugin-systemd-journal >&3 2>&3
  810. fi
  811. fi
  812. fi
  813. fi
  814. [ -n "${logfile}" ] && rm "${logfile}" && logfile=
  815. return 0
  816. }
  817. # Simple function to encapsulate original updater behavior.
  818. update_legacy() {
  819. set_tarball_urls "${RELEASE_CHANNEL}" "${IS_NETDATA_STATIC_BINARY}"
  820. case "${IS_NETDATA_STATIC_BINARY}" in
  821. yes) update_static && exit 0 ;;
  822. *) update_build && exit 0 ;;
  823. esac
  824. }
  825. logfile=
  826. ndtmpdir=
  827. trap cleanup EXIT
  828. if [ -t 2 ] || [ "${GITHUB_ACTIONS}" ]; then
  829. # we are running on a terminal or under CI
  830. # open fd 3 and send it to stderr
  831. exec 3>&2
  832. else
  833. # we are headless
  834. # create a temporary file for the log
  835. logfile="$(mktemp -t netdata-updater.log.XXXXXX)"
  836. # open fd 3 and send it to logfile
  837. exec 3> "${logfile}"
  838. fi
  839. : "${ENVIRONMENT_FILE:=THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT}"
  840. if [ "${ENVIRONMENT_FILE}" = "THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT" ]; then
  841. if [ -r "${script_dir}/../../../etc/netdata/.environment" ] || [ -r "${script_dir}/../../../etc/netdata/.install-type" ]; then
  842. ENVIRONMENT_FILE="${script_dir}/../../../etc/netdata/.environment"
  843. elif [ -r "/etc/netdata/.environment" ] || [ -r "/etc/netdata/.install-type" ]; then
  844. ENVIRONMENT_FILE="/etc/netdata/.environment"
  845. elif [ -r "/opt/netdata/etc/netdata/.environment" ] || [ -r "/opt/netdata/etc/netdata/.install-type" ]; then
  846. ENVIRONMENT_FILE="/opt/netdata/etc/netdata/.environment"
  847. else
  848. 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)"
  849. 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)"
  850. if [ -r "${envpath}" ]; then
  851. ENVIRONMENT_FILE="${envpath}"
  852. elif [ -r "${itpath}" ]; then
  853. ENVIRONMENT_FILE="$(dirname "${itpath}")/.environment"
  854. else
  855. fatal "Cannot find environment file or install type file, unable to update." U0010
  856. fi
  857. fi
  858. fi
  859. if [ -r "${ENVIRONMENT_FILE}" ] ; then
  860. # shellcheck source=/dev/null
  861. . "${ENVIRONMENT_FILE}" || fatal "Failed to source ${ENVIRONMENT_FILE}" U0014
  862. fi
  863. if [ -r "$(dirname "${ENVIRONMENT_FILE}")/.install-type" ]; then
  864. # shellcheck source=/dev/null
  865. . "$(dirname "${ENVIRONMENT_FILE}")/.install-type" || fatal "Failed to source $(dirname "${ENVIRONMENT_FILE}")/.install-type" U0015
  866. fi
  867. UPDATER_CONFIG_PATH="$(dirname "${ENVIRONMENT_FILE}")/netdata-updater.conf"
  868. if [ -r "${UPDATER_CONFIG_PATH}" ]; then
  869. # shellcheck source=/dev/null
  870. . "${UPDATER_CONFIG_PATH}"
  871. fi
  872. [ -z "${NETDATA_ACCEPT_MAJOR_VERSIONS}" ] && NETDATA_ACCEPT_MAJOR_VERSIONS="${NETDATA_DEFAULT_ACCEPT_MAJOR_VERSIONS}"
  873. while [ -n "${1}" ]; do
  874. case "${1}" in
  875. --not-running-from-cron) NETDATA_NOT_RUNNING_FROM_CRON=1 ;;
  876. --no-updater-self-update) NETDATA_NO_UPDATER_SELF_UPDATE=1 ;;
  877. --force-update) NETDATA_FORCE_UPDATE=1 ;;
  878. --non-interactive) INTERACTIVE=0 ;;
  879. --interactive) INTERACTIVE=1 ;;
  880. --tmpdir-path)
  881. NETDATA_TMPDIR_PATH="${2}"
  882. shift 1
  883. ;;
  884. --enable-auto-updates)
  885. enable_netdata_updater "${2}"
  886. exit $?
  887. ;;
  888. --disable-auto-updates)
  889. disable_netdata_updater
  890. exit $?
  891. ;;
  892. *) fatal "Unrecognized option ${1}" U001A ;;
  893. esac
  894. shift 1
  895. done
  896. # Random sleep to alleviate stampede effect of Agents upgrading
  897. # and disconnecting/reconnecting at the same time (or near to).
  898. # But only we're not a controlling terminal (tty)
  899. # Randomly sleep between 1s and 60m
  900. if [ ! -t 1 ] && \
  901. [ -z "${GITHUB_ACTIONS}" ] && \
  902. [ -z "${NETDATA_NOT_RUNNING_FROM_CRON}" ] && \
  903. is_integer "${NETDATA_UPDATER_JITTER}" && \
  904. [ "${NETDATA_UPDATER_JITTER}" -gt 1 ]; then
  905. rnd="$(awk "
  906. BEGIN { srand()
  907. printf(\"%d\\n\", ${NETDATA_UPDATER_JITTER} * rand())
  908. }")"
  909. sleep $(((rnd % NETDATA_UPDATER_JITTER) + 1))
  910. fi
  911. # We dont expect to find lib dir variable on older installations, so load this path if none found
  912. export NETDATA_LIB_DIR="${NETDATA_LIB_DIR:-${NETDATA_PREFIX}/var/lib/netdata}"
  913. # Source the tarball checksum, if not already available from environment (for existing installations with the old logic)
  914. [ -z "${NETDATA_TARBALL_CHECKSUM}" ] && [ -f "${NETDATA_LIB_DIR}/netdata.tarball.checksum" ] && NETDATA_TARBALL_CHECKSUM="$(cat "${NETDATA_LIB_DIR}/netdata.tarball.checksum")"
  915. if echo "$INSTALL_TYPE" | grep -qv ^binpkg && [ "${INSTALL_UID}" != "$(id -u)" ]; then
  916. 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
  917. fi
  918. self_update
  919. # shellcheck disable=SC2153
  920. case "${INSTALL_TYPE}" in
  921. *-build)
  922. validate_environment_file
  923. set_tarball_urls "${RELEASE_CHANNEL}" "${IS_NETDATA_STATIC_BINARY}"
  924. update_build && exit 0
  925. ;;
  926. *-static*)
  927. validate_environment_file
  928. set_tarball_urls "${RELEASE_CHANNEL}" "${IS_NETDATA_STATIC_BINARY}"
  929. update_static && exit 0
  930. ;;
  931. *binpkg*) update_binpkg && exit 0 ;;
  932. "") # Fallback case for no `.install-type` file. This just works like the old install type detection.
  933. validate_environment_file
  934. update_legacy
  935. ;;
  936. custom)
  937. # At this point, we _should_ have a valid `.environment` file, but it's best to just check.
  938. # If we do, then behave like the legacy updater.
  939. if validate_environment_file && [ -n "${IS_NETDATA_STATIC_BINARY}" ]; then
  940. update_legacy
  941. else
  942. fatal "This script does not support updating custom installations without valid environment files." U0012
  943. fi
  944. ;;
  945. oci) fatal "This script does not support updating Netdata inside our official Docker containers, please instead update the container itself." U0013 ;;
  946. *) fatal "Unrecognized installation type (${INSTALL_TYPE}), unable to update." U0014 ;;
  947. esac