kickstart.sh 87 KB

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