netdata-installer.sh 68 KB

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