kickstart.sh 80 KB

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