netdata-installer.sh 69 KB

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