kickstart.sh 92 KB

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