kickstart.sh 89 KB

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