kickstart.sh 75 KB

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