kickstart.sh 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506
  1. #!/bin/sh
  2. #
  3. # SPDX-License-Identifier: GPL-3.0-or-later
  4. #
  5. # Next unused error code: F051A
  6. # ======================================================================
  7. # Constants
  8. DEFAULT_RELEASE_CHANNEL="nightly"
  9. KICKSTART_OPTIONS="${*}"
  10. KICKSTART_SOURCE="$(
  11. self=${0}
  12. while [ -L "${self}" ]
  13. do
  14. cd "${self%/*}" || exit 1
  15. self=$(readlink "${self}")
  16. done
  17. cd "${self%/*}" || exit 1
  18. echo "$(pwd -P)/${self##*/}"
  19. )"
  20. DEFAULT_PLUGIN_PACKAGES=""
  21. PATH="${PATH}:/usr/local/bin:/usr/local/sbin"
  22. REPOCONFIG_DEB_VERSION="2-2"
  23. REPOCONFIG_RPM_VERSION="2-2"
  24. START_TIME="$(date +%s)"
  25. STATIC_INSTALL_ARCHES="x86_64 armv7l armv6l aarch64 ppc64le"
  26. # ======================================================================
  27. # URLs used throughout the script
  28. AGENT_BUG_REPORT_URL="https://github.com/netdata/netdata/issues/new/choose"
  29. CLOUD_BUG_REPORT_URL="https://github.com/netdata/netdata-cloud/issues/new/choose"
  30. DISCORD_INVITE="https://discord.gg/5ygS846fR6"
  31. DISCUSSIONS_URL="https://github.com/netdata/netdata/discussions"
  32. DOCS_URL="https://learn.netdata.cloud/docs/"
  33. FORUM_URL="https://community.netdata.cloud/"
  34. INSTALL_DOC_URL="https://learn.netdata.cloud/docs/install-the-netdata-agent/one-line-installer-for-all-linux-systems"
  35. PACKAGES_SCRIPT="https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/install-required-packages.sh"
  36. PUBLIC_CLOUD_URL="https://app.netdata.cloud"
  37. RELEASE_INFO_URL="https://repo.netdata.cloud/releases"
  38. REPOCONFIG_DEB_URL_PREFIX="https://repo.netdata.cloud/repos/repoconfig"
  39. REPOCONFIG_RPM_URL_PREFIX="https://repo.netdata.cloud/repos/repoconfig"
  40. TELEMETRY_URL="https://us-east1-netdata-analytics-bi.cloudfunctions.net/ingest_agent_events"
  41. # ======================================================================
  42. # Defaults for environment variables
  43. DRY_RUN=0
  44. SELECTED_INSTALL_METHOD="none"
  45. INSTALL_TYPE="unknown"
  46. INSTALL_PREFIX=""
  47. NETDATA_AUTO_UPDATES="default"
  48. NETDATA_CLAIM_URL="https://app.netdata.cloud"
  49. NETDATA_COMMAND="default"
  50. NETDATA_DISABLE_CLOUD=0
  51. NETDATA_INSTALLER_OPTIONS=""
  52. NETDATA_FORCE_METHOD=""
  53. NETDATA_OFFLINE_INSTALL_SOURCE=""
  54. NETDATA_REQUIRE_CLOUD=1
  55. NETDATA_WARNINGS=""
  56. RELEASE_CHANNEL="default"
  57. if [ -n "$DISABLE_TELEMETRY" ]; then
  58. NETDATA_DISABLE_TELEMETRY="${DISABLE_TELEMETRY}"
  59. elif [ -n "$DO_NOT_TRACK" ]; then
  60. NETDATA_DISABLE_TELEMETRY="${DO_NOT_TRACK}"
  61. else
  62. NETDATA_DISABLE_TELEMETRY=0
  63. fi
  64. NETDATA_TARBALL_BASEURL="${NETDATA_TARBALL_BASEURL:-https://github.com/netdata/netdata-nightlies/releases}"
  65. if echo "${0}" | grep -q 'kickstart-static64'; then
  66. NETDATA_FORCE_METHOD='static'
  67. fi
  68. if [ ! -t 1 ]; then
  69. INTERACTIVE=0
  70. else
  71. INTERACTIVE=1
  72. fi
  73. CURL="$(PATH="${PATH}:/opt/netdata/bin" command -v curl 2>/dev/null && true)"
  74. # ======================================================================
  75. # Shared messages used in multiple places throughout the script.
  76. BADCACHE_MSG="Usually this is a result of an older copy of the file being cached somewhere upstream and can be resolved by retrying in an hour"
  77. BADNET_MSG="This is usually a result of a networking issue"
  78. ERROR_F0003="Could not find a usable HTTP client. Either curl or wget is required to proceed with installation."
  79. BADOPT_MSG="If you are following a third-party guide online, please see ${INSTALL_DOC_URL} for current instructions for using this script. If you are using a local copy of this script instead of fetching it from our servers, consider updating it. 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."
  80. # ======================================================================
  81. # Core program logic
  82. main() {
  83. case "${ACTION}" in
  84. uninstall)
  85. uninstall
  86. printf >&2 "Finished uninstalling the Netdata Agent."
  87. deferred_warnings
  88. cleanup
  89. trap - EXIT
  90. exit 0
  91. ;;
  92. reinstall-clean)
  93. NEW_INSTALL_PREFIX="${INSTALL_PREFIX}"
  94. uninstall
  95. cleanup
  96. ACTION=''
  97. INSTALL_PREFIX="${NEW_INSTALL_PREFIX}"
  98. # shellcheck disable=SC2086
  99. main
  100. trap - EXIT
  101. exit 0
  102. ;;
  103. prepare-offline)
  104. prepare_offline_install_source "${OFFLINE_TARGET}"
  105. deferred_warnings
  106. trap - EXIT
  107. exit 0
  108. ;;
  109. esac
  110. handle_existing_install
  111. set_tmpdir
  112. if [ -n "${INSTALL_VERSION}" ]; then
  113. if echo "${INSTALL_VERSION}" | grep -E -o "^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$" > /dev/null 2>&1; then
  114. NEW_SELECTED_RELEASE_CHANNEL="stable"
  115. else
  116. NEW_SELECTED_RELEASE_CHANNEL="nightly"
  117. fi
  118. if ! [ "${NEW_SELECTED_RELEASE_CHANNEL}" = "${SELECTED_RELEASE_CHANNEL}" ]; then
  119. warning "Selected release channel does not match this version and it will be changed automatically."
  120. SELECTED_RELEASE_CHANNEL="${NEW_SELECTED_RELEASE_CHANNEL}"
  121. fi
  122. fi
  123. case "${SYSTYPE}" in
  124. Linux) install_on_linux ;;
  125. Darwin) install_on_macos ;;
  126. FreeBSD) install_on_freebsd ;;
  127. esac
  128. if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then
  129. claim
  130. elif [ "${NETDATA_DISABLE_CLOUD}" -eq 1 ]; then
  131. soft_disable_cloud
  132. fi
  133. set_auto_updates
  134. printf >&2 "%s\n\n" "Successfully installed the Netdata Agent."
  135. deferred_warnings
  136. success_banner
  137. telemetry_event INSTALL_SUCCESS "" ""
  138. cleanup
  139. trap - EXIT
  140. }
  141. # ======================================================================
  142. # Usage info
  143. usage() {
  144. cat << HEREDOC
  145. USAGE: kickstart.sh [options]
  146. where options include:
  147. --non-interactive Do not prompt for user input. (default: prompt if there is a controlling terminal)
  148. --interactive Prompt for user input even if there is no controlling terminal.
  149. --dont-start-it Do not start the agent by default (only for static installs or local builds)
  150. --dry-run Report what we would do with the given options on this system, but don’t actually do anything.
  151. --release-channel Specify the release channel to use for the install (default: ${DEFAULT_RELEASE_CHANNEL})
  152. --stable-channel Equivalent to "--release-channel stable"
  153. --nightly-channel Equivalent to "--release-channel nightly"
  154. --no-updates Do not enable automatic updates (default: enable automatic updates using the best supported scheduling method)
  155. --auto-update Enable automatic updates.
  156. --auto-update-type Specify a particular scheduling type for auto-updates (valid types: systemd, interval, crontab)
  157. --disable-telemetry Opt-out of anonymous statistics.
  158. --native-only Only install if native binary packages are available.
  159. --static-only Only install if a static build is available.
  160. --build-only Only install using a local build.
  161. --disable-cloud Disable support for Netdata Cloud (default: detect)
  162. --require-cloud Only install if Netdata Cloud can be enabled. Overrides --disable-cloud.
  163. --install-prefix <path> Specify an installation prefix for local builds (default: autodetect based on system type).
  164. --old-install-prefix <path> Specify an old local builds installation prefix for uninstall/reinstall (if it's not default).
  165. --install-version <version> Specify the version of Netdata to install.
  166. --claim-token Use a specified token for claiming to Netdata Cloud.
  167. --claim-rooms When claiming, add the node to the specified rooms.
  168. --claim-* Specify other options for the claiming script.
  169. --no-cleanup Don't do any cleanup steps. This is intended to help with debugging the installer.
  170. --local-build-options Specify additional options to pass to the installer code when building locally. Only valid if --build-only is also specified.
  171. --static-install-options Specify additional options to pass to the static installer code. Only valid if --static-only is also specified.
  172. --offline-architecture Limit an offline install source being prepared with --prepare-offline-install-source to only include the specified static build architecture.
  173. The following options are mutually exclusive and specifiy special operations other than trying to install Netdata normally or update an existing install:
  174. --reinstall If there is an existing install, reinstall it instead of trying to update it. If there is no existing install, install netdata normally.
  175. --reinstall-even-if-unsafe If there is an existing install, reinstall it instead of trying to update it, even if doing so is known to potentially break things. If there is no existing install, install Netdata normally.
  176. --reinstall-clean If there is an existing install, uninstall it before trying to install Netdata. Fails if there is no existing install.
  177. --uninstall Uninstall an existing installation of Netdata. Fails if there is no existing install.
  178. --claim-only If there is an existing install, only try to claim it without attempting to update it. If there is no existing install, install and claim Netdata normally.
  179. --repositories-only Only install repository configuration packages instead of doing a full install of Netdata. Automatically sets --native-only.
  180. --prepare-offline-install-source Instead of installing the agent, prepare a directory that can be used to install on another system without needing to download anything.
  181. Additionally, this script may use the following environment variables:
  182. TMPDIR: Used to specify where to put temporary files. On most systems, the default we select
  183. automatically should be fine. The user running the script needs to both be able to
  184. write files to the temporary directory, and run files from that location.
  185. ROOTCMD: Used to specify a command to use to run another command with root privileges if needed. By
  186. default we try to use sudo, doas, or pkexec (in that order of preference), but if
  187. you need special options for one of those to work, or have a different tool to do
  188. the same thing on your system, you can specify it here.
  189. DISABLE_TELEMETRY If set to a value other than 0, behave as if \`--disable-telemetry\` was specified.
  190. HEREDOC
  191. }
  192. # ======================================================================
  193. # Telemetry functions
  194. telemetry_event() {
  195. if [ "${NETDATA_DISABLE_TELEMETRY}" -eq 1 ] || [ "${DRY_RUN}" -eq 1 ]; then
  196. return 0
  197. fi
  198. now="$(date +%s)"
  199. total_duration="$((now - START_TIME))"
  200. if [ -e "/etc/os-release" ]; then
  201. eval "$(grep -E "^(NAME|ID|ID_LIKE|VERSION|VERSION_ID)=" < /etc/os-release | sed 's/^/HOST_/')"
  202. fi
  203. if [ -z "${HOST_NAME}" ] || [ -z "${HOST_VERSION}" ] || [ -z "${HOST_ID}" ]; then
  204. if [ -f "/etc/lsb-release" ]; then
  205. DISTRIB_ID="unknown"
  206. DISTRIB_RELEASE="unknown"
  207. DISTRIB_CODENAME="unknown"
  208. eval "$(grep -E "^(DISTRIB_ID|DISTRIB_RELEASE|DISTRIB_CODENAME)=" < /etc/lsb-release)"
  209. if [ -z "${HOST_NAME}" ]; then HOST_NAME="${DISTRIB_ID}"; fi
  210. if [ -z "${HOST_VERSION}" ]; then HOST_VERSION="${DISTRIB_RELEASE}"; fi
  211. if [ -z "${HOST_ID}" ]; then HOST_ID="${DISTRIB_CODENAME}"; fi
  212. fi
  213. fi
  214. KERNEL_NAME="$(uname -s)"
  215. if [ "${KERNEL_NAME}" = FreeBSD ]; then
  216. TOTAL_RAM="$(sysctl -n hw.physmem)"
  217. elif [ "${KERNEL_NAME}" = Darwin ]; then
  218. TOTAL_RAM="$(sysctl -n hw.memsize)"
  219. elif [ -r /proc/meminfo ]; then
  220. TOTAL_RAM="$(grep -F MemTotal /proc/meminfo | cut -f 2 -d ':' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | cut -f 1 -d ' ')"
  221. TOTAL_RAM="$((TOTAL_RAM * 1024))"
  222. fi
  223. MD5_PATH="$(exec <&- 2>&-; which md5sum || command -v md5sum || type md5sum)"
  224. if [ "${KERNEL_NAME}" = Darwin ] && command -v ioreg >/dev/null 2>&1; then
  225. DISTINCT_ID="macos-$(ioreg -rd1 -c IOPlatformExpertDevice | awk '/IOPlatformUUID/ { split($0, line, "\""); printf("%s\n", line[4]); }')"
  226. elif [ -f /etc/machine-id ] && [ -n "$MD5_PATH" ]; then
  227. DISTINCT_ID="machine-$($MD5_PATH < /etc/machine-id | cut -f1 -d" ")"
  228. elif [ -f /var/db/dbus/machine-id ] && [ -n "$MD5_PATH" ]; then
  229. DISTINCT_ID="dbus-$($MD5_PATH < /var/db/dbus/machine-id | cut -f1 -d" ")"
  230. elif [ -f /var/lib/dbus/machine-id ] && [ -n "$MD5_PATH" ]; then
  231. DISTINCT_ID="dbus-$($MD5_PATH < /var/lib/dbus/machine-id | cut -f1 -d" ")"
  232. elif command -v uuidgen > /dev/null 2>&1; then
  233. DISTINCT_ID="uuid-$(uuidgen | tr '[:upper:]' '[:lower:]')"
  234. else
  235. DISTINCT_ID="null"
  236. fi
  237. REQ_BODY="$(cat << EOF
  238. {
  239. "event": "${1}",
  240. "properties": {
  241. "distinct_id": "${DISTINCT_ID}",
  242. "event_source": "agent installer",
  243. "\$current_url": "agent installer",
  244. "\$pathname": "netdata-installer",
  245. "\$host": "installer.netdata.io",
  246. "\$ip": "127.0.0.1",
  247. "script_variant": "kickstart-ng",
  248. "error_code": "${3}",
  249. "error_message": "${2}",
  250. "install_options": "${KICKSTART_OPTIONS}",
  251. "install_interactivity": "${INTERACTIVE}",
  252. "install_auto_updates": "${NETDATA_AUTO_UPDATES}",
  253. "install_command": "${NETDATA_COMMAND}",
  254. "total_runtime": "${total_duration}",
  255. "selected_install_method": "${SELECTED_INSTALL_METHOD}",
  256. "netdata_release_channel": "${RELEASE_CHANNEL:-null}",
  257. "netdata_install_type": "${INSTALL_TYPE}",
  258. "host_os_name": "${HOST_NAME:-unknown}",
  259. "host_os_id": "${HOST_ID:-unknown}",
  260. "host_os_id_like": "${HOST_ID_LIKE:-unknown}",
  261. "host_os_version": "${HOST_VERSION:-unknown}",
  262. "host_os_version_id": "${HOST_VERSION_ID:-unknown}",
  263. "system_kernel_name": "${KERNEL_NAME}",
  264. "system_kernel_version": "$(uname -r)",
  265. "system_architecture": "$(uname -m)",
  266. "system_total_ram": "${TOTAL_RAM:-unknown}",
  267. "system_distinct_id": "${DISTINCT_ID}"
  268. }
  269. }
  270. EOF
  271. )"
  272. succeeded=0
  273. if [ -n "${CURL}" ]; then
  274. if "${CURL}" --silent -o /dev/null -X POST --max-time 2 --header "Content-Type: application/json" -d "${REQ_BODY}" "${TELEMETRY_URL}" > /dev/null; then
  275. succeeded=1
  276. fi
  277. fi
  278. if [ "${succeeded}" -eq 0 ]; then
  279. if command -v wget > /dev/null 2>&1; then
  280. if wget --help 2>&1 | grep BusyBox > /dev/null 2>&1; then
  281. # BusyBox-compatible version of wget, there is no --no-check-certificate option
  282. wget -q -O - \
  283. -T 1 \
  284. --header 'Content-Type: application/json' \
  285. --post-data "${REQ_BODY}" \
  286. "${TELEMETRY_URL}" > /dev/null
  287. else
  288. wget -q -O - --no-check-certificate \
  289. --method POST \
  290. --timeout=1 \
  291. --header 'Content-Type: application/json' \
  292. --body-data "${REQ_BODY}" \
  293. "${TELEMETRY_URL}" > /dev/null
  294. fi
  295. fi
  296. fi
  297. }
  298. trap_handler() {
  299. code="${1}"
  300. lineno="${2}"
  301. deferred_warnings
  302. printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ERROR ${TPUT_RESET} Installer exited unexpectedly (${code}-${lineno})"
  303. case "${code}" in
  304. 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}." ;;
  305. *)
  306. printf >&2 "%s\n" "This is probably a result of a transient issue on your system. Things should work correctly if you try again."
  307. printf >&2 "%s\n" "If you continue to experience this issue, you can reacn out to us for support on:"
  308. support_list
  309. ;;
  310. esac
  311. telemetry_event INSTALL_CRASH "Installer exited unexpectedly (${code}-${lineno})" "E${code}-${lineno}"
  312. trap - EXIT
  313. cleanup
  314. exit 1
  315. }
  316. trap 'trap_handler 0 ${LINENO}' EXIT
  317. trap 'trap_handler 1 0' HUP
  318. trap 'trap_handler 2 0' INT
  319. trap 'trap_handler 3 0' QUIT
  320. trap 'trap_handler 13 0' PIPE
  321. trap 'trap_handler 15 0' TERM
  322. # ======================================================================
  323. # Utility functions
  324. canonical_path() {
  325. cd "$(dirname "${1}")" || exit 1
  326. case "$(basename "${1}")" in
  327. ..) dirname "$(pwd -P)" ;;
  328. .) pwd -P ;;
  329. *) echo "$(pwd -P)/$(basename "${1}")" ;;
  330. esac
  331. }
  332. setup_terminal() {
  333. TPUT_RESET=""
  334. TPUT_WHITE=""
  335. TPUT_BGRED=""
  336. TPUT_BGGREEN=""
  337. TPUT_BOLD=""
  338. TPUT_DIM=""
  339. # Is stderr on the terminal? If not, then fail
  340. test -t 2 || return 1
  341. if command -v tput > /dev/null 2>&1; then
  342. if num_colors=$(tput colors 2> /dev/null) && [ "${num_colors:-0}" -ge 8 ]; then
  343. # Enable colors
  344. TPUT_RESET="$(tput sgr 0)"
  345. TPUT_WHITE="$(tput setaf 7)"
  346. TPUT_BGRED="$(tput setab 1)"
  347. TPUT_BGGREEN="$(tput setab 2)"
  348. TPUT_BOLD="$(tput bold)"
  349. TPUT_DIM="$(tput dim)"
  350. fi
  351. fi
  352. echo "${TPUT_RESET}"
  353. return 0
  354. }
  355. support_list() {
  356. printf >&2 "%s\n" " - GitHub: ${DISCUSSIONS_URL}"
  357. printf >&2 "%s\n" " - Discord: ${DISCORD_INVITE}"
  358. printf >&2 "%s\n" " - Our community forums: ${FORUM_URL}"
  359. }
  360. success_banner() {
  361. printf >&2 "%s\n" "To view your system's real-time performance metrics, open your web browser and enter http://NODE:19999."
  362. printf >&2 "%s\n\n" "Replace NODE with the IP address or hostname of your Netdata server to access the dashboard."
  363. printf >&2 "%s\n\n" "Official documentation can be found online at ${DOCS_URL}."
  364. if [ -z "${CLAIM_TOKEN}" ]; then
  365. printf >&2 "%s\n\n" "Looking to monitor all of your infrastructure with Netdata? Check out Netdata Cloud at ${PUBLIC_CLOUD_URL}."
  366. fi
  367. printf >&2 "%s\n" "Join our community and connect with us on:"
  368. support_list
  369. }
  370. cleanup() {
  371. if [ -z "${NO_CLEANUP}" ] && [ -n "${tmpdir}" ]; then
  372. cd || true
  373. DRY_RUN=0
  374. run_as_root rm -rf "${tmpdir}"
  375. fi
  376. }
  377. deferred_warnings() {
  378. if [ -n "${NETDATA_WARNINGS}" ]; then
  379. printf >&2 "%s\n" "The following non-fatal warnings or errors were encountered:"
  380. # shellcheck disable=SC2059
  381. printf >&2 "${NETDATA_WARNINGS}"
  382. printf >&2 "\n\n"
  383. fi
  384. }
  385. fatal() {
  386. deferred_warnings
  387. printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${1}"
  388. printf >&2 "%s\n" "For community support, you can connect with us on:"
  389. support_list
  390. telemetry_event "INSTALL_FAILED" "${1}" "${2}"
  391. cleanup
  392. trap - EXIT
  393. exit 1
  394. }
  395. ESCAPED_PRINT_METHOD=
  396. # shellcheck disable=SC3050
  397. if printf "%s " test > /dev/null 2>&1; then
  398. ESCAPED_PRINT_METHOD="printfq"
  399. fi
  400. escaped_print() {
  401. if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]; then
  402. # shellcheck disable=SC3050
  403. printf "%s " "${@}"
  404. else
  405. printf "%s" "${*}"
  406. fi
  407. return 0
  408. }
  409. progress() {
  410. echo >&2 " --- ${TPUT_BOLD}${*}${TPUT_RESET} --- "
  411. }
  412. run_logfile="/dev/null"
  413. run() {
  414. user="${USER--}"
  415. dir="${PWD}"
  416. if [ "$(id -u)" = "0" ]; then
  417. info="[root ${dir}]# "
  418. info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
  419. else
  420. info="[${user} ${dir}]$ "
  421. info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ "
  422. fi
  423. if [ "${DRY_RUN}" -eq 1 ]; then
  424. printf >&2 "%s" "Would run command:\n"
  425. fi
  426. {
  427. printf "%s" "${info}"
  428. escaped_print "${@}"
  429. printf " ... "
  430. } >> "${run_logfile}"
  431. printf >&2 "%s" "${info_console}${TPUT_BOLD}"
  432. escaped_print >&2 "${@}"
  433. printf >&2 "%s\n" "${TPUT_RESET}"
  434. if [ "${DRY_RUN}" -ne 1 ]; then
  435. "${@}"
  436. ret=$?
  437. else
  438. ret=0
  439. fi
  440. if [ ${ret} -ne 0 ]; then
  441. printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET}"
  442. printf "%s\n" "FAILED with exit code ${ret}" >> "${run_logfile}"
  443. # shellcheck disable=SC2089
  444. NETDATA_WARNINGS="${NETDATA_WARNINGS}\n - Command \"${*}\" failed with exit code ${ret}."
  445. else
  446. printf >&2 "%s\n\n" "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET}"
  447. printf "OK\n" >> "${run_logfile}"
  448. fi
  449. return ${ret}
  450. }
  451. run_as_root() {
  452. confirm_root_support
  453. if [ "$(id -u)" -ne "0" ]; then
  454. printf >&2 "Root privileges required to run %s\n" "${*}"
  455. fi
  456. run ${ROOTCMD} "${@}"
  457. }
  458. run_script() {
  459. set_tmpdir
  460. export NETDATA_SCRIPT_STATUS_PATH="${tmpdir}/.script-status"
  461. export NETDATA_SAVE_WARNINGS=1
  462. export NETDATA_PROPAGATE_WARNINGS=1
  463. # shellcheck disable=SC2090
  464. export NETDATA_WARNINGS="${NETDATA_WARNINGS}"
  465. # shellcheck disable=SC2086
  466. run ${ROOTCMD} "${@}"
  467. ret="$?"
  468. if [ -r "${NETDATA_SCRIPT_STATUS_PATH}" ]; then
  469. # shellcheck disable=SC1090
  470. . "${NETDATA_SCRIPT_STATUS_PATH}"
  471. rm -f "${NETDATA_SCRIPT_STATUS_PATH}"
  472. fi
  473. return "${ret}"
  474. }
  475. warning() {
  476. printf >&2 "%s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} WARNING ${TPUT_RESET} ${*}"
  477. NETDATA_WARNINGS="${NETDATA_WARNINGS}\n - ${*}"
  478. }
  479. _cannot_use_tmpdir() {
  480. testfile="$(TMPDIR="${1}" mktemp -q -t netdata-test.XXXXXXXXXX)"
  481. ret=0
  482. if [ -z "${testfile}" ]; then
  483. return "${ret}"
  484. fi
  485. if printf '#!/bin/sh\necho SUCCESS\n' > "${testfile}"; then
  486. if chmod +x "${testfile}"; then
  487. if [ "$("${testfile}")" = "SUCCESS" ]; then
  488. ret=1
  489. fi
  490. fi
  491. fi
  492. rm -f "${testfile}"
  493. return "${ret}"
  494. }
  495. create_tmp_directory() {
  496. if [ -z "${TMPDIR}" ] || _cannot_use_tmpdir "${TMPDIR}"; then
  497. if _cannot_use_tmpdir /tmp; then
  498. if _cannot_use_tmpdir "${PWD}"; then
  499. 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." F0400
  500. else
  501. TMPDIR="${PWD}"
  502. fi
  503. else
  504. TMPDIR="/tmp"
  505. fi
  506. fi
  507. mktemp -d -t netdata-kickstart-XXXXXXXXXX
  508. }
  509. set_tmpdir() {
  510. if [ -z "${tmpdir}" ] || [ ! -d "${tmpdir}" ]; then
  511. tmpdir="$(create_tmp_directory)"
  512. progress "Using ${tmpdir} as a temporary directory."
  513. cd "${tmpdir}" || fatal "Failed to change current working directory to ${tmpdir}." F000A
  514. fi
  515. }
  516. check_for_remote_file() {
  517. url="${1}"
  518. succeeded=0
  519. checked=0
  520. if echo "${url}" | grep -Eq "^file:///"; then
  521. [ -e "${url#file://}" ] || return 1
  522. return 0
  523. elif [ -n "${NETDATA_ASSUME_REMOTE_FILES_ARE_PRESENT}" ]; then
  524. return 0
  525. fi
  526. if [ -n "${CURL}" ]; then
  527. checked=1
  528. if "${CURL}" --output /dev/null --silent --head --fail "${url}"; then
  529. succeeded=1
  530. fi
  531. fi
  532. if [ "${succeeded}" -eq 0 ]; then
  533. if command -v wget > /dev/null 2>&1; then
  534. checked=1
  535. if wget -S --spider "${url}" 2>&1 | grep -q 'HTTP/1.1 200 OK'; then
  536. succeeded=1
  537. fi
  538. fi
  539. fi
  540. if [ "${succeeded}" -eq 1 ]; then
  541. return 0
  542. elif [ "${checked}" -eq 1 ]; then
  543. return 1
  544. else
  545. fatal "${ERROR_F0003}" F0003
  546. fi
  547. }
  548. download() {
  549. url="${1}"
  550. dest="${2}"
  551. succeeded=0
  552. checked=0
  553. if echo "${url}" | grep -Eq "^file:///"; then
  554. run cp "${url#file://}" "${dest}" || return 1
  555. return 0
  556. fi
  557. if [ -n "${CURL}" ]; then
  558. checked=1
  559. if run "${CURL}" --fail -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}"; then
  560. succeeded=1
  561. else
  562. rm -f "${dest}"
  563. fi
  564. fi
  565. if [ "${succeeded}" -eq 0 ]; then
  566. if command -v wget > /dev/null 2>&1; then
  567. checked=1
  568. if run wget -T 15 -O "${dest}" "${url}"; then
  569. succeeded=1
  570. fi
  571. fi
  572. fi
  573. if [ "${succeeded}" -eq 1 ]; then
  574. return 0
  575. elif [ "${checked}" -eq 1 ]; then
  576. return 1
  577. else
  578. fatal "${ERROR_F0003}" F0003
  579. fi
  580. }
  581. get_actual_version() {
  582. major="${1}"
  583. channel="${2}"
  584. url="${RELEASE_INFO_URL}/${channel}/${major}"
  585. if check_for_remote_file "${RELEASE_INFO_URL}"; then
  586. if check_for_remote_file "${url}"; then
  587. download "${url}" -
  588. else
  589. echo "NONE"
  590. fi
  591. else
  592. echo ""
  593. fi
  594. }
  595. get_redirect() {
  596. url="${1}"
  597. succeeded=0
  598. checked=0
  599. if [ -n "${CURL}" ]; then
  600. checked=1
  601. if run sh -c "${CURL} ${url} -s -L -I -o /dev/null -w '%{url_effective}' | grep -Eo '[^/]+$'"; then
  602. succeeded=1
  603. fi
  604. fi
  605. if [ "${succeeded}" -eq 0 ]; then
  606. if command -v wget > /dev/null 2>&1; then
  607. checked=1
  608. if run sh -c "wget -S -O /dev/null ${url} 2>&1 | grep -m 1 Location | grep -Eo '[^/]+$'"; then
  609. succeeded=1
  610. fi
  611. fi
  612. fi
  613. if [ "${succeeded}" -eq 1 ]; then
  614. return 0
  615. elif [ "${checked}" -eq 1 ]; then
  616. return 1
  617. else
  618. fatal "${ERROR_F0003}" F0003
  619. fi
  620. }
  621. safe_sha256sum() {
  622. # Within the context of the installer, we only use -c option that is common between the two commands
  623. # We will have to reconsider if we start using non-common options
  624. if command -v shasum > /dev/null 2>&1; then
  625. shasum -a 256 "$@"
  626. elif command -v sha256sum > /dev/null 2>&1; then
  627. sha256sum "$@"
  628. else
  629. fatal "Could not find a usable checksum tool. Either sha256sum, or a version of shasum supporting SHA256 checksums is required to proceed with installation." F0004
  630. fi
  631. }
  632. get_system_info() {
  633. SYSARCH="$(uname -m)"
  634. case "$(uname -s)" in
  635. Linux)
  636. SYSTYPE="Linux"
  637. if [ -z "${SKIP_DISTRO_DETECTION}" ]; then
  638. os_release_file=
  639. if [ -s "/etc/os-release" ] && [ -r "/etc/os-release" ]; then
  640. os_release_file="/etc/os-release"
  641. elif [ -s "/usr/lib/os-release" ] && [ -r "/usr/lib/os-release" ]; then
  642. os_release_file="/usr/lib/os-release"
  643. else
  644. warning "Cannot find usable OS release information. Native packages will not be available for this install."
  645. fi
  646. if [ -n "${os_release_file}" ]; then
  647. # shellcheck disable=SC1090
  648. . "${os_release_file}"
  649. DISTRO="${ID}"
  650. SYSVERSION="${VERSION_ID}"
  651. SYSCODENAME="${VERSION_CODENAME}"
  652. else
  653. DISTRO="unknown"
  654. DISTRO_COMPAT_NAME="unknown"
  655. SYSVERSION="unknown"
  656. SYSCODENAME="unknown"
  657. fi
  658. else
  659. warning "Distribution auto-detection overridden by user. This is not guaranteed to work, and is not officially supported."
  660. fi
  661. supported_compat_names="debian ubuntu centos fedora opensuse ol amzn arch"
  662. if str_in_list "${DISTRO}" "${supported_compat_names}"; then
  663. DISTRO_COMPAT_NAME="${DISTRO}"
  664. else
  665. case "${DISTRO}" in
  666. opensuse-leap)
  667. DISTRO_COMPAT_NAME="opensuse"
  668. ;;
  669. opensuse-tumbleweed)
  670. DISTRO_COMPAT_NAME="opensuse"
  671. SYSVERSION="tumbleweed"
  672. ;;
  673. cloudlinux|almalinux|centos-stream|rocky|rhel)
  674. DISTRO_COMPAT_NAME="centos"
  675. ;;
  676. artix|manjaro|obarun)
  677. DISTRO_COMPAT_NAME="arch"
  678. ;;
  679. *)
  680. DISTRO_COMPAT_NAME="unknown"
  681. ;;
  682. esac
  683. fi
  684. case "${DISTRO_COMPAT_NAME}" in
  685. centos|ol) SYSVERSION=$(echo "$SYSVERSION" | cut -d'.' -f1) ;;
  686. esac
  687. ;;
  688. Darwin)
  689. SYSTYPE="Darwin"
  690. SYSVERSION="$(sw_vers -buildVersion)"
  691. ;;
  692. FreeBSD)
  693. SYSTYPE="FreeBSD"
  694. SYSVERSION="$(uname -K)"
  695. ;;
  696. *) fatal "Unsupported system type detected. Netdata cannot be installed on this system using this script." F0200 ;;
  697. esac
  698. }
  699. str_in_list() {
  700. printf "%s\n" "${2}" | tr ' ' "\n" | grep -qE "^${1}\$"
  701. return $?
  702. }
  703. confirm_root_support() {
  704. if [ "$(id -u)" -ne "0" ]; then
  705. if [ -z "${ROOTCMD}" ] && command -v sudo > /dev/null; then
  706. if [ "${INTERACTIVE}" -eq 0 ]; then
  707. ROOTCMD="sudo -n"
  708. else
  709. ROOTCMD="sudo"
  710. fi
  711. fi
  712. if [ -z "${ROOTCMD}" ] && command -v doas > /dev/null; then
  713. if [ "${INTERACTIVE}" -eq 0 ]; then
  714. ROOTCMD="doas -n"
  715. else
  716. ROOTCMD="doas"
  717. fi
  718. fi
  719. if [ -z "${ROOTCMD}" ] && command -v pkexec > /dev/null; then
  720. ROOTCMD="pkexec"
  721. fi
  722. if [ -z "${ROOTCMD}" ]; then
  723. fatal "This script needs root privileges to install Netdata, but cannot find a way to gain them (we support sudo, doas, and pkexec). Either re-run this script as root, or set \$ROOTCMD to a command that can be used to gain root privileges." F0201
  724. fi
  725. fi
  726. }
  727. confirm() {
  728. prompt="${1} [y/n]"
  729. while true; do
  730. echo "${prompt}"
  731. read -r yn
  732. case "$yn" in
  733. [Yy]*) return 0;;
  734. [Nn]*) return 1;;
  735. *) echo "Please answer yes or no.";;
  736. esac
  737. done
  738. }
  739. # ======================================================================
  740. # Existing install handling code
  741. update() {
  742. updater="${ndprefix}/usr/libexec/netdata/netdata-updater.sh"
  743. if run_as_root test -x "${updater}"; then
  744. if [ "${DRY_RUN}" -eq 1 ]; then
  745. progress "Would attempt to update existing installation by running the updater script located at: ${updater}"
  746. return 0
  747. fi
  748. if [ "${INTERACTIVE}" -eq 0 ]; then
  749. opts="--non-interactive"
  750. else
  751. opts="--interactive"
  752. fi
  753. if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
  754. export NETDATA_OFFLINE_INSTALL_SOURCE="${NETDATA_OFFLINE_INSTALL_SOURCE}"
  755. fi
  756. if run_script "${updater}" ${opts} --not-running-from-cron; then
  757. progress "Updated existing install at ${ndprefix}"
  758. return 0
  759. else
  760. if [ -n "${EXIT_REASON}" ]; then
  761. fatal "Failed to update existing Netdata install at ${ndprefix}: ${EXIT_REASON}" "${EXIT_CODE}"
  762. else
  763. fatal "Failed to update existing Netdata install at ${ndprefix}: Encountered an unhandled error in the updater. Further information about this error may be displayed above." U0000
  764. fi
  765. fi
  766. else
  767. warning "Could not find a usable copy of the updater script. We are unable to update this system in place."
  768. return 1
  769. fi
  770. }
  771. uninstall() {
  772. set_tmpdir
  773. get_system_info
  774. detect_existing_install
  775. if [ -n "${OLD_INSTALL_PREFIX}" ]; then
  776. INSTALL_PREFIX="$(echo "${OLD_INSTALL_PREFIX}/" | sed 's/$/netdata/g')"
  777. else
  778. INSTALL_PREFIX="${ndprefix}"
  779. fi
  780. uninstaller="${INSTALL_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh"
  781. uninstaller_url="https://raw.githubusercontent.com/netdata/netdata/master/packaging/installer/netdata-uninstaller.sh"
  782. if [ $INTERACTIVE = 0 ]; then
  783. FLAGS="--yes --force"
  784. else
  785. FLAGS="--yes"
  786. fi
  787. if run_as_root test -x "${uninstaller}"; then
  788. if [ "${DRY_RUN}" -eq 1 ]; then
  789. progress "Would attempt to uninstall existing install with uninstaller script found at: ${uninstaller}"
  790. return 0
  791. else
  792. progress "Found existing netdata-uninstaller. Running it.."
  793. # shellcheck disable=SC2086
  794. if ! run_script "${uninstaller}" ${FLAGS}; then
  795. warning "Uninstaller failed. Some parts of Netdata may still be present on the system."
  796. fi
  797. fi
  798. else
  799. if [ "${DRY_RUN}" -eq 1 ]; then
  800. progress "Would download installer script from: ${uninstaller_url}"
  801. progress "Would attempt to uninstall existing install with downloaded uninstaller script."
  802. return 0
  803. else
  804. progress "Downloading netdata-uninstaller ..."
  805. download "${uninstaller_url}" "${tmpdir}/netdata-uninstaller.sh"
  806. chmod +x "${tmpdir}/netdata-uninstaller.sh"
  807. # shellcheck disable=SC2086
  808. if ! run_script "${tmpdir}/netdata-uninstaller.sh" ${FLAGS}; then
  809. warning "Uninstaller failed. Some parts of Netdata may still be present on the system."
  810. fi
  811. fi
  812. fi
  813. }
  814. detect_existing_install() {
  815. set_tmpdir
  816. progress "Checking for existing installations of Netdata..."
  817. EXISTING_INSTALL_IS_NATIVE="0"
  818. if [ -n "${INSTALL_PREFIX}" ]; then
  819. searchpath="/opt/netdata/bin:${INSTALL_PREFIX}/bin:${INSTALL_PREFIX}/sbin:${INSTALL_PREFIX}/usr/bin:${INSTALL_PREFIX}/usr/sbin:${PATH}"
  820. searchpath="${INSTALL_PREFIX}/netdata/bin:${INSTALL_PREFIX}/netdata/sbin:${INSTALL_PREFIX}/netdata/usr/bin:${INSTALL_PREFIX}/netdata/usr/sbin:${searchpath}"
  821. else
  822. searchpath="/opt/netdata/bin:${PATH}"
  823. fi
  824. while [ -n "${searchpath}" ]; do
  825. _ndpath="$(PATH="${searchpath}" command -v netdata 2>/dev/null)"
  826. if [ -n "${_ndpath}" ]; then
  827. _ndpath="$(canonical_path "${_ndpath}")"
  828. fi
  829. if [ -z "${ndpath}" ] && [ -n "${_ndpath}" ]; then
  830. ndpath="${_ndpath}"
  831. elif [ -n "${_ndpath}" ] && [ "${ndpath}" != "${_ndpath}" ]; then
  832. fatal "Multiple installs of Netdata agent detected (located at '${ndpath}' and '${_ndpath}'). Such a setup is not generally supported. If you are certain you want to operate on one of them despite this, use the '--install-prefix' option to specifiy the install you want to operate on." F0517
  833. fi
  834. if [ -n "${INSTALL_PREFIX}" ] && [ -n "${ndpath}" ]; then
  835. break
  836. elif [ -z "${_ndpath}" ]; then
  837. break
  838. elif echo "${searchpath}" | grep -v ':'; then
  839. searchpath=""
  840. else
  841. searchpath="$(echo "${searchpath}" | cut -f 2- -d ':')"
  842. fi
  843. done
  844. if pkg_installed netdata; then
  845. ndprefix="/"
  846. EXISTING_INSTALL_IS_NATIVE="1"
  847. elif [ -n "${ndpath}" ]; then
  848. case "${ndpath}" in
  849. */usr/bin/netdata|*/usr/sbin/netdata) ndprefix="$(dirname "$(dirname "$(dirname "${ndpath}")")")" ;;
  850. *) ndprefix="$(dirname "$(dirname "${ndpath}")")" ;;
  851. esac
  852. if echo "${ndprefix}" | grep -Eq '^/usr$'; then
  853. ndprefix="$(dirname "${ndprefix}")"
  854. fi
  855. fi
  856. if [ -n "${ndprefix}" ]; then
  857. typefile="${ndprefix}/etc/netdata/.install-type"
  858. if [ -r "${typefile}" ]; then
  859. # shellcheck disable=SC1090,SC1091
  860. . "${typefile}"
  861. else
  862. INSTALL_TYPE="unknown"
  863. fi
  864. envfile="${ndprefix}/etc/netdata/.environment"
  865. if [ "${INSTALL_TYPE}" = "unknown" ] || [ "${INSTALL_TYPE}" = "custom" ]; then
  866. if [ -r "${envfile}" ]; then
  867. # shellcheck disable=SC1090,SC1091
  868. . "${envfile}"
  869. if [ -n "${NETDATA_IS_STATIC_INSTALL}" ]; then
  870. if [ "${NETDATA_IS_STATIC_INSTALL}" = "yes" ]; then
  871. INSTALL_TYPE="legacy-static"
  872. else
  873. INSTALL_TYPE="legacy-build"
  874. fi
  875. fi
  876. fi
  877. fi
  878. fi
  879. }
  880. handle_existing_install() {
  881. detect_existing_install
  882. if [ -z "${ndprefix}" ] || [ -z "${INSTALL_TYPE}" ]; then
  883. progress "No existing installations of netdata found, assuming this is a fresh install."
  884. return 0
  885. fi
  886. case "${INSTALL_TYPE}" in
  887. kickstart-*|legacy-*|binpkg-*|manual-static|unknown)
  888. if [ "${INSTALL_TYPE}" = "unknown" ]; then
  889. if [ "${EXISTING_INSTALL_IS_NATIVE}" -eq 1 ]; then
  890. warning "Found an existing netdata install managed by the system package manager, but could not determine the install type. Usually this means you installed an unsupported third-party netdata package. This script supports claiming most such installs, but attempting to update or reinstall them using this script may be dangerous."
  891. else
  892. warning "Found an existing netdata install at ${ndprefix}, but could not determine the install type. Usually this means you installed Netdata through your distribution’s regular package repositories or some other unsupported method."
  893. fi
  894. else
  895. progress "Found an existing netdata install at ${ndprefix}, with installation type '${INSTALL_TYPE}'."
  896. fi
  897. if [ "${ACTION}" = "reinstall" ] || [ "${ACTION}" = "unsafe-reinstall" ]; then
  898. progress "Found an existing netdata install at ${ndprefix}, but user requested reinstall, continuing."
  899. case "${INSTALL_TYPE}" in
  900. binpkg-*) NETDATA_FORCE_METHOD='native' ;;
  901. *-build) NETDATA_FORCE_METHOD='build' ;;
  902. *-static) NETDATA_FORCE_METHOD='static' ;;
  903. *)
  904. if [ "${ACTION}" = "unsafe-reinstall" ]; then
  905. warning "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, but the user has requested we proceed."
  906. elif [ "${INTERACTIVE}" -eq 0 ]; then
  907. fatal "User requested reinstall, but we cannot safely reinstall over top of a ${INSTALL_TYPE} installation, exiting." F0104
  908. else
  909. if [ "${EXISTING_INSTALL_IS_NATIVE}" ]; then
  910. reinstall_prompt="Reinstalling over top of an existing install managed by the system package manager is known to cause things to break, are you sure you want to continue?"
  911. else
  912. reinstall_prompt="Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, do you want to continue?"
  913. fi
  914. if confirm "${reinstall_prompt}"; then
  915. progress "OK, continuing."
  916. else
  917. fatal "Cancelling reinstallation at user request." F0105
  918. fi
  919. fi
  920. ;;
  921. esac
  922. return 0
  923. elif [ "${INSTALL_TYPE}" = "unknown" ]; then
  924. claimonly_notice="If you just want to claim this install, you should re-run this command with the --claim-only option instead."
  925. if [ "${EXISTING_INSTALL_IS_NATIVE}" -eq 1 ]; then
  926. failmsg="Attempting to update an installation managed by the system package manager is known to not work in most cases. If you are trying to install the latest version of Netdata, you will need to manually uninstall it through your system package manager. ${claimonly_notice}"
  927. promptmsg="Attempting to update an installation managed by the system package manager is known to not work in most cases. If you are trying to install the latest version of Netdata, you will need to manually uninstall it through your system package manager. ${claimonly_notice} Are you sure you want to continue?"
  928. else
  929. failmsg="We do not support trying to update or claim installations when we cannot determine the install type. You will need to uninstall the existing install using the same method you used to install it to proceed. ${claimonly_notice}"
  930. promptmsg="Attempting to update an existing install with an unknown installation type is not officially supported. It may work, but it also might break your system. ${claimonly_notice} Are you sure you want to continue?"
  931. fi
  932. if [ "${INTERACTIVE}" -eq 0 ] && [ "${ACTION}" != "claim" ]; then
  933. fatal "${failmsg}" F0106
  934. elif [ "${INTERACTIVE}" -eq 1 ] && [ "${ACTION}" != "claim" ]; then
  935. if confirm "${promptmsg}"; then
  936. progress "OK, continuing"
  937. else
  938. fatal "Cancelling update of unknown installation type at user request." F050C
  939. fi
  940. fi
  941. fi
  942. ret=0
  943. if [ "${ACTION}" != "claim" ]; then
  944. if ! update; then
  945. warning "Failed to update existing Netdata install at ${ndprefix}."
  946. else
  947. progress "Successfully updated existing netdata install at ${ndprefix}."
  948. fi
  949. else
  950. warning "Not updating existing install at ${ndprefix}."
  951. fi
  952. if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then
  953. progress "Attempting to claim existing install at ${ndprefix}."
  954. INSTALL_PREFIX="${ndprefix}"
  955. claim
  956. ret=$?
  957. elif [ "${ACTION}" = "claim" ]; then
  958. fatal "User asked to claim, but did not provide a claiming token." F0202
  959. else
  960. progress "Not attempting to claim existing install at ${ndprefix} (no claiming token provided)."
  961. fi
  962. deferred_warnings
  963. success_banner
  964. cleanup
  965. trap - EXIT
  966. exit $ret
  967. ;;
  968. oci)
  969. fatal "This is an OCI container, use the regular container lifecycle management commands for your container tools instead of this script for managing it." F0203
  970. ;;
  971. *)
  972. if [ "${ACTION}" = "reinstall" ] || [ "${ACTION}" = "unsafe-reinstall" ]; then
  973. if [ "${ACTION}" = "unsafe-reinstall" ]; then
  974. warning "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, but the user has requested we proceed."
  975. elif [ "${INTERACTIVE}" -eq 0 ]; then
  976. fatal "User requested reinstall, but we cannot safely reinstall over top of a ${INSTALL_TYPE} installation, exiting." F0104
  977. else
  978. if confirm "Reinstalling over top of a ${INSTALL_TYPE} installation may be unsafe, do you want to continue?"; then
  979. progress "OK, continuing."
  980. else
  981. fatal "Cancelling reinstallation at user request." F0105
  982. fi
  983. fi
  984. else
  985. if [ -n "${NETDATA_CLAIM_TOKEN}" ]; then
  986. progress "Attempting to claim existing install at ${ndprefix}."
  987. INSTALL_PREFIX="${ndprefix}"
  988. claim
  989. ret=$?
  990. cleanup
  991. trap - EXIT
  992. exit $ret
  993. elif [ "${ACTION}" = "claim" ]; then
  994. fatal "User asked to claim, but did not provide a claiming token." F0202
  995. else
  996. fatal "Found an existing netdata install at ${ndprefix}, but the install type is '${INSTALL_TYPE}', which is not supported by this script, refusing to proceed." F0103
  997. fi
  998. fi
  999. ;;
  1000. esac
  1001. }
  1002. soft_disable_cloud() {
  1003. set_tmpdir
  1004. cloud_prefix="${INSTALL_PREFIX}/var/lib/netdata/cloud.d"
  1005. run_as_root mkdir -p "${cloud_prefix}"
  1006. cat > "${tmpdir}/cloud.conf" << EOF
  1007. [global]
  1008. enabled = no
  1009. EOF
  1010. run_as_root cp "${tmpdir}/cloud.conf" "${cloud_prefix}/cloud.conf"
  1011. if [ -z "${NETDATA_NO_START}" ]; then
  1012. case "${SYSTYPE}" in
  1013. Darwin) run_as_root launchctl kickstart -k com.github.netdata ;;
  1014. FreeBSD) run_as_root service netdata restart ;;
  1015. Linux)
  1016. initpath="$(run_as_root readlink /proc/1/exe)"
  1017. if command -v service > /dev/null 2>&1; then
  1018. run_as_root service netdata restart
  1019. elif command -v rc-service > /dev/null 2>&1; then
  1020. run_as_root rc-service netdata restart
  1021. elif [ "$(basename "${initpath}" 2> /dev/null)" = "systemd" ]; then
  1022. run_as_root systemctl restart netdata
  1023. elif [ -f /etc/init.d/netdata ]; then
  1024. run_as_root /etc/init.d/netdata restart
  1025. fi
  1026. ;;
  1027. esac
  1028. fi
  1029. }
  1030. confirm_install_prefix() {
  1031. if [ -n "${INSTALL_PREFIX}" ] && [ "${NETDATA_FORCE_METHOD}" != 'build' ]; then
  1032. fatal "The --install-prefix option is only supported together with the --build-only option." F0204
  1033. fi
  1034. if [ -n "${INSTALL_PREFIX}" ]; then
  1035. NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --install-prefix ${INSTALL_PREFIX}"
  1036. else
  1037. case "${SYSTYPE}" in
  1038. Darwin)
  1039. INSTALL_PREFIX="/usr/local/netdata"
  1040. NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --install-no-prefix ${INSTALL_PREFIX}"
  1041. ;;
  1042. FreeBSD)
  1043. INSTALL_PREFIX="/usr/local"
  1044. NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --install-no-prefix ${INSTALL_PREFIX}"
  1045. ;;
  1046. esac
  1047. fi
  1048. }
  1049. # ======================================================================
  1050. # Claiming support code
  1051. check_claim_opts() {
  1052. # shellcheck disable=SC2235,SC2030
  1053. if [ -z "${NETDATA_CLAIM_TOKEN}" ] && [ -n "${NETDATA_CLAIM_ROOMS}" ]; then
  1054. fatal "Invalid claiming options, claim rooms may only be specified when a token is specified." F0204
  1055. elif [ -z "${NETDATA_CLAIM_TOKEN}" ] && [ -n "${NETDATA_CLAIM_EXTRA}" ]; then
  1056. fatal "Invalid claiming options, a claiming token must be specified." F0204
  1057. elif [ "${NETDATA_DISABLE_CLOUD}" -eq 1 ] && [ -n "${NETDATA_CLAIM_TOKEN}" ]; then
  1058. fatal "Cloud explicitly disabled, but automatic claiming requested. Either enable Netdata Cloud, or remove the --claim-* options." F0204
  1059. fi
  1060. }
  1061. is_netdata_running() {
  1062. if command -v pgrep > /dev/null 2>&1; then
  1063. if pgrep netdata; then
  1064. return 0
  1065. else
  1066. return 1
  1067. fi
  1068. else
  1069. if [ -z "${INSTALL_PREFIX}" ]; then
  1070. NETDATACLI_PATH=/usr/sbin/netdatacli
  1071. elif [ "${INSTALL_PREFIX}" = "/opt/netdata" ]; then
  1072. NETDATACLI_PATH="/opt/netdata/bin/netdatacli"
  1073. else
  1074. NETDATACLI_PATH="${INSTALL_PREFIX}/netdata/usr/sbin/netdatacli"
  1075. fi
  1076. if "${NETDATACLI_PATH}" ping > /dev/null 2>&1; then
  1077. return 0
  1078. else
  1079. return 1
  1080. fi
  1081. fi
  1082. }
  1083. claim() {
  1084. if [ "${DRY_RUN}" -eq 1 ]; then
  1085. progress "Would attempt to claim agent to ${NETDATA_CLAIM_URL}"
  1086. else
  1087. progress "Attempting to claim agent to ${NETDATA_CLAIM_URL}"
  1088. fi
  1089. if command -v netdata-claim.sh > /dev/null 2>&1; then
  1090. NETDATA_CLAIM_PATH="$(command -v netdata-claim.sh)"
  1091. elif [ -z "${INSTALL_PREFIX}" ] || [ "${INSTALL_PREFIX}" = "/" ]; then
  1092. NETDATA_CLAIM_PATH=/usr/sbin/netdata-claim.sh
  1093. elif [ "${INSTALL_PREFIX}" = "/opt/netdata" ]; then
  1094. NETDATA_CLAIM_PATH="/opt/netdata/bin/netdata-claim.sh"
  1095. elif [ ! -d "${INSTALL_PREFIX}/netdata" ]; then
  1096. if [ -d "${INSTALL_PREFIX}/usr" ]; then
  1097. NETDATA_CLAIM_PATH="${INSTALL_PREFIX}/usr/sbin/netdata-claim.sh"
  1098. else
  1099. NETDATA_CLAIM_PATH="${INSTALL_PREFIX}/sbin/netdata-claim.sh"
  1100. fi
  1101. else
  1102. NETDATA_CLAIM_PATH="${INSTALL_PREFIX}/netdata/usr/sbin/netdata-claim.sh"
  1103. fi
  1104. err_msg=
  1105. err_code=
  1106. if [ -z "${NETDATA_CLAIM_PATH}" ]; then
  1107. err_msg="Unable to claim node: could not find usable claiming script. Reinstalling Netdata may resolve this."
  1108. err_code=F050B
  1109. elif [ ! -e "${NETDATA_CLAIM_PATH}" ]; then
  1110. err_msg="Unable to claim node: ${NETDATA_CLAIM_PATH} does not exist."
  1111. err_code=F0512
  1112. elif [ ! -f "${NETDATA_CLAIM_PATH}" ]; then
  1113. err_msg="Unable to claim node: ${NETDATA_CLAIM_PATH} is not a file."
  1114. err_code=F0513
  1115. elif [ ! -x "${NETDATA_CLAIM_PATH}" ]; then
  1116. err_msg="Unable to claim node: claiming script at ${NETDATA_CLAIM_PATH} is not executable. Reinstalling Netdata may resolve this."
  1117. err_code=F0514
  1118. fi
  1119. if [ -n "$err_msg" ]; then
  1120. if [ "${ACTION}" = "claim" ]; then
  1121. fatal "$err_msg" "$err_code"
  1122. else
  1123. warning "$err_msg"
  1124. return 1
  1125. fi
  1126. fi
  1127. if ! is_netdata_running; then
  1128. NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -daemon-not-running"
  1129. fi
  1130. # shellcheck disable=SC2086
  1131. run_as_root "${NETDATA_CLAIM_PATH}" -token="${NETDATA_CLAIM_TOKEN}" -rooms="${NETDATA_CLAIM_ROOMS}" -url="${NETDATA_CLAIM_URL}" ${NETDATA_CLAIM_EXTRA}
  1132. case $? in
  1133. 0)
  1134. progress "Successfully claimed node"
  1135. return 0
  1136. ;;
  1137. 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}" ;;
  1138. 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." ;;
  1139. 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}." ;;
  1140. 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." ;;
  1141. 5)
  1142. 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."
  1143. return 0
  1144. ;;
  1145. 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." ;;
  1146. 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." ;;
  1147. 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." ;;
  1148. 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." ;;
  1149. 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." ;;
  1150. 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)\"" ;;
  1151. 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}." ;;
  1152. 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}." ;;
  1153. 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." ;;
  1154. *) 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}" ;;
  1155. esac
  1156. if [ "${ACTION}" = "claim" ]; then
  1157. deferred_warnings
  1158. printf >&2 "%s\n" "For community support, you can connect with us on:"
  1159. support_list
  1160. cleanup
  1161. trap - EXIT
  1162. exit 1
  1163. fi
  1164. }
  1165. # ======================================================================
  1166. # Auto-update handling code.
  1167. set_auto_updates() {
  1168. if run_as_root test -x "${INSTALL_PREFIX}/usr/libexec/netdata/netdata-updater.sh"; then
  1169. updater="${INSTALL_PREFIX}/usr/libexec/netdata/netdata-updater.sh"
  1170. elif run_as_root test -x "${INSTALL_PREFIX}/netdata/usr/libexec/netdata/netdata-updater.sh"; then
  1171. updater="${INSTALL_PREFIX}/netdata/usr/libexec/netdata/netdata-updater.sh"
  1172. else
  1173. warning "Could not find netdata-updater.sh. This means that auto-updates cannot (currently) be enabled on this system. See https://learn.netdata.cloud/docs/agent/packaging/installer/update for more information about updating Netdata."
  1174. return 0
  1175. fi
  1176. if [ "${AUTO_UPDATE}" -eq 1 ]; then
  1177. if [ "${DRY_RUN}" -eq 1 ]; then
  1178. progress "Would have attempted to enable automatic updates."
  1179. # This first case is for catching using a new kickstart script with an old build. It can be safely removed after v1.34.0 is released.
  1180. elif ! run_as_root grep -q '\-\-enable-auto-updates' "${updater}"; then
  1181. echo
  1182. elif ! run_as_root "${updater}" --enable-auto-updates "${NETDATA_AUTO_UPDATE_TYPE}"; then
  1183. warning "Failed to enable auto updates. Netdata will still work, but you will need to update manually."
  1184. fi
  1185. else
  1186. if [ "${DRY_RUN}" -eq 1 ]; then
  1187. progress "Would have attempted to disable automatic updates."
  1188. else
  1189. run_as_root "${updater}" --disable-auto-updates
  1190. fi
  1191. fi
  1192. }
  1193. # ======================================================================
  1194. # Native package install code.
  1195. # Check for an already installed package with a given name.
  1196. pkg_installed() {
  1197. case "${SYSTYPE}" in
  1198. Linux)
  1199. case "${DISTRO_COMPAT_NAME}" in
  1200. debian|ubuntu)
  1201. # shellcheck disable=SC2016
  1202. dpkg-query --show --showformat '${Status}' "${1}" 2>&1 | cut -f 1 -d ' ' | grep -q '^install$'
  1203. return $?
  1204. ;;
  1205. centos|fedora|opensuse|ol|amzn)
  1206. rpm -q "${1}" > /dev/null 2>&1
  1207. return $?
  1208. ;;
  1209. alpine)
  1210. apk -e info "${1}" > /dev/null 2>&1
  1211. return $?
  1212. ;;
  1213. arch)
  1214. pacman -Qi "${1}" > /dev/null 2>&1
  1215. return $?
  1216. ;;
  1217. *) return 1 ;;
  1218. esac
  1219. ;;
  1220. Darwin)
  1221. if command -v brew > /dev/null 2>&1; then
  1222. brew list "${1}" > /dev/null 2>&1
  1223. return $?
  1224. else
  1225. return 1
  1226. fi
  1227. ;;
  1228. FreeBSD)
  1229. if pkg -N > /dev/null 2>&1; then
  1230. pkg info "${1}" > /dev/null 2>&1
  1231. return $?
  1232. else
  1233. return 1
  1234. fi
  1235. ;;
  1236. *) return 1 ;;
  1237. esac
  1238. }
  1239. # Check for the existence of a usable netdata package in the repo.
  1240. netdata_avail_check() {
  1241. case "${DISTRO_COMPAT_NAME}" in
  1242. debian|ubuntu)
  1243. env DEBIAN_FRONTEND=noninteractive apt-cache policy netdata | grep -q repo.netdata.cloud/repos/;
  1244. return $?
  1245. ;;
  1246. centos|fedora|ol|amzn)
  1247. # shellcheck disable=SC2086
  1248. LC_ALL=C ${pm_cmd} search --nogpgcheck -v netdata | grep -qE 'Repo *: netdata(-edge)?$'
  1249. return $?
  1250. ;;
  1251. opensuse)
  1252. zypper packages -r "$(zypper repos | grep -E 'netdata |netdata-edge ' | cut -f 1 -d '|' | tr -d ' ')" | grep -E 'netdata '
  1253. return $?
  1254. ;;
  1255. *) return 1 ;;
  1256. esac
  1257. }
  1258. # Check for any distro-specific dependencies we know we need.
  1259. check_special_native_deps() {
  1260. if [ "${DISTRO_COMPAT_NAME}" = "centos" ] && [ "${SYSVERSION}" -gt 6 ]; then
  1261. progress "EPEL is required on this system, checking if it’s available."
  1262. if LC_ALL=C ${pm_cmd} search --nogpgcheck -v epel-release | grep -q "No matches found"; then
  1263. warning "Unable to find a suitable source for libuv, cannot install using native packages on this system."
  1264. return 1
  1265. else
  1266. progress "EPEL is available, attempting to install so that required dependencies are available."
  1267. # shellcheck disable=SC2086
  1268. if ! run_as_root env ${env} ${pm_cmd} ${install_subcmd} ${pkg_install_opts} epel-release; then
  1269. warning "Failed to install EPEL, even though it is required to install native packages on this system."
  1270. return 1
  1271. fi
  1272. fi
  1273. fi
  1274. }
  1275. cleanup_apt_cache() {
  1276. cache_dir="/var/cache/apt/archives"
  1277. if [ -d "${cache_dir}" ]; then
  1278. run_as_root find "${cache_dir}" -type f -name 'netdata*.deb' -delete
  1279. fi
  1280. }
  1281. common_rpm_opts() {
  1282. pkg_type="rpm"
  1283. pkg_suffix=".noarch"
  1284. pkg_vsep="-"
  1285. INSTALL_TYPE="binpkg-rpm"
  1286. NATIVE_VERSION="${INSTALL_VERSION:+"-${INSTALL_VERSION}.${SYSARCH}"}"
  1287. }
  1288. common_dnf_opts() {
  1289. if [ "${INTERACTIVE}" = "0" ]; then
  1290. interactive_opts="-y"
  1291. fi
  1292. if command -v dnf > /dev/null; then
  1293. pm_cmd="dnf"
  1294. repo_subcmd="makecache"
  1295. else
  1296. pm_cmd="yum"
  1297. fi
  1298. install_subcmd="install"
  1299. pkg_install_opts="${interactive_opts}"
  1300. repo_update_opts="${interactive_opts}"
  1301. uninstall_subcmd="remove"
  1302. }
  1303. try_package_install() {
  1304. failed_refresh_msg="Failed to refresh repository metadata. ${BADNET_MSG} or incompatibilities with one or more third-party package repositories in the system package manager configuration."
  1305. if [ -z "${DISTRO_COMPAT_NAME}" ] || [ "${DISTRO_COMPAT_NAME}" = "unknown" ]; then
  1306. warning "Unable to determine Linux distribution for native packages."
  1307. return 2
  1308. elif [ -z "${SYSCODENAME}" ]; then
  1309. case "${DISTRO_COMPAT_NAME}" in
  1310. debian|ubuntu)
  1311. warning "Release codename not set. Unable to check availability of native packages for this system."
  1312. return 2
  1313. ;;
  1314. esac
  1315. fi
  1316. set_tmpdir
  1317. if [ "${DRY_RUN}" -eq 1 ]; then
  1318. progress "Would attempt to install using native packages..."
  1319. else
  1320. progress "Attempting to install using native packages..."
  1321. fi
  1322. if [ "${SELECTED_RELEASE_CHANNEL}" = "nightly" ]; then
  1323. release="-edge"
  1324. else
  1325. release=""
  1326. fi
  1327. interactive_opts=""
  1328. env=""
  1329. case "${DISTRO_COMPAT_NAME}" in
  1330. debian|ubuntu)
  1331. if [ "${INTERACTIVE}" = "0" ]; then
  1332. install_subcmd="-o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold install"
  1333. interactive_opts="-y"
  1334. env="DEBIAN_FRONTEND=noninteractive"
  1335. else
  1336. install_subcmd="install"
  1337. fi
  1338. needs_early_refresh=1
  1339. needs_apt_cache_cleanup=1
  1340. pm_cmd="apt-get"
  1341. repo_subcmd="update"
  1342. pkg_type="deb"
  1343. pkg_vsep="_"
  1344. pkg_install_opts="${interactive_opts}"
  1345. repo_update_opts="${interactive_opts}"
  1346. uninstall_subcmd="purge"
  1347. repo_prefix="${DISTRO_COMPAT_NAME}/${SYSCODENAME}"
  1348. pkg_suffix="+${DISTRO_COMPAT_NAME}${SYSVERSION}_all"
  1349. INSTALL_TYPE="binpkg-deb"
  1350. NATIVE_VERSION="${INSTALL_VERSION:+"=${INSTALL_VERSION}"}"
  1351. ;;
  1352. centos)
  1353. common_rpm_opts
  1354. common_dnf_opts
  1355. repo_prefix="el/${SYSVERSION}"
  1356. # if [ "${SYSVERSION}" -lt 8 ]; then
  1357. # explicitly_install_native_plugins=1
  1358. # fi
  1359. ;;
  1360. fedora|ol)
  1361. common_rpm_opts
  1362. common_dnf_opts
  1363. repo_prefix="${DISTRO_COMPAT_NAME}/${SYSVERSION}"
  1364. ;;
  1365. opensuse)
  1366. if [ "${INTERACTIVE}" = "0" ]; then
  1367. install_subcmd="--non-interactive --no-gpg-checks install"
  1368. else
  1369. install_subcmd="--no-gpg-checks install"
  1370. fi
  1371. common_rpm_opts
  1372. pm_cmd="zypper"
  1373. repo_subcmd="--gpg-auto-import-keys refresh"
  1374. repo_prefix="opensuse/${SYSVERSION}"
  1375. pkg_install_opts="${interactive_opts} --allow-unsigned-rpm"
  1376. repo_update_opts=""
  1377. uninstall_subcmd="remove"
  1378. ;;
  1379. amzn)
  1380. common_rpm_opts
  1381. common_dnf_opts
  1382. repo_prefix="amazonlinux/${SYSVERSION}"
  1383. ;;
  1384. *)
  1385. warning "We do not provide native packages for ${DISTRO}."
  1386. return 2
  1387. ;;
  1388. esac
  1389. if [ -n "${SKIP_DISTRO_DETECTION}" ]; then
  1390. warning "Attempting to use native packages with a distro override. This is not officially supported, but may work in some cases. If your system requires a distro override to use native packages, please open an feature request at ${AGENT_BUG_REPORT_URL} about it so that we can update the installer to auto-detect this."
  1391. fi
  1392. if [ -n "${INSTALL_VERSION}" ]; then
  1393. if echo "${INSTALL_VERSION}" | grep -q "nightly"; then
  1394. new_release="-edge"
  1395. else
  1396. new_release=
  1397. fi
  1398. if { [ -n "${new_release}" ] && [ -z "${release}" ]; } || { [ -z "${new_release}" ] && [ -n "${release}" ]; }; then
  1399. warning "Selected release channel does not match this version and it will be changed automatically."
  1400. fi
  1401. release="${new_release}"
  1402. fi
  1403. repoconfig_name="netdata-repo${release}"
  1404. case "${pkg_type}" in
  1405. deb)
  1406. repoconfig_file="${repoconfig_name}${pkg_vsep}${REPOCONFIG_DEB_VERSION}${pkg_suffix}.${pkg_type}"
  1407. repoconfig_url="${REPOCONFIG_DEB_URL_PREFIX}/${repo_prefix}/${repoconfig_file}"
  1408. ref_check_url="${REPOCONFIG_DEB_URL_PREFIX}"
  1409. ;;
  1410. rpm)
  1411. repoconfig_file="${repoconfig_name}${pkg_vsep}${REPOCONFIG_RPM_VERSION}${pkg_suffix}.${pkg_type}"
  1412. repoconfig_url="${REPOCONFIG_RPM_URL_PREFIX}/${repo_prefix}/${SYSARCH}/${repoconfig_file}"
  1413. ref_check_url="${REPOCONFIG_RPM_URL_PREFIX}"
  1414. ;;
  1415. esac
  1416. if ! pkg_installed "${repoconfig_name}"; then
  1417. progress "Checking for availability of repository configuration package."
  1418. if ! check_for_remote_file "${ref_check_url}"; then
  1419. NETDATA_ASSUME_REMOTE_FILES_ARE_PRESENT=1
  1420. fi
  1421. if ! check_for_remote_file "${repoconfig_url}"; then
  1422. warning "No repository configuration package available for ${DISTRO} ${SYSVERSION}. Cannot install native packages on this system."
  1423. return 2
  1424. fi
  1425. if ! download "${repoconfig_url}" "${tmpdir}/${repoconfig_file}"; then
  1426. fatal "Failed to download repository configuration package. ${BADNET_MSG}." F0209
  1427. fi
  1428. if [ -n "${needs_early_refresh}" ]; then
  1429. # shellcheck disable=SC2086
  1430. if ! run_as_root env ${env} ${pm_cmd} ${repo_subcmd} ${repo_update_opts}; then
  1431. warning "${failed_refresh_msg}"
  1432. return 2
  1433. fi
  1434. if [ -n "${needs_apt_cache_cleanup}" ]; then
  1435. cleanup_apt_cache
  1436. fi
  1437. fi
  1438. # shellcheck disable=SC2086
  1439. if ! run_as_root env ${env} ${pm_cmd} ${install_subcmd} ${pkg_install_opts} "${tmpdir}/${repoconfig_file}"; then
  1440. warning "Failed to install repository configuration package."
  1441. return 2
  1442. fi
  1443. if [ -n "${repo_subcmd}" ]; then
  1444. # shellcheck disable=SC2086
  1445. if ! run_as_root env ${env} ${pm_cmd} ${repo_subcmd} ${repo_update_opts}; then
  1446. fatal "${failed_refresh_msg} In most cases, disabling any third-party repositories on the system and re-running the installer with the same options should work. If that does not work, consider using a static build with the --static-only option instead of native packages." F0205
  1447. fi
  1448. fi
  1449. else
  1450. progress "Repository configuration is already present, attempting to install netdata."
  1451. fi
  1452. if [ "${ACTION}" = "repositories-only" ]; then
  1453. progress "Successfully installed repository configuraion package."
  1454. deferred_warnings
  1455. cleanup
  1456. trap - EXIT
  1457. exit 1
  1458. fi
  1459. if ! check_special_native_deps; then
  1460. warning "Could not find secondary dependencies for ${DISTRO} on ${SYSARCH}."
  1461. if [ -z "${NO_CLEANUP}" ]; then
  1462. progress "Attempting to uninstall repository configuration package."
  1463. # shellcheck disable=SC2086
  1464. run_as_root env ${env} ${pm_cmd} ${uninstall_subcmd} ${pkg_install_opts} "${repoconfig_name}"
  1465. fi
  1466. return 2
  1467. fi
  1468. if ! netdata_avail_check "${DISTRO_COMPAT_NAME}"; then
  1469. warning "Could not find a usable native package for ${DISTRO} on ${SYSARCH}."
  1470. if [ -z "${NO_CLEANUP}" ]; then
  1471. progress "Attempting to uninstall repository configuration package."
  1472. # shellcheck disable=SC2086
  1473. run_as_root env ${env} ${pm_cmd} ${uninstall_subcmd} ${pkg_install_opts} "${repoconfig_name}"
  1474. fi
  1475. return 2
  1476. fi
  1477. if [ "${NETDATA_DISABLE_TELEMETRY}" -eq 1 ]; then
  1478. run_as_root mkdir -p "/etc/netdata"
  1479. run_as_root touch "/etc/netdata/.opt-out-from-anonymous-statistics"
  1480. fi
  1481. # shellcheck disable=SC2086
  1482. if ! run_as_root env ${env} ${pm_cmd} ${install_subcmd} ${pkg_install_opts} "netdata${NATIVE_VERSION}"; then
  1483. warning "Failed to install Netdata package."
  1484. if [ -z "${NO_CLEANUP}" ]; then
  1485. progress "Attempting to uninstall repository configuration package."
  1486. # shellcheck disable=SC2086
  1487. run_as_root env ${env} ${pm_cmd} ${uninstall_subcmd} ${pkg_install_opts} "${repoconfig_name}"
  1488. fi
  1489. return 2
  1490. fi
  1491. if [ -n "${explicitly_install_native_plugins}" ]; then
  1492. progress "Installing external plugins."
  1493. # shellcheck disable=SC2086
  1494. if ! run_as_root env ${env} ${pm_cmd} ${install_subcmd} ${DEFAULT_PLUGIN_PACKAGES}; then
  1495. warning "Failed to install external plugin packages. Some collectors may not be available."
  1496. fi
  1497. fi
  1498. }
  1499. # ======================================================================
  1500. # Static build install code
  1501. # shellcheck disable=SC2034,SC2086,SC2126
  1502. set_static_archive_urls() {
  1503. if [ -z "${2}" ]; then
  1504. arch="${SYSARCH}"
  1505. else
  1506. arch="${2}"
  1507. fi
  1508. if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
  1509. path="$(cd "${NETDATA_OFFLINE_INSTALL_SOURCE}" || exit 1; pwd)"
  1510. export NETDATA_STATIC_ARCHIVE_URL="file://${path}/netdata-${arch}-latest.gz.run"
  1511. export NETDATA_STATIC_ARCHIVE_NAME="netdata-${arch}-latest.gz.run"
  1512. export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="file://${path}/sha256sums.txt"
  1513. elif [ "${1}" = "stable" ]; then
  1514. if [ -n "${INSTALL_VERSION}" ]; then
  1515. export NETDATA_STATIC_ARCHIVE_URL="https://github.com/netdata/netdata/releases/download/v${INSTALL_VERSION}/netdata-${arch}-v${INSTALL_VERSION}.gz.run"
  1516. export NETDATA_STATIC_ARCHIVE_OLD_URL="https://github.com/netdata/netdata/releases/download/v${INSTALL_VERSION}/netdata-v${INSTALL_VERSION}.gz.run"
  1517. export NETDATA_STATIC_ARCHIVE_NAME="netdata-${arch}-v${INSTALL_VERSION}.gz.run"
  1518. export NETDATA_STATIC_ARCHIVE_OLD_NAME="netdata-v${INSTALL_VERSION}.gz.run"
  1519. export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/v${INSTALL_VERSION}/sha256sums.txt"
  1520. else
  1521. latest="$(get_redirect "https://github.com/netdata/netdata/releases/latest")"
  1522. export NETDATA_STATIC_ARCHIVE_URL="https://github.com/netdata/netdata/releases/download/${latest}/netdata-${arch}-latest.gz.run"
  1523. export NETDATA_STATIC_ARCHIVE_NAME="netdata-${arch}-latest.gz.run"
  1524. export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/${latest}/sha256sums.txt"
  1525. fi
  1526. else
  1527. if [ -n "${INSTALL_VERSION}" ]; then
  1528. export NETDATA_STATIC_ARCHIVE_URL="${NETDATA_TARBALL_BASEURL}/download/v${INSTALL_VERSION}/netdata-${arch}-v${INSTALL_VERSION}.gz.run"
  1529. export NETDATA_STATIC_ARCHIVE_OLD_URL="${NETDATA_TARBALL_BASEURL}/download/v${INSTALL_VERSION}/netdata-v${INSTALL_VERSION}.gz.run"
  1530. export NETDATA_STATIC_ARCHIVE_NAME="netdata-${arch}-v${INSTALL_VERSION}.gz.run"
  1531. export NETDATA_STATIC_ARCHIVE_OLD_NAME="netdata-v${INSTALL_VERSION}.gz.run"
  1532. export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="${NETDATA_TARBALL_BASEURL}/download/v${INSTALL_VERSION}/sha256sums.txt"
  1533. else
  1534. tag="$(get_redirect "${NETDATA_TARBALL_BASEURL}/latest")"
  1535. export NETDATA_STATIC_ARCHIVE_URL="${NETDATA_TARBALL_BASEURL}/download/${tag}/netdata-${arch}-latest.gz.run"
  1536. export NETDATA_STATIC_ARCHIVE_NAME="netdata-${arch}-latest.gz.run"
  1537. export NETDATA_STATIC_ARCHIVE_CHECKSUM_URL="${NETDATA_TARBALL_BASEURL}/download/${tag}/sha256sums.txt"
  1538. fi
  1539. fi
  1540. }
  1541. try_static_install() {
  1542. set_static_archive_urls "${SELECTED_RELEASE_CHANNEL}"
  1543. if [ "${DRY_RUN}" -eq 1 ]; then
  1544. progress "Would attempt to install using static build..."
  1545. else
  1546. progress "Attempting to install using static build..."
  1547. fi
  1548. if ! check_for_remote_file "${NETDATA_TARBALL_BASEURL}"; then
  1549. NETDATA_ASSUME_REMOTE_FILES_ARE_PRESENT=1
  1550. fi
  1551. # Check status code first, so that we can provide nicer fallback for dry runs.
  1552. if check_for_remote_file "${NETDATA_STATIC_ARCHIVE_URL}"; then
  1553. netdata_agent="${NETDATA_STATIC_ARCHIVE_NAME}"
  1554. elif [ "${SYSARCH}" = "x86_64" ] && check_for_remote_file "${NETDATA_STATIC_ARCHIVE_OLD_URL}"; then
  1555. netdata_agent="${NETDATA_STATIC_ARCHIVE_OLD_NAME}"
  1556. export NETDATA_STATIC_ARCHIVE_URL="${NETDATA_STATIC_ARCHIVE_OLD_URL}"
  1557. else
  1558. warning "Could not find a ${SELECTED_RELEASE_CHANNEL} static build for ${SYSARCH} CPUs. This usually means there is some networking issue preventing access to https://github.com/ from this system."
  1559. return 2
  1560. fi
  1561. if ! download "${NETDATA_STATIC_ARCHIVE_URL}" "${tmpdir}/${netdata_agent}"; then
  1562. fatal "Unable to download static build archive for ${SYSARCH}. ${BADNET_MSG}." F0208
  1563. fi
  1564. if ! download "${NETDATA_STATIC_ARCHIVE_CHECKSUM_URL}" "${tmpdir}/sha256sum.txt"; then
  1565. fatal "Unable to fetch checksums to verify static build archive. ${BADNET_MSG}." F0206
  1566. fi
  1567. if [ "${DRY_RUN}" -eq 1 ]; then
  1568. progress "Would validate SHA256 checksum of downloaded static build archive."
  1569. else
  1570. if [ -z "${INSTALL_VERSION}" ]; then
  1571. if ! grep "${netdata_agent}" "${tmpdir}/sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then
  1572. fatal "Static binary checksum validation failed. ${BADCACHE_MSG}." F0207
  1573. fi
  1574. fi
  1575. fi
  1576. if [ "${INTERACTIVE}" -eq 0 ]; then
  1577. opts="${opts} --accept"
  1578. fi
  1579. env_cmd="env NETDATA_CERT_TEST_URL=${NETDATA_CLAIM_URL} NETDATA_CERT_MODE=check"
  1580. if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
  1581. env_cmd="env NETDATA_CERT_TEST_URL=${NETDATA_CLAIM_URL} NETDATA_CERT_MODE=auto"
  1582. fi
  1583. progress "Installing netdata"
  1584. # shellcheck disable=SC2086
  1585. if ! run_as_root ${env_cmd} /bin/sh "${tmpdir}/${netdata_agent}" ${opts} -- ${NETDATA_INSTALLER_OPTIONS}; then
  1586. warning "Failed to install static build of Netdata on ${SYSARCH}."
  1587. run rm -rf /opt/netdata
  1588. return 2
  1589. fi
  1590. if [ "${DRY_RUN}" -ne 1 ]; then
  1591. install_type_file="/opt/netdata/etc/netdata/.install-type"
  1592. if [ -f "${install_type_file}" ]; then
  1593. run_as_root sh -c "cat \"${install_type_file}\" > \"${tmpdir}/install-type\""
  1594. run_as_root chown "$(id -u)":"$(id -g)" "${tmpdir}/install-type"
  1595. # shellcheck disable=SC1090,SC1091
  1596. . "${tmpdir}/install-type"
  1597. cat > "${tmpdir}/install-type" <<- EOF
  1598. INSTALL_TYPE='kickstart-static'
  1599. PREBUILT_ARCH='${PREBUILT_ARCH}'
  1600. EOF
  1601. run_as_root chown netdata:netdata "${tmpdir}/install-type"
  1602. run_as_root cp "${tmpdir}/install-type" "${install_type_file}"
  1603. fi
  1604. fi
  1605. }
  1606. # ======================================================================
  1607. # Local build install code
  1608. set_source_archive_urls() {
  1609. if [ "$1" = "stable" ]; then
  1610. if [ -n "${INSTALL_VERSION}" ]; then
  1611. export NETDATA_SOURCE_ARCHIVE_URL="https://github.com/netdata/netdata/releases/download/v${INSTALL_VERSION}/netdata-v${INSTALL_VERSION}.tar.gz"
  1612. export NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/v${INSTALL_VERSION}/sha256sums.txt"
  1613. else
  1614. latest="$(get_redirect "https://github.com/netdata/netdata/releases/latest")"
  1615. export NETDATA_SOURCE_ARCHIVE_URL="https://github.com/netdata/netdata/releases/download/${latest}/netdata-${latest}.tar.gz"
  1616. export NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL="https://github.com/netdata/netdata/releases/download/${latest}/sha256sums.txt"
  1617. fi
  1618. else
  1619. if [ -n "${INSTALL_VERSION}" ]; then
  1620. export NETDATA_SOURCE_ARCHIVE_URL="${NETDATA_TARBALL_BASEURL}/download/v${INSTALL_VERSION}/netdata-latest.tar.gz"
  1621. export NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL="${NETDATA_TARBALL_BASEURL}/download/v${INSTALL_VERSION}/sha256sums.txt"
  1622. else
  1623. tag="$(get_redirect "${NETDATA_TARBALL_BASEURL}/latest")"
  1624. export NETDATA_SOURCE_ARCHIVE_URL="${NETDATA_TARBALL_BASEURL}/download/${tag}/netdata-latest.tar.gz"
  1625. export NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL="${NETDATA_TARBALL_BASEURL}/download/${tag}/sha256sums.txt"
  1626. fi
  1627. fi
  1628. }
  1629. install_local_build_dependencies() {
  1630. set_tmpdir
  1631. bash="$(command -v bash 2> /dev/null)"
  1632. if [ -z "${bash}" ] || [ ! -x "${bash}" ]; then
  1633. warning "Unable to find a usable version of \`bash\` (required for local build)."
  1634. return 1
  1635. fi
  1636. if ! download "${PACKAGES_SCRIPT}" "${tmpdir}/install-required-packages.sh"; then
  1637. fatal "Failed to download dependency handling script for local build. ${BADNET_MSG}." F000D
  1638. fi
  1639. if [ "${DRY_RUN}" -eq 1 ]; then
  1640. progress "Would run downloaded script to install required build dependencies..."
  1641. else
  1642. progress "Running downloaded script to install required build dependencies..."
  1643. fi
  1644. if [ "${INTERACTIVE}" -eq 0 ]; then
  1645. opts="--dont-wait --non-interactive"
  1646. fi
  1647. # shellcheck disable=SC2086
  1648. if [ "$(uname -s)" = "Darwin" ]; then
  1649. if ! run "${bash}" "${tmpdir}/install-required-packages.sh" ${opts} netdata; then
  1650. warning "Failed to install all required packages, but installation might still be possible."
  1651. fi
  1652. else
  1653. if ! run_as_root "${bash}" "${tmpdir}/install-required-packages.sh" ${opts} netdata; then
  1654. warning "Failed to install all required packages, but installation might still be possible."
  1655. fi
  1656. fi
  1657. }
  1658. build_and_install() {
  1659. if [ "${DRY_RUN}" -eq 1 ]; then
  1660. progress "Would attempt to build netdata..."
  1661. else
  1662. progress "Building netdata..."
  1663. fi
  1664. echo "INSTALL_TYPE='kickstart-build'" > system/.install-type
  1665. opts="${NETDATA_INSTALLER_OPTIONS}"
  1666. if [ "${INTERACTIVE}" -eq 0 ]; then
  1667. opts="${opts} --dont-wait"
  1668. fi
  1669. if [ "${SELECTED_RELEASE_CHANNEL}" = "stable" ]; then
  1670. opts="${opts} --stable-channel"
  1671. fi
  1672. if [ "${NETDATA_REQUIRE_CLOUD}" -eq 1 ]; then
  1673. opts="${opts} --require-cloud"
  1674. elif [ "${NETDATA_DISABLE_CLOUD}" -eq 1 ]; then
  1675. opts="${opts} --disable-cloud"
  1676. fi
  1677. # shellcheck disable=SC2086
  1678. run_script ./netdata-installer.sh ${opts}
  1679. case $? in
  1680. 1)
  1681. if [ -n "${EXIT_REASON}" ]; then
  1682. fatal "netdata-installer.sh failed to run: ${EXIT_REASON}" "${EXIT_CODE}"
  1683. else
  1684. fatal "netdata-installer.sh failed to run: Encountered an unhandled error in the installer code." I0000
  1685. fi
  1686. ;;
  1687. 2) fatal "Insufficient RAM to install netdata." F0008 ;;
  1688. esac
  1689. }
  1690. try_build_install() {
  1691. set_tmpdir
  1692. if [ "${DRY_RUN}" -eq 1 ]; then
  1693. progress "Would attempt to install by building locally..."
  1694. else
  1695. progress "Attempting to install by building locally..."
  1696. fi
  1697. if ! install_local_build_dependencies; then
  1698. return 1
  1699. fi
  1700. set_source_archive_urls "${SELECTED_RELEASE_CHANNEL}"
  1701. if [ -n "${INSTALL_VERSION}" ]; then
  1702. if ! download "${NETDATA_SOURCE_ARCHIVE_URL}" "${tmpdir}/netdata-v${INSTALL_VERSION}.tar.gz"; then
  1703. fatal "Failed to download source tarball for local build. ${BADNET_MSG}." F000B
  1704. fi
  1705. elif ! download "${NETDATA_SOURCE_ARCHIVE_URL}" "${tmpdir}/netdata-latest.tar.gz"; then
  1706. fatal "Failed to download source tarball for local build. ${BADNET_MSG}." F000B
  1707. fi
  1708. if ! download "${NETDATA_SOURCE_ARCHIVE_CHECKSUM_URL}" "${tmpdir}/sha256sum.txt"; then
  1709. fatal "Failed to download checksums for source tarball verification. ${BADNET_MSG}." F000C
  1710. fi
  1711. if [ "${DRY_RUN}" -eq 1 ]; then
  1712. progress "Would validate SHA256 checksum of downloaded source archive."
  1713. else
  1714. if [ -z "${INSTALL_VERSION}" ]; then
  1715. # shellcheck disable=SC2086
  1716. if ! grep netdata-latest.tar.gz "${tmpdir}/sha256sum.txt" | safe_sha256sum -c - > /dev/null 2>&1; then
  1717. fatal "Tarball checksum validation failed. ${BADCACHE_MSG}." F0005
  1718. fi
  1719. fi
  1720. fi
  1721. if [ -n "${INSTALL_VERSION}" ]; then
  1722. run tar -xf "${tmpdir}/netdata-v${INSTALL_VERSION}.tar.gz" -C "${tmpdir}"
  1723. rm -rf "${tmpdir}/netdata-v${INSTALL_VERSION}.tar.gz" > /dev/null 2>&1
  1724. else
  1725. run tar -xf "${tmpdir}/netdata-latest.tar.gz" -C "${tmpdir}"
  1726. rm -rf "${tmpdir}/netdata-latest.tar.gz" > /dev/null 2>&1
  1727. fi
  1728. if [ "${DRY_RUN}" -ne 1 ]; then
  1729. cd "$(find "${tmpdir}" -mindepth 1 -maxdepth 1 -type d -name netdata-)" || fatal "Cannot change directory to netdata source tree" F0006
  1730. fi
  1731. if [ -x netdata-installer.sh ] || [ "${DRY_RUN}" -eq 1 ]; then
  1732. build_and_install || return 1
  1733. else
  1734. # This case is needed because some platforms produce an extra directory on the source tarball extraction.
  1735. if [ "$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ] && [ -x "$(find . -mindepth 1 -maxdepth 1 -type d)/netdata-installer.sh" ]; then
  1736. cd "$(find . -mindepth 1 -maxdepth 1 -type d)" && build_and_install || return 1
  1737. else
  1738. fatal "Cannot install netdata from source (the source directory does not include netdata-installer.sh)." F0009
  1739. fi
  1740. fi
  1741. }
  1742. # ======================================================================
  1743. # Offline install support code
  1744. prepare_offline_install_source() {
  1745. if [ -e "${1}" ]; then
  1746. if [ ! -d "${1}" ]; then
  1747. fatal "${1} is not a directory, unable to prepare offline install source." F0503
  1748. fi
  1749. else
  1750. run mkdir -p "${1}" || fatal "Unable to create target directory for offline install preparation." F0504
  1751. fi
  1752. run cd "${1}" || fatal "Failed to switch to target directory for offline install preparation." F0505
  1753. case "${NETDATA_FORCE_METHOD}" in
  1754. static|'')
  1755. set_static_archive_urls "${SELECTED_RELEASE_CHANNEL}" "x86_64"
  1756. if ! check_for_remote_file "${NETDATA_TARBALL_BASEURL}"; then
  1757. NETDATA_ASSUME_REMOTE_FILES_ARE_PRESENT=1
  1758. fi
  1759. if check_for_remote_file "${NETDATA_STATIC_ARCHIVE_URL}"; then
  1760. for arch in $(echo "${NETDATA_OFFLINE_ARCHES:-${STATIC_INSTALL_ARCHES}}" | awk '{for (i=1;i<=NF;i++) if (!a[$i]++) printf("%s%s",$i,FS)}{printf("\n")}'); do
  1761. set_static_archive_urls "${SELECTED_RELEASE_CHANNEL}" "${arch}"
  1762. if check_for_remote_file "${NETDATA_STATIC_ARCHIVE_URL}"; then
  1763. progress "Fetching ${NETDATA_STATIC_ARCHIVE_URL}"
  1764. if ! download "${NETDATA_STATIC_ARCHIVE_URL}" "netdata-${arch}-latest.gz.run"; then
  1765. warning "Failed to download static installer archive for ${arch}. ${BADNET_MSG}."
  1766. fi
  1767. else
  1768. progress "Skipping ${NETDATA_STATIC_ARCHIVE_URL} as it does not exist on the server."
  1769. fi
  1770. done
  1771. legacy=0
  1772. else
  1773. 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."
  1774. progress "Fetching ${NETDATA_STATIC_ARCHIVE_OLD_URL}"
  1775. legacy=1
  1776. if ! download "${NETDATA_STATIC_ARCHIVE_OLD_URL}" "netdata-x86_64-latest.gz.run"; then
  1777. warning "Failed to download static installer archive for x86_64. ${BADNET_MSG}."
  1778. fi
  1779. fi
  1780. if ! find . -name '*.gz.run'; then
  1781. fatal "Did not actually download any static installer archives, cannot continue. ${BADNET_MSG}." F0516
  1782. fi
  1783. progress "Fetching ${NETDATA_STATIC_ARCHIVE_CHECKSUM_URL}"
  1784. if ! download "${NETDATA_STATIC_ARCHIVE_CHECKSUM_URL}" "sha256sums.txt"; then
  1785. fatal "Failed to download checksum file. ${BADNET_MSG}." F0506
  1786. fi
  1787. ;;
  1788. esac
  1789. if [ "${legacy:-0}" -eq 1 ]; then
  1790. sed -e 's/netdata-latest.gz.run/netdata-x86_64-latest.gz.run' sha256sums.txt > sha256sums.tmp
  1791. mv sha256sums.tmp sha256sums.txt
  1792. fi
  1793. if [ "${DRY_RUN}" -ne 1 ]; then
  1794. progress "Verifying checksums."
  1795. if ! grep -e "$(find . -name '*.gz.run')" sha256sums.txt | safe_sha256sum -c -; then
  1796. fatal "Checksums for offline install files are incorrect. ${BADCACHE_MSG}." F0507
  1797. fi
  1798. else
  1799. progress "Would verify SHA256 checksums of downloaded installation files."
  1800. fi
  1801. if [ "${DRY_RUN}" -ne 1 ]; then
  1802. progress "Preparing install script."
  1803. cat > "install.sh" <<-EOF
  1804. #!/bin/sh
  1805. dir=\$(CDPATH= cd -- "\$(dirname -- "\$0")" && pwd)
  1806. "\${dir}/kickstart.sh" --offline-install-source "\${dir}" \${@}
  1807. EOF
  1808. chmod +x "install.sh"
  1809. else
  1810. progress "Would create install script"
  1811. fi
  1812. if [ "${DRY_RUN}" -ne 1 ]; then
  1813. progress "Copying kickstart script."
  1814. cp "${KICKSTART_SOURCE}" "kickstart.sh"
  1815. chmod +x "kickstart.sh"
  1816. else
  1817. progress "Would copy kickstart.sh to offline install source directory"
  1818. fi
  1819. if [ "${DRY_RUN}" -ne 1 ]; then
  1820. progress "Saving release channel information."
  1821. echo "${SELECTED_RELEASE_CHANNEL}" > "channel"
  1822. else
  1823. progress "Would save release channel information to offline install source directory"
  1824. fi
  1825. progress "Finished preparing offline install source directory at ${1}. You can now copy this directory to a target system and then run the script ‘install.sh’ from it to install on that system."
  1826. }
  1827. # ======================================================================
  1828. # Per system-type install logic
  1829. install_on_linux() {
  1830. if [ "${NETDATA_FORCE_METHOD}" != 'static' ] && [ "${NETDATA_FORCE_METHOD}" != 'build' ] && [ -z "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
  1831. SELECTED_INSTALL_METHOD="native"
  1832. try_package_install
  1833. case "$?" in
  1834. 0)
  1835. NETDATA_INSTALL_SUCCESSFUL=1
  1836. INSTALL_PREFIX="/"
  1837. ;;
  1838. 1) fatal "Unable to install on this system." F0300 ;;
  1839. 2)
  1840. case "${NETDATA_FORCE_METHOD}" in
  1841. native) fatal "Could not install native binary packages." F0301 ;;
  1842. *) warning "Could not install native binary packages, falling back to alternative installation method." ;;
  1843. esac
  1844. ;;
  1845. esac
  1846. fi
  1847. if [ "${NETDATA_FORCE_METHOD}" != 'native' ] && [ "${NETDATA_FORCE_METHOD}" != 'build' ] && [ -z "${NETDATA_INSTALL_SUCCESSFUL}" ]; then
  1848. SELECTED_INSTALL_METHOD="static"
  1849. INSTALL_TYPE="kickstart-static"
  1850. try_static_install
  1851. case "$?" in
  1852. 0)
  1853. NETDATA_INSTALL_SUCCESSFUL=1
  1854. INSTALL_PREFIX="/opt/netdata"
  1855. ;;
  1856. 1) fatal "Unable to install on this system." F0302 ;;
  1857. 2)
  1858. case "${NETDATA_FORCE_METHOD}" in
  1859. static) fatal "Could not install static build." F0303 ;;
  1860. *) warning "Could not install static build, falling back to alternative installation method." ;;
  1861. esac
  1862. ;;
  1863. esac
  1864. fi
  1865. if [ "${NETDATA_FORCE_METHOD}" != 'native' ] && [ "${NETDATA_FORCE_METHOD}" != 'static' ] && [ -z "${NETDATA_INSTALL_SUCCESSFUL}" ]; then
  1866. SELECTED_INSTALL_METHOD="build"
  1867. INSTALL_TYPE="kickstart-build"
  1868. try_build_install
  1869. case "$?" in
  1870. 0) NETDATA_INSTALL_SUCCESSFUL=1 ;;
  1871. *) fatal "Unable to install on this system." F0304 ;;
  1872. esac
  1873. fi
  1874. }
  1875. install_on_macos() {
  1876. case "${NETDATA_FORCE_METHOD}" in
  1877. native) fatal "User requested native package, but native packages are not available for macOS. Try installing without \`--only-native\` option." F0305 ;;
  1878. static) fatal "User requested static build, but static builds are not available for macOS. Try installing without \`--only-static\` option." F0306 ;;
  1879. *)
  1880. SELECTED_INSTALL_METHOD="build"
  1881. INSTALL_TYPE="kickstart-build"
  1882. try_build_install
  1883. case "$?" in
  1884. 0) NETDATA_INSTALL_SUCCESSFUL=1 ;;
  1885. *) fatal "Unable to install on this system." F0307 ;;
  1886. esac
  1887. ;;
  1888. esac
  1889. }
  1890. install_on_freebsd() {
  1891. case "${NETDATA_FORCE_METHOD}" in
  1892. native) fatal "User requested native package, but native packages are not available for FreeBSD. Try installing without \`--only-native\` option." F0308 ;;
  1893. static) fatal "User requested static build, but static builds are not available for FreeBSD. Try installing without \`--only-static\` option." F0309 ;;
  1894. *)
  1895. SELECTED_INSTALL_METHOD="build"
  1896. INSTALL_TYPE="kickstart-build"
  1897. try_build_install
  1898. case "$?" in
  1899. 0) NETDATA_INSTALL_SUCCESSFUL=1 ;;
  1900. *) fatal "Unable to install on this system." F030A ;;
  1901. esac
  1902. ;;
  1903. esac
  1904. }
  1905. # ======================================================================
  1906. # Argument parsing code
  1907. handle_major_version() {
  1908. CONTINUE_INSTALL_PROMPT="Attempting to install will use the latest version available overall. Do you wish to continue the install?"
  1909. if [ -z "${INSTALL_MAJOR_VERSION}" ]; then
  1910. return
  1911. fi
  1912. actual_version="$(get_actual_version "v${INSTALL_MAJOR_VERSION}" "${RELEASE_CHANNEL}")"
  1913. if [ -z "${actual_version}" ]; then
  1914. if [ "${INTERACTIVE}" -eq 0 ]; then
  1915. fatal "Could not determine the lastest releaase in channel '${RELEASE_CHANNEL}' with major version '${INSTALL_MAJOR_VERSION}'" F0517
  1916. else
  1917. if confirm "Unable to determine the correct version to install for major version '${INSTALL_MAJOR_VERSION}'. ${CONTINUE_INSTALL_PROMPT}"; then
  1918. progress "User requested continuing the install with the latest version."
  1919. else
  1920. fatal "Cancelling installation at user request." F0518
  1921. fi
  1922. fi
  1923. elif [ "${actual_version}" = 'NONE' ]; then
  1924. if [ "${INTERACTIVE}" -eq 0 ]; then
  1925. warning "No releases with major version '${INSTALL_MAJOR_VERSION}' have been published. Continuing the install with the latest version instead."
  1926. else
  1927. if confirm "No releases with major version '${INSTALL_MAJOR_VERSION}' have been published. ${CONTINUE_INSTALL_PROMPT}"; then
  1928. progress "User requested continuing the install with the latest version."
  1929. else
  1930. fatal "Cancelling installation at user request." F0519
  1931. fi
  1932. fi
  1933. else
  1934. INSTALL_VERSION="${actual_version}"
  1935. fi
  1936. }
  1937. validate_args() {
  1938. check_claim_opts
  1939. if [ -n "${NETDATA_FORCE_METHOD}" ]; then
  1940. SELECTED_INSTALL_METHOD="${NETDATA_FORCE_METHOD}"
  1941. fi
  1942. if [ "${ACTION}" = "repositories-only" ] && [ "${NETDATA_FORCE_METHOD}" != "native" ]; then
  1943. fatal "Repositories can only be installed for native installs." F050D
  1944. fi
  1945. if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
  1946. case "${NETDATA_FORCE_METHOD}" in
  1947. native|build) fatal "Offline installs are only supported for static builds currently." F0502 ;;
  1948. esac
  1949. if [ ! -d "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
  1950. fatal "Offline install source must be a directory." F0519
  1951. fi
  1952. fi
  1953. if [ -n "${LOCAL_BUILD_OPTIONS}" ]; then
  1954. case "${NETDATA_FORCE_METHOD}" in
  1955. build) NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} ${LOCAL_BUILD_OPTIONS}" ;;
  1956. *) fatal "Specifying local build options is only supported when the --build-only option is also specified." F0401 ;;
  1957. esac
  1958. fi
  1959. if [ -n "${STATIC_INSTALL_OPTIONS}" ]; then
  1960. case "${NETDATA_FORCE_METHOD}" in
  1961. static) NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} ${STATIC_INSTALL_OPTIONS}" ;;
  1962. *) fatal "Specifying installer options options is only supported when the --static-only option is also specified." F0402 ;;
  1963. esac
  1964. fi
  1965. if [ "${RELEASE_CHANNEL}" = "default" ]; then
  1966. if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ]; then
  1967. SELECTED_RELEASE_CHANNEL="$(cat "${NETDATA_OFFLINE_INSTALL_SOURCE}/channel")"
  1968. if [ -z "${SELECTED_RELEASE_CHANNEL}" ]; then
  1969. fatal "Could not find a release channel indicator in ${NETDATA_OFFLINE_INSTALL_SOURCE}." F0508
  1970. fi
  1971. else
  1972. SELECTED_RELEASE_CHANNEL="${DEFAULT_RELEASE_CHANNEL}"
  1973. fi
  1974. else
  1975. if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ] && [ "${RELEASE_CHANNEL}" != "$(cat "${NETDATA_OFFLINE_INSTALL_SOURCE}/channel")" ]; then
  1976. fatal "Release channal '${RELEASE_CHANNEL}' requested, but indicated offline installation source release channel is '$(cat "${NETDATA_OFFLINE_INSTALL_SOURCE}/channel")'." F0509
  1977. fi
  1978. SELECTED_RELEASE_CHANNEL="${RELEASE_CHANNEL}"
  1979. fi
  1980. if [ -n "${INSTALL_MAJOR_VERSION}" ] && [ -n "${INSTALL_VERSION}" ]; then
  1981. fatal "Only one of --install-version or --install-major-version may be specified." F0515
  1982. fi
  1983. handle_major_version # Appropriately updates INSTALL_VERSION if INSTALL_MAJOR_VERSION is set.
  1984. if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ] && [ -n "${INSTALL_VERSION}" ]; then
  1985. fatal "Specifying an install version alongside an offline install source is not supported." F050A
  1986. fi
  1987. if [ "${NETDATA_AUTO_UPDATES}" = "default" ]; then
  1988. if [ -n "${NETDATA_OFFLINE_INSTALL_SOURCE}" ] || [ -n "${INSTALL_VERSION}" ]; then
  1989. AUTO_UPDATE=0
  1990. else
  1991. AUTO_UPDATE=1
  1992. fi
  1993. elif [ "${NETDATA_INSTALL_MAJOR_VERSION}" ]; then
  1994. warning "Forcibly disabling auto updates as a specific major version was requested."
  1995. AUTO_UPDATE=0
  1996. elif [ "${NETDATA_AUTO_UPDATES}" = 1 ]; then
  1997. AUTO_UPDATE=1
  1998. else
  1999. AUTO_UPDATE=0
  2000. fi
  2001. }
  2002. set_action() {
  2003. new_action="${1}"
  2004. if [ -n "${ACTION}" ]; then
  2005. warning "Ignoring previously specified '${ACTION}' operation in favor of '${new_action}' specified later on the command line."
  2006. fi
  2007. ACTION="${new_action}"
  2008. NETDATA_COMMAND="${new_action}"
  2009. }
  2010. parse_args() {
  2011. while [ -n "${1}" ]; do
  2012. case "${1}" in
  2013. "--help")
  2014. usage
  2015. cleanup
  2016. trap - EXIT
  2017. exit 0
  2018. ;;
  2019. "--no-cleanup") NO_CLEANUP=1 ;;
  2020. "--dont-wait"|"--non-interactive") INTERACTIVE=0 ;;
  2021. "--interactive") INTERACTIVE=1 ;;
  2022. "--dry-run") DRY_RUN=1 ;;
  2023. "--release-channel")
  2024. RELEASE_CHANNEL="$(echo "${2}" | tr '[:upper:]' '[:lower:]')"
  2025. case "${RELEASE_CHANNEL}" in
  2026. nightly|stable|default) shift 1 ;;
  2027. *)
  2028. echo "Unrecognized value for --release-channel. Valid release channels are: stable, nightly, default"
  2029. exit 1
  2030. ;;
  2031. esac
  2032. ;;
  2033. "--stable-channel") RELEASE_CHANNEL="stable" ;;
  2034. "--nightly-channel") RELEASE_CHANNEL="nightly" ;;
  2035. "--reinstall") set_action 'reinstall' ;;
  2036. "--reinstall-even-if-unsafe") set_action 'unsafe-reinstall' ;;
  2037. "--reinstall-clean") set_action 'reinstall-clean' ;;
  2038. "--uninstall") set_action 'uninstall' ;;
  2039. "--claim-only") set_action 'claim' ;;
  2040. "--no-updates") NETDATA_AUTO_UPDATES=0 ;;
  2041. "--auto-update") NETDATA_AUTO_UPDATES="1" ;;
  2042. "--auto-update-type"|"--auto-update-method")
  2043. NETDATA_AUTO_UPDATE_TYPE="$(echo "${2}" | tr '[:upper:]' '[:lower:]')"
  2044. case "${NETDATA_AUTO_UPDATE_TYPE}" in
  2045. systemd|interval|crontab) shift 1 ;;
  2046. *)
  2047. echo "Unrecognized value for --auto-update-type. Valid values are: systemd, interval, crontab"
  2048. exit 1
  2049. ;;
  2050. esac
  2051. ;;
  2052. "--disable-cloud")
  2053. NETDATA_DISABLE_CLOUD=1
  2054. NETDATA_REQUIRE_CLOUD=0
  2055. ;;
  2056. "--require-cloud")
  2057. NETDATA_DISABLE_CLOUD=0
  2058. NETDATA_REQUIRE_CLOUD=1
  2059. ;;
  2060. "--dont-start-it")
  2061. NETDATA_NO_START=1
  2062. NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --dont-start-it"
  2063. ;;
  2064. "--disable-telemetry")
  2065. NETDATA_DISABLE_TELEMETRY="1"
  2066. NETDATA_INSTALLER_OPTIONS="${NETDATA_INSTALLER_OPTIONS} --disable-telemetry"
  2067. ;;
  2068. "--install-prefix")
  2069. INSTALL_PREFIX="${2}"
  2070. shift 1
  2071. ;;
  2072. "--old-install-prefix")
  2073. OLD_INSTALL_PREFIX="${2}"
  2074. shift 1
  2075. ;;
  2076. "--install-major-version")
  2077. INSTALL_MAJOR_VERSION="${2}"
  2078. shift 1
  2079. ;;
  2080. "--install-version")
  2081. INSTALL_VERSION="${2}"
  2082. AUTO_UPDATE=0
  2083. shift 1
  2084. ;;
  2085. "--distro-override")
  2086. if [ -n "${2}" ]; then
  2087. SKIP_DISTRO_DETECTION=1
  2088. DISTRO="$(echo "${2}" | cut -f 1 -d ':' | tr '[:upper:]' '[:lower:]')"
  2089. SYSVERSION="$(echo "${2}" | cut -f 2 -d ':')"
  2090. SYSCODENAME="$(echo "${2}" | cut -f 3 -d ':' | tr '[:upper:]' '[:lower:]')"
  2091. if [ -z "${SYSVERSION}" ]; then
  2092. fatal "You must specify a release as well as a distribution name." F0510
  2093. fi
  2094. shift 1
  2095. else
  2096. fatal "A distribution name and release must be specified for the --distro-override option." F050F
  2097. fi
  2098. ;;
  2099. "--repositories-only")
  2100. set_action 'repositories-only'
  2101. NETDATA_FORCE_METHOD="native"
  2102. ;;
  2103. "--native-only") NETDATA_FORCE_METHOD="native" ;;
  2104. "--static-only") NETDATA_FORCE_METHOD="static" ;;
  2105. "--build-only") NETDATA_FORCE_METHOD="build" ;;
  2106. "--claim-token")
  2107. NETDATA_CLAIM_TOKEN="${2}"
  2108. shift 1
  2109. ;;
  2110. "--claim-rooms")
  2111. NETDATA_CLAIM_ROOMS="${2}"
  2112. shift 1
  2113. ;;
  2114. "--claim-url")
  2115. NETDATA_CLAIM_URL="${2}"
  2116. shift 1
  2117. ;;
  2118. "--claim-"*)
  2119. optname="$(echo "${1}" | cut -d '-' -f 4-)"
  2120. case "${optname}" in
  2121. id|proxy|user|hostname)
  2122. NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -${optname}=${2}"
  2123. shift 1
  2124. ;;
  2125. verbose|insecure|noproxy|noreload|daemon-not-running) NETDATA_CLAIM_EXTRA="${NETDATA_CLAIM_EXTRA} -${optname}" ;;
  2126. *) warning "Ignoring unrecognized claiming option ${optname}" ;;
  2127. esac
  2128. ;;
  2129. "--local-build-options")
  2130. LOCAL_BUILD_OPTIONS="${LOCAL_BUILD_OPTIONS} ${2}"
  2131. shift 1
  2132. ;;
  2133. "--static-install-options")
  2134. STATIC_INSTALL_OPTIONS="${STATIC_INSTALL_OPTIONS} ${2}"
  2135. shift 1
  2136. ;;
  2137. "--prepare-offline-install-source")
  2138. if [ -n "${2}" ]; then
  2139. set_action 'prepare-offline'
  2140. OFFLINE_TARGET="${2}"
  2141. shift 1
  2142. else
  2143. fatal "A target directory must be specified with the --prepare-offline-install-source option." F0500
  2144. fi
  2145. ;;
  2146. "--offline-architecture")
  2147. if echo "${STATIC_INSTALL_ARCHES}" | grep -qw "${2}"; then
  2148. NETDATA_OFFLINE_ARCHES="${NETDATA_OFFLINE_ARCHES} ${2}"
  2149. else
  2150. fatal "${2} is not a recognized static build architecture (supported architectures are ${STATIC_INSTALL_ARCHES})" F0518
  2151. fi
  2152. shift 1
  2153. ;;
  2154. "--offline-install-source")
  2155. if [ -d "${2}" ]; then
  2156. NETDATA_OFFLINE_INSTALL_SOURCE="${2}"
  2157. # shellcheck disable=SC2164
  2158. NETDATA_TARBALL_BASEURL="file://$(cd "${2}"; pwd)"
  2159. shift 1
  2160. else
  2161. fatal "A source directory must be specified with the --offline-install-source option." F0501
  2162. fi
  2163. ;;
  2164. "--"|"all"|"--yes"|"-y"|"--force"|"--accept") warning "Option '${1}' is not recognized, ignoring it. ${BADOPT_MSG}" ;;
  2165. *) fatal "Unrecognized option '${1}'. ${BADOPT_MSG}" F050E ;;
  2166. esac
  2167. shift 1
  2168. done
  2169. validate_args
  2170. }
  2171. # ======================================================================
  2172. # Main program
  2173. setup_terminal || echo > /dev/null
  2174. # shellcheck disable=SC2068
  2175. parse_args $@
  2176. confirm_root_support
  2177. get_system_info
  2178. confirm_install_prefix
  2179. main