functions.sh 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184
  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 [ "${ENABLE_GO:-1}" -eq 1 ]; then
  255. enable_feature PLUGIN_GO 1
  256. else
  257. enable_feature PLUGIN_GO 0
  258. fi
  259. if [ "${ENABLE_PYTHON:-1}" -eq 1 ]; then
  260. enable_feature PLUGIN_PYTHON 1
  261. else
  262. enable_feature PLUGIN_PYTHON 0
  263. fi
  264. if [ "${ENABLE_CHARTS:-1}" -eq 1 ]; then
  265. enable_feature PLUGIN_CHARTS 1
  266. else
  267. enable_feature PLUGIN_CHARTS 0
  268. fi
  269. if [ "${USE_SYSTEM_PROTOBUF:-0}" -eq 1 ]; then
  270. enable_feature BUNDLED_PROTOBUF 0
  271. else
  272. enable_feature BUNDLED_PROTOBUF 1
  273. fi
  274. if [ -z "${ENABLE_SYSTEMD_JOURNAL}" ]; then
  275. if check_for_module libsystemd; then
  276. if check_for_module libelogind; then
  277. ENABLE_SYSTEMD_JOURNAL=0
  278. else
  279. ENABLE_SYSTEMD_JOURNAL=1
  280. fi
  281. else
  282. ENABLE_SYSTEMD_JOURNAL=0
  283. fi
  284. fi
  285. enable_feature PLUGIN_SYSTEMD_JOURNAL "${ENABLE_SYSTEMD_JOURNAL}"
  286. if command -v cups-config >/dev/null 2>&1 || check_for_module libcups || check_for_module cups; then
  287. ENABLE_CUPS=1
  288. else
  289. ENABLE_CUPS=0
  290. fi
  291. enable_feature PLUGIN_CUPS "${ENABLE_CUPS}"
  292. IS_LINUX=0
  293. [ "$(uname -s)" = "Linux" ] && IS_LINUX=1
  294. enable_feature PLUGIN_DEBUGFS "${IS_LINUX}"
  295. enable_feature PLUGIN_PERF "${IS_LINUX}"
  296. enable_feature PLUGIN_SLABINFO "${IS_LINUX}"
  297. enable_feature PLUGIN_CGROUP_NETWORK "${IS_LINUX}"
  298. enable_feature PLUGIN_LOCAL_LISTENERS "${IS_LINUX}"
  299. enable_feature PLUGIN_NETWORK_VIEWER "${IS_LINUX}"
  300. enable_feature PLUGIN_EBPF "${ENABLE_EBPF:-0}"
  301. enable_feature BUNDLED_JSONC "${NETDATA_BUILD_JSON_C:-0}"
  302. enable_feature DBENGINE "${ENABLE_DBENGINE:-1}"
  303. enable_feature H2O "${ENABLE_H2O:-0}"
  304. enable_feature ML "${NETDATA_ENABLE_ML:-1}"
  305. enable_feature PLUGIN_APPS "${ENABLE_APPS:-1}"
  306. check_for_feature EXPORTER_PROMETHEUS_REMOTE_WRITE "${EXPORTER_PROMETHEUS}" snappy
  307. check_for_feature EXPORTER_MONGODB "${EXPORTER_MONGODB}" libmongoc-1.0
  308. check_for_feature PLUGIN_FREEIPMI "${ENABLE_FREEIPMI}" libipmimonitoring
  309. check_for_feature PLUGIN_NFACCT "${ENABLE_NFACCT}" libnetfilter_acct libnml
  310. check_for_feature PLUGIN_XENSTAT "${ENABLE_XENSTAT}" xenstat xenlight
  311. }
  312. # -----------------------------------------------------------------------------
  313. # portable service command
  314. service_cmd="$(command -v service 2> /dev/null || true)"
  315. rcservice_cmd="$(command -v rc-service 2> /dev/null || true)"
  316. systemctl_cmd="$(command -v systemctl 2> /dev/null || true)"
  317. service() {
  318. cmd="${1}"
  319. action="${2}"
  320. if [ -n "${systemctl_cmd}" ]; then
  321. run "${systemctl_cmd}" "${action}" "${cmd}"
  322. return $?
  323. elif [ -n "${service_cmd}" ]; then
  324. run "${service_cmd}" "${cmd}" "${action}"
  325. return $?
  326. elif [ -n "${rcservice_cmd}" ]; then
  327. run "${rcservice_cmd}" "${cmd}" "${action}"
  328. return $?
  329. fi
  330. return 1
  331. }
  332. # -----------------------------------------------------------------------------
  333. # portable pidof
  334. safe_pidof() {
  335. pidof_cmd="$(command -v pidof 2> /dev/null)"
  336. if [ -n "${pidof_cmd}" ]; then
  337. ${pidof_cmd} "${@}"
  338. return $?
  339. else
  340. ps -acxo pid,comm |
  341. sed "s/^ *//g" |
  342. grep netdata |
  343. cut -d ' ' -f 1
  344. return $?
  345. fi
  346. }
  347. # -----------------------------------------------------------------------------
  348. find_processors() {
  349. # Most UNIX systems have `nproc` as part of their userland (including Linux and BSD)
  350. if command -v nproc > /dev/null; then
  351. nproc && return
  352. fi
  353. # macOS has no nproc but it may have gnproc installed from Homebrew or from Macports.
  354. if command -v gnproc > /dev/null; then
  355. gnproc && return
  356. fi
  357. if [ -f "/proc/cpuinfo" ]; then
  358. # linux
  359. cpus=$(grep -c ^processor /proc/cpuinfo)
  360. else
  361. # freebsd
  362. cpus=$(sysctl hw.ncpu 2> /dev/null | grep ^hw.ncpu | cut -d ' ' -f 2)
  363. fi
  364. if [ -z "${cpus}" ] || [ $((cpus)) -lt 1 ]; then
  365. echo 1
  366. else
  367. echo "${cpus}"
  368. fi
  369. }
  370. # -----------------------------------------------------------------------------
  371. exit_reason() {
  372. if [ -n "${NETDATA_SAVE_WARNINGS}" ]; then
  373. EXIT_REASON="${1}"
  374. EXIT_CODE="${2}"
  375. if [ -n "${NETDATA_PROPAGATE_WARNINGS}" ]; then
  376. if [ -n "${NETDATA_SCRIPT_STATUS_PATH}" ]; then
  377. {
  378. echo "EXIT_REASON=\"${EXIT_REASON}\""
  379. echo "EXIT_CODE=\"${EXIT_CODE}\""
  380. echo "NETDATA_WARNINGS=\"${NETDATA_WARNINGS}${SAVED_WARNINGS}\""
  381. } >> "${NETDATA_SCRIPT_STATUS_PATH}"
  382. else
  383. export EXIT_REASON
  384. export EXIT_CODE
  385. export NETDATA_WARNINGS="${NETDATA_WARNINGS}${SAVED_WARNINGS}"
  386. fi
  387. fi
  388. fi
  389. }
  390. fatal() {
  391. printf >&2 "%s ABORTED %s %s \n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}" "${1}"
  392. if [ -n "${NETDATA_SAVE_WARNINGS}" ]; then
  393. SAVED_WARNINGS="${SAVED_WARNINGS}\n - ${1}"
  394. fi
  395. exit_reason "${1}" "${2}"
  396. exit 1
  397. }
  398. warning() {
  399. printf >&2 "%s WARNING %s %s\n\n" "${TPUT_BGYELLOW}${TPUT_BLACK}${TPUT_BOLD}" "${TPUT_RESET}" "${1}"
  400. if [ -n "${NETDATA_SAVE_WARNINGS}" ]; then
  401. SAVED_WARNINGS="${SAVED_WARNINGS}\n - ${1}"
  402. fi
  403. }
  404. run_ok() {
  405. printf >&2 "%s OK %s %s\n\n" "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}" "${1:-''}"
  406. }
  407. run_failed() {
  408. printf >&2 "%s FAILED %s %s\n\n" "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD}" "${TPUT_RESET}" "${1:-''}"
  409. if [ -n "${NETDATA_SAVE_WARNINGS}" ] && [ -n "${1:-''}" ]; then
  410. SAVED_WARNINGS="${SAVED_WARNINGS}\n - ${1}"
  411. fi
  412. }
  413. ESCAPED_PRINT_METHOD=
  414. if printf "%s " test > /dev/null 2>&1; then
  415. ESCAPED_PRINT_METHOD="printfq"
  416. fi
  417. escaped_print() {
  418. if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]; then
  419. printf "%s " "${@}"
  420. else
  421. printf "%s" "${*}"
  422. fi
  423. return 0
  424. }
  425. run_logfile="/dev/null"
  426. run() {
  427. local_user="${USER--}"
  428. local_dir="${PWD}"
  429. if [ "${UID}" = "0" ]; then
  430. info="[root ${local_dir}]# "
  431. info_console="[${TPUT_DIM}${local_dir}${TPUT_RESET}]# "
  432. else
  433. info="[${local_user} ${local_dir}]$ "
  434. info_console="[${TPUT_DIM}${local_dir}${TPUT_RESET}]$ "
  435. fi
  436. {
  437. printf "%s" "${info}"
  438. escaped_print "${@}"
  439. printf "%s" " ... "
  440. } >> "${run_logfile}"
  441. printf >&2 "%s" "${info_console}${TPUT_BOLD}${TPUT_YELLOW}"
  442. escaped_print >&2 "${@}"
  443. printf >&2 "%s\n" "${TPUT_RESET}"
  444. "${@}"
  445. ret=$?
  446. if [ ${ret} -ne 0 ]; then
  447. run_failed
  448. printf >> "${run_logfile}" "FAILED with exit code %s\n" "${ret}"
  449. if [ -n "${NETDATA_SAVE_WARNINGS}" ]; then
  450. SAVED_WARNINGS="${SAVED_WARNINGS}\n - Command '${*}' failed with exit code ${ret}."
  451. fi
  452. else
  453. run_ok
  454. printf >> "${run_logfile}" "OK\n"
  455. fi
  456. return ${ret}
  457. }
  458. iscontainer() {
  459. # man systemd-detect-virt
  460. cmd=$(command -v systemd-detect-virt 2> /dev/null)
  461. if [ -n "${cmd}" ] && [ -x "${cmd}" ]; then
  462. "${cmd}" --container > /dev/null 2>&1 && return 0
  463. fi
  464. # /proc/1/sched exposes the host's pid of our init !
  465. # http://stackoverflow.com/a/37016302
  466. pid=$(head -n 1 /proc/1/sched 2> /dev/null | {
  467. # shellcheck disable=SC2034
  468. IFS='(),#:' read -r name pid th threads
  469. echo "$pid"
  470. })
  471. if [ -n "${pid}" ]; then
  472. pid=$((pid + 0))
  473. [ ${pid} -gt 1 ] && return 0
  474. fi
  475. # lxc sets environment variable 'container'
  476. # shellcheck disable=SC2154
  477. [ -n "${container}" ] && return 0
  478. # docker creates /.dockerenv
  479. # http://stackoverflow.com/a/25518345
  480. [ -f "/.dockerenv" ] && return 0
  481. # ubuntu and debian supply /bin/running-in-container
  482. # https://www.apt-browse.org/browse/ubuntu/trusty/main/i386/upstart/1.12.1-0ubuntu4/file/bin/running-in-container
  483. if [ -x "/bin/running-in-container" ]; then
  484. "/bin/running-in-container" > /dev/null 2>&1 && return 0
  485. fi
  486. return 1
  487. }
  488. get_os_key() {
  489. if [ -f /etc/os-release ]; then
  490. # shellcheck disable=SC1091
  491. . /etc/os-release || return 1
  492. echo "${ID}-${VERSION_ID}"
  493. elif [ -f /etc/redhat-release ]; then
  494. cat /etc/redhat-release
  495. else
  496. echo "unknown"
  497. fi
  498. }
  499. get_group(){
  500. if command -v getent > /dev/null 2>&1; then
  501. getent group "${1:-""}"
  502. else
  503. grep "^${1}:" /etc/group
  504. fi
  505. }
  506. issystemd() {
  507. pids=''
  508. p=''
  509. myns=''
  510. ns=''
  511. systemctl=''
  512. # if there is no systemctl command, it is not systemd
  513. systemctl=$(command -v systemctl 2> /dev/null)
  514. if [ -z "${systemctl}" ] || [ ! -x "${systemctl}" ]; then
  515. return 1
  516. fi
  517. # Check the output of systemctl is-system-running.
  518. # If this reports 'offline', it’s not systemd. If it reports 'unknown'
  519. # or nothing at all (which indicates the command is not supported), it
  520. # may or may not be systemd, so continue to other checks. If it reports
  521. # anything else, it is systemd.
  522. case "$(systemctl is-system-running)" in
  523. offline) return 1 ;;
  524. unknown) : ;;
  525. "") : ;;
  526. *) return 0 ;;
  527. esac
  528. # if pid 1 is systemd, it is systemd
  529. [ "$(basename "$(readlink /proc/1/exe)" 2> /dev/null)" = "systemd" ] && return 0
  530. # if systemd is not running, it is not systemd
  531. pids=$(safe_pidof systemd 2> /dev/null)
  532. [ -z "${pids}" ] && return 1
  533. # check if the running systemd processes are not in our namespace
  534. myns="$(readlink /proc/self/ns/pid 2> /dev/null)"
  535. for p in ${pids}; do
  536. ns="$(readlink "/proc/${p}/ns/pid" 2> /dev/null)"
  537. # if pid of systemd is in our namespace, it is systemd
  538. [ -n "${myns}" ] && [ "${myns}" = "${ns}" ] && return 0
  539. done
  540. # else, it is not systemd
  541. return 1
  542. }
  543. get_systemd_service_dir() {
  544. unit_paths="$(systemctl show -p UnitPath | cut -f 2- -d '=' | tr ' ' '\n')"
  545. if [ -n "${unit_paths}" ]; then
  546. lib_paths="$(echo "${unit_paths}" | grep -vE '^/(run|etc)' | awk '{line[NR] = $0} END {for (i = NR; i > 0; i--) print line[i]}')"
  547. etc_paths="$(echo "${unit_paths}" | grep -E '^/etc' | grep -vE '(attached|control)$')"
  548. else
  549. lib_paths="/usr/lib/systemd/system /lib/systemd/system /usr/local/lib/systemd/system"
  550. etc_paths="/etc/systemd/system"
  551. fi
  552. for path in ${lib_paths} ${etc_paths}; do
  553. if [ -d "${path}" ] && [ -w "${path}" ]; then
  554. echo "${path}"
  555. return 0
  556. fi
  557. done
  558. }
  559. run_install_service_script() {
  560. if [ -z "${tmpdir}" ]; then
  561. tmpdir="${TMPDIR:-/tmp}"
  562. fi
  563. # shellcheck disable=SC2154
  564. save_path="${tmpdir}/netdata-service-cmds"
  565. # shellcheck disable=SC2068
  566. "${NETDATA_PREFIX}/usr/libexec/netdata/install-service.sh" --save-cmds "${save_path}" ${@}
  567. case $? in
  568. 0)
  569. if [ -r "${save_path}" ]; then
  570. # shellcheck disable=SC1090
  571. . "${save_path}"
  572. fi
  573. if [ -z "${NETDATA_INSTALLER_START_CMD}" ]; then
  574. if [ -n "${NETDATA_START_CMD}" ]; then
  575. NETDATA_INSTALLER_START_CMD="${NETDATA_START_CMD}"
  576. else
  577. NETDATA_INSTALLER_START_CMD="netdata"
  578. fi
  579. fi
  580. ;;
  581. 1)
  582. if [ -z "${NETDATA_SERVICE_WARNED_1}" ]; then
  583. warning "Intenral error encountered while attempting to install or manage Netdata as a system service. This is probably a bug."
  584. NETDATA_SERVICE_WARNED_1=1
  585. fi
  586. ;;
  587. 2)
  588. if [ -z "${NETDATA_SERVICE_WARNED_2}" ]; then
  589. 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."
  590. NETDATA_SERVICE_WARNED_2=1
  591. fi
  592. ;;
  593. 3)
  594. if [ -z "${NETDATA_SERVICE_WARNED_3}" ]; then
  595. warning "Detected an unsupported system service manager. Manual setup will be required to manage Netdata as a system service."
  596. NETDATA_SERVICE_WARNED_3=1
  597. fi
  598. ;;
  599. 4)
  600. if [ -z "${NETDATA_SERVICE_WARNED_4}" ]; then
  601. 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."
  602. NETDATA_SERVICE_WARNED_4=1
  603. fi
  604. ;;
  605. 5)
  606. if [ -z "${NETDATA_SERVICE_WARNED_5}" ]; then
  607. warning "We do not support managing Netdata as a system service on this platform. Manual setup will be required."
  608. NETDATA_SERVICE_WARNED_5=1
  609. fi
  610. ;;
  611. esac
  612. }
  613. install_netdata_service() {
  614. if [ "${UID}" -eq 0 ]; then
  615. if [ -x "${NETDATA_PREFIX}/usr/libexec/netdata/install-service.sh" ]; then
  616. run_install_service_script && return 0
  617. else
  618. warning "Could not find service install script, not installing Netdata as a system service."
  619. fi
  620. fi
  621. return 1
  622. }
  623. # -----------------------------------------------------------------------------
  624. # stop netdata
  625. pidisnetdata() {
  626. if [ -d /proc/self ]; then
  627. if [ -z "$1" ] || [ ! -f "/proc/$1/stat" ]; then
  628. return 1
  629. fi
  630. [ "$(cut -d '(' -f 2 "/proc/$1/stat" | cut -d ')' -f 1)" = "netdata" ] && return 0
  631. return 1
  632. fi
  633. return 0
  634. }
  635. stop_netdata_on_pid() {
  636. pid="${1}"
  637. ret=0
  638. count=0
  639. pidisnetdata "${pid}" || return 0
  640. printf >&2 "Stopping netdata on pid %s ..." "${pid}"
  641. while [ -n "${pid}" ] && [ ${ret} -eq 0 ]; do
  642. if [ ${count} -gt 24 ]; then
  643. warning "Cannot stop netdata agent with PID ${pid}."
  644. return 1
  645. fi
  646. count=$((count + 1))
  647. pidisnetdata "${pid}" || ret=1
  648. if [ ${ret} -eq 1 ]; then
  649. break
  650. fi
  651. if [ ${count} -lt 12 ]; then
  652. run kill "${pid}" 2> /dev/null
  653. ret=$?
  654. else
  655. run kill -9 "${pid}" 2> /dev/null
  656. ret=$?
  657. fi
  658. test ${ret} -eq 0 && printf >&2 "." && sleep 5
  659. done
  660. echo >&2
  661. if [ ${ret} -eq 0 ]; then
  662. warning "Failed to stop netdata agent process with PID ${pid}."
  663. return 1
  664. fi
  665. echo >&2 "netdata on pid ${pid} stopped."
  666. return 0
  667. }
  668. netdata_pids() {
  669. myns="$(readlink /proc/self/ns/pid 2> /dev/null)"
  670. for p in \
  671. $(cat /var/run/netdata.pid 2> /dev/null) \
  672. $(cat /var/run/netdata/netdata.pid 2> /dev/null) \
  673. $(safe_pidof netdata 2> /dev/null); do
  674. ns="$(readlink "/proc/${p}/ns/pid" 2> /dev/null)"
  675. if [ -z "${myns}" ] || [ -z "${ns}" ] || [ "${myns}" = "${ns}" ]; then
  676. pidisnetdata "${p}" && echo "${p}"
  677. fi
  678. done
  679. }
  680. stop_all_netdata() {
  681. stop_success=0
  682. if [ -x "${NETDATA_PREFIX}/usr/libexec/netdata/install-service.sh" ]; then
  683. run_install_service_script --cmds-only
  684. fi
  685. if [ "${UID}" -eq 0 ]; then
  686. uname="$(uname 2>/dev/null)"
  687. # Any of these may fail, but we need to not bail if they do.
  688. if [ -n "${NETDATA_STOP_CMD}" ]; then
  689. if ${NETDATA_STOP_CMD}; then
  690. stop_success=1
  691. sleep 5
  692. fi
  693. elif issystemd; then
  694. if systemctl stop netdata; then
  695. stop_success=1
  696. sleep 5
  697. fi
  698. elif [ "${uname}" = "Darwin" ]; then
  699. if launchctl stop netdata; then
  700. stop_success=1
  701. sleep 5
  702. fi
  703. elif [ "${uname}" = "FreeBSD" ]; then
  704. if /etc/rc.d/netdata stop; then
  705. stop_success=1
  706. sleep 5
  707. fi
  708. else
  709. if service netdata stop; then
  710. stop_success=1
  711. sleep 5
  712. fi
  713. fi
  714. fi
  715. if [ "$stop_success" = "0" ]; then
  716. if [ -n "$(netdata_pids)" ] && [ -n "$(command -v netdatacli)" ]; then
  717. netdatacli shutdown-agent
  718. sleep 20
  719. fi
  720. for p in $(netdata_pids); do
  721. # shellcheck disable=SC2086
  722. stop_netdata_on_pid ${p}
  723. done
  724. fi
  725. }
  726. # -----------------------------------------------------------------------------
  727. # restart netdata
  728. restart_netdata() {
  729. netdata="${1}"
  730. shift
  731. started=0
  732. progress "Restarting netdata instance"
  733. if [ -x "${NETDATA_PREFIX}/usr/libexec/netdata/install-service.sh" ]; then
  734. run_install_service_script --cmds-only
  735. fi
  736. if [ -z "${NETDATA_INSTALLER_START_CMD}" ]; then
  737. if [ -n "${NETDATA_START_CMD}" ]; then
  738. NETDATA_INSTALLER_START_CMD="${NETDATA_START_CMD}"
  739. else
  740. NETDATA_INSTALLER_START_CMD="${netdata}"
  741. fi
  742. fi
  743. if [ "${UID}" -eq 0 ]; then
  744. echo >&2
  745. echo >&2 "Stopping all netdata threads"
  746. run stop_all_netdata
  747. echo >&2 "Starting netdata using command '${NETDATA_INSTALLER_START_CMD}'"
  748. # shellcheck disable=SC2086
  749. run ${NETDATA_INSTALLER_START_CMD} && started=1
  750. if [ ${started} -eq 1 ] && sleep 5 && [ -z "$(netdata_pids)" ]; then
  751. echo >&2 "Ooops! it seems netdata is not started."
  752. started=0
  753. fi
  754. if [ ${started} -eq 0 ]; then
  755. echo >&2 "Attempting another netdata start using command '${NETDATA_INSTALLER_START_CMD}'"
  756. # shellcheck disable=SC2086
  757. run ${NETDATA_INSTALLER_START_CMD} && started=1
  758. fi
  759. if [ ${started} -eq 1 ] && sleep 5 && [ -z "$(netdata_pids)" ]; then
  760. echo >&2 "Hm... it seems netdata is still not started."
  761. started=0
  762. fi
  763. fi
  764. if [ ${started} -eq 0 ]; then
  765. # still not started... another forced attempt, just run the binary
  766. warning "Netdata service still not started, attempting another forced restart by running '${netdata} ${*}'"
  767. run stop_all_netdata
  768. run "${netdata}" "${@}"
  769. return $?
  770. fi
  771. return 0
  772. }
  773. # -----------------------------------------------------------------------------
  774. # install netdata logrotate
  775. install_netdata_logrotate() {
  776. src="${NETDATA_PREFIX}/usr/lib/netdata/system/logrotate/netdata"
  777. if [ "${UID}" -eq 0 ]; then
  778. if [ -d /etc/logrotate.d ]; then
  779. if [ ! -f /etc/logrotate.d/netdata ]; then
  780. run cp "${src}" /etc/logrotate.d/netdata
  781. fi
  782. if [ -f /etc/logrotate.d/netdata ]; then
  783. run chmod 644 /etc/logrotate.d/netdata
  784. fi
  785. return 0
  786. fi
  787. fi
  788. return 1
  789. }
  790. # -----------------------------------------------------------------------------
  791. # install netdata journald configuration
  792. install_netdata_journald_conf() {
  793. src="${NETDATA_PREFIX}/usr/lib/netdata/system/systemd/journald@netdata.conf"
  794. [ ! -d /usr/lib/systemd/ ] && return 0
  795. [ "${UID}" -ne 0 ] && return 1
  796. if [ ! -d /usr/lib/systemd/journald@netdata.conf.d/ ]; then
  797. run mkdir /usr/lib/systemd/journald@netdata.conf.d/
  798. fi
  799. run cp "${src}" /usr/lib/systemd/journald@netdata.conf.d/netdata.conf
  800. if [ -f /usr/lib/systemd/journald@netdata.conf.d/netdata.conf ]; then
  801. run chmod 644 /usr/lib/systemd/journald@netdata.conf.d/netdata.conf
  802. fi
  803. return 0
  804. }
  805. # -----------------------------------------------------------------------------
  806. # create netdata.conf
  807. create_netdata_conf() {
  808. path="${1}"
  809. url="${2}"
  810. if [ -s "${path}" ]; then
  811. return 0
  812. fi
  813. if [ -n "$url" ]; then
  814. echo >&2 "Downloading default configuration from netdata..."
  815. sleep 5
  816. # remove a possibly obsolete configuration file
  817. [ -f "${path}.new" ] && rm "${path}.new"
  818. # disable a proxy to get data from the local netdata
  819. export http_proxy=
  820. export https_proxy=
  821. check_for_curl
  822. if [ -n "${curl}" ]; then
  823. run "${curl}" -sSL --connect-timeout 10 --retry 3 "${url}" > "${path}.new"
  824. elif command -v wget 1> /dev/null 2>&1; then
  825. run wget -T 15 -O - "${url}" > "${path}.new"
  826. fi
  827. if [ -s "${path}.new" ]; then
  828. run mv "${path}.new" "${path}"
  829. run_ok "New configuration saved for you to edit at ${path}"
  830. else
  831. [ -f "${path}.new" ] && rm "${path}.new"
  832. run_failed "Cannot download configuration from netdata daemon using url '${url}'"
  833. url=''
  834. fi
  835. fi
  836. if [ -z "$url" ]; then
  837. cat << EOF > "${path}"
  838. # netdata can generate its own config which is available at 'http://<IP>:19999/netdata.conf'
  839. # You can download it using:
  840. # curl -o ${path} http://localhost:19999/netdata.conf
  841. # or
  842. # wget -O ${path} http://localhost:19999/netdata.conf
  843. EOF
  844. fi
  845. }
  846. portable_add_user() {
  847. username="${1}"
  848. homedir="${2}"
  849. [ -z "${homedir}" ] && homedir="/tmp"
  850. # Check if user exists
  851. if command -v getent > /dev/null 2>&1; then
  852. if getent passwd "${username}" > /dev/null 2>&1; then
  853. echo >&2 "User '${username}' already exists."
  854. return 0
  855. fi
  856. elif command -v dscl > /dev/null 2>&1; then
  857. if dscl . read /Users/"${username}" >/dev/null 2>&1; then
  858. echo >&2 "User '${username}' already exists."
  859. return 0
  860. fi
  861. else
  862. if cut -d ':' -f 1 < /etc/passwd | grep "^${username}$" 1> /dev/null 2>&1; then
  863. echo >&2 "User '${username}' already exists."
  864. return 0
  865. fi
  866. fi
  867. echo >&2 "Adding ${username} user account with home ${homedir} ..."
  868. nologin="$(command -v nologin || echo '/bin/false')"
  869. if command -v useradd 1> /dev/null 2>&1; then
  870. run useradd -r -g "${username}" -c "${username}" -s "${nologin}" --no-create-home -d "${homedir}" "${username}" && return 0
  871. elif command -v pw 1> /dev/null 2>&1; then
  872. run pw useradd "${username}" -d "${homedir}" -g "${username}" -s "${nologin}" && return 0
  873. elif command -v adduser 1> /dev/null 2>&1; then
  874. run adduser -h "${homedir}" -s "${nologin}" -D -G "${username}" "${username}" && return 0
  875. elif command -v sysadminctl 1> /dev/null 2>&1; then
  876. gid=$(dscl . read /Groups/"${username}" 2>/dev/null | grep PrimaryGroupID | grep -Eo "[0-9]+")
  877. if run sysadminctl -addUser "${username}" -shell /usr/bin/false -home /var/empty -GID "$gid"; then
  878. # FIXME: I think the proper solution is to create a role account:
  879. # -roleAccount + name starting with _ and UID in 200-400 range.
  880. run dscl . create /Users/"${username}" IsHidden 1
  881. return 0
  882. fi
  883. fi
  884. warning "Failed to add ${username} user account!"
  885. return 1
  886. }
  887. portable_add_group() {
  888. groupname="${1}"
  889. # Check if group exist
  890. if get_group "${groupname}" > /dev/null 2>&1; then
  891. echo >&2 "Group '${groupname}' already exists."
  892. return 0
  893. fi
  894. echo >&2 "Adding ${groupname} user group ..."
  895. # Linux
  896. if command -v groupadd 1> /dev/null 2>&1; then
  897. run groupadd -r "${groupname}" && return 0
  898. elif command -v pw 1> /dev/null 2>&1; then
  899. run pw groupadd "${groupname}" && return 0
  900. elif command -v addgroup 1> /dev/null 2>&1; then
  901. run addgroup "${groupname}" && return 0
  902. elif command -v dseditgroup 1> /dev/null 2>&1; then
  903. dseditgroup -o create "${groupname}" && return 0
  904. fi
  905. warning >&2 "Failed to add ${groupname} user group !"
  906. return 1
  907. }
  908. portable_add_user_to_group() {
  909. groupname="${1}"
  910. username="${2}"
  911. # Check if group exist
  912. if ! get_group "${groupname}" > /dev/null 2>&1; then
  913. echo >&2 "Group '${groupname}' does not exist."
  914. # Don’t treat this as a failure, if the group does not exist we should not be trying to add the user to it.
  915. return 0
  916. fi
  917. # Check if user is in group
  918. if get_group "${groupname}" | cut -d ':' -f 4 | grep -wq "${username}"; then
  919. # username is already there
  920. echo >&2 "User '${username}' is already in group '${groupname}'."
  921. return 0
  922. else
  923. # username is not in group
  924. echo >&2 "Adding ${username} user to the ${groupname} group ..."
  925. # Linux
  926. if command -v usermod 1> /dev/null 2>&1; then
  927. run usermod -a -G "${groupname}" "${username}" && return 0
  928. elif command -v pw 1> /dev/null 2>&1; then
  929. run pw groupmod "${groupname}" -m "${username}" && return 0
  930. elif command -v addgroup 1> /dev/null 2>&1; then
  931. run addgroup "${username}" "${groupname}" && return 0
  932. elif command -v dseditgroup 1> /dev/null 2>&1; then
  933. dseditgroup -u "${username}" "${groupname}" && return 0
  934. fi
  935. warning >&2 "Failed to add user ${username} to group ${groupname}!"
  936. return 1
  937. fi
  938. }
  939. safe_sha256sum() {
  940. # Within the context of the installer, we only use -c option that is common between the two commands
  941. # We will have to reconsider if we start non-common options
  942. if command -v sha256sum > /dev/null 2>&1; then
  943. sha256sum "$@"
  944. elif command -v shasum > /dev/null 2>&1; then
  945. shasum -a 256 "$@"
  946. else
  947. fatal "I could not find a suitable checksum binary to use" "L0001"
  948. fi
  949. }
  950. _get_scheduler_type() {
  951. if _get_intervaldir > /dev/null ; then
  952. echo 'interval'
  953. elif issystemd ; then
  954. echo 'systemd'
  955. elif [ -d /etc/cron.d ] ; then
  956. echo 'crontab'
  957. else
  958. echo 'none'
  959. fi
  960. }
  961. _get_intervaldir() {
  962. if [ -d /etc/cron.daily ]; then
  963. echo /etc/cron.daily
  964. elif [ -d /etc/periodic/daily ]; then
  965. echo /etc/periodic/daily
  966. else
  967. return 1
  968. fi
  969. return 0
  970. }
  971. install_netdata_updater() {
  972. if [ "${INSTALLER_DIR}" ] && [ -f "${INSTALLER_DIR}/packaging/installer/netdata-updater.sh" ]; then
  973. cat "${INSTALLER_DIR}/packaging/installer/netdata-updater.sh" > "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" || return 1
  974. fi
  975. if [ "${NETDATA_SOURCE_DIR}" ] && [ -f "${NETDATA_SOURCE_DIR}/packaging/installer/netdata-updater.sh" ]; then
  976. cat "${NETDATA_SOURCE_DIR}/packaging/installer/netdata-updater.sh" > "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh" || return 1
  977. fi
  978. # these files are installed by cmake
  979. libsysdir="${NETDATA_PREFIX}/usr/lib/netdata/system/systemd/"
  980. if [ -d "${libsysdir}" ] && issystemd && [ -n "$(get_systemd_service_dir)" ]; then
  981. cat "${libsysdir}/netdata-updater.timer" > "$(get_systemd_service_dir)/netdata-updater.timer"
  982. cat "${libsysdir}/netdata-updater.service" > "$(get_systemd_service_dir)/netdata-updater.service"
  983. fi
  984. 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
  985. chmod 0755 "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh"
  986. echo >&2 "Update script is located at ${TPUT_GREEN}${TPUT_BOLD}${NETDATA_PREFIX}/usr/libexec/netdata/netdata-updater.sh${TPUT_RESET}"
  987. echo >&2
  988. return 0
  989. }
  990. set_netdata_updater_channel() {
  991. sed -i -e "s/^RELEASE_CHANNEL=.*/RELEASE_CHANNEL=\"${RELEASE_CHANNEL}\"/" "${NETDATA_USER_CONFIG_DIR}/.environment"
  992. }