kickstart.sh 86 KB

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