netdata-installer.sh 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021
  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. # reload the user profile
  24. # shellcheck source=/dev/null
  25. [ -f /etc/profile ] && . /etc/profile
  26. # make sure /etc/profile does not change our current directory
  27. cd "${NETDATA_SOURCE_DIR}" || exit 1
  28. # -----------------------------------------------------------------------------
  29. # load the required functions
  30. if [ -f "${INSTALLER_DIR}/packaging/installer/functions.sh" ]; then
  31. # shellcheck source=packaging/installer/functions.sh
  32. source "${INSTALLER_DIR}/packaging/installer/functions.sh" || exit 1
  33. else
  34. # shellcheck source=packaging/installer/functions.sh
  35. source "${NETDATA_SOURCE_DIR}/packaging/installer/functions.sh" || exit 1
  36. fi
  37. download() {
  38. url="${1}"
  39. dest="${2}"
  40. if command -v curl >/dev/null 2>&1; then
  41. run curl -sSL --connect-timeout 10 --retry 3 "${url}" >"${dest}" || fatal "Cannot download ${url}"
  42. elif command -v wget >/dev/null 2>&1; then
  43. run wget -T 15 -O - "${url}" >"${dest}" || fatal "Cannot download ${url}"
  44. else
  45. fatal "I need curl or wget to proceed, but neither is available on this system."
  46. fi
  47. }
  48. # make sure we save all commands we run
  49. run_logfile="netdata-installer.log"
  50. # -----------------------------------------------------------------------------
  51. # fix PKG_CHECK_MODULES error
  52. if [ -d /usr/share/aclocal ]; then
  53. ACLOCAL_PATH=${ACLOCAL_PATH-/usr/share/aclocal}
  54. export ACLOCAL_PATH
  55. fi
  56. export LC_ALL=C
  57. umask 002
  58. # Be nice on production environments
  59. renice 19 $$ >/dev/null 2>/dev/null
  60. # you can set CFLAGS before running installer
  61. CFLAGS="${CFLAGS--O2}"
  62. [ "z${CFLAGS}" = "z-O3" ] && CFLAGS="-O2"
  63. # keep a log of this command
  64. # shellcheck disable=SC2129
  65. printf "\\n# " >>netdata-installer.log
  66. date >>netdata-installer.log
  67. printf 'CFLAGS="%s" ' "${CFLAGS}" >>netdata-installer.log
  68. printf "%q " "${PROGRAM}" "${@}" >>netdata-installer.log
  69. printf "\\n" >>netdata-installer.log
  70. REINSTALL_COMMAND="$(
  71. printf "%q " "${PROGRAM}" "${@}"
  72. printf "\\n"
  73. )"
  74. # remove options that shown not be inherited by netdata-updater.sh
  75. REINSTALL_COMMAND="${REINSTALL_COMMAND// --dont-wait/}"
  76. REINSTALL_COMMAND="${REINSTALL_COMMAND// --dont-start-it/}"
  77. if [ "${REINSTALL_COMMAND:0:1}" != "." ] && [ "${REINSTALL_COMMAND:0:1}" != "/" ] && [ -f "./${PROGRAM}" ]; then
  78. REINSTALL_COMMAND="./${REINSTALL_COMMAND}"
  79. fi
  80. banner_nonroot_install() {
  81. cat <<NONROOTNOPREFIX
  82. ${TPUT_RED}${TPUT_BOLD}Sorry! This will fail!${TPUT_RESET}
  83. You are attempting to install netdata as non-root, but you plan
  84. to install it in system paths.
  85. Please set an installation prefix, like this:
  86. $PROGRAM ${@} --install /tmp
  87. or, run the installer as root:
  88. sudo $PROGRAM ${@}
  89. We suggest to install it as root, or certain data collectors will
  90. not be able to work. Netdata drops root privileges when running.
  91. So, if you plan to keep it, install it as root to get the full
  92. functionality.
  93. NONROOTNOPREFIX
  94. }
  95. banner_root_notify() {
  96. cat <<NONROOT
  97. ${TPUT_RED}${TPUT_BOLD}IMPORTANT${TPUT_RESET}:
  98. You are about to install netdata as a non-root user.
  99. Netdata will work, but a few data collection modules that
  100. require root access will fail.
  101. If you installing netdata permanently on your system, run
  102. the installer like this:
  103. ${TPUT_YELLOW}${TPUT_BOLD}sudo $PROGRAM ${@}${TPUT_RESET}
  104. NONROOT
  105. }
  106. usage() {
  107. netdata_banner "installer command line options"
  108. cat <<HEREDOC
  109. USAGE: ${PROGRAM} [options]
  110. where options include:
  111. --install <path> Install netdata in <path>. Ex. --install /opt will put netdata in /opt/netdata
  112. --dont-start-it Do not (re)start netdata after installation
  113. --dont-wait Run installation in non-interactive mode
  114. --auto-update or -u Install netdata-updater in cron to update netdata automatically once per day
  115. --stable-channel Use packages from GitHub release pages instead of GCS (nightly updates).
  116. This results in less frequent updates.
  117. --disable-go Disable installation of go.d.plugin.
  118. --enable-plugin-freeipmi Enable the FreeIPMI plugin. Default: enable it when libipmimonitoring is available.
  119. --disable-plugin-freeipmi
  120. --enable-plugin-nfacct Enable nfacct plugin. Default: enable it when libmnl and libnetfilter_acct are available.
  121. --disable-plugin-nfacct
  122. --enable-plugin-xenstat Enable the xenstat plugin. Default: enable it when libxenstat and libyajl are available
  123. --disable-plugin-xenstat Disable the xenstat plugin.
  124. --enable-lto Enable Link-Time-Optimization. Default: enabled
  125. --disable-lto
  126. --disable-x86-sse Disable SSE instructions. By default SSE optimizations are enabled.
  127. --zlib-is-really-here or
  128. --libs-are-really-here If you get errors about missing zlib or libuuid but you know it is available, you might
  129. have a broken pkg-config. Use this option to proceed without checking pkg-config.
  130. --disable-telemetry Use this flag to opt-out from our anonymous telemetry progam.
  131. Netdata will by default be compiled with gcc optimization -O2
  132. If you need to pass different CFLAGS, use something like this:
  133. CFLAGS="<gcc options>" ${PROGRAM} [options]
  134. For the installer to complete successfully, you will need these packages installed:
  135. gcc make autoconf automake pkg-config zlib1g-dev (or zlib-devel) uuid-dev (or libuuid-devel)
  136. For the plugins, you will at least need:
  137. curl, bash v4+, python v2 or v3, node.js
  138. HEREDOC
  139. }
  140. DONOTSTART=0
  141. DONOTWAIT=0
  142. AUTOUPDATE=0
  143. NETDATA_PREFIX=
  144. LIBS_ARE_HERE=0
  145. NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS-}"
  146. RELEASE_CHANNEL="nightly"
  147. while [ -n "${1}" ]; do
  148. case "${1}" in
  149. "--zlib-is-really-here") LIBS_ARE_HERE=1;;
  150. "--libs-are-really-here") LIBS_ARE_HERE=1;;
  151. "--dont-start-it") DONOTSTART=1;;
  152. "--dont-wait") DONOTWAIT=1;;
  153. "--auto-update"|"-u") AUTOUPDATE=1;;
  154. "--stable-channel") RELEASE_CHANNEL="stable";;
  155. "--enable-plugin-freeipmi") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-freeipmi/} --enable-plugin-freeipmi";;
  156. "--disable-plugin-freeipmi") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-plugin-freeipmi/} --disable-plugin-freeipmi";;
  157. "--enable-plugin-nfacct") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-nfacct/} --enable-plugin-nfacct";;
  158. "--disable-plugin-nfacct") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-plugin-nfacct/} --disable-plugin-nfacct";;
  159. "--enable-plugin-xenstat") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-xenstat/} --enable-plugin-xenstat";;
  160. "--disable-plugin-xenstat") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-plugin-xenstat/} --disable-plugin-xenstat";;
  161. "--enable-lto") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-lto/} --enable-lto";;
  162. "--disable-lto") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-lto/} --disable-lto";;
  163. "--disable-x86-sse") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-x86-sse/} --disable-x86-sse";;
  164. "--disable-telemetry") NETDATA_DISABLE_TELEMETRY=1;;
  165. "--disable-go") NETDATA_DISABLE_GO=1;;
  166. "--install")
  167. NETDATA_PREFIX="${2}/netdata"
  168. shift 1
  169. ;;
  170. "--help"|"-h")
  171. usage
  172. exit 1
  173. ;;
  174. *)
  175. run_failed "I cannot understand option '$1'."
  176. usage
  177. exit 1
  178. ;;
  179. esac
  180. shift 1
  181. done
  182. # replace multiple spaces with a single space
  183. NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS// / }"
  184. if [ "${UID}" -ne 0 ]; then
  185. if [ -z "${NETDATA_PREFIX}" ]; then
  186. netdata_banner "wrong command line options!"
  187. banner_nonroot_install "${@}"
  188. exit 1
  189. else
  190. banner_root_notify "${@}"
  191. fi
  192. fi
  193. netdata_banner "real-time performance monitoring, done right!"
  194. cat <<BANNER1
  195. You are about to build and install netdata to your system.
  196. It will be installed at these locations:
  197. - the daemon at ${TPUT_CYAN}${NETDATA_PREFIX}/usr/sbin/netdata${TPUT_RESET}
  198. - config files in ${TPUT_CYAN}${NETDATA_PREFIX}/etc/netdata${TPUT_RESET}
  199. - web files in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/share/netdata${TPUT_RESET}
  200. - plugins in ${TPUT_CYAN}${NETDATA_PREFIX}/usr/libexec/netdata${TPUT_RESET}
  201. - cache files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/cache/netdata${TPUT_RESET}
  202. - db files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/lib/netdata${TPUT_RESET}
  203. - log files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/log/netdata${TPUT_RESET}
  204. BANNER1
  205. [ "${UID}" -eq 0 ] && cat <<BANNER2
  206. - pid file at ${TPUT_CYAN}${NETDATA_PREFIX}/var/run/netdata.pid${TPUT_RESET}
  207. - logrotate file at ${TPUT_CYAN}/etc/logrotate.d/netdata${TPUT_RESET}
  208. BANNER2
  209. cat <<BANNER3
  210. This installer allows you to change the installation path.
  211. Press Control-C and run the same command with --help for help.
  212. BANNER3
  213. have_autotools=
  214. if [ "$(type autoreconf 2>/dev/null)" ]; then
  215. autoconf_maj_min() {
  216. local maj min IFS=.-
  217. maj=$1
  218. min=$2
  219. set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
  220. eval $maj=\$1 $min=\$2
  221. }
  222. autoconf_maj_min AMAJ AMIN
  223. if [ "$AMAJ" -gt 2 ]; then
  224. have_autotools=Y
  225. elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]; then
  226. have_autotools=Y
  227. else
  228. echo "Found autotools $AMAJ.$AMIN"
  229. fi
  230. else
  231. echo "No autotools found"
  232. fi
  233. if [ ! "$have_autotools" ]; then
  234. if [ -f configure ]; then
  235. echo "Will skip autoreconf step"
  236. else
  237. netdata_banner "autotools v2.60 required"
  238. cat <<"EOF"
  239. -------------------------------------------------------------------------------
  240. autotools 2.60 or later is required
  241. Sorry, you do not seem to have autotools 2.60 or later, which is
  242. required to build from the git sources of netdata.
  243. EOF
  244. exit 1
  245. fi
  246. fi
  247. if [ ${DONOTWAIT} -eq 0 ]; then
  248. if [ -n "${NETDATA_PREFIX}" ]; then
  249. echo -n "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to '${TPUT_CYAN}${NETDATA_PREFIX}${TPUT_YELLOW}'${TPUT_RESET} > "
  250. else
  251. echo -n "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to your system${TPUT_RESET} > "
  252. fi
  253. read -ern1
  254. if [ "$REPLY" != '' ]; then
  255. exit 1
  256. fi
  257. fi
  258. build_error() {
  259. netdata_banner "sorry, it failed to build..."
  260. cat <<EOF
  261. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  262. Sorry! netdata failed to build...
  263. You may need to check these:
  264. 1. The package uuid-dev (or libuuid-devel) has to be installed.
  265. If your system cannot find libuuid, although it is installed
  266. run me with the option: --libs-are-really-here
  267. 2. The package zlib1g-dev (or zlib-devel) has to be installed.
  268. If your system cannot find zlib, although it is installed
  269. run me with the option: --libs-are-really-here
  270. 3. You need basic build tools installed, like:
  271. gcc make autoconf automake pkg-config
  272. Autoconf version 2.60 or higher is required.
  273. If you still cannot get it to build, ask for help at github:
  274. https://github.com/netdata/netdata/issues
  275. EOF
  276. trap - EXIT
  277. exit 1
  278. }
  279. if [ ${LIBS_ARE_HERE} -eq 1 ]; then
  280. shift
  281. echo >&2 "ok, assuming libs are really installed."
  282. export ZLIB_CFLAGS=" "
  283. export ZLIB_LIBS="-lz"
  284. export UUID_CFLAGS=" "
  285. export UUID_LIBS="-luuid"
  286. fi
  287. trap build_error EXIT
  288. # -----------------------------------------------------------------------------
  289. echo >&2
  290. progress "Run autotools to configure the build environment"
  291. if [ "$have_autotools" ]; then
  292. run autoreconf -ivf || exit 1
  293. fi
  294. run ./configure \
  295. --prefix="${NETDATA_PREFIX}/usr" \
  296. --sysconfdir="${NETDATA_PREFIX}/etc" \
  297. --localstatedir="${NETDATA_PREFIX}/var" \
  298. --with-zlib \
  299. --with-math \
  300. --with-user=netdata \
  301. ${NETDATA_CONFIGURE_OPTIONS} \
  302. CFLAGS="${CFLAGS}" || exit 1
  303. # remove the build_error hook
  304. trap - EXIT
  305. # -----------------------------------------------------------------------------
  306. progress "Cleanup compilation directory"
  307. run make clean
  308. # -----------------------------------------------------------------------------
  309. progress "Compile netdata"
  310. run make -j$(find_processors) || exit 1
  311. # -----------------------------------------------------------------------------
  312. progress "Migrate configuration files for node.d.plugin and charts.d.plugin"
  313. # migrate existing configuration files
  314. # for node.d and charts.d
  315. if [ -d "${NETDATA_PREFIX}/etc/netdata" ]; then
  316. # the configuration directory exists
  317. if [ ! -d "${NETDATA_PREFIX}/etc/netdata/charts.d" ]; then
  318. run mkdir "${NETDATA_PREFIX}/etc/netdata/charts.d"
  319. fi
  320. # move the charts.d config files
  321. 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
  322. for y in "" ".old" ".orig"; do
  323. if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}" ]; then
  324. run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}"
  325. fi
  326. done
  327. done
  328. if [ ! -d "${NETDATA_PREFIX}/etc/netdata/node.d" ]; then
  329. run mkdir "${NETDATA_PREFIX}/etc/netdata/node.d"
  330. fi
  331. # move the node.d config files
  332. for x in named sma_webbox snmp; do
  333. for y in "" ".old" ".orig"; do
  334. if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}" ]; then
  335. run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}"
  336. fi
  337. done
  338. done
  339. fi
  340. # -----------------------------------------------------------------------------
  341. # shellcheck disable=SC2230
  342. md5sum="$(command -v md5sum 2>/dev/null || command -v md5 2>/dev/null)"
  343. deleted_stock_configs=0
  344. if [ ! -f "${NETDATA_PREFIX}/etc/netdata/.installer-cleanup-of-stock-configs-done" ]; then
  345. progress "Backup existing netdata configuration before installing it"
  346. if [ "${BASH_VERSINFO[0]}" -ge "4" ]; then
  347. declare -A configs_signatures=()
  348. if [ -f "configs.signatures" ]; then
  349. source "configs.signatures" || echo >&2 "ERROR: Failed to load configs.signatures !"
  350. fi
  351. fi
  352. config_signature_matches() {
  353. local md5="${1}" file="${2}"
  354. if [ "${BASH_VERSINFO[0]}" -ge "4" ]; then
  355. [ "${configs_signatures[${md5}]}" = "${file}" ] && return 0
  356. return 1
  357. fi
  358. if [ -f "configs.signatures" ]; then
  359. grep "\['${md5}'\]='${file}'" "configs.signatures" >/dev/null
  360. return $?
  361. fi
  362. return 1
  363. }
  364. # clean up stock config files from the user configuration directory
  365. for x in $(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.*' \)); do
  366. if [ -f "${x}" ]; then
  367. # find it relative filename
  368. f="${x/${NETDATA_PREFIX}\/etc\/netdata\//}"
  369. # find the stock filename
  370. t="${f/.conf.installer_backup.*/.conf}"
  371. t="${t/.conf.old/.conf}"
  372. t="${t/.conf.orig/.conf}"
  373. t="${t/orig\//}"
  374. if [ -z "${md5sum}" -o ! -x "${md5sum}" ]; then
  375. # we don't have md5sum - keep it
  376. echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RET}is not known to distribution${TPUT_RESET}. Keeping it."
  377. else
  378. # find its checksum
  379. md5="$(${md5sum} <"${x}" | cut -d ' ' -f 1)"
  380. if config_signature_matches "${md5}" "${t}"; then
  381. # it is a stock version - remove it
  382. echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' is stock version of '${t}'."
  383. run rm -f "${x}"
  384. deleted_stock_configs=$((deleted_stock_configs + 1))
  385. else
  386. # edited by user - keep it
  387. echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RED} does not match stock of${TPUT_RESET} ${TPUT_CYAN}'${t}'${TPUT_RESET}. Keeping it."
  388. fi
  389. fi
  390. fi
  391. done
  392. fi
  393. touch "${NETDATA_PREFIX}/etc/netdata/.installer-cleanup-of-stock-configs-done"
  394. # -----------------------------------------------------------------------------
  395. progress "Install netdata"
  396. run make install || exit 1
  397. # -----------------------------------------------------------------------------
  398. progress "Fix generated files permissions"
  399. run find ./system/ -type f -a \! -name \*.in -a \! -name Makefile\* -a \! -name \*.conf -a \! -name \*.service -a \! -name \*.logrotate -exec chmod 755 {} \;
  400. # -----------------------------------------------------------------------------
  401. progress "Add user netdata to required user groups"
  402. NETDATA_WANTED_GROUPS="docker nginx varnish haproxy adm nsd proxy squid ceph nobody"
  403. NETDATA_ADDED_TO_GROUPS=""
  404. if [ "${UID}" -eq 0 ]; then
  405. portable_add_group netdata || :
  406. portable_add_user netdata "${NETDATA_PREFIX}/var/lib/netdata" || :
  407. for g in ${NETDATA_WANTED_GROUPS}; do
  408. # shellcheck disable=SC2086
  409. portable_add_user_to_group ${g} netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} ${g}"
  410. done
  411. else
  412. run_failed "The installer does not run as root."
  413. fi
  414. # -----------------------------------------------------------------------------
  415. progress "Install logrotate configuration for netdata"
  416. install_netdata_logrotate
  417. # -----------------------------------------------------------------------------
  418. progress "Read installation options from netdata.conf"
  419. # create an empty config if it does not exist
  420. [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] &&
  421. touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  422. # function to extract values from the config file
  423. config_option() {
  424. local section="${1}" key="${2}" value="${3}"
  425. if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]; then
  426. "${NETDATA_PREFIX}/usr/sbin/netdata" \
  427. -c "${NETDATA_PREFIX}/etc/netdata/netdata.conf" \
  428. -W get "${section}" "${key}" "${value}" ||
  429. echo "${value}"
  430. else
  431. echo "${value}"
  432. fi
  433. }
  434. # the user netdata will run as
  435. if [ "${UID}" = "0" ]; then
  436. NETDATA_USER="$(config_option "global" "run as user" "netdata")"
  437. ROOT_USER="root"
  438. else
  439. NETDATA_USER="${USER}"
  440. ROOT_USER="${NETDATA_USER}"
  441. fi
  442. NETDATA_GROUP="$(id -g -n "${NETDATA_USER}")"
  443. [ -z "${NETDATA_GROUP}" ] && NETDATA_GROUP="${NETDATA_USER}"
  444. # the owners of the web files
  445. NETDATA_WEB_USER="$(config_option "web" "web files owner" "${NETDATA_USER}")"
  446. NETDATA_WEB_GROUP="${NETDATA_GROUP}"
  447. if [ "${UID}" = "0" ] && [ "${NETDATA_USER}" != "${NETDATA_WEB_USER}" ]; then
  448. NETDATA_WEB_GROUP="$(id -g -n "${NETDATA_WEB_USER}")"
  449. [ -z "${NETDATA_WEB_GROUP}" ] && NETDATA_WEB_GROUP="${NETDATA_WEB_USER}"
  450. fi
  451. NETDATA_WEB_GROUP="$(config_option "web" "web files group" "${NETDATA_WEB_GROUP}")"
  452. # port
  453. defport=19999
  454. NETDATA_PORT="$(config_option "web" "default port" ${defport})"
  455. # directories
  456. NETDATA_LIB_DIR="$(config_option "global" "lib directory" "${NETDATA_PREFIX}/var/lib/netdata")"
  457. NETDATA_CACHE_DIR="$(config_option "global" "cache directory" "${NETDATA_PREFIX}/var/cache/netdata")"
  458. NETDATA_WEB_DIR="$(config_option "global" "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web")"
  459. NETDATA_LOG_DIR="$(config_option "global" "log directory" "${NETDATA_PREFIX}/var/log/netdata")"
  460. NETDATA_USER_CONFIG_DIR="$(config_option "global" "config directory" "${NETDATA_PREFIX}/etc/netdata")"
  461. NETDATA_STOCK_CONFIG_DIR="$(config_option "global" "stock config directory" "${NETDATA_PREFIX}/usr/lib/netdata/conf.d")"
  462. NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
  463. cat <<OPTIONSEOF
  464. Permissions
  465. - netdata user : ${NETDATA_USER}
  466. - netdata group : ${NETDATA_GROUP}
  467. - web files user : ${NETDATA_WEB_USER}
  468. - web files group : ${NETDATA_WEB_GROUP}
  469. - root user : ${ROOT_USER}
  470. Directories
  471. - netdata user config dir : ${NETDATA_USER_CONFIG_DIR}
  472. - netdata stock config dir : ${NETDATA_STOCK_CONFIG_DIR}
  473. - netdata log dir : ${NETDATA_LOG_DIR}
  474. - netdata run dir : ${NETDATA_RUN_DIR}
  475. - netdata lib dir : ${NETDATA_LIB_DIR}
  476. - netdata web dir : ${NETDATA_WEB_DIR}
  477. - netdata cache dir : ${NETDATA_CACHE_DIR}
  478. Other
  479. - netdata port : ${NETDATA_PORT}
  480. OPTIONSEOF
  481. # -----------------------------------------------------------------------------
  482. progress "Fix permissions of netdata directories (using user '${NETDATA_USER}')"
  483. if [ ! -d "${NETDATA_RUN_DIR}" ]; then
  484. # this is needed if NETDATA_PREFIX is not empty
  485. run mkdir -p "${NETDATA_RUN_DIR}" || exit 1
  486. fi
  487. # --- conf dir ----
  488. for x in "python.d" "charts.d" "node.d" "health.d" "statsd.d" "go.d"; do
  489. if [ ! -d "${NETDATA_USER_CONFIG_DIR}/${x}" ]; then
  490. echo >&2 "Creating directory '${NETDATA_USER_CONFIG_DIR}/${x}'"
  491. run mkdir -p "${NETDATA_USER_CONFIG_DIR}/${x}" || exit 1
  492. fi
  493. done
  494. run chown -R "${ROOT_USER}:${NETDATA_GROUP}" "${NETDATA_USER_CONFIG_DIR}"
  495. run find "${NETDATA_USER_CONFIG_DIR}" -type f -exec chmod 0640 {} \;
  496. run find "${NETDATA_USER_CONFIG_DIR}" -type d -exec chmod 0755 {} \;
  497. run chmod 755 "${NETDATA_USER_CONFIG_DIR}/edit-config"
  498. # --- stock conf dir ----
  499. [ ! -d "${NETDATA_STOCK_CONFIG_DIR}" ] && mkdir -p "${NETDATA_STOCK_CONFIG_DIR}"
  500. helplink="000.-.USE.THE.orig.LINK.TO.COPY.AND.EDIT.STOCK.CONFIG.FILES"
  501. [ ${deleted_stock_configs} -eq 0 ] && helplink=""
  502. for link in "orig" "${helplink}"; do
  503. if [ ! -z "${link}" ]; then
  504. [ -L "${NETDATA_USER_CONFIG_DIR}/${link}" ] && run rm -f "${NETDATA_USER_CONFIG_DIR}/${link}"
  505. run ln -s "${NETDATA_STOCK_CONFIG_DIR}" "${NETDATA_USER_CONFIG_DIR}/${link}"
  506. fi
  507. done
  508. run chown -R "${ROOT_USER}:${NETDATA_GROUP}" "${NETDATA_STOCK_CONFIG_DIR}"
  509. run find "${NETDATA_STOCK_CONFIG_DIR}" -type f -exec chmod 0640 {} \;
  510. run find "${NETDATA_STOCK_CONFIG_DIR}" -type d -exec chmod 0755 {} \;
  511. # --- web dir ----
  512. if [ ! -d "${NETDATA_WEB_DIR}" ]; then
  513. echo >&2 "Creating directory '${NETDATA_WEB_DIR}'"
  514. run mkdir -p "${NETDATA_WEB_DIR}" || exit 1
  515. fi
  516. run chown -R "${NETDATA_WEB_USER}:${NETDATA_WEB_GROUP}" "${NETDATA_WEB_DIR}"
  517. run find "${NETDATA_WEB_DIR}" -type f -exec chmod 0664 {} \;
  518. run find "${NETDATA_WEB_DIR}" -type d -exec chmod 0775 {} \;
  519. # --- data dirs ----
  520. for x in "${NETDATA_LIB_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}"; do
  521. if [ ! -d "${x}" ]; then
  522. echo >&2 "Creating directory '${x}'"
  523. run mkdir -p "${x}" || exit 1
  524. fi
  525. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${x}"
  526. #run find "${x}" -type f -exec chmod 0660 {} \;
  527. #run find "${x}" -type d -exec chmod 0770 {} \;
  528. done
  529. run chmod 755 "${NETDATA_LOG_DIR}"
  530. # --- plugins ----
  531. if [ "${UID}" -eq 0 ]; then
  532. # find the admin group
  533. admin_group=
  534. test -z "${admin_group}" && getent group root >/dev/null 2>&1 && admin_group="root"
  535. test -z "${admin_group}" && getent group daemon >/dev/null 2>&1 && admin_group="daemon"
  536. test -z "${admin_group}" && admin_group="${NETDATA_GROUP}"
  537. run chown "${NETDATA_USER}:${admin_group}" "${NETDATA_LOG_DIR}"
  538. run chown -R "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata"
  539. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
  540. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
  541. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0750 {} \;
  542. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
  543. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
  544. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  545. capabilities=0
  546. if ! iscontainer && command -v setcap 1>/dev/null 2>&1; then
  547. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  548. if run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"; then
  549. # if we managed to setcap, but we fail to execute apps.plugin setuid to root
  550. "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" -t >/dev/null 2>&1 && capabilities=1 || capabilities=0
  551. fi
  552. fi
  553. if [ $capabilities -eq 0 ]; then
  554. # fix apps.plugin to be setuid to root
  555. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
  556. fi
  557. fi
  558. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin" ]; then
  559. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
  560. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/freeipmi.plugin"
  561. fi
  562. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin" ]; then
  563. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
  564. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/nfacct.plugin"
  565. fi
  566. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin" ]; then
  567. run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
  568. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
  569. fi
  570. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping" ]; then
  571. run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
  572. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
  573. fi
  574. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network" ]; then
  575. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
  576. run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network"
  577. fi
  578. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh" ]; then
  579. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
  580. run chmod 0550 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/cgroup-network-helper.sh"
  581. fi
  582. else
  583. # non-privileged user installation
  584. run chown "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_LOG_DIR}"
  585. run chown -R "${NETDATA_USER}:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata"
  586. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0755 {} \;
  587. run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
  588. fi
  589. # -----------------------------------------------------------------------------
  590. install_go() {
  591. # When updating this value, ensure correct checksums in packaging/go.d.checksums
  592. GO_PACKAGE_VERSION="v0.4.0"
  593. ARCH_MAP=(
  594. 'i386::386'
  595. 'i686::386'
  596. 'x86_64::amd64'
  597. 'aarch64::arm64'
  598. 'armv64::arm64'
  599. 'armv6l::arm'
  600. 'armv7l::arm'
  601. 'armv5tel::arm'
  602. )
  603. if [ -z "${NETDATA_DISABLE_GO+x}" ]; then
  604. progress "Install go.d.plugin"
  605. ARCH=$(uname -m)
  606. OS=$(uname -s | tr '[:upper:]' '[:lower:]')
  607. for index in "${ARCH_MAP[@]}" ; do
  608. KEY="${index%%::*}"
  609. VALUE="${index##*::}"
  610. if [ "$KEY" == "$ARCH" ]; then
  611. ARCH="${VALUE}"
  612. break
  613. fi
  614. done
  615. tmp=$(mktemp -d /tmp/netdata-go-XXXXXX)
  616. GO_PACKAGE_BASENAME="go.d.plugin-$GO_PACKAGE_VERSION.$OS-$ARCH"
  617. download "https://github.com/netdata/go.d.plugin/releases/download/$GO_PACKAGE_VERSION/$GO_PACKAGE_BASENAME" "${tmp}/$GO_PACKAGE_BASENAME"
  618. download "https://github.com/netdata/go.d.plugin/releases/download/$GO_PACKAGE_VERSION/config.tar.gz" "${tmp}/config.tar.gz"
  619. grep "${GO_PACKAGE_BASENAME}\$" "${INSTALLER_DIR}/packaging/go.d.checksums" > "${tmp}/sha256sums.txt" 2>/dev/null
  620. grep "config.tar.gz" "${INSTALLER_DIR}/packaging/go.d.checksums" >> "${tmp}/sha256sums.txt" 2>/dev/null
  621. # Checksum validation
  622. if ! (cd "${tmp}" && safe_sha256sum -c "sha256sums.txt"); then
  623. run_failed "go.d.plugin package files checksum validation failed."
  624. return 1
  625. fi
  626. # Install new files
  627. run rm -rf "${NETDATA_STOCK_CONFIG_DIR}/go.d"
  628. run rm -rf "${NETDATA_STOCK_CONFIG_DIR}/go.d.conf"
  629. run tar -xf "${tmp}/config.tar.gz" -C "${NETDATA_STOCK_CONFIG_DIR}/"
  630. run chown -R "${ROOT_USER}:${NETDATA_GROUP}" "${NETDATA_STOCK_CONFIG_DIR}"
  631. run mv "${tmp}/$GO_PACKAGE_BASENAME" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  632. if [ "${UID}" -eq 0 ]; then
  633. run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  634. fi
  635. run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
  636. fi
  637. return 0
  638. }
  639. install_go
  640. # -----------------------------------------------------------------------------
  641. progress "Install netdata at system init"
  642. NETDATA_START_CMD="${NETDATA_PREFIX}/usr/sbin/netdata"
  643. install_netdata_service || run_failed "Cannot install netdata init service."
  644. # -----------------------------------------------------------------------------
  645. # check if we can re-start netdata
  646. # TODO(paulfantom): Creation of configuration file should be handled by a build system. Additionally we shouldn't touch configuration files in /etc/netdata/...
  647. started=0
  648. if [ ${DONOTSTART} -eq 1 ]; then
  649. create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  650. else
  651. if ! restart_netdata "${NETDATA_PREFIX}/usr/sbin/netdata" "${@}"; then
  652. fatal "Cannot start netdata!"
  653. fi
  654. started=1
  655. run_ok "netdata started!"
  656. create_netdata_conf "${NETDATA_PREFIX}/etc/netdata/netdata.conf" "http://localhost:${NETDATA_PORT}/netdata.conf"
  657. fi
  658. if [ "${UID}" -eq 0 ]; then
  659. run chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  660. fi
  661. run chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
  662. if [ "$(uname)" = "Linux" ]; then
  663. # -------------------------------------------------------------------------
  664. progress "Check KSM (kernel memory deduper)"
  665. ksm_is_available_but_disabled() {
  666. cat <<KSM1
  667. ${TPUT_BOLD}Memory de-duplication instructions${TPUT_RESET}
  668. You have kernel memory de-duper (called Kernel Same-page Merging,
  669. or KSM) available, but it is not currently enabled.
  670. To enable it run:
  671. ${TPUT_YELLOW}${TPUT_BOLD}echo 1 >/sys/kernel/mm/ksm/run${TPUT_RESET}
  672. ${TPUT_YELLOW}${TPUT_BOLD}echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs${TPUT_RESET}
  673. If you enable it, you will save 40-60% of netdata memory.
  674. KSM1
  675. }
  676. ksm_is_not_available() {
  677. cat <<KSM2
  678. ${TPUT_BOLD}Memory de-duplication not present in your kernel${TPUT_RESET}
  679. It seems you do not have kernel memory de-duper (called Kernel Same-page
  680. Merging, or KSM) available.
  681. To enable it, you need a kernel built with CONFIG_KSM=y
  682. If you can have it, you will save 40-60% of netdata memory.
  683. KSM2
  684. }
  685. if [ -f "/sys/kernel/mm/ksm/run" ]; then
  686. if [ "$(cat "/sys/kernel/mm/ksm/run")" != "1" ]; then
  687. ksm_is_available_but_disabled
  688. fi
  689. else
  690. ksm_is_not_available
  691. fi
  692. fi
  693. # -----------------------------------------------------------------------------
  694. progress "Check version.txt"
  695. if [ ! -s web/gui/version.txt ]; then
  696. cat <<VERMSG
  697. ${TPUT_BOLD}Version update check warning${TPUT_RESET}
  698. The way you downloaded netdata, we cannot find its version. This means the
  699. Update check on the dashboard, will not work.
  700. If you want to have version update check, please re-install it
  701. following the procedure in:
  702. https://docs.netdata.cloud/packaging/installer/
  703. VERMSG
  704. fi
  705. if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
  706. # -----------------------------------------------------------------------------
  707. progress "Check apps.plugin"
  708. if [ "${UID}" -ne 0 ]; then
  709. cat <<SETUID_WARNING
  710. ${TPUT_BOLD}apps.plugin needs privileges${TPUT_RESET}
  711. Since you have installed netdata as a normal user, to have apps.plugin collect
  712. all the needed data, you have to give it the access rights it needs, by running
  713. either of the following sets of commands:
  714. To run apps.plugin with escalated capabilities:
  715. ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
  716. ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 0750 \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
  717. ${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}
  718. or, to run apps.plugin as root:
  719. ${TPUT_YELLOW}${TPUT_BOLD}sudo chown root:${NETDATA_GROUP} \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
  720. ${TPUT_YELLOW}${TPUT_BOLD}sudo chmod 4750 \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin\"${TPUT_RESET}
  721. apps.plugin is performing a hard-coded function of data collection for all
  722. running processes. It cannot be instructed from the netdata daemon to perform
  723. any task, so it is pretty safe to do this.
  724. SETUID_WARNING
  725. fi
  726. fi
  727. # -----------------------------------------------------------------------------
  728. progress "Copy uninstaller"
  729. sed "s|ENVIRONMENT_FILE=\"/etc/netdata/.environment\"|ENVIRONMENT_FILE=\"${NETDATA_PREFIX}/etc/netdata/.environment\"|" packaging/installer/netdata-uninstaller.sh > ${NETDATA_PREFIX}/usr/libexec/netdata-uninstaller.sh
  730. chmod 750 ${NETDATA_PREFIX}/usr/libexec/netdata-uninstaller.sh
  731. # -----------------------------------------------------------------------------
  732. progress "Basic netdata instructions"
  733. cat <<END
  734. netdata by default listens on all IPs on port ${NETDATA_PORT},
  735. so you can access it with:
  736. ${TPUT_CYAN}${TPUT_BOLD}http://this.machine.ip:${NETDATA_PORT}/${TPUT_RESET}
  737. To stop netdata run:
  738. ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_STOP_CMD}${TPUT_RESET}
  739. To start netdata run:
  740. ${TPUT_YELLOW}${TPUT_BOLD}${NETDATA_START_CMD}${TPUT_RESET}
  741. END
  742. echo >&2 "Uninstall script copied to: ${TPUT_RED}${TPUT_BOLD}${NETDATA_PREFIX}/usr/libexec/netdata-uninstaller.sh${TPUT_RESET}"
  743. if [ "${AUTOUPDATE}" = "1" ]; then
  744. if [ "${UID}" -ne "0" ]; then
  745. echo >&2 "You need to run the installer as root for auto-updating via cron."
  746. else
  747. crondir=
  748. [ -d "/etc/periodic/daily" ] && crondir="/etc/periodic/daily"
  749. [ -d "/etc/cron.daily" ] && crondir="/etc/cron.daily"
  750. if [ -z "${crondir}" ]; then
  751. echo >&2 "Cannot figure out the cron directory to install netdata-updater"
  752. else
  753. if [ -f "${crondir}/netdata-updater.sh" ]; then
  754. progress "Removing incorrect netdata-updater filename in cron"
  755. rm -f "${crondir}/netdata-updater.sh"
  756. fi
  757. progress "Installing new netdata-updater in cron"
  758. rm -f "${crondir}/netdata-updater"
  759. if [ -f "${INSTALLER_DIR}/packaging/installer/netdata-updater.sh" ]; then
  760. sed "s|THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT|${NETDATA_USER_CONFIG_DIR}/.environment|" "${INSTALLER_DIR}/packaging/installer/netdata-updater.sh" > "${crondir}/netdata-updater" || exit 1
  761. else
  762. sed "s|THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT|${NETDATA_USER_CONFIG_DIR}/.environment|" "${NETDATA_SOURCE_DIR}/packaging/installer/netdata-updater.sh" > "${crondir}/netdata-updater" || exit 1
  763. fi
  764. chmod 0755 ${crondir}/netdata-updater
  765. echo >&2 "Update script is located at ${TPUT_GREEN}${TPUT_BOLD}${crondir}/netdata-updater${TPUT_RESET}"
  766. echo >&2
  767. echo >&2 "${TPUT_DIM}${TPUT_BOLD}netdata-updater${TPUT_RESET}${TPUT_DIM} works from cron. It will trigger an email from cron"
  768. echo >&2 "only if it fails (it should not print anything when it can update netdata).${TPUT_RESET}"
  769. fi
  770. fi
  771. fi
  772. # Save environment variables
  773. cat <<EOF > "${NETDATA_USER_CONFIG_DIR}/.environment"
  774. # Created by installer
  775. PATH="${PATH}"
  776. CFLAGS="${CFLAGS}"
  777. NETDATA_PREFIX="${NETDATA_PREFIX}"
  778. NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS}"
  779. NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS}"
  780. INSTALL_UID="${UID}"
  781. NETDATA_GROUP="${NETDATA_GROUP}"
  782. REINSTALL_COMMAND="${REINSTALL_COMMAND}"
  783. RELEASE_CHANNEL="${RELEASE_CHANNEL}"
  784. # This value is meant to be populated by autoupdater (if enabled)
  785. NETDATA_TARBALL_CHECKSUM="new_installation"
  786. EOF
  787. # Opt-out from telemetry program
  788. if [ -n "${NETDATA_DISABLE_TELEMETRY+x}" ]; then
  789. touch "${NETDATA_USER_CONFIG_DIR}/.opt-out-from-anonymous-statistics"
  790. fi
  791. # -----------------------------------------------------------------------------
  792. echo >&2
  793. progress "We are done!"
  794. if [ ${started} -eq 1 ]; then
  795. netdata_banner "is installed and running now!"
  796. else
  797. netdata_banner "is installed now!"
  798. fi
  799. echo >&2 " enjoy real-time performance and health monitoring..."
  800. echo >&2
  801. exit 0