netdata-installer.sh 69 KB

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