kickstart.sh 83 KB

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