kickstart.sh 80 KB

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