functions.sh 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-3.0-or-later
  3. # next unused error code: L0003
  4. # make sure we have a UID
  5. [ -z "${UID}" ] && UID="$(id -u)"
  6. # -----------------------------------------------------------------------------
  7. setup_terminal() {
  8. TPUT_RESET=""
  9. TPUT_BLACK=""
  10. TPUT_RED=""
  11. TPUT_GREEN=""
  12. TPUT_YELLOW=""
  13. TPUT_BLUE=""
  14. TPUT_PURPLE=""
  15. TPUT_CYAN=""
  16. TPUT_WHITE=""
  17. TPUT_BGBLACK=""
  18. TPUT_BGRED=""
  19. TPUT_BGGREEN=""
  20. TPUT_BGYELLOW=""
  21. TPUT_BGBLUE=""
  22. TPUT_BGPURPLE=""
  23. TPUT_BGCYAN=""
  24. TPUT_BGWHITE=""
  25. TPUT_BOLD=""
  26. TPUT_DIM=""
  27. TPUT_UNDERLINED=""
  28. TPUT_BLINK=""
  29. TPUT_INVERTED=""
  30. TPUT_STANDOUT=""
  31. TPUT_BELL=""
  32. TPUT_CLEAR=""
  33. # Is stderr on the terminal? If not, then fail
  34. test -t 2 || return 1
  35. if command -v tput 1> /dev/null 2>&1; then
  36. if [ $(($(tput colors 2> /dev/null))) -ge 8 ]; then
  37. # Enable colors
  38. TPUT_RESET="$(tput sgr 0)"
  39. # shellcheck disable=SC2034
  40. TPUT_BLACK="$(tput setaf 0)"
  41. # shellcheck disable=SC2034
  42. TPUT_RED="$(tput setaf 1)"
  43. TPUT_GREEN="$(tput setaf 2)"
  44. # shellcheck disable=SC2034
  45. TPUT_YELLOW="$(tput setaf 3)"
  46. # shellcheck disable=SC2034
  47. TPUT_BLUE="$(tput setaf 4)"
  48. # shellcheck disable=SC2034
  49. TPUT_PURPLE="$(tput setaf 5)"
  50. # shellcheck disable=SC2034
  51. TPUT_CYAN="$(tput setaf 6)"
  52. TPUT_WHITE="$(tput setaf 7)"
  53. # shellcheck disable=SC2034
  54. TPUT_BGBLACK="$(tput setab 0)"
  55. TPUT_BGRED="$(tput setab 1)"
  56. TPUT_BGGREEN="$(tput setab 2)"
  57. # shellcheck disable=SC2034
  58. TPUT_BGYELLOW="$(tput setab 3)"
  59. # shellcheck disable=SC2034
  60. TPUT_BGBLUE="$(tput setab 4)"
  61. # shellcheck disable=SC2034
  62. TPUT_BGPURPLE="$(tput setab 5)"
  63. # shellcheck disable=SC2034
  64. TPUT_BGCYAN="$(tput setab 6)"
  65. # shellcheck disable=SC2034
  66. TPUT_BGWHITE="$(tput setab 7)"
  67. TPUT_BOLD="$(tput bold)"
  68. TPUT_DIM="$(tput dim)"
  69. # shellcheck disable=SC2034
  70. TPUT_UNDERLINED="$(tput smul)"
  71. # shellcheck disable=SC2034
  72. TPUT_BLINK="$(tput blink)"
  73. # shellcheck disable=SC2034
  74. TPUT_INVERTED="$(tput rev)"
  75. # shellcheck disable=SC2034
  76. TPUT_STANDOUT="$(tput smso)"
  77. # shellcheck disable=SC2034
  78. TPUT_BELL="$(tput bel)"
  79. # shellcheck disable=SC2034
  80. TPUT_CLEAR="$(tput clear)"
  81. fi
  82. fi
  83. return 0
  84. }
  85. setup_terminal || echo > /dev/null
  86. progress() {
  87. echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "
  88. }
  89. check_for_curl() {
  90. if [ -z "${curl}" ]; then
  91. curl="$(PATH="${PATH}:/opt/netdata/bin" command -v curl 2>/dev/null && true)"
  92. fi
  93. }
  94. get() {
  95. url="${1}"
  96. checked=0
  97. succeeded=0
  98. check_for_curl
  99. if [ -n "${curl}" ]; then
  100. checked=1
  101. if "${curl}" -q -o - -sSL --connect-timeout 10 --retry 3 "${url}"; then
  102. succeeded=1
  103. fi
  104. fi
  105. if [ "${succeeded}" -eq 0 ]; then
  106. if command -v wget > /dev/null 2>&1; then
  107. checked=1
  108. if wget -T 15 -O - "${url}"; then
  109. succeeded=1
  110. fi
  111. fi
  112. fi
  113. if [ "${succeeded}" -eq 1 ]; then
  114. return 0
  115. elif [ "${checked}" -eq 1 ]; then
  116. return 1
  117. else
  118. fatal "I need curl or wget to proceed, but neither is available on this system." "L0002"
  119. fi
  120. }
  121. download_file() {
  122. url="${1}"
  123. dest="${2}"
  124. name="${3}"
  125. opt="${4}"
  126. check_for_curl
  127. if [ -n "${curl}" ]; then
  128. checked=1
  129. if run "${curl}" -q -sSL --connect-timeout 10 --retry 3 --output "${dest}" "${url}"; then
  130. succeeded=1
  131. else
  132. rm -f "${dest}"
  133. fi
  134. fi
  135. if [ "${succeeded}" -eq 0 ]; then
  136. if command -v wget > /dev/null 2>&1; then
  137. checked=1
  138. if run wget -T 15 -O "${dest}" "${url}"; then
  139. succeeded=1
  140. fi
  141. fi
  142. fi
  143. if [ "${succeeded}" -eq 1 ]; then
  144. return 0
  145. elif [ "${checked}" -eq 1 ]; then
  146. return 1
  147. else
  148. echo >&2
  149. echo >&2 "Downloading ${name} from '${url}' failed because of missing mandatory packages."
  150. if [ -n "$opt" ]; then
  151. echo >&2 "Either add packages or disable it by issuing '--disable-${opt}' in the installer"
  152. fi
  153. echo >&2
  154. run_failed "I need curl or wget to proceed, but neither is available on this system."
  155. fi
  156. }
  157. # -----------------------------------------------------------------------------
  158. # external component handling
  159. fetch_and_verify() {
  160. component="${1}"
  161. url="${2}"
  162. base_name="${3}"
  163. tmp="${4}"
  164. override="${5}"
  165. if [ -z "${override}" ]; then
  166. download_file "${url}" "${tmp}/${base_name}" "${component}"
  167. else
  168. progress "Using provided ${component} archive ${override}"
  169. run cp "${override}" "${tmp}/${base_name}"
  170. fi
  171. if [ ! -f "${tmp}/${base_name}" ] || [ ! -s "${tmp}/${base_name}" ]; then
  172. run_failed "Unable to find usable archive for ${component}"
  173. return 1
  174. fi
  175. grep "${base_name}\$" "${INSTALLER_DIR}/packaging/${component}.checksums" > "${tmp}/sha256sums.txt" 2> /dev/null
  176. # Checksum validation
  177. if ! (cd "${tmp}" && safe_sha256sum -c "sha256sums.txt"); then
  178. run_failed "${component} files checksum validation failed."
  179. return 1
  180. fi
  181. }
  182. # -----------------------------------------------------------------------------
  183. netdata_banner() {
  184. l1=" ^" \
  185. l2=" |.-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-" \
  186. l4=" +----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--->" \
  187. space=" "
  188. l3f=" | '-' '-' '-' '-' '-'"
  189. l3e=" '-' '-' '-' '-' '-' "
  190. netdata="netdata"
  191. chartcolor="${TPUT_DIM}"
  192. echo >&2
  193. echo >&2 "${chartcolor}${l1}${TPUT_RESET}"
  194. echo >&2 "${chartcolor}${l2%-. .-. .-. .-. .-. .-. .-. .-}${space}${TPUT_RESET}${TPUT_BOLD}${TPUT_GREEN}${netdata}${TPUT_RESET}${chartcolor}${l2# |.-. .-. .-. .-. .-. .-. .-. }${TPUT_RESET}"
  195. echo >&2 "${chartcolor}${l3f}${l3e}${TPUT_RESET}"
  196. echo >&2 "${chartcolor}${l4}${TPUT_RESET}"
  197. echo >&2
  198. }
  199. # -----------------------------------------------------------------------------
  200. # Feature management and configuration commands
  201. enable_feature() {
  202. NETDATA_CMAKE_OPTIONS="$(echo "${NETDATA_CMAKE_OPTIONS}" | sed -e "s/-DENABLE_${1}=Off[[:space:]]*//g" -e "s/-DENABLE_${1}=On[[:space:]]*//g")"
  203. if [ "${2}" -eq 1 ]; then
  204. NETDATA_CMAKE_OPTIONS="$(echo "${NETDATA_CMAKE_OPTIONS}" | sed "s/$/ -DENABLE_${1}=On/")"
  205. else
  206. NETDATA_CMAKE_OPTIONS="$(echo "${NETDATA_CMAKE_OPTIONS}" | sed "s/$/ -DENABLE_${1}=Off/")"
  207. fi
  208. }
  209. check_for_module() {
  210. if [ -z "${pkgconf}" ]; then
  211. pkgconf="$(command -v pkgconf 2>/dev/null)"
  212. [ -z "${pkgconf}" ] && pkgconf="$(command -v pkg-config 2>/dev/null)"
  213. [ -z "${pkgconf}" ] && fatal "Unable to find a usable pkgconf/pkg-config command, cannot build Netdata." I0013
  214. fi
  215. "${pkgconf}" "${1}"
  216. return "${?}"
  217. }
  218. check_for_feature() {
  219. feature_name="${1}"
  220. feature_state="${2}"
  221. shift 2
  222. feature_modules="${*}"
  223. if [ -z "${feature_state}" ]; then
  224. # shellcheck disable=SC2086
  225. if check_for_module ${feature_modules}; then
  226. enable_feature "${feature_name}" 1
  227. else
  228. enable_feature "${feature_name}" 0
  229. fi
  230. else
  231. enable_feature "${feature_name}" "${feature_state}"
  232. fi
  233. }
  234. prepare_cmake_options() {
  235. NETDATA_CMAKE_OPTIONS="-S ./ -B ${NETDATA_BUILD_DIR} ${CMAKE_OPTS} ${NETDATA_PREFIX+-DCMAKE_INSTALL_PREFIX="${NETDATA_PREFIX}"} ${NETDATA_USER:+-DNETDATA_USER=${NETDATA_USER}} ${NETDATA_CMAKE_OPTIONS} "
  236. NEED_OLD_CXX=0
  237. if [ "${FORCE_LEGACY_CXX:-0}" -eq 1 ]; then
  238. NEED_OLD_CXX=1
  239. else
  240. if command -v gcc >/dev/null 2>&1; then
  241. if [ "$(gcc --version | head -n 1 | sed 's/(.*) //' | cut -f 2 -d ' ' | cut -f 1 -d '.')" -lt 5 ]; then
  242. NEED_OLD_CXX=1
  243. fi
  244. fi
  245. if command -v clang >/dev/null 2>&1; then
  246. if [ "$(clang --version | head -n 1 | cut -f 3 -d ' ' | cut -f 1 -d '.')" -lt 4 ]; then
  247. NEED_OLD_CXX=1
  248. fi
  249. fi
  250. fi
  251. if [ "${NEED_OLD_CXX}" -eq 1 ]; then
  252. NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS} -DUSE_CXX_11=On"
  253. fi
  254. if [ -n "${NETDATA_ENABLE_LTO}" ]; then
  255. if [ "${NETDATA_ENABLE_LTO}" -eq 1 ]; then
  256. NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS} -DDISABLE_LTO=Off"
  257. else
  258. NETDATA_CMAKE_OPTIONS="${NETDATA_CMAKE_OPTIONS} -DDISABLE_LTO=On"
  259. fi
  260. fi
  261. if [ "${ENABLE_GO:-1}" -eq 1 ]; then
  262. enable_feature PLUGIN_GO 1
  263. else
  264. enable_feature PLUGIN_GO 0
  265. fi
  266. if [ "${ENABLE_PYTHON:-1}" -eq 1 ]; then
  267. enable_feature PLUGIN_PYTHON 1
  268. else
  269. enable_feature PLUGIN_PYTHON 0
  270. fi
  271. if [ "${ENABLE_CHARTS:-1}" -eq 1 ]; then
  272. enable_feature PLUGIN_CHARTS 1
  273. else
  274. enable_feature PLUGIN_CHARTS 0
  275. fi
  276. if [ "${USE_SYSTEM_PROTOBUF:-0}" -eq 1 ]; then
  277. enable_feature BUNDLED_PROTOBUF 0
  278. else
  279. enable_feature BUNDLED_PROTOBUF 1
  280. fi
  281. if [ -z "${ENABLE_SYSTEMD_JOURNAL}" ]; then
  282. if check_for_module libsystemd; then
  283. if check_for_module libelogind; then
  284. ENABLE_SYSTEMD_JOURNAL=0
  285. else
  286. ENABLE_SYSTEMD_JOURNAL=1
  287. fi
  288. else
  289. ENABLE_SYSTEMD_JOURNAL=0
  290. fi
  291. fi
  292. enable_feature PLUGIN_SYSTEMD_JOURNAL "${ENABLE_SYSTEMD_JOURNAL}"
  293. if command -v cups-config >/dev/null 2>&1 || check_for_module libcups || check_for_module cups; then
  294. ENABLE_CUPS=1
  295. else
  296. ENABLE_CUPS=0
  297. fi
  298. enable_feature PLUGIN_CUPS "${ENABLE_CUPS}"
  299. IS_LINUX=0
  300. [ "$(uname -s)" = "Linux" ] && IS_LINUX=1
  301. enable_feature PLUGIN_DEBUGFS "${IS_LINUX}"
  302. enable_feature PLUGIN_PERF "${IS_LINUX}"
  303. enable_feature PLUGIN_SLABINFO "${IS_LINUX}"
  304. enable_feature PLUGIN_CGROUP_NETWORK "${IS_LINUX}"
  305. enable_feature PLUGIN_LOCAL_LISTENERS "${IS_LINUX}"
  306. enable_feature PLUGIN_NETWORK_VIEWER "${IS_LINUX}"
  307. enable_feature PLUGIN_EBPF "${ENABLE_EBPF:-0}"
  308. enable_feature BUNDLED_JSONC "${NETDATA_BUILD_JSON_C:-0}"
  309. enable_feature DBENGINE "${ENABLE_DBENGINE:-1}"
  310. enable_feature H2O "${ENABLE_H2O:-0}"
  311. enable_feature ML "${NETDATA_ENABLE_ML:-1}"
  312. enable_feature PLUGIN_APPS "${ENABLE_APPS:-1}"
  313. check_for_feature EXPORTER_PROMETHEUS_REMOTE_WRITE "${EXPORTER_PROMETHEUS}" snappy
  314. check_for_feature EXPORTER_MONGODB "${EXPORTER_MONGODB}" libmongoc-1.0
  315. check_for_feature PLUGIN_FREEIPMI "${ENABLE_FREEIPMI}" libipmimonitoring
  316. check_for_feature PLUGIN_NFACCT "${ENABLE_NFACCT}" libnetfilter_acct libnml
  317. check_for_feature PLUGIN_XENSTAT "${ENABLE_XENSTAT}" xenstat xenlight
  318. }
  319. # -----------------------------------------------------------------------------
  320. # portable service command
  321. service_cmd="$(command -v service 2> /dev/null || true)"
  322. rcservice_cmd="$(command -v rc-service 2> /dev/null || true)"
  323. systemctl_cmd="$(command -v systemctl 2> /dev/null || true)"
  324. service() {
  325. cmd="${1}"
  326. action="${2}"
  327. if [ -n "${systemctl_cmd}" ]; then
  328. run "${systemctl_cmd}" "${action}" "${cmd}"
  329. return $?
  330. elif [ -n "${service_cmd}" ]; then
  331. run "${service_cmd}" "${cmd}" "${action}"
  332. return $?
  333. elif [ -n "${rcservice_cmd}" ]; then
  334. run "${rcservice_cmd}" "${cmd}" "${action}"
  335. return $?
  336. fi
  337. return 1
  338. }
  339. # -----------------------------------------------------------------------------
  340. # portable pidof
  341. safe_pidof() {
  342. pidof_cmd="$(command -v pidof 2> /dev/null)"
  343. if [ -n "${pidof_cmd}" ]; then
  344. ${pidof_cmd} "${@}"
  345. return $?
  346. else
  347. ps -acxo pid,comm |
  348. sed "s/^ *//g" |
  349. grep netdata |
  350. cut -d ' ' -f 1
  351. return $?
  352. fi
  353. }
  354. # -----------------------------------------------------------------------------
  355. find_processors() {
  356. # Most UNIX systems have `nproc` as part of their userland (including Linux and BSD)
  357. if command -v nproc > /dev/null; then
  358. nproc && return
  359. fi
  360. # macOS has no nproc but it may have gnproc installed from Homebrew or from Macports.
  361. if command -v gnproc > /dev/null; then
  362. gnproc && return
  363. fi
  364. if [ -f "/proc/cpuinfo" ]; then
  365. # linux
  366. cpus=$(grep -c ^processor /proc/cpuinfo)
  367. else
  368. # freebsd
  369. cpus=$(sysctl hw.ncpu 2> /dev/null | grep ^hw.ncpu | cut -d ' ' -f 2)
  370. fi
  371. if [ -z "${cpus}" ] || [ $((cpus)) -lt 1 ]; then
  372. echo 1
  373. else
  374. echo "${cpus}"
  375. fi
  376. }
  377. # -----------------------------------------------------------------------------
  378. exit_reason() {
  379. if [ -n "${NETDATA_SAVE_WARNINGS}" ]; then
  380. EXIT_REASON="${1}"
  381. EXIT_CODE="${2}"
  382. if [ -n "${NETDATA_PROPAGATE_WARNINGS}" ]; then
  383. if [ -n "${NETDATA_SCRIPT_STATUS_PATH}" ]; then
  384. {
  385. echo "EXIT_REASON=\"${EXIT_REASON}\""
  386. echo "EXIT_CODE=\"${EXIT_CODE}\""
  387. echo "NETDATA_WARNINGS=\"${NETDATA_WARNINGS}${SAVED_WARNINGS}\""
  388. } >> "${NETDATA_SCRIPT_STATUS_PATH}"
  389. else
  390. export EXIT_REASON
  391. export EXIT_CODE
  392. export NETDATA_WARNINGS="${NETDATA_WARNINGS}${SAVED_WARNINGS}"
  393. fi
  394. fi
  395. fi
  396. }
  397. fatal() {
  398. printf >&2 "%s ABORTED %s %s \n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}" "${1}"
  399. if [ -n "${NETDATA_SAVE_WARNINGS}" ]; then
  400. SAVED_WARNINGS="${SAVED_WARNINGS}\n - ${1}"
  401. fi
  402. exit_reason "${1}" "${2}"
  403. exit 1
  404. }
  405. warning() {
  406. printf >&2 "%s WARNING %s %s\n\n" "${TPUT_BGYELLOW}${TPUT_BLACK}${TPUT_BOLD}" "${TPUT_RESET}" "${1}"
  407. if [ -n "${NETDATA_SAVE_WARNINGS}" ]; then
  408. SAVED_WARNINGS="${SAVED_WARNINGS}\n - ${1}"
  409. fi
  410. }
  411. run_ok() {
  412. printf >&2 "%s OK %s %s\n\n" "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}" "${1:-''}"
  413. }
  414. run_failed() {
  415. printf >&2 "%s FAILED %s %s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}" "${1:-''}"
  416. if [ -n "${NETDATA_SAVE_WARNINGS}" ] && [ -n "${1:-''}" ]; then
  417. SAVED_WARNINGS="${SAVED_WARNINGS}\n - ${1}"
  418. fi
  419. }
  420. ESCAPED_PRINT_METHOD=
  421. if printf "%s " test > /dev/null 2>&1; then
  422. ESCAPED_PRINT_METHOD="printfq"
  423. fi
  424. escaped_print() {
  425. if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]; then
  426. printf "%s " "${@}"
  427. else
  428. printf "%s" "${*}"
  429. fi
  430. return 0
  431. }
  432. run_logfile="/dev/null"
  433. run() {
  434. local_user="${USER--}"
  435. local_dir="${PWD}"
  436. if [ "${UID}" = "0" ]; then
  437. info="[root ${local_dir}]# "
  438. info_console="[${TPUT_DIM}${local_dir}${TPUT_RESET}]# "
  439. else
  440. info="[${local_user} ${local_dir}]$ "
  441. info_console="[${TPUT_DIM}${local_dir}${TPUT_RESET}]$ "
  442. fi
  443. {
  444. printf "%s" "${info}"
  445. escaped_print "${@}"
  446. printf "%s" " ... "
  447. } >> "${run_logfile}"
  448. printf >&2 "%s" "${info_console}${TPUT_BOLD}${TPUT_YELLOW}"
  449. escaped_print >&2 "${@}"
  450. printf >&2 "%s\n" "${TPUT_RESET}"
  451. "${@}"
  452. ret=$?
  453. if [ ${ret} -ne 0 ]; then
  454. run_failed
  455. printf >> "${run_logfile}" "FAILED with exit code %s\n" "${ret}"
  456. if [ -n "${NETDATA_SAVE_WARNINGS}" ]; then
  457. SAVED_WARNINGS="${SAVED_WARNINGS}\n - Command '${*}' failed with exit code ${ret}."
  458. fi
  459. else
  460. run_ok
  461. printf >> "${run_logfile}" "OK\n"
  462. fi
  463. return ${ret}
  464. }
  465. iscontainer() {
  466. # man systemd-detect-virt
  467. cmd=$(command -v systemd-detect-virt 2> /dev/null)
  468. if [ -n "${cmd}" ] && [ -x "${cmd}" ]; then
  469. "${cmd}" --container > /dev/null 2>&1 && return 0
  470. fi
  471. # /proc/1/sched exposes the host's pid of our init !
  472. # http://stackoverflow.com/a/37016302
  473. pid=$(head -n 1 /proc/1/sched 2> /dev/null | {
  474. # shellcheck disable=SC2034
  475. IFS='(),#:' read -r name pid th threads
  476. echo "$pid"
  477. })
  478. if [ -n "${pid}" ]; then
  479. pid=$((pid + 0))
  480. [ ${pid} -gt 1 ] && return 0
  481. fi
  482. # lxc sets environment variable 'container'
  483. # shellcheck disable=SC2154
  484. [ -n "${container}" ] && return 0
  485. # docker creates /.dockerenv
  486. # http://stackoverflow.com/a/25518345
  487. [ -f "/.dockerenv" ] && return 0
  488. # ubuntu and debian supply /bin/running-in-container
  489. # https://www.apt-browse.org/browse/ubuntu/trusty/main/i386/upstart/1.12.1-0ubuntu4/file/bin/running-in-container
  490. if [ -x "/bin/running-in-container" ]; then
  491. "/bin/running-in-container" > /dev/null 2>&1 && return 0
  492. fi
  493. return 1
  494. }
  495. get_os_key() {
  496. if [ -f /etc/os-release ]; then
  497. # shellcheck disable=SC1091
  498. . /etc/os-release || return 1
  499. echo "${ID}-${VERSION_ID}"
  500. elif [ -f /etc/redhat-release ]; then
  501. cat /etc/redhat-release
  502. else
  503. echo "unknown"
  504. fi
  505. }
  506. get_group(){
  507. if command -v getent > /dev/null 2>&1; then
  508. getent group "${1:-""}"
  509. else
  510. grep "^${1}:" /etc/group
  511. fi
  512. }
  513. issystemd() {
  514. pids=''
  515. p=''
  516. myns=''
  517. ns=''
  518. systemctl=''
  519. # if there is no systemctl command, it is not systemd
  520. systemctl=$(command -v systemctl 2> /dev/null)
  521. if [ -z "${systemctl}" ] || [ ! -x "${systemctl}" ]; then
  522. return 1
  523. fi
  524. # Check the output of systemctl is-system-running.
  525. # If this reports 'offline', it’s not systemd. If it reports 'unknown'
  526. # or nothing at all (which indicates the command is not supported), it
  527. # may or may not be systemd, so continue to other checks. If it reports
  528. # anything else, it is systemd.
  529. case "$(systemctl is-system-running)" in
  530. offline) return 1 ;;
  531. unknown) : ;;
  532. "") : ;;
  533. *) return 0 ;;
  534. esac
  535. # if pid 1 is systemd, it is systemd
  536. [ "$(basename "$(readlink /proc/1/exe)" 2> /dev/null)" = "systemd" ] && return 0
  537. # if systemd is not running, it is not systemd
  538. pids=$(safe_pidof systemd 2> /dev/null)
  539. [ -z "${pids}" ] && return 1
  540. # check if the running systemd processes are not in our namespace
  541. myns="$(readlink /proc/self/ns/pid 2> /dev/null)"
  542. for p in ${pids}; do
  543. ns="$(readlink "/proc/${p}/ns/pid" 2> /dev/null)"
  544. # if pid of systemd is in our namespace, it is systemd
  545. [ -n "${myns}" ] && [ "${myns}" = "${ns}" ] && return 0
  546. done
  547. # else, it is not systemd
  548. return 1
  549. }
  550. get_systemd_service_dir() {
  551. unit_paths="$(systemctl show -p UnitPath | cut -f 2- -d '=' | tr ' ' '\n')"
  552. if [ -n "${unit_paths}" ]; then
  553. lib_paths="$(echo "${unit_paths}" | grep -vE '^/(run|etc)' | awk '{line[NR] = $0} END {for (i = NR; i > 0; i--) print line[i]}')"
  554. etc_paths="$(echo "${unit_paths}" | grep -E '^/etc' | grep -vE '(attached|control)$')"
  555. else
  556. lib_paths="/usr/lib/systemd/system /lib/systemd/system /usr/local/lib/systemd/system"
  557. etc_paths="/etc/systemd/system"
  558. fi
  559. for path in ${lib_paths} ${etc_paths}; do
  560. if [ -d "${path}" ] && [ -w "${path}" ]; then
  561. echo "${path}"
  562. return 0
  563. fi
  564. done
  565. }
  566. run_install_service_script() {
  567. if [ -z "${tmpdir}" ]; then
  568. tmpdir="${TMPDIR:-/tmp}"
  569. fi
  570. # shellcheck disable=SC2154
  571. save_path="${tmpdir}/netdata-service-cmds"
  572. # shellcheck disable=SC2068
  573. "${NETDATA_PREFIX}/usr/libexec/netdata/install-service.sh" --save-cmds "${save_path}" ${@}
  574. case $? in
  575. 0)
  576. if [ -r "${save_path}" ]; then
  577. # shellcheck disable=SC1090
  578. . "${save_path}"
  579. fi
  580. if [ -z "${NETDATA_INSTALLER_START_CMD}" ]; then
  581. if [ -n "${NETDATA_START_CMD}" ]; then
  582. NETDATA_INSTALLER_START_CMD="${NETDATA_START_CMD}"
  583. else
  584. NETDATA_INSTALLER_START_CMD="netdata"
  585. fi
  586. fi
  587. ;;
  588. 1)
  589. if [ -z "${NETDATA_SERVICE_WARNED_1}" ]; then
  590. warning "Intenral error encountered while attempting to install or manage Netdata as a system service. This is probably a bug."
  591. NETDATA_SERVICE_WARNED_1=1
  592. fi
  593. ;;
  594. 2)
  595. if [ -z "${NETDATA_SERVICE_WARNED_2}" ]; then
  596. warning "Failed to detect system service manager type. Cannot cleanly install or manage Netdata as a system service. If you are running this script in a container, this is expected and can safely be ignored."
  597. NETDATA_SERVICE_WARNED_2=1
  598. fi
  599. ;;
  600. 3)
  601. if [ -z "${NETDATA_SERVICE_WARNED_3}" ]; then
  602. warning "Detected an unsupported system service manager. Manual setup will be required to manage Netdata as a system service."
  603. NETDATA_SERVICE_WARNED_3=1
  604. fi
  605. ;;
  606. 4)
  607. if [ -z "${NETDATA_SERVICE_WARNED_4}" ]; then
  608. warning "Detected a supported system service manager, but failed to install Netdata as a system service. Usually this is a result of incorrect permissions. Manually running ${NETDATA_PREFIX}/usr/libexec/netdata/install-service.sh may provide more information about the exact issue."
  609. NETDATA_SERVICE_WARNED_4=1
  610. fi
  611. ;;
  612. 5)
  613. if [ -z "${NETDATA_SERVICE_WARNED_5}" ]; then
  614. warning "We do not support managing Netdata as a system service on this platform. Manual setup will be required."
  615. NETDATA_SERVICE_WARNED_5=1
  616. fi
  617. ;;
  618. esac
  619. }
  620. install_netdata_service() {
  621. if [ "${UID}" -eq 0 ]; then
  622. if [ -x "${NETDATA_PREFIX}/usr/libexec/netdata/install-service.sh" ]; then
  623. run_install_service_script && return 0
  624. else
  625. warning "Could not find service install script, not installing Netdata as a system service."
  626. fi
  627. fi
  628. return 1
  629. }
  630. # -----------------------------------------------------------------------------
  631. # stop netdata
  632. pidisnetdata() {
  633. if [ -d /proc/self ]; then
  634. if [ -z "$1" ] || [ ! -f "/proc/$1/stat" ]; then
  635. return 1
  636. fi
  637. [ "$(cut -d '(' -f 2 "/proc/$1/stat" | cut -d ')' -f 1)" = "netdata" ] && return 0
  638. return 1
  639. fi
  640. return 0
  641. }
  642. stop_netdata_on_pid() {
  643. pid="${1}"
  644. ret=0
  645. count=0
  646. pidisnetdata "${pid}" || return 0
  647. printf >&2 "Stopping netdata on pid %s ..." "${pid}"
  648. while [ -n "${pid}" ] && [ ${ret} -eq 0 ]; do
  649. if [ ${count} -gt 24 ]; then
  650. warning "Cannot stop netdata agent with PID ${pid}."
  651. return 1
  652. fi
  653. count=$((count + 1))
  654. pidisnetdata "${pid}" || ret=1
  655. if [ ${ret} -eq 1 ]; then
  656. break
  657. fi
  658. if [ ${count} -lt 12 ]; then
  659. run kill "${pid}" 2> /dev/null
  660. ret=$?
  661. else
  662. run kill -9 "${pid}" 2> /dev/null
  663. ret=$?
  664. fi
  665. test ${ret} -eq 0 && printf >&2 "." && sleep 5
  666. done
  667. echo >&2
  668. if [ ${ret} -eq 0 ]; then
  669. warning "Failed to stop netdata agent process with PID ${pid}."
  670. return 1
  671. fi
  672. echo >&2 "netdata on pid ${pid} stopped."
  673. return 0
  674. }
  675. netdata_pids() {
  676. myns="$(readlink /proc/self/ns/pid 2> /dev/null)"
  677. for p in \
  678. $(cat /var/run/netdata.pid 2> /dev/null) \
  679. $(cat /var/run/netdata/netdata.pid 2> /dev/null) \
  680. $(safe_pidof netdata 2> /dev/null); do
  681. ns="$(readlink "/proc/${p}/ns/pid" 2> /dev/null)"
  682. if [ -z "${myns}" ] || [ -z "${ns}" ] || [ "${myns}" = "${ns}" ]; then
  683. pidisnetdata "${p}" && echo "${p}"
  684. fi
  685. done
  686. }
  687. stop_all_netdata() {
  688. stop_success=0
  689. if [ -x "${NETDATA_PREFIX}/usr/libexec/netdata/install-service.sh" ]; then
  690. run_install_service_script --cmds-only
  691. fi
  692. if [ "${UID}" -eq 0 ]; then
  693. uname="$(uname 2>/dev/null)"
  694. # Any of these may fail, but we need to not bail if they do.
  695. if [ -n "${NETDATA_STOP_CMD}" ]; then
  696. if ${NETDATA_STOP_CMD}; then
  697. stop_success=1
  698. sleep 5
  699. fi
  700. elif issystemd; then
  701. if systemctl stop netdata; then
  702. stop_success=1
  703. sleep 5
  704. fi
  705. elif [ "${uname}" = "Darwin" ]; then
  706. if launchctl stop netdata; then
  707. stop_success=1
  708. sleep 5
  709. fi
  710. elif [ "${uname}" = "FreeBSD" ]; then
  711. if /etc/rc.d/netdata stop; then
  712. stop_success=1
  713. sleep 5
  714. fi
  715. else
  716. if service netdata stop; then
  717. stop_success=1
  718. sleep 5
  719. fi
  720. fi
  721. fi
  722. if [ "$stop_success" = "0" ]; then
  723. if [ -n "$(netdata_pids)" ] && [ -n "$(command -v netdatacli)" ]; then
  724. netdatacli shutdown-agent
  725. sleep 20
  726. fi
  727. for p in $(netdata_pids); do
  728. # shellcheck disable=SC2086
  729. stop_netdata_on_pid ${p}
  730. done
  731. fi
  732. }
  733. # -----------------------------------------------------------------------------
  734. # restart netdata
  735. restart_netdata() {
  736. netdata="${1}"
  737. shift
  738. started=0
  739. progress "Restarting netdata instance"
  740. if [ -x "${NETDATA_PREFIX}/usr/libexec/netdata/install-service.sh" ]; then
  741. run_install_service_script --cmds-only
  742. fi
  743. if [ -z "${NETDATA_INSTALLER_START_CMD}" ]; then
  744. if [ -n "${NETDATA_START_CMD}" ]; then
  745. NETDATA_INSTALLER_START_CMD="${NETDATA_START_CMD}"
  746. else
  747. NETDATA_INSTALLER_START_CMD="${netdata}"
  748. fi
  749. fi
  750. if [ "${UID}" -eq 0 ]; then
  751. echo >&2
  752. echo >&2 "Stopping all netdata threads"
  753. run stop_all_netdata
  754. echo >&2 "Starting netdata using command '${NETDATA_INSTALLER_START_CMD}'"
  755. # shellcheck disable=SC2086
  756. run ${NETDATA_INSTALLER_START_CMD} && started=1
  757. if [ ${started} -eq 1 ] && sleep 5 && [ -z "$(netdata_pids)" ]; then
  758. echo >&2 "Ooops! it seems netdata is not started."
  759. started=0
  760. fi
  761. if [ ${started} -eq 0 ]; then
  762. echo >&2 "Attempting another netdata start using command '${NETDATA_INSTALLER_START_CMD}'"
  763. # shellcheck disable=SC2086
  764. run ${NETDATA_INSTALLER_START_CMD} && started=1
  765. fi
  766. if [ ${started} -eq 1 ] && sleep 5 && [ -z "$(netdata_pids)" ]; then
  767. echo >&2 "Hm... it seems netdata is still not started."
  768. started=0
  769. fi
  770. fi
  771. if [ ${started} -eq 0 ]; then
  772. # still not started... another forced attempt, just run the binary
  773. warning "Netdata service still not started, attempting another forced restart by running '${netdata} ${*}'"
  774. run stop_all_netdata
  775. run "${netdata}" "${@}"
  776. return $?
  777. fi
  778. return 0
  779. }
  780. # -----------------------------------------------------------------------------
  781. # install netdata logrotate
  782. install_netdata_logrotate() {
  783. src="${NETDATA_PREFIX}/usr/lib/netdata/system/logrotate/netdata"
  784. if [ "${UID}" -eq 0 ]; then
  785. if [ -d /etc/logrotate.d ]; then
  786. if [ ! -f /etc/logrotate.d/netdata ]; then
  787. run cp "${src}" /etc/logrotate.d/netdata
  788. fi
  789. if [ -f /etc/logrotate.d/netdata ]; then
  790. run chmod 644 /etc/logrotate.d/netdata
  791. fi
  792. return 0
  793. fi
  794. fi
  795. return 1
  796. }
  797. # -----------------------------------------------------------------------------
  798. # install netdata journald configuration
  799. install_netdata_journald_conf() {
  800. src="${NETDATA_PREFIX}/usr/lib/netdata/system/systemd/journald@netdata.conf"
  801. [ ! -d /usr/lib/systemd/ ] && return 0
  802. [ "${UID}" -ne 0 ] && return 1
  803. if [ ! -d /usr/lib/systemd/journald@netdata.conf.d/ ]; then
  804. run mkdir /usr/lib/systemd/journald@netdata.conf.d/
  805. fi
  806. run cp "${src}" /usr/lib/systemd/journald@netdata.conf.d/netdata.conf
  807. if [ -f /usr/lib/systemd/journald@netdata.conf.d/netdata.conf ]; then
  808. run chmod 644 /usr/lib/systemd/journald@netdata.conf.d/netdata.conf
  809. fi
  810. return 0
  811. }
  812. # -----------------------------------------------------------------------------
  813. # create netdata.conf
  814. create_netdata_conf() {
  815. path="${1}"
  816. url="${2}"
  817. if [ -s "${path}" ]; then
  818. return 0
  819. fi
  820. if [ -n "$url" ]; then
  821. echo >&2 "Downloading default configuration from netdata..."
  822. sleep 5
  823. # remove a possibly obsolete configuration file
  824. [ -f "${path}.new" ] && rm "${path}.new"
  825. # disable a proxy to get data from the local netdata
  826. export http_proxy=
  827. export https_proxy=
  828. check_for_curl
  829. if [ -n "${curl}" ]; then
  830. run "${curl}" -sSL --connect-timeout 10 --retry 3 "${url}" > "${path}.new"
  831. elif command -v wget 1> /dev/null 2>&1; then
  832. run wget -T 15 -O - "${url}" > "${path}.new"
  833. fi
  834. if [ -s "${path}.new" ]; then
  835. run mv "${path}.new" "${path}"
  836. run_ok "New configuration saved for you to edit at ${path}"
  837. else
  838. [ -f "${path}.new" ] && rm "${path}.new"
  839. run_failed "Cannot download configuration from netdata daemon using url '${url}'"
  840. url=''
  841. fi
  842. fi
  843. if [ -z "$url" ]; then
  844. cat << EOF > "${path}"
  845. # netdata can generate its own config which is available at 'http://<IP>:19999/netdata.conf'
  846. # You can download it using:
  847. # curl -o ${path} http://localhost:19999/netdata.conf
  848. # or
  849. # wget -O ${path} http://localhost:19999/netdata.conf
  850. EOF
  851. fi
  852. }
  853. portable_add_user() {
  854. username="${1}"
  855. homedir="${2}"
  856. [ -z "${homedir}" ] && homedir="/tmp"
  857. # Check if user exists
  858. if command -v getent > /dev/null 2>&1; then
  859. if getent passwd "${username}" > /dev/null 2>&1; then
  860. echo >&2 "User '${username}' already exists."
  861. return 0
  862. fi
  863. elif command -v dscl > /dev/null 2>&1; then
  864. if dscl . read /Users/"${username}" >/dev/null 2>&1; then
  865. echo >&2 "User '${username}' already exists."
  866. return 0
  867. fi
  868. else
  869. if cut -d ':' -f 1 < /etc/passwd | grep "^${username}$" 1> /dev/null 2>&1; then
  870. echo >&2 "User '${username}' already exists."
  871. return 0
  872. fi
  873. fi
  874. echo >&2 "Adding ${username} user account with home ${homedir} ..."
  875. nologin="$(command -v nologin || echo '/bin/false')"
  876. if command -v useradd 1> /dev/null 2>&1; then
  877. run useradd -r -g "${username}" -c "${username}" -s "${nologin}" --no-create-home -d "${homedir}" "${username}" && return 0
  878. elif command -v pw 1> /dev/null 2>&1; then
  879. run pw useradd "${username}" -d "${homedir}" -g "${username}" -s "${nologin}" && return 0
  880. elif command -v adduser 1> /dev/null 2>&1; then
  881. run adduser -h "${homedir}" -s "${nologin}" -D -G "${username}" "${username}" && return 0
  882. elif command -v sysadminctl 1> /dev/null 2>&1; then
  883. gid=$(dscl . read /Groups/"${username}" 2>/dev/null | grep PrimaryGroupID | grep -Eo "[0-9]+")
  884. if run sysadminctl -addUser "${username}" -shell /usr/bin/false -home /var/empty -GID "$gid"; then
  885. # FIXME: I think the proper solution is to create a role account:
  886. # -roleAccount + name starting with _ and UID in 200-400 range.
  887. run dscl . create /Users/"${username}" IsHidden 1
  888. return 0
  889. fi
  890. fi
  891. warning "Failed to add ${username} user account!"
  892. return 1
  893. }
  894. portable_add_group() {
  895. groupname="${1}"
  896. # Check if group exist
  897. if get_group "${groupname}" > /dev/null 2>&1; then
  898. echo >&2 "Group '${groupname}' already exists."
  899. return 0
  900. fi
  901. echo >&2 "Adding ${groupname} user group ..."
  902. # Linux
  903. if command -v groupadd 1> /dev/null 2>&1; then
  904. run groupadd -r "${groupname}" && return 0
  905. elif command -v pw 1> /dev/null 2>&1; then
  906. run pw groupadd "${groupname}" && return 0
  907. elif command -v addgroup 1> /dev/null 2>&1; then
  908. run addgroup "${groupname}" && return 0
  909. elif command -v dseditgroup 1> /dev/null 2>&1; then
  910. dseditgroup -o create "${groupname}" && return 0
  911. fi
  912. warning >&2 "Failed to add ${groupname} user group !"
  913. return 1
  914. }
  915. portable_add_user_to_group() {
  916. groupname="${1}"
  917. username="${2}"
  918. # Check if group exist
  919. if ! get_group "${groupname}" > /dev/null 2>&1; then
  920. echo >&2 "Group '${groupname}' does not exist."
  921. # Don’t treat this as a failure, if the group does not exist we should not be trying to add the user to it.
  922. return 0
  923. fi
  924. # Check if user is in group
  925. if get_group "${groupname}" | cut -d ':' -f 4 | grep -wq "${username}"; then
  926. # username is already there
  927. echo >&2 "User '${username}' is already in group '${groupname}'."
  928. return 0
  929. else
  930. # username is not in group
  931. echo >&2 "Adding ${username} user to the ${groupname} group ..."
  932. # Linux
  933. if command -v usermod 1> /dev/null 2>&1; then
  934. run usermod -a -G "${groupname}" "${username}" && return 0
  935. elif command -v pw 1> /dev/null 2>&1; then
  936. run pw groupmod "${groupname}" -m "${username}" && return 0
  937. elif command -v addgroup 1> /dev/null 2>&1; then
  938. run addgroup "${username}" "${groupname}" && return 0
  939. elif command -v dseditgroup 1> /dev/null 2>&1; then
  940. dseditgroup -u "${username}" "${groupname}" && return 0
  941. fi
  942. warning >&2 "Failed to add user ${username} to group ${groupname}!"
  943. return 1
  944. fi
  945. }
  946. safe_sha256sum() {
  947. # Within the context of the installer, we only use -c option that is common between the two commands
  948. # We will have to reconsider if we start non-common options
  949. if command -v sha256sum > /dev/null 2>&1; then
  950. sha256sum "$@"
  951. elif command -v shasum > /dev/null 2>&1; then
  952. shasum -a 256 "$@"
  953. else
  954. fatal "I could not find a suitable checksum binary to use" "L0001"
  955. fi
  956. }
  957. _get_scheduler_type() {
  958. if _get_intervaldir > /dev/null ; then
  959. echo 'interval'
  960. elif issystemd ; then
  961. echo 'systemd'
  962. elif [ -d /etc/cron.d ] ; then
  963. echo 'crontab'
  964. else
  965. echo 'none'
  966. fi
  967. }
  968. _get_intervaldir() {
  969. if [ -d /etc/cron.daily ]; then
  970. echo /etc/cron.daily
  971. elif [ -d /etc/periodic/daily ]; then
  972. echo /etc/periodic/daily
  973. else
  974. return 1
  975. fi
  976. return 0
  977. }
  978. install_netdata_updater() {
  979. if [ "${INSTALLER_DIR}" ] && [ -f "${INSTALLER_DIR}/packaging/installer/netdata-updater.sh" ]; then
  980. cat "${INSTALLER_DIR}/packaging/installer/netdata-updater.sh" > "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" || return 1
  981. fi
  982. if [ "${NETDATA_SOURCE_DIR}" ] && [ -f "${NETDATA_SOURCE_DIR}/packaging/installer/netdata-updater.sh" ]; then
  983. cat "${NETDATA_SOURCE_DIR}/packaging/installer/netdata-updater.sh" > "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" || return 1
  984. fi
  985. # these files are installed by cmake
  986. libsysdir="${NETDATA_PREFIX}/usr/lib/netdata/system/systemd/"
  987. if [ -d "${libsysdir}" ] && issystemd && [ -n "$(get_systemd_service_dir)" ]; then
  988. cat "${libsysdir}/netdata-updater.timer" > "$(get_systemd_service_dir)/netdata-updater.timer"
  989. cat "${libsysdir}/netdata-updater.service" > "$(get_systemd_service_dir)/netdata-updater.service"
  990. fi
  991. sed -i -e "s|THIS_SHOULD_BE_REPLACED_BY_INSTALLER_SCRIPT|${NETDATA_USER_CONFIG_DIR}/.environment|" "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" || return 1
  992. chmod 0755 "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh"
  993. echo >&2 "Update script is located at ${TPUT_GREEN}${TPUT_BOLD}${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh${TPUT_RESET}"
  994. echo >&2
  995. return 0
  996. }
  997. set_netdata_updater_channel() {
  998. sed -i -e "s/^RELEASE_CHANNEL=.*/RELEASE_CHANNEL=\"${RELEASE_CHANNEL}\"/" "${NETDATA_USER_CONFIG_DIR}/.environment"
  999. }