netdata-installer.sh 65 KB

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