kickstart.sh 85 KB

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