kickstart.sh 91 KB

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