kickstart.sh 93 KB

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