kickstart.sh 75 KB

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