kickstart.sh 91 KB

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