netdata-installer.sh 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-3.0-or-later
  3. # Next unused error code: I0012
  4. export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
  5. uniquepath() {
  6. path=""
  7. tmp="$(mktemp)"
  8. (echo "${PATH}" | tr ":" "\n") > "$tmp"
  9. while read -r REPLY;
  10. do
  11. if echo "${path}" | grep -v "(^|:)${REPLY}(:|$)"; then
  12. [ -n "${path}" ] && path="${path}:"
  13. path="${path}${REPLY}"
  14. fi
  15. done < "$tmp"
  16. rm "$tmp"
  17. [ -n "${path}" ]
  18. export PATH="${path%:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin}"
  19. } > /dev/null
  20. uniquepath
  21. PROGRAM="$0"
  22. NETDATA_SOURCE_DIR="$(pwd)"
  23. INSTALLER_DIR="$(dirname "${PROGRAM}")"
  24. if [ "${NETDATA_SOURCE_DIR}" != "${INSTALLER_DIR}" ] && [ "${INSTALLER_DIR}" != "." ]; then
  25. echo >&2 "Warning: you are currently in '${NETDATA_SOURCE_DIR}' but the installer is in '${INSTALLER_DIR}'."
  26. fi
  27. # -----------------------------------------------------------------------------
  28. # reload the user profile
  29. # shellcheck source=/dev/null
  30. [ -f /etc/profile ] && . /etc/profile
  31. # make sure /etc/profile does not change our current directory
  32. cd "${NETDATA_SOURCE_DIR}" || exit 1
  33. # -----------------------------------------------------------------------------
  34. # load the required functions
  35. if [ -f "${INSTALLER_DIR}/packaging/installer/functions.sh" ]; then
  36. # shellcheck source=packaging/installer/functions.sh
  37. . "${INSTALLER_DIR}/packaging/installer/functions.sh" || exit 1
  38. else
  39. # shellcheck source=packaging/installer/functions.sh
  40. . "${NETDATA_SOURCE_DIR}/packaging/installer/functions.sh" || exit 1
  41. fi
  42. # Used to enable saved warnings support in functions.sh
  43. # shellcheck disable=SC2034
  44. NETDATA_SAVE_WARNINGS=1
  45. # -----------------------------------------------------------------------------
  46. # figure out an appropriate temporary directory
  47. _cannot_use_tmpdir() {
  48. testfile="$(TMPDIR="${1}" mktemp -q -t netdata-test.XXXXXXXXXX)"
  49. ret=0
  50. if [ -z "${testfile}" ]; then
  51. return "${ret}"
  52. fi
  53. if printf '#!/bin/sh\necho SUCCESS\n' > "${testfile}"; then
  54. if chmod +x "${testfile}"; then
  55. if [ "$("${testfile}")" = "SUCCESS" ]; then
  56. ret=1
  57. fi
  58. fi
  59. fi
  60. rm -f "${testfile}"
  61. return "${ret}"
  62. }
  63. if [ -z "${TMPDIR}" ] || _cannot_use_tmpdir "${TMPDIR}"; then
  64. if _cannot_use_tmpdir /tmp; then
  65. if _cannot_use_tmpdir "${PWD}"; then
  66. 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." I0000
  67. else
  68. TMPDIR="${PWD}"
  69. fi
  70. else
  71. TMPDIR="/tmp"
  72. fi
  73. fi
  74. # -----------------------------------------------------------------------------
  75. # set up handling for deferred error messages
  76. #
  77. # This leverages the saved warnings functionality shared with some functions from functions.sh
  78. print_deferred_errors() {
  79. if [ -n "${SAVED_WARNINGS}" ]; then
  80. printf >&2 "\n"
  81. printf >&2 "%b\n" "The following warnings and non-fatal errors were encountered during the installation process:"
  82. printf >&2 "%b\n" "${SAVED_WARNINGS}"
  83. printf >&2 "\n"
  84. fi
  85. }
  86. download_go() {
  87. download_file "${1}" "${2}" "go.d plugin" "go"
  88. }
  89. # make sure we save all commands we run
  90. # Variable is used by code in the packaging/installer/functions.sh
  91. # shellcheck disable=SC2034
  92. run_logfile="netdata-installer.log"
  93. # -----------------------------------------------------------------------------
  94. # fix PKG_CHECK_MODULES error
  95. if [ -d /usr/share/aclocal ]; then
  96. ACLOCAL_PATH=${ACLOCAL_PATH-/usr/share/aclocal}
  97. export ACLOCAL_PATH
  98. fi
  99. export LC_ALL=C
  100. umask 002
  101. # Be nice on production environments
  102. renice 19 $$ > /dev/null 2> /dev/null
  103. # you can set CFLAGS before running installer
  104. # shellcheck disable=SC2269
  105. LDFLAGS="${LDFLAGS}"
  106. CFLAGS="${CFLAGS-"-O2 -pipe"}"
  107. [ "z${CFLAGS}" = "z-O3" ] && CFLAGS="-O2"
  108. # shellcheck disable=SC2269
  109. ACLK="${ACLK}"
  110. # keep a log of this command
  111. {
  112. printf "\n# "
  113. date
  114. printf 'CFLAGS="%s" ' "${CFLAGS}"
  115. printf 'LDFLAGS="%s" ' "${LDFLAGS}"
  116. printf "%s" "${PROGRAM}" "${@}"
  117. printf "\n"
  118. } >> netdata-installer.log
  119. REINSTALL_OPTIONS="$(
  120. printf "%s" "${*}"
  121. printf "\n"
  122. )"
  123. # remove options that shown not be inherited by netdata-updater.sh
  124. REINSTALL_OPTIONS="$(echo "${REINSTALL_OPTIONS}" | sed 's/--dont-wait//g' | sed 's/--dont-start-it//g')"
  125. banner_nonroot_install() {
  126. cat << NONROOTNOPREFIX
  127. ${TPUT_RED}${TPUT_BOLD}Sorry! This will fail!${TPUT_RESET}
  128. You are attempting to install netdata as a non-root user, but you plan
  129. to install it in system paths.
  130. Please set an installation prefix, like this:
  131. $PROGRAM ${@} --install-prefix /tmp
  132. or, run the installer as root:
  133. sudo $PROGRAM ${@}
  134. We suggest to install it as root, or certain data collectors will
  135. not be able to work. Netdata drops root privileges when running.
  136. So, if you plan to keep it, install it as root to get the full
  137. functionality.
  138. NONROOTNOPREFIX
  139. }
  140. banner_root_notify() {
  141. cat << NONROOT
  142. ${TPUT_RED}${TPUT_BOLD}IMPORTANT${TPUT_RESET}:
  143. You are about to install netdata as a non-root user.
  144. Netdata will work, but a few data collection modules that
  145. require root access will fail.
  146. If you are installing netdata permanently on your system, run
  147. the installer like this:
  148. ${TPUT_YELLOW}${TPUT_BOLD}sudo $PROGRAM ${@}${TPUT_RESET}
  149. NONROOT
  150. }
  151. usage() {
  152. netdata_banner
  153. progress "installer command line options"
  154. cat << HEREDOC
  155. USAGE: ${PROGRAM} [options]
  156. where options include:
  157. --install-prefix <path> Install netdata in <path>. Ex. --install-prefix /opt will put netdata in /opt/netdata.
  158. --dont-start-it Do not (re)start netdata after installation.
  159. --dont-wait Run installation in non-interactive mode.
  160. --stable-channel Use packages from GitHub release pages instead of nightly updates.
  161. This results in less frequent updates.
  162. --nightly-channel Use most recent nightly updates instead of GitHub releases.
  163. This results in more frequent updates.
  164. --disable-go Disable installation of go.d.plugin.
  165. --disable-ebpf Disable eBPF Kernel plugin. Default: enabled.
  166. --disable-cloud Disable all Netdata Cloud functionality.
  167. --require-cloud Fail the install if it can't build Netdata Cloud support.
  168. --enable-plugin-freeipmi Enable the FreeIPMI plugin. Default: enable it when libipmimonitoring is available.
  169. --disable-plugin-freeipmi Explicitly disable the FreeIPMI plugin.
  170. --disable-https Explicitly disable TLS support.
  171. --disable-dbengine Explicitly disable DB engine support.
  172. --enable-plugin-nfacct Enable nfacct plugin. Default: enable it when libmnl and libnetfilter_acct are available.
  173. --disable-plugin-nfacct Explicitly disable the nfacct plugin.
  174. --enable-plugin-xenstat Enable the xenstat plugin. Default: enable it when libxenstat and libyajl are available.
  175. --disable-plugin-xenstat Explicitly disable the xenstat plugin.
  176. --enable-exporting-kinesis Enable AWS Kinesis exporting connector. Default: enable it when libaws_cpp_sdk_kinesis
  177. and its dependencies are available.
  178. --disable-exporting-kinesis Explicitly disable AWS Kinesis exporting connector.
  179. --enable-exporting-prometheus-remote-write Enable Prometheus remote write exporting connector. Default: enable it
  180. when libprotobuf and libsnappy are available.
  181. --disable-exporting-prometheus-remote-write Explicitly disable Prometheus remote write exporting connector.
  182. --enable-exporting-mongodb Enable MongoDB exporting connector. Default: enable it when libmongoc is available.
  183. --disable-exporting-mongodb Explicitly disable MongoDB exporting connector.
  184. --enable-exporting-pubsub Enable Google Cloud PubSub exporting connector. Default: enable it when
  185. libgoogle_cloud_cpp_pubsub_protos and its dependencies are available.
  186. --disable-exporting-pubsub Explicitly disable Google Cloud PubSub exporting connector.
  187. --enable-lto Enable link-time optimization. Default: disabled.
  188. --disable-lto Explicitly disable link-time optimization.
  189. --enable-ml Enable anomaly detection with machine learning. Default: autodetect.
  190. --disable-ml Explicitly disable anomaly detection with machine learning.
  191. --disable-x86-sse Disable SSE instructions & optimizations. Default: enabled.
  192. --use-system-protobuf Use a system copy of libprotobuf instead of bundled copy. Default: bundled.
  193. --zlib-is-really-here
  194. --libs-are-really-here If you see errors about missing zlib or libuuid but you know it is available, you might
  195. have a broken pkg-config. Use this option to proceed without checking pkg-config.
  196. --disable-telemetry Opt-out from our anonymous telemetry program. (DISABLE_TELEMETRY=1)
  197. --skip-available-ram-check Skip checking the amount of RAM the system has and pretend it has enough to build safely.
  198. Netdata will by default be compiled with gcc optimization -O2
  199. If you need to pass different CFLAGS, use something like this:
  200. CFLAGS="<gcc options>" ${PROGRAM} [options]
  201. If you also need to provide different LDFLAGS, use something like this:
  202. LDFLAGS="<extra ldflag options>" ${PROGRAM} [options]
  203. or use the following if both LDFLAGS and CFLAGS need to be overridden:
  204. CFLAGS="<gcc options>" LDFLAGS="<extra ld options>" ${PROGRAM} [options]
  205. For the installer to complete successfully, you will need these packages installed:
  206. gcc
  207. make
  208. autoconf
  209. automake
  210. pkg-config
  211. zlib1g-dev (or zlib-devel)
  212. uuid-dev (or libuuid-devel)
  213. For the plugins, you will at least need:
  214. curl
  215. bash (v4+)
  216. python (v2 or v3)
  217. node.js
  218. HEREDOC
  219. }
  220. DONOTSTART=0
  221. DONOTWAIT=0
  222. NETDATA_PREFIX=
  223. LIBS_ARE_HERE=0
  224. NETDATA_ENABLE_ML=""
  225. NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS-}"
  226. RELEASE_CHANNEL="nightly" # valid values are 'nightly' and 'stable'
  227. IS_NETDATA_STATIC_BINARY="${IS_NETDATA_STATIC_BINARY:-"no"}"
  228. while [ -n "${1}" ]; do
  229. case "${1}" in
  230. "--zlib-is-really-here") LIBS_ARE_HERE=1 ;;
  231. "--libs-are-really-here") LIBS_ARE_HERE=1 ;;
  232. "--use-system-protobuf")
  233. USE_SYSTEM_PROTOBUF=1
  234. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--without-bundled-protobuf}" | sed 's/$/ --without-bundled-protobuf/g')"
  235. ;;
  236. "--dont-scrub-cflags-even-though-it-may-break-things") DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS=1 ;;
  237. "--dont-start-it") DONOTSTART=1 ;;
  238. "--dont-wait") DONOTWAIT=1 ;;
  239. "--auto-update" | "-u") ;;
  240. "--auto-update-type") ;;
  241. "--stable-channel") RELEASE_CHANNEL="stable" ;;
  242. "--nightly-channel") RELEASE_CHANNEL="nightly" ;;
  243. "--enable-plugin-freeipmi") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-plugin-freeipmi)}" | sed 's/$/ --enable-plugin-freeipmi/g')" ;;
  244. "--disable-plugin-freeipmi") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-plugin-freeipmi)}" | sed 's/$/ --disable-plugin-freeipmi/g')" ;;
  245. "--disable-https") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-https)}" | sed 's/$/ --disable-plugin-https/g')" ;;
  246. "--disable-dbengine")
  247. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-dbengine)}" | sed 's/$/ --disable-dbengine/g')"
  248. ;;
  249. "--enable-plugin-nfacct") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-plugin-nfacct)}" | sed 's/$/ --enable-plugin-nfacct/g')" ;;
  250. "--disable-plugin-nfacct") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-plugin-nfacct)}" | sed 's/$/ --disable-plugin-nfacct/g')" ;;
  251. "--enable-plugin-xenstat") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-plugin-xenstat)}" | sed 's/$/ --enable-plugin-xenstat/g')" ;;
  252. "--disable-plugin-xenstat") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-plugin-xenstat)}" | sed 's/$/ --disable-plugin-xenstat/g')" ;;
  253. "--enable-exporting-kinesis" | "--enable-backend-kinesis")
  254. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-exporting-kinesis)}" | sed 's/$/ --enable-exporting-kinesis/g')" ;;
  255. "--disable-exporting-kinesis" | "--disable-backend-kinesis")
  256. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-exporting-kinesis)}" | sed 's/$/ --disable-exporting-kinesis/g')" ;;
  257. "--enable-exporting-prometheus-remote-write" | "--enable-backend-prometheus-remote-write")
  258. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-exporting-prometheus-remote-write)}" | sed 's/$/ --enable-exporting-prometheus-remote-write/g')" ;;
  259. "--disable-exporting-prometheus-remote-write" | "--disable-backend-prometheus-remote-write")
  260. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-exporting-prometheus-remote-write)}" | sed 's/$/ --disable-exporting-prometheus-remote-write/g')"
  261. NETDATA_DISABLE_PROMETHEUS=1
  262. ;;
  263. "--enable-exporting-mongodb" | "--enable-backend-mongodb")
  264. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-exporting-mongodb)}" | sed 's/$/ --enable-exporting-mongodb/g')" ;;
  265. "--disable-exporting-mongodb" | "--disable-backend-mongodb")
  266. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-exporting-mongodb)}" | sed 's/$/ --disable-exporting-mongodb/g')" ;;
  267. "--enable-exporting-pubsub") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-exporting-pubsub)}" | sed 's/$/ --enable-exporting-pubsub/g')" ;;
  268. "--disable-exporting-pubsub") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-exporting-pubsub)}" | sed 's/$/ --disable-exporting-pubsub/g')" ;;
  269. "--enable-lto") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-lto)}" | sed 's/$/ --enable-lto/g')" ;;
  270. "--enable-ml")
  271. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-ml)}" | sed 's/$/ --enable-ml/g')"
  272. NETDATA_ENABLE_ML=1
  273. ;;
  274. "--disable-ml")
  275. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-ml)}" | sed 's/$/ --disable-ml/g')"
  276. NETDATA_ENABLE_ML=0
  277. ;;
  278. "--disable-lto") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-lto)}" | sed 's/$/ --disable-lto/g')" ;;
  279. "--disable-x86-sse") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-x86-sse)}" | sed 's/$/ --disable-x86-sse/g')" ;;
  280. "--disable-telemetry") NETDATA_DISABLE_TELEMETRY=1 ;;
  281. "--disable-go") NETDATA_DISABLE_GO=1 ;;
  282. "--enable-ebpf") NETDATA_DISABLE_EBPF=0 ;;
  283. "--disable-ebpf") NETDATA_DISABLE_EBPF=1 NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-ebpf)}" | sed 's/$/ --disable-ebpf/g')" ;;
  284. "--skip-available-ram-check") SKIP_RAM_CHECK=1 ;;
  285. "--one-time-build") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-dependency-tracking)}" | sed 's/$/ --disable-dependency-tracking/g')" ;;
  286. "--disable-cloud")
  287. if [ -n "${NETDATA_REQUIRE_CLOUD}" ]; then
  288. warning "Cloud explicitly enabled, ignoring --disable-cloud."
  289. else
  290. NETDATA_DISABLE_CLOUD=1
  291. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-cloud)}" | sed 's/$/ --disable-cloud/g')"
  292. fi
  293. ;;
  294. "--require-cloud")
  295. if [ -n "${NETDATA_DISABLE_CLOUD}" ]; then
  296. warning "Cloud explicitly disabled, ignoring --require-cloud."
  297. else
  298. NETDATA_REQUIRE_CLOUD=1
  299. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-cloud)}" | sed 's/$/ --enable-cloud/g')"
  300. fi
  301. ;;
  302. "--build-json-c")
  303. NETDATA_BUILD_JSON_C=1
  304. ;;
  305. "--install-prefix")
  306. NETDATA_PREFIX="${2}/netdata"
  307. shift 1
  308. ;;
  309. "--install-no-prefix")
  310. NETDATA_PREFIX="${2}"
  311. shift 1
  312. ;;
  313. "--help" | "-h")
  314. usage
  315. exit 1
  316. ;;
  317. *)
  318. echo >&2 "Unrecognized option '${1}'."
  319. exit_reason "Unrecognized option '${1}'." I000E
  320. usage
  321. exit 1
  322. ;;
  323. esac
  324. shift 1
  325. done
  326. if [ ! "${DISABLE_TELEMETRY:-0}" -eq 0 ] ||
  327. [ -n "$DISABLE_TELEMETRY" ] ||
  328. [ ! "${DO_NOT_TRACK:-0}" -eq 0 ] ||
  329. [ -n "$DO_NOT_TRACK" ]; then
  330. NETDATA_DISABLE_TELEMETRY=1
  331. fi
  332. make="make"
  333. # See: https://github.com/netdata/netdata/issues/9163
  334. if [ "$(uname -s)" = "FreeBSD" ]; then
  335. make="gmake"
  336. NETDATA_CONFIGURE_OPTIONS="$NETDATA_CONFIGURE_OPTIONS --disable-dependency-tracking"
  337. fi
  338. if [ "$(uname -s)" = "Linux" ] && [ -f /proc/meminfo ]; then
  339. mega="$((1024 * 1024))"
  340. base=1024
  341. scale=256
  342. # shellcheck disable=SC2086
  343. if [ -n "${MAKEOPTS}" ]; then
  344. proc_count="$(echo ${MAKEOPTS} | grep -oE '\-j *[[:digit:]]+' | tr -d '\-j ')"
  345. else
  346. proc_count="$(find_processors)"
  347. fi
  348. target_ram="$((base * mega + (scale * mega * (proc_count - 1))))"
  349. total_ram="$(grep MemTotal /proc/meminfo | cut -d ':' -f 2 | tr -d ' kB')"
  350. total_ram="$((total_ram * 1024))"
  351. if [ "${total_ram}" -le "$((base * mega))" ] && [ -z "${NETDATA_ENABLE_ML}" ]; then
  352. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-ml)}" | sed 's/$/ --disable-ml/g')"
  353. NETDATA_ENABLE_ML=0
  354. fi
  355. if [ -z "${MAKEOPTS}" ]; then
  356. MAKEOPTS="-j${proc_count}"
  357. while [ "${target_ram}" -gt "${total_ram}" ] && [ "${proc_count}" -gt 1 ]; do
  358. proc_count="$((proc_count - 1))"
  359. target_ram="$((base * mega + (scale * mega * (proc_count - 1))))"
  360. MAKEOPTS="-j${proc_count}"
  361. done
  362. else
  363. if [ "${target_ram}" -gt "${total_ram}" ] && [ "${proc_count}" -gt 1 ] && [ -z "${SKIP_RAM_CHECK}" ]; then
  364. target_ram="$(echo "${target_ram}" | awk '{$1/=1024*1024*1024;printf "%.2fGiB\n",$1}')"
  365. total_ram="$(echo "${total_ram}" | awk '{$1/=1024*1024*1024;printf "%.2fGiB\n",$1}')"
  366. run_failed "Netdata needs ${target_ram} of RAM to safely install, but this system only has ${total_ram}. Try reducing the number of processes used for the install using the \$MAKEOPTS variable."
  367. exit_reason "Insufficient RAM to safely install." I000F
  368. exit 2
  369. fi
  370. fi
  371. fi
  372. # set default make options
  373. if [ -z "${MAKEOPTS}" ]; then
  374. MAKEOPTS="-j$(find_processors)"
  375. elif echo "${MAKEOPTS}" | grep -vqF -e "-j"; then
  376. MAKEOPTS="${MAKEOPTS} -j$(find_processors)"
  377. fi
  378. if [ "$(id -u)" -ne 0 ]; then
  379. if [ -z "${NETDATA_PREFIX}" ]; then
  380. netdata_banner
  381. banner_nonroot_install "${@}"
  382. exit_reason "Attempted install as non-root user to /." I0010
  383. exit 1
  384. else
  385. banner_root_notify "${@}"
  386. fi
  387. fi
  388. netdata_banner
  389. progress "real-time performance monitoring, done right!"
  390. cat << BANNER1
  391. You are about to build and install netdata to your system.
  392. The build process will use ${TPUT_CYAN}${TMPDIR}${TPUT_RESET} for
  393. any temporary files. You can override this by setting \$TMPDIR to a
  394. writable directory where you can execute files.
  395. It will be installed at these locations:
  396. - the daemon at ${TPUT_CYAN}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}
  397. - config files in ${TPUT_CYAN}${NETDATA_PREFIX}/etc/netdata${TPUT_RESET}
  398. - web files in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/share/netdata${TPUT_RESET}
  399. - plugins in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/libexec/netdata${TPUT_RESET}
  400. - cache files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/cache/netdata${TPUT_RESET}
  401. - db files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/lib/netdata${TPUT_RESET}
  402. - log files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/log/netdata${TPUT_RESET}
  403. BANNER1
  404. [ "$(id -u)" -eq 0 ] && cat << BANNER2
  405. - pid file at ${TPUT_CYAN}${NETDATA_PREFIX}/var/run/netdata.pid${TPUT_RESET}
  406. - logrotate file at ${TPUT_CYAN}/etc/logrotate.d/netdata${TPUT_RESET}
  407. BANNER2
  408. cat << BANNER3
  409. This installer allows you to change the installation path.
  410. Press Control-C and run the same command with --help for help.
  411. BANNER3
  412. if [ -z "$NETDATA_DISABLE_TELEMETRY" ]; then
  413. cat << BANNER4
  414. ${TPUT_YELLOW}${TPUT_BOLD}NOTE${TPUT_RESET}:
  415. Anonymous usage stats will be collected and sent to Netdata.
  416. To opt-out, pass --disable-telemetry option to the installer or export
  417. the environment variable DISABLE_TELEMETRY to a non-zero or non-empty value
  418. (e.g: export DISABLE_TELEMETRY=1).
  419. BANNER4
  420. fi
  421. have_autotools=
  422. if [ "$(type autoreconf 2> /dev/null)" ]; then
  423. autoconf_maj_min() {
  424. OLDIFS=$IFS
  425. IFS=.-
  426. maj=$1
  427. min=$2
  428. # shellcheck disable=SC2046
  429. set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
  430. # shellcheck disable=SC2086
  431. eval $maj=\$1 $min=\$2
  432. IFS=$OLDIFS
  433. }
  434. autoconf_maj_min AMAJ AMIN
  435. if [ "$AMAJ" -gt 2 ]; then
  436. have_autotools=Y
  437. elif [ "$AMAJ" -eq 2 ] && [ "$AMIN" -ge 60 ]; then
  438. have_autotools=Y
  439. else
  440. echo "Found autotools $AMAJ.$AMIN"
  441. fi
  442. else
  443. echo "No autotools found"
  444. fi
  445. if [ ! "$have_autotools" ]; then
  446. if [ -f configure ]; then
  447. echo "Will skip autoreconf step"
  448. else
  449. fatal "Could not find a usable version of GNU autotools, which is required for building Netdata. Version 2.60 or later of GNU autotools is required." I0001
  450. fi
  451. fi
  452. if [ ${DONOTWAIT} -eq 0 ]; then
  453. if [ -n "${NETDATA_PREFIX}" ]; then
  454. printf '%s' "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to '${TPUT_CYAN}${NETDATA_PREFIX}${TPUT_YELLOW}'${TPUT_RESET} > "
  455. else
  456. printf '%s' "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to your system${TPUT_RESET} > "
  457. fi
  458. read -r REPLY
  459. if [ "$REPLY" != '' ]; then
  460. exit_reason "User did not accept install attempt." I0011
  461. exit 1
  462. fi
  463. fi
  464. build_error() {
  465. netdata_banner
  466. trap - EXIT
  467. fatal "Netdata failed to build for an unknown reason." I0002
  468. }
  469. if [ ${LIBS_ARE_HERE} -eq 1 ]; then
  470. shift
  471. echo >&2 "ok, assuming libs are really installed."
  472. export ZLIB_CFLAGS=" "
  473. export ZLIB_LIBS="-lz"
  474. export UUID_CFLAGS=" "
  475. export UUID_LIBS="-luuid"
  476. fi
  477. trap build_error EXIT
  478. # -----------------------------------------------------------------------------
  479. build_protobuf() {
  480. env_cmd=''
  481. if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
  482. env_cmd="env CFLAGS='-fPIC -pipe' CXXFLAGS='-fPIC -pipe' LDFLAGS="
  483. fi
  484. cd "${1}" > /dev/null || return 1
  485. if ! run eval "${env_cmd} ./configure --disable-shared --without-zlib --disable-dependency-tracking --with-pic"; then
  486. cd - > /dev/null || return 1
  487. return 1
  488. fi
  489. if ! run eval "${env_cmd} ${make} ${MAKEOPTS}"; then
  490. cd - > /dev/null || return 1
  491. return 1
  492. fi
  493. cd - > /dev/null || return 1
  494. }
  495. copy_protobuf() {
  496. target_dir="${PWD}/externaldeps/protobuf"
  497. run mkdir -p "${target_dir}" || return 1
  498. run cp -a "${1}/src" "${target_dir}" || return 1
  499. }
  500. bundle_protobuf() {
  501. if [ -n "${NETDATA_DISABLE_CLOUD}" ] && [ -n "${NETDATA_DISABLE_PROMETHEUS}" ]; then
  502. echo "Skipping protobuf"
  503. return 0
  504. fi
  505. if [ -n "${USE_SYSTEM_PROTOBUF}" ]; then
  506. echo "Skipping protobuf"
  507. warning "You have requested use of a system copy of protobuf. This should work, but it is not recommended as it's very likely to break if you upgrade the currently installed version of protobuf."
  508. return 0
  509. fi
  510. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling protobuf."
  511. PROTOBUF_PACKAGE_VERSION="$(cat packaging/protobuf.version)"
  512. if [ -f "${PWD}/externaldeps/protobuf/.version" ] && [ "${PROTOBUF_PACKAGE_VERSION}" = "$(cat "${PWD}/externaldeps/protobuf/.version")" ]
  513. then
  514. echo >&2 "Found compiled protobuf, same version, not compiling it again. Remove file '${PWD}/externaldeps/protobuf/.version' to recompile."
  515. NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --with-bundled-protobuf"
  516. return 0
  517. fi
  518. tmp="$(mktemp -d -t netdata-protobuf-XXXXXX)"
  519. PROTOBUF_PACKAGE_BASENAME="protobuf-cpp-${PROTOBUF_PACKAGE_VERSION}.tar.gz"
  520. if fetch_and_verify "protobuf" \
  521. "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_PACKAGE_VERSION}/${PROTOBUF_PACKAGE_BASENAME}" \
  522. "${PROTOBUF_PACKAGE_BASENAME}" \
  523. "${tmp}" \
  524. "${NETDATA_LOCAL_TARBALL_VERRIDE_PROTOBUF}"; then
  525. if run tar --no-same-owner -xf "${tmp}/${PROTOBUF_PACKAGE_BASENAME}" -C "${tmp}" &&
  526. build_protobuf "${tmp}/protobuf-${PROTOBUF_PACKAGE_VERSION}" &&
  527. copy_protobuf "${tmp}/protobuf-${PROTOBUF_PACKAGE_VERSION}" &&
  528. echo "${PROTOBUF_PACKAGE_VERSION}" >"${PWD}/externaldeps/protobuf/.version" &&
  529. rm -rf "${tmp}"; then
  530. run_ok "protobuf built and prepared."
  531. NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --with-bundled-protobuf"
  532. else
  533. run_failed "Failed to build protobuf. Netdata Cloud support will not be available in this build."
  534. fi
  535. else
  536. run_failed "Unable to fetch sources for protobuf. Netdata Cloud support will not be available in this build."
  537. fi
  538. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  539. }
  540. bundle_protobuf
  541. # -----------------------------------------------------------------------------
  542. build_jsonc() {
  543. env_cmd=''
  544. if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
  545. env_cmd="env CFLAGS='-fPIC -pipe' CXXFLAGS='-fPIC -pipe' LDFLAGS="
  546. fi
  547. cd "${1}" > /dev/null || exit 1
  548. run eval "${env_cmd} cmake -DBUILD_SHARED_LIBS=OFF ."
  549. run eval "${env_cmd} ${make} ${MAKEOPTS}"
  550. cd - > /dev/null || return 1
  551. }
  552. copy_jsonc() {
  553. target_dir="${PWD}/externaldeps/jsonc"
  554. run mkdir -p "${target_dir}" "${target_dir}/json-c" || return 1
  555. run cp "${1}/libjson-c.a" "${target_dir}/libjson-c.a" || return 1
  556. # shellcheck disable=SC2086
  557. run cp ${1}/*.h "${target_dir}/json-c" || return 1
  558. }
  559. bundle_jsonc() {
  560. # If --build-json-c flag or not json-c on system, then bundle our own json-c
  561. if [ -z "${NETDATA_BUILD_JSON_C}" ] && pkg-config json-c; then
  562. return 0
  563. fi
  564. if [ -z "$(command -v cmake)" ]; then
  565. run_failed "Could not find cmake, which is required to build JSON-C. The install process will continue, but Netdata Cloud support will be disabled."
  566. return 0
  567. fi
  568. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling JSON-C."
  569. progress "Prepare JSON-C"
  570. JSONC_PACKAGE_VERSION="$(cat packaging/jsonc.version)"
  571. tmp="$(mktemp -d -t netdata-jsonc-XXXXXX)"
  572. JSONC_PACKAGE_BASENAME="json-c-${JSONC_PACKAGE_VERSION}.tar.gz"
  573. if fetch_and_verify "jsonc" \
  574. "https://github.com/json-c/json-c/archive/${JSONC_PACKAGE_BASENAME}" \
  575. "${JSONC_PACKAGE_BASENAME}" \
  576. "${tmp}" \
  577. "${NETDATA_LOCAL_TARBALL_OVERRIDE_JSONC}"; then
  578. if run tar --no-same-owner -xf "${tmp}/${JSONC_PACKAGE_BASENAME}" -C "${tmp}" &&
  579. build_jsonc "${tmp}/json-c-json-c-${JSONC_PACKAGE_VERSION}" &&
  580. copy_jsonc "${tmp}/json-c-json-c-${JSONC_PACKAGE_VERSION}" &&
  581. rm -rf "${tmp}"; then
  582. run_ok "JSON-C built and prepared."
  583. else
  584. run_failed "Failed to build JSON-C, Netdata Cloud support will be disabled in this build."
  585. fi
  586. else
  587. run_failed "Unable to fetch sources for JSON-C, Netdata Cloud support will be disabled in this build."
  588. fi
  589. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  590. }
  591. bundle_jsonc
  592. # -----------------------------------------------------------------------------
  593. build_yaml() {
  594. env_cmd=''
  595. if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
  596. env_cmd="env CFLAGS='-fPIC -pipe -Wno-unused-value' CXXFLAGS='-fPIC -pipe' LDFLAGS="
  597. fi
  598. cd "${1}" > /dev/null || return 1
  599. run eval "${env_cmd} ./configure --disable-shared --disable-dependency-tracking --with-pic"
  600. run eval "${env_cmd} ${make} ${MAKEOPTS}"
  601. cd - > /dev/null || return 1
  602. }
  603. copy_yaml() {
  604. target_dir="${PWD}/externaldeps/libyaml"
  605. run mkdir -p "${target_dir}" || return 1
  606. run cp "${1}/src/.libs/libyaml.a" "${target_dir}/libyaml.a" || return 1
  607. run cp "${1}/include/yaml.h" "${target_dir}/" || return 1
  608. }
  609. bundle_yaml() {
  610. if pkg-config yaml-0.1; then
  611. return 0
  612. fi
  613. if [ -z "$(command -v cmake)" ]; then
  614. run_failed "Could not find cmake, which is required to build YAML. Critical error."
  615. return 0
  616. fi
  617. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling YAML."
  618. progress "Prepare YAML"
  619. YAML_PACKAGE_VERSION="$(cat packaging/yaml.version)"
  620. tmp="$(mktemp -d -t netdata-yaml-XXXXXX)"
  621. YAML_PACKAGE_BASENAME="yaml-${YAML_PACKAGE_VERSION}.tar.gz"
  622. if fetch_and_verify "yaml" \
  623. "https://github.com/yaml/libyaml/releases/download/${YAML_PACKAGE_VERSION}/${YAML_PACKAGE_BASENAME}" \
  624. "${YAML_PACKAGE_BASENAME}" \
  625. "${tmp}" \
  626. "${NETDATA_LOCAL_TARBALL_OVERRIDE_YAML}"; then
  627. if run tar --no-same-owner -xf "${tmp}/${YAML_PACKAGE_BASENAME}" -C "${tmp}" &&
  628. build_yaml "${tmp}/yaml-${YAML_PACKAGE_VERSION}" &&
  629. copy_yaml "${tmp}/yaml-${YAML_PACKAGE_VERSION}" &&
  630. rm -rf "${tmp}"; then
  631. run_ok "YAML built and prepared."
  632. else
  633. run_failed "Failed to build YAML, critical error."
  634. fi
  635. else
  636. run_failed "Unable to fetch sources for YAML, critical error."
  637. fi
  638. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  639. }
  640. bundle_yaml
  641. # -----------------------------------------------------------------------------
  642. get_kernel_version() {
  643. r="$(uname -r | cut -f 1 -d '-')"
  644. tmpfile="$(mktemp)"
  645. echo "${r}" | tr '.' ' ' > "${tmpfile}"
  646. read -r maj min patch _ < "${tmpfile}"
  647. rm -f "${tmpfile}"
  648. printf "%03d%03d%03d" "${maj}" "${min}" "${patch}"
  649. }
  650. detect_libc() {
  651. libc=
  652. if ldd --version 2>&1 | grep -q -i glibc; then
  653. echo >&2 " Detected GLIBC"
  654. libc="glibc"
  655. elif ldd --version 2>&1 | grep -q -i 'gnu libc'; then
  656. echo >&2 " Detected GLIBC"
  657. libc="glibc"
  658. elif ldd --version 2>&1 | grep -q -i musl; then
  659. echo >&2 " Detected musl"
  660. libc="musl"
  661. else
  662. cmd=$(ldd /bin/sh | grep -w libc | cut -d" " -f 3)
  663. if bash -c "${cmd}" 2>&1 | grep -q -i "GNU C Library"; then
  664. echo >&2 " Detected GLIBC"
  665. libc="glibc"
  666. fi
  667. fi
  668. if [ -z "$libc" ]; then
  669. warning "Cannot detect a supported libc on your system, eBPF support will be disabled."
  670. return 1
  671. fi
  672. echo "${libc}"
  673. return 0
  674. }
  675. rename_libbpf_packaging() {
  676. if [ "$(get_kernel_version)" -ge "004014000" ]; then
  677. cp packaging/current_libbpf.checksums packaging/libbpf.checksums
  678. cp packaging/current_libbpf.version packaging/libbpf.version
  679. else
  680. cp packaging/libbpf_0_0_9.checksums packaging/libbpf.checksums
  681. cp packaging/libbpf_0_0_9.version packaging/libbpf.version
  682. fi
  683. }
  684. build_libbpf() {
  685. cd "${1}/src" > /dev/null || return 1
  686. mkdir root build
  687. # shellcheck disable=SC2086
  688. run env CFLAGS='-fPIC -pipe' CXXFLAGS='-fPIC -pipe' LDFLAGS= BUILD_STATIC_ONLY=y OBJDIR=build DESTDIR=.. ${make} ${MAKEOPTS} install
  689. cd - > /dev/null || return 1
  690. }
  691. copy_libbpf() {
  692. target_dir="${PWD}/externaldeps/libbpf"
  693. if [ "$(uname -m)" = x86_64 ]; then
  694. lib_subdir="lib64"
  695. else
  696. lib_subdir="lib"
  697. fi
  698. run mkdir -p "${target_dir}" || return 1
  699. run cp "${1}/usr/${lib_subdir}/libbpf.a" "${target_dir}/libbpf.a" || return 1
  700. run cp -r "${1}/usr/include" "${target_dir}" || return 1
  701. run cp -r "${1}/include/uapi" "${target_dir}/include" || return 1
  702. }
  703. bundle_libbpf() {
  704. if { [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 1 ]; } || [ "$(uname -s)" != Linux ]; then
  705. return 0
  706. fi
  707. # When libc is not detected, we do not have necessity to compile libbpf and we should not do download of eBPF programs
  708. libc="${EBPF_LIBC:-"$(detect_libc)"}"
  709. if [ -z "$libc" ]; then
  710. NETDATA_DISABLE_EBPF=1
  711. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-ebpf)}" | sed 's/$/ --disable-ebpf/g')"
  712. return 0
  713. fi
  714. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling libbpf."
  715. rename_libbpf_packaging
  716. progress "Prepare libbpf"
  717. LIBBPF_PACKAGE_VERSION="$(cat packaging/libbpf.version)"
  718. tmp="$(mktemp -d -t netdata-libbpf-XXXXXX)"
  719. LIBBPF_PACKAGE_BASENAME="v${LIBBPF_PACKAGE_VERSION}.tar.gz"
  720. if fetch_and_verify "libbpf" \
  721. "https://github.com/netdata/libbpf/archive/${LIBBPF_PACKAGE_BASENAME}" \
  722. "${LIBBPF_PACKAGE_BASENAME}" \
  723. "${tmp}" \
  724. "${NETDATA_LOCAL_TARBALL_OVERRIDE_LIBBPF}"; then
  725. if run tar --no-same-owner -xf "${tmp}/${LIBBPF_PACKAGE_BASENAME}" -C "${tmp}" &&
  726. build_libbpf "${tmp}/libbpf-${LIBBPF_PACKAGE_VERSION}" &&
  727. copy_libbpf "${tmp}/libbpf-${LIBBPF_PACKAGE_VERSION}" &&
  728. rm -rf "${tmp}"; then
  729. run_ok "libbpf built and prepared."
  730. else
  731. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
  732. fatal "failed to build libbpf." I0005
  733. else
  734. run_failed "Failed to build libbpf. eBPF support will be disabled"
  735. fi
  736. fi
  737. else
  738. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
  739. fatal "Failed to fetch sources for libbpf." I0006
  740. else
  741. run_failed "Unable to fetch sources for libbpf. eBPF support will be disabled"
  742. fi
  743. fi
  744. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  745. }
  746. bundle_libbpf
  747. copy_co_re() {
  748. cp -R "${1}/includes" "collectors/ebpf.plugin/"
  749. }
  750. bundle_ebpf_co_re() {
  751. if { [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 1 ]; } || [ "$(uname -s)" != Linux ]; then
  752. return 0
  753. fi
  754. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling libbpf."
  755. progress "eBPF CO-RE"
  756. CORE_PACKAGE_VERSION="$(cat packaging/ebpf-co-re.version)"
  757. tmp="$(mktemp -d -t netdata-ebpf-co-re-XXXXXX)"
  758. CORE_PACKAGE_BASENAME="netdata-ebpf-co-re-glibc-${CORE_PACKAGE_VERSION}.tar.xz"
  759. if fetch_and_verify "ebpf-co-re" \
  760. "https://github.com/netdata/ebpf-co-re/releases/download/${CORE_PACKAGE_VERSION}/${CORE_PACKAGE_BASENAME}" \
  761. "${CORE_PACKAGE_BASENAME}" \
  762. "${tmp}" \
  763. "${NETDATA_LOCAL_TARBALL_OVERRIDE_CORE}"; then
  764. if run tar --no-same-owner -xf "${tmp}/${CORE_PACKAGE_BASENAME}" -C "${tmp}" &&
  765. copy_co_re "${tmp}" &&
  766. rm -rf "${tmp}"; then
  767. run_ok "libbpf built and prepared."
  768. else
  769. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
  770. fatal "Failed to get eBPF CO-RE files." I0007
  771. else
  772. run_failed "Failed to get eBPF CO-RE files. eBPF support will be disabled"
  773. NETDATA_DISABLE_EBPF=1
  774. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-ebpf)}" | sed 's/$/ --disable-ebpf/g')"
  775. fi
  776. fi
  777. else
  778. if [ -n "${NETDATA_DISABLE_EBPF}" ] && [ "${NETDATA_DISABLE_EBPF}" = 0 ]; then
  779. fatal "Failed to fetch eBPF CO-RE files." I0008
  780. else
  781. run_failed "Failed to fetch eBPF CO-RE files. eBPF support will be disabled"
  782. NETDATA_DISABLE_EBPF=1
  783. NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-ebpf)}" | sed 's/$/ --disable-ebpf/g')"
  784. fi
  785. fi
  786. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  787. }
  788. bundle_ebpf_co_re
  789. # -----------------------------------------------------------------------------
  790. # If we have the dashboard switching logic, make sure we're on the classic
  791. # dashboard during the install (updates don't work correctly otherwise).
  792. if [ -x "${NETDATA_PREFIX}/usr/libexec/netdata-switch-dashboard.sh" ]; then
  793. "${NETDATA_PREFIX}/usr/libexec/netdata-switch-dashboard.sh" classic
  794. fi
  795. # -----------------------------------------------------------------------------
  796. # By default, `git` does not update local tags based on remotes. Because
  797. # we use the most recent tag as part of our version determination in
  798. # our build, this can lead to strange versions that look ancient but are
  799. # actually really recent. To avoid this, try and fetch tags if we're
  800. # working in a git checkout.
  801. if [ -d ./.git ] ; then
  802. echo >&2
  803. progress "Updating tags in git to ensure a consistent version number"
  804. run git fetch -t || true
  805. fi
  806. # -----------------------------------------------------------------------------
  807. echo >&2
  808. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Configuring Netdata."
  809. progress "Run autotools to configure the build environment"
  810. if [ "$have_autotools" ]; then
  811. if ! run autoreconf -ivf; then
  812. fatal "Failed to prepare Netdata sources." I0009
  813. fi
  814. fi
  815. # function to extract values from the config file
  816. config_option() {
  817. section="${1}"
  818. key="${2}"
  819. value="${3}"
  820. if [ -x "${NETDATA_PREFIX}/usr/sbin/netdata" ] && [ -r "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]; then
  821. "${NETDATA_PREFIX}/usr/sbin/netdata" \
  822. -c "${NETDATA_PREFIX}/etc/netdata/netdata.conf" \
  823. -W get "${section}" "${key}" "${value}" ||
  824. echo "${value}"
  825. else
  826. echo "${value}"
  827. fi
  828. }
  829. # the user netdata will run as
  830. if [ "$(id -u)" = "0" ]; then
  831. NETDATA_USER="$(config_option "global" "run as user" "netdata")"
  832. ROOT_USER="root"
  833. else
  834. NETDATA_USER="${USER}"
  835. ROOT_USER="${USER}"
  836. fi
  837. NETDATA_GROUP="$(id -g -n "${NETDATA_USER}")"
  838. [ -z "${NETDATA_GROUP}" ] && NETDATA_GROUP="${NETDATA_USER}"
  839. echo >&2 "Netdata user and group set to: ${NETDATA_USER}/${NETDATA_GROUP}"
  840. # shellcheck disable=SC2086
  841. if ! run ./configure \
  842. --prefix="${NETDATA_PREFIX}/usr" \
  843. --sysconfdir="${NETDATA_PREFIX}/etc" \
  844. --localstatedir="${NETDATA_PREFIX}/var" \
  845. --libexecdir="${NETDATA_PREFIX}/usr/libexec" \
  846. --libdir="${NETDATA_PREFIX}/usr/lib" \
  847. --with-zlib \
  848. --with-math \
  849. --with-user="${NETDATA_USER}" \
  850. ${NETDATA_CONFIGURE_OPTIONS} \
  851. CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}"; then
  852. fatal "Failed to configure Netdata sources." I000A
  853. fi
  854. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  855. # remove the build_error hook
  856. trap - EXIT
  857. # -----------------------------------------------------------------------------
  858. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Building Netdata."
  859. progress "Cleanup compilation directory"
  860. run $make clean
  861. # -----------------------------------------------------------------------------
  862. progress "Compile netdata"
  863. # shellcheck disable=SC2086
  864. if ! run $make ${MAKEOPTS}; then
  865. fatal "Failed to build Netdata." I000B
  866. fi
  867. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  868. # -----------------------------------------------------------------------------
  869. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing Netdata."
  870. # -----------------------------------------------------------------------------
  871. # shellcheck disable=SC2230
  872. md5sum="$(command -v md5sum 2> /dev/null || command -v md5 2> /dev/null)"
  873. deleted_stock_configs=0
  874. if [ ! -f "${NETDATA_PREFIX}/etc/netdata/.installer-cleanup-of-stock-configs-done" ]; then
  875. progress "Backup existing netdata configuration before installing it"
  876. config_signature_matches() {
  877. md5="${1}"
  878. file="${2}"
  879. if [ -f "configs.signatures" ]; then
  880. grep "\['${md5}'\]='${file}'" "configs.signatures" > /dev/null
  881. return $?
  882. fi
  883. return 1
  884. }
  885. # clean up stock config files from the user configuration directory
  886. (find -L "${NETDATA_PREFIX}/etc/netdata" -type f -not -path '*/\.*' -not -path "${NETDATA_PREFIX}/etc/netdata/orig/*" \( -name '*.conf.old' -o -name '*.conf' -o -name '*.conf.orig' -o -name '*.conf.installer_backup.*' \)) | while IFS= read -r x; do
  887. if [ -f "${x}" ]; then
  888. # find it relative filename
  889. p="$(echo "${NETDATA_PREFIX}/etc/netdata" | sed -e 's/\//\\\//')"
  890. f="$(echo "${x}" | sed -e "s/${p}//")"
  891. # find the stock filename
  892. t="$(echo "${f}" | sed -e 's/\.conf\.installer_backup\..*/\.conf/')"
  893. t="$(echo "${t}" | sed -e 's/\.conf\.old/\.conf/')"
  894. t="$(echo "${t}" | sed -e 's/\.conf\.orig/\.conf/')"
  895. t="$(echo "${t}" | sed -e 's/orig//')"
  896. if [ -z "${md5sum}" ] || [ ! -x "${md5sum}" ]; then
  897. # we don't have md5sum - keep it
  898. echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RED}is not known to distribution${TPUT_RESET}. Keeping it."
  899. else
  900. # find its checksum
  901. md5="$(${md5sum} < "${x}" | cut -d ' ' -f 1)"
  902. if config_signature_matches "${md5}" "${t}"; then
  903. # it is a stock version - remove it
  904. echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' is stock version of '${t}'."
  905. run rm -f "${x}"
  906. # shellcheck disable=SC2030
  907. deleted_stock_configs=$((deleted_stock_configs + 1))
  908. else
  909. # edited by user - keep it
  910. echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RED} does not match stock of${TPUT_RESET} ${TPUT_CYAN}'${t}'${TPUT_RESET}. Keeping it."
  911. fi
  912. fi
  913. fi
  914. done
  915. fi
  916. touch "${NETDATA_PREFIX}/etc/netdata/.installer-cleanup-of-stock-configs-done"
  917. # -----------------------------------------------------------------------------
  918. progress "Install netdata"
  919. if ! run $make install; then
  920. fatal "Failed to install Netdata." I000C
  921. fi
  922. # -----------------------------------------------------------------------------
  923. progress "Fix generated files permissions"
  924. run chmod 755 ./system/*/init.d/netdata ./system/*/rc.d/netdata ./system/runit/run ./system/install-service.sh
  925. # -----------------------------------------------------------------------------
  926. progress "Creating standard user and groups for netdata"
  927. NETDATA_WANTED_GROUPS="docker nginx varnish haproxy adm nsd proxy squid ceph nobody"
  928. NETDATA_ADDED_TO_GROUPS=""
  929. if [ "$(id -u)" -eq 0 ]; then
  930. progress "Adding group 'netdata'"
  931. portable_add_group netdata || :
  932. progress "Adding user 'netdata'"
  933. portable_add_user netdata "${NETDATA_PREFIX}/var/lib/netdata" || :
  934. progress "Assign user 'netdata' to required groups"
  935. for g in ${NETDATA_WANTED_GROUPS}; do
  936. # shellcheck disable=SC2086
  937. portable_add_user_to_group ${g} netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} ${g}"
  938. done
  939. # Netdata must be able to read /etc/pve/qemu-server/* and /etc/pve/lxc/*
  940. # for reading VMs/containers names, CPU and memory limits on Proxmox.
  941. if [ -d "/etc/pve" ]; then
  942. portable_add_user_to_group "www-data" netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} www-data"
  943. fi
  944. else
  945. run_failed "The installer does not run as root. Nothing to do for user and groups"
  946. fi
  947. # -----------------------------------------------------------------------------
  948. progress "Install logrotate configuration for netdata"
  949. install_netdata_logrotate
  950. # -----------------------------------------------------------------------------
  951. progress "Read installation options from netdata.conf"
  952. # create an empty config if it does not exist
  953. [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] &&
  954. touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  955. # port
  956. defport=19999
  957. NETDATA_PORT="$(config_option "web" "default port" ${defport})"
  958. # directories
  959. NETDATA_LIB_DIR="$(config_option "global" "lib directory" "${NETDATA_PREFIX}/var/lib/netdata")"
  960. NETDATA_CACHE_DIR="$(config_option "global" "cache directory" "${NETDATA_PREFIX}/var/cache/netdata")"
  961. NETDATA_WEB_DIR="$(config_option "global" "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web")"
  962. NETDATA_LOG_DIR="$(config_option "global" "log directory" "${NETDATA_PREFIX}/var/log/netdata")"
  963. NETDATA_USER_CONFIG_DIR="$(config_option "global" "config directory" "${NETDATA_PREFIX}/etc/netdata")"
  964. NETDATA_STOCK_CONFIG_DIR="$(config_option "global" "stock config directory" "${NETDATA_PREFIX}/usr/lib/netdata/conf.d")"
  965. NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
  966. NETDATA_CLAIMING_DIR="${NETDATA_LIB_DIR}/cloud.d"
  967. cat << OPTIONSEOF
  968. Permissions
  969. - netdata user : ${NETDATA_USER}
  970. - netdata group : ${NETDATA_GROUP}
  971. - root user : ${ROOT_USER}
  972. Directories
  973. - netdata user config dir : ${NETDATA_USER_CONFIG_DIR}
  974. - netdata stock config dir : ${NETDATA_STOCK_CONFIG_DIR}
  975. - netdata log dir : ${NETDATA_LOG_DIR}
  976. - netdata run dir : ${NETDATA_RUN_DIR}
  977. - netdata lib dir : ${NETDATA_LIB_DIR}
  978. - netdata web dir : ${NETDATA_WEB_DIR}
  979. - netdata cache dir : ${NETDATA_CACHE_DIR}
  980. Other
  981. - netdata port : ${NETDATA_PORT}
  982. OPTIONSEOF
  983. # -----------------------------------------------------------------------------
  984. progress "Fix permissions of netdata directories (using user '${NETDATA_USER}')"
  985. if [ ! -d "${NETDATA_RUN_DIR}" ]; then
  986. # this is needed if NETDATA_PREFIX is not empty
  987. if ! run mkdir -p "${NETDATA_RUN_DIR}"; then
  988. warning "Failed to create ${NETDATA_RUN_DIR}, it must becreated by hand or the Netdata Agent will not be able to be started."
  989. fi
  990. fi
  991. # --- stock conf dir ----
  992. [ ! -d "${NETDATA_STOCK_CONFIG_DIR}" ] && mkdir -p "${NETDATA_STOCK_CONFIG_DIR}"
  993. helplink="000.-.USE.THE.orig.LINK.TO.COPY.AND.EDIT.STOCK.CONFIG.FILES"
  994. # shellcheck disable=SC2031
  995. [ ${deleted_stock_configs} -eq 0 ] && helplink=""
  996. for link in "orig" "${helplink}"; do
  997. if [ -n "${link}" ]; then
  998. [ -L "${NETDATA_USER_CONFIG_DIR}/${link}" ] && run rm -f "${NETDATA_USER_CONFIG_DIR}/${link}"
  999. run ln -s "${NETDATA_STOCK_CONFIG_DIR}" "${NETDATA_USER_CONFIG_DIR}/${link}"
  1000. fi
  1001. done
  1002. # --- web dir ----
  1003. if [ ! -d "${NETDATA_WEB_DIR}" ]; then
  1004. echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
  1005. run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
  1006. fi
  1007. run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
  1008. run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
  1009. # --- data dirs ----
  1010. for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"; do
  1011. if [ ! -d "${x}" ]; then
  1012. echo >&2 "Creating directory '${x}'"
  1013. if ! run mkdir -p "${x}"; then
  1014. warning "Failed to create ${x}, it must be created by hand or the Netdata Agent will not be able to be started."
  1015. fi
  1016. fi
  1017. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${x}"
  1018. #run find "${x}" -type f -exec chmod 0660 {} \;
  1019. #run find "${x}" -type d -exec chmod 0770 {} \;
  1020. done
  1021. run chmod 755 "${NETDATA_LOG_DIR}"
  1022. # --- claiming dir ----
  1023. if [ ! -d "${NETDATA_CLAIMING_DIR}" ]; then
  1024. echo >&2 "Creating directory '${NETDATA_CLAIMING_DIR}'"
  1025. if ! run mkdir -p "${NETDATA_CLAIMING_DIR}"; then
  1026. warning "failed to create ${NETDATA_CLAIMING_DIR}, it will need to be created manually."
  1027. fi
  1028. fi
  1029. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_CLAIMING_DIR}"
  1030. run chmod 770 "${NETDATA_CLAIMING_DIR}"
  1031. # --- plugins ----
  1032. if [ "$(id -u)" -eq 0 ]; then
  1033. # find the admin group
  1034. admin_group=
  1035. test -z "${admin_group}" && get_group root > /dev/null 2>&1 && admin_group="root"
  1036. test -z "${admin_group}" && get_group daemon > /dev/null 2>&1 && admin_group="daemon"
  1037. test -z "${admin_group}" && admin_group="${NETDATA_GROUP}"
  1038. run chown "${NETDATA_USER}:${admin_group}" "${NETDATA_LOG_DIR}"
  1039. run chown -R "root:${admin_group}" "${NETDATA_PREFIX}/usr/libexec/netdata"
  1040. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
  1041. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
  1042. # shellcheck disable=SC2086
  1043. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chown :${NETDATA_GROUP} {} \;
  1044. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0750 {} \;
  1045. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
  1046. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
  1047. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  1048. capabilities=0
  1049. if ! iscontainer && command -v setcap 1> /dev/null 2>&1; then
  1050. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  1051. if run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"; then
  1052. # if we managed to setcap, but we fail to execute apps.plugin setuid to root
  1053. "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -t > /dev/null 2>&1 && capabilities=1 || capabilities=0
  1054. fi
  1055. fi
  1056. if [ $capabilities -eq 0 ]; then
  1057. # fix apps.plugin to be setuid to root
  1058. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  1059. fi
  1060. fi
  1061. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin" ]; then
  1062. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
  1063. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
  1064. fi
  1065. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin" ]; then
  1066. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
  1067. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
  1068. fi
  1069. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin" ]; then
  1070. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
  1071. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
  1072. fi
  1073. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin" ]; then
  1074. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  1075. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
  1076. run sh -c "setcap cap_perfmon+ep \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin\" || setcap cap_sys_admin+ep \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin\""
  1077. fi
  1078. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin" ]; then
  1079. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  1080. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  1081. run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
  1082. fi
  1083. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping" ]; then
  1084. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
  1085. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
  1086. fi
  1087. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin" ]; then
  1088. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin"
  1089. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin"
  1090. fi
  1091. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network" ]; then
  1092. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
  1093. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
  1094. fi
  1095. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh" ]; then
  1096. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
  1097. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
  1098. fi
  1099. else
  1100. # non-privileged user installation
  1101. run chown "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_LOG_DIR}"
  1102. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata"
  1103. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
  1104. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
  1105. fi
  1106. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1107. # -----------------------------------------------------------------------------
  1108. # govercomp compares go.d.plugin versions. Exit codes:
  1109. # 0 - version1 == version2
  1110. # 1 - version1 > version2
  1111. # 2 - version2 > version1
  1112. # 3 - error
  1113. # shellcheck disable=SC2086
  1114. govercomp() {
  1115. # version in file:
  1116. # - v0.14.0
  1117. #
  1118. # 'go.d.plugin -v' output variants:
  1119. # - go.d.plugin, version: unknown
  1120. # - go.d.plugin, version: v0.14.1
  1121. # - go.d.plugin, version: v0.14.1-dirty
  1122. # - go.d.plugin, version: v0.14.1-1-g4c5f98c
  1123. # - go.d.plugin, version: v0.14.1-1-g4c5f98c-dirty
  1124. # we need to compare only MAJOR.MINOR.PATCH part
  1125. ver1=$(echo "$1" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+")
  1126. ver2=$(echo "$2" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+")
  1127. if [ ${#ver1} -eq 0 ] || [ ${#ver2} -eq 0 ]; then
  1128. return 3
  1129. fi
  1130. num1=$(echo $ver1 | grep -o -E '\.' | wc -l)
  1131. num2=$(echo $ver2 | grep -o -E '\.' | wc -l)
  1132. if [ ${num1} -ne ${num2} ]; then
  1133. return 3
  1134. fi
  1135. for i in $(seq 1 $((num1+1))); do
  1136. x=$(echo $ver1 | cut -d'.' -f$i)
  1137. y=$(echo $ver2 | cut -d'.' -f$i)
  1138. if [ "${x}" -gt "${y}" ]; then
  1139. return 1
  1140. elif [ "${y}" -gt "${x}" ]; then
  1141. return 2
  1142. fi
  1143. done
  1144. return 0
  1145. }
  1146. should_install_go() {
  1147. if [ -n "${NETDATA_DISABLE_GO+x}" ]; then
  1148. return 1
  1149. fi
  1150. version_in_file="$(cat packaging/go.d.version 2> /dev/null)"
  1151. binary_version=$("${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/go.d.plugin -v 2> /dev/null)
  1152. govercomp "$version_in_file" "$binary_version"
  1153. case $? in
  1154. 0) return 1 ;; # =
  1155. 2) return 1 ;; # <
  1156. *) return 0 ;; # >, error
  1157. esac
  1158. }
  1159. install_go() {
  1160. if ! should_install_go; then
  1161. return 0
  1162. fi
  1163. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing go.d.plugin."
  1164. # When updating this value, ensure correct checksums in packaging/go.d.checksums
  1165. GO_PACKAGE_VERSION="$(cat packaging/go.d.version)"
  1166. ARCH_MAP='
  1167. i386::386
  1168. i686::386
  1169. x86_64::amd64
  1170. aarch64::arm64
  1171. armv64::arm64
  1172. armv6l::arm
  1173. armv7l::arm
  1174. armv5tel::arm
  1175. '
  1176. progress "Install go.d.plugin"
  1177. ARCH=$(uname -m)
  1178. OS=$(uname -s | tr '[:upper:]' '[:lower:]')
  1179. for index in ${ARCH_MAP}; do
  1180. KEY="${index%%::*}"
  1181. VALUE="${index##*::}"
  1182. if [ "$KEY" = "$ARCH" ]; then
  1183. ARCH="${VALUE}"
  1184. break
  1185. fi
  1186. done
  1187. tmp="$(mktemp -d -t netdata-go-XXXXXX)"
  1188. GO_PACKAGE_BASENAME="go.d.plugin-${GO_PACKAGE_VERSION}.${OS}-${ARCH}.tar.gz"
  1189. if [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}" ]; then
  1190. download_go "https://github.com/netdata/go.d.plugin/releases/download/${GO_PACKAGE_VERSION}/${GO_PACKAGE_BASENAME}" "${tmp}/${GO_PACKAGE_BASENAME}"
  1191. else
  1192. progress "Using provided go.d tarball ${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}"
  1193. run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN}" "${tmp}/${GO_PACKAGE_BASENAME}"
  1194. fi
  1195. if [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}" ]; then
  1196. download_go "https://github.com/netdata/go.d.plugin/releases/download/${GO_PACKAGE_VERSION}/config.tar.gz" "${tmp}/config.tar.gz"
  1197. else
  1198. progress "Using provided config file for go.d ${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}"
  1199. run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_GO_PLUGIN_CONFIG}" "${tmp}/config.tar.gz"
  1200. fi
  1201. if [ ! -f "${tmp}/${GO_PACKAGE_BASENAME}" ] || [ ! -f "${tmp}/config.tar.gz" ] || [ ! -s "${tmp}/config.tar.gz" ] || [ ! -s "${tmp}/${GO_PACKAGE_BASENAME}" ]; then
  1202. run_failed "go.d plugin download failed, go.d plugin will not be available"
  1203. echo >&2 "Either check the error or consider disabling it by issuing '--disable-go' in the installer"
  1204. echo >&2
  1205. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1206. return 0
  1207. fi
  1208. grep "${GO_PACKAGE_BASENAME}\$" "${INSTALLER_DIR}/packaging/go.d.checksums" > "${tmp}/sha256sums.txt" 2> /dev/null
  1209. grep "config.tar.gz" "${INSTALLER_DIR}/packaging/go.d.checksums" >> "${tmp}/sha256sums.txt" 2> /dev/null
  1210. # Checksum validation
  1211. if ! (cd "${tmp}" && safe_sha256sum -c "sha256sums.txt"); then
  1212. echo >&2 "go.d plugin checksum validation failure."
  1213. echo >&2 "Either check the error or consider disabling it by issuing '--disable-go' in the installer"
  1214. echo >&2
  1215. run_failed "go.d.plugin package files checksum validation failed. go.d.plugin will not be available."
  1216. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1217. return 0
  1218. fi
  1219. # Install new files
  1220. run rm -rf "${NETDATA_STOCK_CONFIG_DIR}/go.d"
  1221. run rm -rf "${NETDATA_STOCK_CONFIG_DIR}/go.d.conf"
  1222. run tar --no-same-owner -xf "${tmp}/config.tar.gz" -C "${NETDATA_STOCK_CONFIG_DIR}/"
  1223. run chown -R "${ROOT_USER}:${ROOT_GROUP}" "${NETDATA_STOCK_CONFIG_DIR}"
  1224. run tar --no-same-owner -xf "${tmp}/${GO_PACKAGE_BASENAME}"
  1225. run mv "${GO_PACKAGE_BASENAME%.tar.gz}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  1226. if [ "$(id -u)" -eq 0 ]; then
  1227. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  1228. fi
  1229. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  1230. rm -rf "${tmp}"
  1231. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1232. }
  1233. install_go
  1234. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin" ]; then
  1235. if command -v setcap 1>/dev/null 2>&1; then
  1236. run setcap "cap_net_admin+epi cap_net_raw=eip" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  1237. fi
  1238. fi
  1239. should_install_ebpf() {
  1240. if [ "${NETDATA_DISABLE_EBPF:=0}" -eq 1 ]; then
  1241. run_failed "eBPF has been explicitly disabled, it will not be available in this install."
  1242. return 1
  1243. fi
  1244. if [ "$(uname -s)" != "Linux" ] || [ "$(uname -m)" != "x86_64" ]; then
  1245. if [ "${NETDATA_DISABLE_EBPF:=1}" -eq 0 ]; then
  1246. run_failed "Currently eBPF is only supported on Linux on X86_64."
  1247. fi
  1248. return 1
  1249. fi
  1250. # Check Kernel Config
  1251. if ! run "${INSTALLER_DIR}"/packaging/check-kernel-config.sh; then
  1252. warning "Kernel unsupported or missing required config (eBPF may not work on your system)"
  1253. fi
  1254. return 0
  1255. }
  1256. remove_old_ebpf() {
  1257. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf_process.plugin" ]; then
  1258. echo >&2 "Removing alpha eBPF collector."
  1259. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf_process.plugin"
  1260. fi
  1261. if [ -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_process.conf" ]; then
  1262. echo >&2 "Removing alpha eBPF stock file"
  1263. rm -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_process.conf"
  1264. fi
  1265. if [ -f "${NETDATA_PREFIX}/etc/netdata/ebpf_process.conf" ]; then
  1266. echo >&2 "Renaming eBPF configuration file."
  1267. mv "${NETDATA_PREFIX}/etc/netdata/ebpf_process.conf" "${NETDATA_PREFIX}/etc/netdata/ebpf.d.conf"
  1268. fi
  1269. # Added to remove eBPF programs with name pattern: NAME_VERSION.SUBVERSION.PATCH
  1270. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf_process.3.10.0.o" ]; then
  1271. echo >&2 "Removing old eBPF programs with patch."
  1272. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/rnetdata_ebpf"*.?.*.*.o
  1273. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf"*.?.*.*.o
  1274. fi
  1275. # Remove old eBPF program to store new eBPF program inside subdirectory
  1276. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf_process.3.10.o" ]; then
  1277. echo >&2 "Removing old eBPF programs installed in old directory."
  1278. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/rnetdata_ebpf"*.?.*.o
  1279. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/pnetdata_ebpf"*.?.*.o
  1280. fi
  1281. # Remove old eBPF programs that did not have "rhf" suffix
  1282. if [ ! -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.d/pnetdata_ebpf_process.3.10.rhf.o" ]; then
  1283. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.d/"*.o
  1284. fi
  1285. # Remove old reject list from previous directory
  1286. if [ -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_kernel_reject_list.txt" ]; then
  1287. echo >&2 "Removing old ebpf_kernel_reject_list.txt."
  1288. rm -f "${NETDATA_PREFIX}/usr/lib/netdata/conf.d/ebpf_kernel_reject_list.txt"
  1289. fi
  1290. # Remove old reset script
  1291. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/reset_netdata_trace.sh" ]; then
  1292. echo >&2 "Removing old reset_netdata_trace.sh."
  1293. rm -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/reset_netdata_trace.sh"
  1294. fi
  1295. }
  1296. install_ebpf() {
  1297. if ! should_install_ebpf; then
  1298. return 0
  1299. fi
  1300. [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Installing eBPF code."
  1301. remove_old_ebpf
  1302. progress "Installing eBPF plugin"
  1303. # Detect libc
  1304. libc="${EBPF_LIBC:-"$(detect_libc)"}"
  1305. EBPF_VERSION="$(cat packaging/ebpf.version)"
  1306. EBPF_TARBALL="netdata-kernel-collector-${libc}-${EBPF_VERSION}.tar.xz"
  1307. tmp="$(mktemp -d -t netdata-ebpf-XXXXXX)"
  1308. if ! fetch_and_verify "ebpf" \
  1309. "https://github.com/netdata/kernel-collector/releases/download/${EBPF_VERSION}/${EBPF_TARBALL}" \
  1310. "${EBPF_TARBALL}" \
  1311. "${tmp}" \
  1312. "${NETDATA_LOCAL_TARBALL_OVERRIDE_EBPF}"; then
  1313. run_failed "Failed to download eBPF collector package"
  1314. echo 2>&" Removing temporary directory ${tmp} ..."
  1315. rm -rf "${tmp}"
  1316. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1317. return 1
  1318. fi
  1319. echo >&2 " Extracting ${EBPF_TARBALL} ..."
  1320. tar --no-same-owner -xf "${tmp}/${EBPF_TARBALL}" -C "${tmp}"
  1321. # chown everything to root:netdata before we start copying out of our package
  1322. run chown -R root:netdata "${tmp}"
  1323. if [ ! -d "${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/ebpf.d ]; then
  1324. mkdir "${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/ebpf.d
  1325. RET=$?
  1326. if [ "${RET}" != "0" ]; then
  1327. rm -rf "${tmp}"
  1328. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1329. return 1
  1330. fi
  1331. fi
  1332. run cp -a -v "${tmp}"/*netdata_ebpf_*.o "${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/ebpf.d
  1333. rm -rf "${tmp}"
  1334. [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
  1335. }
  1336. progress "eBPF Kernel Collector"
  1337. install_ebpf
  1338. # -----------------------------------------------------------------------------
  1339. progress "Telemetry configuration"
  1340. # Opt-out from telemetry program
  1341. if [ -n "${NETDATA_DISABLE_TELEMETRY+x}" ]; then
  1342. run touch "${NETDATA_USER_CONFIG_DIR}/.opt-out-from-anonymous-statistics"
  1343. else
  1344. printf "You can opt out from anonymous statistics via the --disable-telemetry option, or by creating an empty file %s \n\n" "${NETDATA_USER_CONFIG_DIR}/.opt-out-from-anonymous-statistics"
  1345. fi
  1346. # -----------------------------------------------------------------------------
  1347. progress "Install netdata at system init"
  1348. # By default we assume the shutdown/startup of the Netdata Agent are effectively
  1349. # without any system supervisor/init like SystemD or SysV. So we assume the most
  1350. # basic startup/shutdown commands...
  1351. NETDATA_STOP_CMD="${NETDATA_PREFIX}/usr/sbin/netdatacli shutdown-agent"
  1352. NETDATA_START_CMD="${NETDATA_PREFIX}/usr/sbin/netdata"
  1353. if grep -q docker /proc/1/cgroup > /dev/null 2>&1; then
  1354. # If docker runs systemd for some weird reason, let the install proceed
  1355. is_systemd_running="NO"
  1356. if command -v pidof > /dev/null 2>&1; then
  1357. is_systemd_running="$(pidof /usr/sbin/init || pidof systemd || echo "NO")"
  1358. else
  1359. is_systemd_running="$( (pgrep -q -f systemd && echo "1") || echo "NO")"
  1360. fi
  1361. if [ "${is_systemd_running}" = "1" ]; then
  1362. echo >&2 "Found systemd within the docker container, running install_netdata_service() method"
  1363. install_netdata_service || run_failed "Cannot install netdata init service."
  1364. else
  1365. echo >&2 "We are running within a docker container, will not be installing netdata service"
  1366. fi
  1367. echo >&2
  1368. else
  1369. install_netdata_service || run_failed "Cannot install netdata init service."
  1370. fi
  1371. # -----------------------------------------------------------------------------
  1372. # check if we can re-start netdata
  1373. # TODO(paulfantom): Creation of configuration file should be handled by a build system. Additionally we shouldn't touch configuration files in /etc/netdata/...
  1374. started=0
  1375. if [ ${DONOTSTART} -eq 1 ]; then
  1376. create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  1377. else
  1378. if ! restart_netdata "${NETDATA_PREFIX}/usr/sbin/netdata" "${@}"; then
  1379. fatal "Cannot start netdata!" I000D
  1380. fi
  1381. started=1
  1382. run_ok "netdata started!"
  1383. create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf" "http://localhost:${NETDATA_PORT}/netdata.conf"
  1384. fi
  1385. run chmod 0644 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  1386. if [ "$(uname)" = "Linux" ]; then
  1387. # -------------------------------------------------------------------------
  1388. progress "Check KSM (kernel memory deduper)"
  1389. ksm_is_available_but_disabled() {
  1390. cat << KSM1
  1391. ${TPUT_BOLD}Memory de-duplication instructions${TPUT_RESET}
  1392. You have kernel memory de-duper (called Kernel Same-page Merging,
  1393. or KSM) available, but it is not currently enabled.
  1394. To enable it run:
  1395. ${TPUT_YELLOW}${TPUT_BOLD}echo 1 >/sys/kernel/mm/ksm/run${TPUT_RESET}
  1396. ${TPUT_YELLOW}${TPUT_BOLD}echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs${TPUT_RESET}
  1397. If you enable it, you will save 40-60% of netdata memory.
  1398. KSM1
  1399. }
  1400. ksm_is_not_available() {
  1401. cat << KSM2
  1402. ${TPUT_BOLD}Memory de-duplication not present in your kernel${TPUT_RESET}
  1403. It seems you do not have kernel memory de-duper (called Kernel Same-page
  1404. Merging, or KSM) available.
  1405. To enable it, you need a kernel built with CONFIG_KSM=y
  1406. If you can have it, you will save 40-60% of netdata memory.
  1407. KSM2
  1408. }
  1409. if [ -f "/sys/kernel/mm/ksm/run" ]; then
  1410. if [ "$(cat "/sys/kernel/mm/ksm/run")" != "1" ]; then
  1411. ksm_is_available_but_disabled
  1412. fi
  1413. else
  1414. ksm_is_not_available
  1415. fi
  1416. fi
  1417. # -----------------------------------------------------------------------------
  1418. progress "Check version.txt"
  1419. if [ ! -s web/gui/version.txt ]; then
  1420. cat << VERMSG
  1421. ${TPUT_BOLD}Version update check warning${TPUT_RESET}
  1422. The way you downloaded netdata, we cannot find its version. This means the
  1423. Update check on the dashboard, will not work.
  1424. If you want to have version update check, please re-install it
  1425. following the procedure in:
  1426. https://docs.netdata.cloud/packaging/installer/
  1427. VERMSG
  1428. fi
  1429. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
  1430. # -----------------------------------------------------------------------------
  1431. progress "Check apps.plugin"
  1432. if [ "$(id -u)" -ne 0 ]; then
  1433. cat << SETUID_WARNING
  1434. ${TPUT_BOLD}apps.plugin needs privileges${TPUT_RESET}
  1435. Since you have installed netdata as a normal user, to have apps.plugin collect
  1436. all the needed data, you have to give it the access rights it needs, by running
  1437. either of the following sets of commands:
  1438. To run apps.plugin with escalated capabilities:
  1439. ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1440. ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1441. ${TPUT_YELLOW}${TPUT_BOLD}sudo setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1442. or, to run apps.plugin as root:
  1443. ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1444. ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"${TPUT_RESET}
  1445. apps.plugin is performing a hard-coded function of data collection for all
  1446. running processes. It cannot be instructed from the netdata daemon to perform
  1447. any task, so it is pretty safe to do this.
  1448. SETUID_WARNING
  1449. fi
  1450. fi
  1451. # -----------------------------------------------------------------------------
  1452. progress "Copy uninstaller"
  1453. if [ -f "${NETDATA_PREFIX}"/usr/libexec/netdata-uninstaller.sh ]; then
  1454. echo >&2 "Removing uninstaller from old location"
  1455. rm -f "${NETDATA_PREFIX}"/usr/libexec/netdata-uninstaller.sh
  1456. fi
  1457. sed "s|ENVIRONMENT_FILE=\"/etc/netdata/.environment\"|ENVIRONMENT_FILE=\"${NETDATA_PREFIX}/etc/netdata/.environment\"|" packaging/installer/netdata-uninstaller.sh > "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh"
  1458. chmod 750 "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh"
  1459. # -----------------------------------------------------------------------------
  1460. progress "Basic netdata instructions"
  1461. cat << END
  1462. netdata by default listens on all IPs on port ${NETDATA_PORT},
  1463. so you can access it with:
  1464. ${TPUT_CYAN}${TPUT_BOLD}http://this.machine.ip:${NETDATA_PORT}/${TPUT_RESET}
  1465. To stop netdata run:
  1466. ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_STOP_CMD}${TPUT_RESET}
  1467. To start netdata run:
  1468. ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_START_CMD}${TPUT_RESET}
  1469. END
  1470. echo >&2 "Uninstall script copied to: ${TPUT_RED}${TPUT_BOLD}${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh${TPUT_RESET}"
  1471. echo >&2
  1472. # -----------------------------------------------------------------------------
  1473. progress "Installing (but not enabling) the netdata updater tool"
  1474. install_netdata_updater || run_failed "Cannot install netdata updater tool."
  1475. # -----------------------------------------------------------------------------
  1476. progress "Wrap up environment set up"
  1477. # Save environment variables
  1478. echo >&2 "Preparing .environment file"
  1479. cat << EOF > "${NETDATA_USER_CONFIG_DIR}/.environment"
  1480. # Created by installer
  1481. PATH="${PATH}"
  1482. CFLAGS="${CFLAGS}"
  1483. LDFLAGS="${LDFLAGS}"
  1484. MAKEOPTS="${MAKEOPTS}"
  1485. NETDATA_TMPDIR="${TMPDIR}"
  1486. NETDATA_PREFIX="${NETDATA_PREFIX}"
  1487. NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS}"
  1488. NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS}"
  1489. INSTALL_UID="$(id -u)"
  1490. NETDATA_GROUP="${NETDATA_GROUP}"
  1491. REINSTALL_OPTIONS="${REINSTALL_OPTIONS}"
  1492. RELEASE_CHANNEL="${RELEASE_CHANNEL}"
  1493. IS_NETDATA_STATIC_BINARY="${IS_NETDATA_STATIC_BINARY}"
  1494. NETDATA_LIB_DIR="${NETDATA_LIB_DIR}"
  1495. EOF
  1496. run chmod 0644 "${NETDATA_USER_CONFIG_DIR}/.environment"
  1497. echo >&2 "Setting netdata.tarball.checksum to 'new_installation'"
  1498. cat << EOF > "${NETDATA_LIB_DIR}/netdata.tarball.checksum"
  1499. new_installation
  1500. EOF
  1501. print_deferred_errors
  1502. # -----------------------------------------------------------------------------
  1503. echo >&2
  1504. progress "We are done!"
  1505. if [ ${started} -eq 1 ]; then
  1506. netdata_banner
  1507. progress "is installed and running now!"
  1508. else
  1509. netdata_banner
  1510. progress "is installed now!"
  1511. fi
  1512. echo >&2 " enjoy real-time performance and health monitoring..."
  1513. echo >&2
  1514. exit 0