@cryptotaxi247 / netdata-1 / commits / 87071cbae

update scripts for POSIX compatibility (#11961)

maneamarius committed Feb 8, 2022 at 14:38 UTC 87071cbae24e9266f327509c39057c55eb628911
2 files changed +231 -226
netdata-installer.sh
+175 -154
@@ -1,20 +1,23 @@
1 -#!/usr/bin/env bash
1 +#!/bin/sh
2
3 # SPDX-License-Identifier: GPL-3.0-or-later
4 -# shellcheck disable=SC2046,SC2086,SC2166
4
5 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
6 uniquepath() {
8 - local path=""
9 - while read -r; do
10 - if [[ ! ${path} =~ (^|:)"${REPLY}"(:|$) ]]; then
7 + path=""
8 + tmp="$(mktemp)"
9 + (echo "${PATH}" | tr ":" "\n") > "$tmp"
10 + while read -r REPLY;
11 + do
12 + if echo "${path}" | grep -v "(^|:)${REPLY}(:|$)"; then
13 [ -n "${path}" ] && path="${path}:"
14 path="${path}${REPLY}"
15 fi
14 - done < <(echo "${PATH}" | tr ":" "\n")
15 -
16 - [ -n "${path}" ] && [[ ${PATH} =~ /bin ]] && [[ ${PATH} =~ /sbin ]] && export PATH="${path}"
17 -}
16 + done < "$tmp"
17 +rm "$tmp"
18 + [ -n "${path}" ]
19 +export PATH="${path%:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin}"
20 +} > /dev/null
21 uniquepath
22
23 PROGRAM="$0"
@@ -58,7 +61,6 @@ cd "${NETDATA_SOURCE_DIR}" || exit 1
61 # -----------------------------------------------------------------------------
62 # figure out an appropriate temporary directory
63 _cannot_use_tmpdir() {
61 - local testfile ret
64 testfile="$(TMPDIR="${1}" mktemp -q -t netdata-test.XXXXXXXXXX)"
65 ret=0
66
@@ -108,8 +110,7 @@ print_deferred_errors() {
110 if [ -n "${NETDATA_DEFERRED_ERRORS}" ]; then
111 echo >&2
112 echo >&2 "The following non-fatal errors were encountered during the installation process:"
111 - # shellcheck disable=SC2059
112 - printf >&2 "${NETDATA_DEFERRED_ERRORS}"
113 + printf '%s' >&2 "${NETDATA_DEFERRED_ERRORS}"
114 echo >&2
115 fi
116 }
@@ -119,10 +120,10 @@ print_deferred_errors() {
120
121 if [ -f "${INSTALLER_DIR}/packaging/installer/functions.sh" ]; then
122 # shellcheck source=packaging/installer/functions.sh
122 - source "${INSTALLER_DIR}/packaging/installer/functions.sh" || exit 1
123 + . "${INSTALLER_DIR}/packaging/installer/functions.sh" || exit 1
124 else
125 # shellcheck source=packaging/installer/functions.sh
125 - source "${NETDATA_SOURCE_DIR}/packaging/installer/functions.sh" || exit 1
126 + . "${NETDATA_SOURCE_DIR}/packaging/installer/functions.sh" || exit 1
127 fi
128
129 download_go() {
@@ -130,6 +131,8 @@ download_go() {
131 }
132
133 # make sure we save all commands we run
134 +# Variable is used by code in the packaging/installer/functions.sh
135 +# shellcheck disable=SC2034
136 run_logfile="netdata-installer.log"
137
138
@@ -148,19 +151,22 @@ umask 002
151 renice 19 $$ > /dev/null 2> /dev/null
152
153 # you can set CFLAGS before running installer
154 +# shellcheck disable=SC2269
155 LDFLAGS="${LDFLAGS}"
156 CFLAGS="${CFLAGS--O2}"
157 [ "z${CFLAGS}" = "z-O3" ] && CFLAGS="-O2"
158 +# shellcheck disable=SC2269
159 ACLK="${ACLK}"
160
161 # keep a log of this command
157 -# shellcheck disable=SC2129
158 -printf "\n# " >> netdata-installer.log
159 -date >> netdata-installer.log
160 -printf 'CFLAGS="%s" ' "${CFLAGS}" >> netdata-installer.log
161 -printf 'LDFLAGS="%s" ' "${LDFLAGS}" >> netdata-installer.log
162 -printf "%q " "${PROGRAM}" "${@}" >> netdata-installer.log
163 -printf "\n" >> netdata-installer.log
162 +{
163 + printf "\n# "
164 + date
165 + printf 'CFLAGS="%s" ' "${CFLAGS}"
166 + printf 'LDFLAGS="%s" ' "${LDFLAGS}"
167 + printf "%s" "${PROGRAM}" "${@}"
168 + printf "\n"
169 +} >> netdata-installer.log
170
171 REINSTALL_OPTIONS="$(
172 printf "%s" "${*}"
@@ -210,7 +216,8 @@ NONROOT
216 }
217
218 usage() {
213 - netdata_banner "installer command line options"
219 + netdata_banner
220 + progress "installer command line options"
221 cat << HEREDOC
222
223 USAGE: ${PROGRAM} [options]
@@ -299,10 +306,9 @@ while [ -n "${1}" ]; do
306 case "${1}" in
307 "--zlib-is-really-here") LIBS_ARE_HERE=1 ;;
308 "--libs-are-really-here") LIBS_ARE_HERE=1 ;;
302 - "--use-system-lws") USE_SYSTEM_LWS=1 ;;
309 "--use-system-protobuf")
310 USE_SYSTEM_PROTOBUF=1
305 - NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--without-bundled-protobuf/} --without-bundled-protobuf"
311 + NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--without-bundled-protobuf}" | sed 's/$/ --without-bundled-protobuf/g')"
312 ;;
313 "--dont-scrub-cflags-even-though-it-may-break-things") DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS=1 ;;
314 "--dont-start-it") DONOTSTART=1 ;;
@@ -322,52 +328,52 @@ while [ -n "${1}" ]; do
328 ;;
329 "--stable-channel") RELEASE_CHANNEL="stable" ;;
330 "--nightly-channel") RELEASE_CHANNEL="nightly" ;;
325 - "--enable-plugin-freeipmi") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-freeipmi/} --enable-plugin-freeipmi" ;;
326 - "--disable-plugin-freeipmi") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-plugin-freeipmi/} --disable-plugin-freeipmi" ;;
327 - "--disable-https") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-https/} --disable-https" ;;
331 + "--enable-plugin-freeipmi") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-plugin-freeipmi)}" | sed 's/$/ --enable-plugin-freeipmi/g')" ;;
332 + "--disable-plugin-freeipmi") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-plugin-freeipmi)}" | sed 's/$/ --disable-plugin-freeipmi/g')" ;;
333 + "--disable-https") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-https)}" | sed 's/$/ --disable-plugin-https/g')" ;;
334 "--disable-dbengine")
329 - NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-dbengine/} --disable-dbengine"
335 + NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-dbengine)}" | sed 's/$/ --disable-dbengine/g')"
336 NETDATA_DISABLE_DBENGINE=1
337 ;;
332 - "--enable-plugin-nfacct") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-nfacct/} --enable-plugin-nfacct" ;;
333 - "--disable-plugin-nfacct") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-plugin-nfacct/} --disable-plugin-nfacct" ;;
334 - "--enable-plugin-xenstat") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-plugin-xenstat/} --enable-plugin-xenstat" ;;
335 - "--disable-plugin-xenstat") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-plugin-xenstat/} --disable-plugin-xenstat" ;;
336 - "--enable-backend-kinesis") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-backend-kinesis/} --enable-backend-kinesis" ;;
337 - "--disable-backend-kinesis") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-backend-kinesis/} --disable-backend-kinesis" ;;
338 - "--enable-backend-prometheus-remote-write") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-backend-prometheus-remote-write/} --enable-backend-prometheus-remote-write" ;;
338 + "--enable-plugin-nfacct") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-plugin-nfacct)}" | sed 's/$/ --enable-plugin-nfacct/g')" ;;
339 + "--disable-plugin-nfacct") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-plugin-nfacct)}" | sed 's/$/ --disable-plugin-nfacct/g')" ;;
340 + "--enable-plugin-xenstat") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-plugin-xenstat)}" | sed 's/$/ --enable-plugin-xenstat/g')" ;;
341 + "--disable-plugin-xenstat") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-plugin-xenstat)}" | sed 's/$/ --disable-plugin-xenstat/g')" ;;
342 + "--enable-backend-kinesis") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-backend-kinesis)}" | sed 's/$/ --enable-backend-kinesis/g')" ;;
343 + "--disable-backend-kinesis") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-backend-kinesis)}" | sed 's/$/ --disable-backend-kinesis/g')" ;;
344 + "--enable-backend-prometheus-remote-write") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-backend-prometheus-remote-write)}" | sed 's/$/ --enable-backend-prometheus-remote-write/g')" ;;
345 "--disable-backend-prometheus-remote-write")
340 - NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-backend-prometheus-remote-write/} --disable-backend-prometheus-remote-write"
346 + NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-backend-prometheus-remote-write)}" | sed 's/$/ --disable-backend-prometheus-remote-write/g')"
347 NETDATA_DISABLE_PROMETHEUS=1
348 ;;
343 - "--enable-backend-mongodb") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-backend-mongodb/} --enable-backend-mongodb" ;;
344 - "--disable-backend-mongodb") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-backend-mongodb/} --disable-backend-mongodb" ;;
345 - "--enable-exporting-pubsub") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-exporting-pubsub/} --enable-exporting-pubsub" ;;
346 - "--disable-exporting-pubsub") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-exporting-pubsub/} --disable-exporting-pubsub" ;;
347 - "--enable-lto") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-lto/} --enable-lto" ;;
349 + "--enable-backend-mongodb") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-backend-mongodb)}" | sed 's/$/ --enable-backend-mongodb/g')" ;;
350 + "--disable-backend-mongodb") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-backend-mongodb)}" | sed 's/$/ --disable-backend-mongodb/g')" ;;
351 + "--enable-exporting-pubsub") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-exporting-pubsub)}" | sed 's/$/ --enable-exporting-pubsub/g')" ;;
352 + "--disable-exporting-pubsub") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-exporting-pubsub)}" | sed 's/$/ --disable-exporting-pubsub/g')" ;;
353 + "--enable-lto") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-lto)}" | sed 's/$/ --enable-lto/g')" ;;
354 "--enable-ml")
349 - NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-ml/} --enable-ml"
355 + NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-ml)}" | sed 's/$/ --enable-ml/g')"
356 NETDATA_ENABLE_ML=1
357 ;;
358 "--disable-ml")
353 - NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-ml/} --disable-ml"
359 + NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-ml)}" | sed 's/$/ --disable-ml/g')"
360 NETDATA_ENABLE_ML=0
361 ;;
356 - "--enable-ml-tests") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-ml-tests/} --enable-ml-tests" ;;
357 - "--disable-ml-tests") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-ml-tests/} --disable-ml-tests" ;;
358 - "--disable-lto") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-lto/} --disable-lto" ;;
359 - "--disable-x86-sse") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-x86-sse/} --disable-x86-sse" ;;
362 + "--enable-ml-tests") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-ml-tests)}" | sed 's/$/ --enable-ml-tests/g')" ;;
363 + "--disable-ml-tests") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-ml-tests)}" | sed 's/$/ --disable-ml-tests/g')" ;;
364 + "--disable-lto") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-lto)}" | sed 's/$/ --disable-lto/g')" ;;
365 + "--disable-x86-sse") NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-x86-sse)}" | sed 's/$/ --disable-x86-sse/g')" ;;
366 "--disable-telemetry") NETDATA_DISABLE_TELEMETRY=1 ;;
367 "--disable-go") NETDATA_DISABLE_GO=1 ;;
368 "--enable-ebpf") NETDATA_DISABLE_EBPF=0 ;;
363 - "--disable-ebpf") NETDATA_DISABLE_EBPF=1 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-ebpf/} --disable-ebpf" ;;
369 + "--disable-ebpf") NETDATA_DISABLE_EBPF=1 NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-ebpf)}" | sed 's/$/ --disable-ebpf/g')" ;;
370 "--skip-available-ram-check") SKIP_RAM_CHECK=1 ;;
371 "--disable-cloud")
372 if [ -n "${NETDATA_REQUIRE_CLOUD}" ]; then
373 echo "Cloud explicitly enabled, ignoring --disable-cloud."
374 else
375 NETDATA_DISABLE_CLOUD=1
370 - NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-cloud/} --disable-cloud"
376 + NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-cloud)}" | sed 's/$/ --disable-cloud/g')"
377 fi
378 ;;
379 "--require-cloud")
@@ -375,7 +381,7 @@ while [ -n "${1}" ]; do
381 echo "Cloud explicitly disabled, ignoring --require-cloud."
382 else
383 NETDATA_REQUIRE_CLOUD=1
378 - NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--enable-cloud/} --enable-cloud"
384 + NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--enable-cloud)}" | sed 's/$/ --enable-cloud/g')"
385 fi
386 ;;
387 "--build-json-c")
@@ -412,14 +418,12 @@ if [ "$(uname -s)" = "FreeBSD" ]; then
418 NETDATA_CONFIGURE_OPTIONS="$NETDATA_CONFIGURE_OPTIONS --disable-dependency-tracking"
419 fi
420
415 -# replace multiple spaces with a single space
416 -NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS// / }"
417 -
421 if [ "$(uname -s)" = "Linux" ] && [ -f /proc/meminfo ]; then
422 mega="$((1024 * 1024))"
423 base=1024
424 scale=256
425
426 + # shellcheck disable=SC2086
427 if [ -n "${MAKEOPTS}" ]; then
428 proc_count="$(echo ${MAKEOPTS} | grep -oE '\-j *[[:digit:]]+' | tr -d '\-j ')"
429 else
@@ -431,7 +435,7 @@ if [ "$(uname -s)" = "Linux" ] && [ -f /proc/meminfo ]; then
435 total_ram="$((total_ram * 1024))"
436
437 if [ "${total_ram}" -le "$((base * mega))" ] && [ -z "${NETDATA_ENABLE_ML}" ]; then
434 - NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-ml/} --disable-ml"
438 + NETDATA_CONFIGURE_OPTIONS="$(echo "${NETDATA_CONFIGURE_OPTIONS%--disable-ml)}" | sed 's/$/ --disable-ml/g')"
439 NETDATA_ENABLE_ML=0
440 fi
441
@@ -461,9 +465,10 @@ elif echo "${MAKEOPTS}" | grep -vqF -e "-j"; then
465 MAKEOPTS="${MAKEOPTS} -j$(find_processors)"
466 fi
467
464 -if [ "${UID}" -ne 0 ]; then
468 +if [ "$(id -u)" -ne 0 ]; then
469 if [ -z "${NETDATA_PREFIX}" ]; then
466 - netdata_banner "wrong command line options!"
470 + netdata_banner
471 + progress "wrong command line options!"
472 banner_nonroot_install "${@}"
473 exit 1
474 else
@@ -471,7 +476,8 @@ if [ "${UID}" -ne 0 ]; then
476 fi
477 fi
478
474 -netdata_banner "real-time performance monitoring, done right!"
479 +netdata_banner
480 +progress "real-time performance monitoring, done right!"
481 cat << BANNER1
482
483 You are about to build and install netdata to your system.
@@ -491,7 +497,7 @@ cat << BANNER1
497 - log files in ${TPUT_CYAN}${NETDATA_PREFIX}/var/log/netdata${TPUT_RESET}
498 BANNER1
499
494 -[ "${UID}" -eq 0 ] && cat << BANNER2
500 +[ "$(id -u)" -eq 0 ] && cat << BANNER2
501 - pid file at ${TPUT_CYAN}${NETDATA_PREFIX}/var/run/netdata.pid${TPUT_RESET}
502 - logrotate file at ${TPUT_CYAN}/etc/logrotate.d/netdata${TPUT_RESET}
503 BANNER2
@@ -518,19 +524,22 @@ fi
524 have_autotools=
525 if [ "$(type autoreconf 2> /dev/null)" ]; then
526 autoconf_maj_min() {
521 - local maj min IFS=.-
522 -
527 + OLDIFS=$IFS
528 + IFS=.-
529 maj=$1
530 min=$2
531
532 + # shellcheck disable=SC2046
533 set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
534 + # shellcheck disable=SC2086
535 eval $maj=\$1 $min=\$2
536 + IFS=$OLDIFS
537 }
538 autoconf_maj_min AMAJ AMIN
539
540 if [ "$AMAJ" -gt 2 ]; then
541 have_autotools=Y
533 - elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]; then
542 + elif [ "$AMAJ" -eq 2 ] && [ "$AMIN" -ge 60 ]; then
543 have_autotools=Y
544 else
545 echo "Found autotools $AMAJ.$AMIN"
@@ -543,7 +552,8 @@ if [ ! "$have_autotools" ]; then
552 if [ -f configure ]; then
553 echo "Will skip autoreconf step"
554 else
546 - netdata_banner "autotools v2.60 required"
555 + netdata_banner
556 + progress "autotools v2.60 required"
557 cat << "EOF"
558
559 -------------------------------------------------------------------------------
@@ -559,11 +569,11 @@ fi
569
570 if [ ${DONOTWAIT} -eq 0 ]; then
571 if [ -n "${NETDATA_PREFIX}" ]; then
562 - echo -n "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to '${TPUT_CYAN}${NETDATA_PREFIX}${TPUT_YELLOW}'${TPUT_RESET} > "
572 + printf '%s' "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to '${TPUT_CYAN}${NETDATA_PREFIX}${TPUT_YELLOW}'${TPUT_RESET} > "
573 else
564 - echo -n "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to your system${TPUT_RESET} > "
574 + printf '%s' "${TPUT_BOLD}${TPUT_GREEN}Press ENTER to build and install netdata to your system${TPUT_RESET} > "
575 fi
566 - read -ern1
576 + read -r REPLY
577 if [ "$REPLY" != '' ]; then
578 exit 1
579 fi
@@ -571,7 +581,8 @@ if [ ${DONOTWAIT} -eq 0 ]; then
581 fi
582
583 build_error() {
574 - netdata_banner "sorry, it failed to build..."
584 + netdata_banner
585 + progress "sorry, it failed to build..."
586 cat << EOF
587
588 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -623,26 +634,27 @@ fi
634 trap build_error EXIT
635
636 # -----------------------------------------------------------------------------
626 -
637 build_protobuf() {
628 - local env_cmd=''
638 + env_cmd=''
639
640 if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
641 env_cmd="env CFLAGS=-fPIC CXXFLAGS= LDFLAGS="
642 fi
643
634 - pushd "${1}" > /dev/null || return 1
644 + cd "${1}" > /dev/null || return 1
645 + # shellcheck disable=SC2086
646 if ! run ${env_cmd} ./configure --disable-shared --without-zlib --disable-dependency-tracking --with-pic; then
636 - popd > /dev/null || return 1
647 + cd - > /dev/null || return 1
648 return 1
649 fi
650
651 + # shellcheck disable=SC2086
652 if ! run ${env_cmd} $make ${MAKEOPTS}; then
641 - popd > /dev/null || return 1
653 + cd - > /dev/null || return 1
654 return 1
655 fi
656
645 - popd > /dev/null || return 1
657 + cd - > /dev/null || return 1
658 }
659
660 copy_protobuf() {
@@ -699,8 +711,8 @@ bundle_protobuf
711 # -----------------------------------------------------------------------------
712
713 build_judy() {
702 - local env_cmd=''
703 - local libtoolize="libtoolize"
714 + env_cmd=''
715 + libtoolize="libtoolize"
716
717 if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
718 env_cmd="env CFLAGS=-fPIC CXXFLAGS= LDFLAGS="
@@ -710,7 +722,8 @@ build_judy() {
722 libtoolize="glibtoolize"
723 fi
724
713 - pushd "${1}" > /dev/null || return 1
725 + cd "${1}" > /dev/null || return 1
726 + # shellcheck disable=SC2086
727 if run ${env_cmd} ${libtoolize} --force --copy &&
728 run ${env_cmd} aclocal &&
729 run ${env_cmd} autoheader &&
@@ -719,9 +732,9 @@ build_judy() {
732 run ${env_cmd} ./configure &&
733 run ${env_cmd} ${make} ${MAKEOPTS} -C src &&
734 run ${env_cmd} ar -r src/libJudy.a src/Judy*/*.o; then
722 - popd > /dev/null || return 1
735 + cd - > /dev/null || return 1
736 else
724 - popd > /dev/null || return 1
737 + cd - > /dev/null || return 1
738 return 1
739 fi
740 }
@@ -793,18 +806,19 @@ bundle_judy() {
806 bundle_judy
807
808 # -----------------------------------------------------------------------------
796 -
809 build_jsonc() {
798 - local env_cmd=''
810 + env_cmd=''
811
812 if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
813 env_cmd="env CFLAGS=-fPIC CXXFLAGS= LDFLAGS="
814 fi
815
804 - pushd "${1}" > /dev/null || exit 1
816 + cd "${1}" > /dev/null || exit 1
817 + # shellcheck disable=SC2086
818 run ${env_cmd} cmake -DBUILD_SHARED_LIBS=OFF .
819 + # shellcheck disable=SC2086
820 run ${env_cmd} ${make} ${MAKEOPTS}
807 - popd > /dev/null || exit 1
821 + cd - > /dev/null || exit 1
822 }
823
824 copy_jsonc() {
@@ -813,6 +827,7 @@ copy_jsonc() {
827 run mkdir -p "${target_dir}" "${target_dir}/json-c" || return 1
828
829 run cp "${1}/libjson-c.a" "${target_dir}/libjson-c.a" || return 1
830 + # shellcheck disable=SC2086
831 run cp ${1}/*.h "${target_dir}/json-c" || return 1
832 }
833
@@ -866,9 +881,14 @@ bundle_jsonc
881 get_kernel_version() {
882 r="$(uname -r | cut -f 1 -d '-')"
883
869 - read -r -a p <<< "$(echo "${r}" | tr '.' ' ')"
884 + tmpfile="$(mktemp)"
885 + echo "${r}" | tr '.' ' ' > "${tmpfile}"
886 +
887 + read -r maj min patch _ < "${tmpfile}"
888 +
889 + rm -f "${tmpfile}"
890
871 - printf "%03d%03d%03d" "${p[0]}" "${p[1]}" "${p[2]}"
891 + printf "%03d%03d%03d" "${maj}" "${min}" "${patch}"
892 }
893
894 rename_libbpf_packaging() {
@@ -883,10 +903,11 @@ rename_libbpf_packaging() {
903
904
905 build_libbpf() {
886 - pushd "${1}/src" > /dev/null || exit 1
906 + cd "${1}/src" > /dev/null || exit 1
907 mkdir root build
908 + # shellcheck disable=SC2086
909 run env CFLAGS=-fPIC CXXFLAGS= LDFLAGS= BUILD_STATIC_ONLY=y OBJDIR=build DESTDIR=.. ${make} ${MAKEOPTS} install
889 - popd > /dev/null || exit 1
910 + cd - > /dev/null || exit 1
911 }
912
913 copy_libbpf() {
@@ -981,6 +1002,7 @@ if [ "$have_autotools" ]; then
1002 run autoreconf -ivf || exit 1
1003 fi
1004
1005 +# shellcheck disable=SC2086
1006 run ./configure \
1007 --prefix="${NETDATA_PREFIX}/usr" \
1008 --sysconfdir="${NETDATA_PREFIX}/etc" \
@@ -1008,6 +1030,7 @@ run $make clean
1030 # -----------------------------------------------------------------------------
1031 progress "Compile netdata"
1032
1033 +# shellcheck disable=SC2086
1034 run $make ${MAKEOPTS} || exit 1
1035
1036 [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
@@ -1029,7 +1052,7 @@ if [ -d "${NETDATA_PREFIX}/etc/netdata" ]; then
1052 # move the charts.d config files
1053 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
1054 for y in "" ".old" ".orig"; do
1032 - if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}" ]; then
1055 + if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" ] && [ ! -f "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}" ]; then
1056 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/charts.d/${x}.conf${y}"
1057 fi
1058 done
@@ -1042,7 +1065,7 @@ if [ -d "${NETDATA_PREFIX}/etc/netdata" ]; then
1065 # move the node.d config files
1066 for x in named sma_webbox snmp; do
1067 for y in "" ".old" ".orig"; do
1045 - if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" -a ! -f "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}" ]; then
1068 + if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" ] && [ ! -f "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}" ]; then
1069 run mv -f "${NETDATA_PREFIX}/etc/netdata/${x}.conf${y}" "${NETDATA_PREFIX}/etc/netdata/node.d/${x}.conf${y}"
1070 fi
1071 done
@@ -1059,20 +1082,9 @@ if [ ! -f "${NETDATA_PREFIX}/etc/netdata/.installer-cleanup-of-stock-configs-don
1082
1083 progress "Backup existing netdata configuration before installing it"
1084
1062 - if [ "${BASH_VERSINFO[0]}" -ge "4" ]; then
1063 - declare -A configs_signatures=()
1064 - if [ -f "configs.signatures" ]; then
1065 - source "configs.signatures" || echo >&2 "ERROR: Failed to load configs.signatures !"
1066 - fi
1067 - fi
1068 -
1085 config_signature_matches() {
1070 - local md5="${1}" file="${2}"
1071 -
1072 - if [ "${BASH_VERSINFO[0]}" -ge "4" ]; then
1073 - [ "${configs_signatures[${md5}]}" = "${file}" ] && return 0
1074 - return 1
1075 - fi
1086 + md5="${1}"
1087 + file="${2}"
1088
1089 if [ -f "configs.signatures" ]; then
1090 grep "\['${md5}'\]='${file}'" "configs.signatures" > /dev/null
@@ -1083,18 +1095,18 @@ if [ ! -f "${NETDATA_PREFIX}/etc/netdata/.installer-cleanup-of-stock-configs-don
1095 }
1096
1097 # clean up stock config files from the user configuration directory
1086 - while IFS= read -r -d '' x; do
1098 + (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.*' \)) | while IFS= read -r x; do
1099 if [ -f "${x}" ]; then
1100 # find it relative filename
1089 - f="${x/${NETDATA_PREFIX}\/etc\/netdata\//}"
1101 + f=$("$x" | sed "${NETDATA_PREFIX}/etc/netdata/")
1102
1103 # find the stock filename
1092 - t="${f/.conf.installer_backup.*/.conf}"
1093 - t="${t/.conf.old/.conf}"
1094 - t="${t/.conf.orig/.conf}"
1095 - t="${t/orig\//}"
1104 + t=$("${f}" | sed ".conf.installer_backup.*/.conf")
1105 + t=$("${t}" | sed ".conf.old/.conf")
1106 + t=$("${t}" | sed ".conf.orig/.conf")
1107 + t=$("${t}" | sed "orig//")
1108
1097 - if [ -z "${md5sum}" -o ! -x "${md5sum}" ]; then
1109 + if [ -z "${md5sum}" ] || [ ! -x "${md5sum}" ]; then
1110 # we don't have md5sum - keep it
1111 echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' ${TPUT_RED}is not known to distribution${TPUT_RESET}. Keeping it."
1112 else
@@ -1102,9 +1114,10 @@ if [ ! -f "${NETDATA_PREFIX}/etc/netdata/.installer-cleanup-of-stock-configs-don
1114 md5="$(${md5sum} < "${x}" | cut -d ' ' -f 1)"
1115
1116 if config_signature_matches "${md5}" "${t}"; then
1105 - # it is a stock version - remove it
1117 + # it is a stock version - remove it
1118 echo >&2 "File '${TPUT_CYAN}${x}${TPUT_RESET}' is stock version of '${t}'."
1119 run rm -f "${x}"
1120 + # shellcheck disable=SC2030
1121 deleted_stock_configs=$((deleted_stock_configs + 1))
1122 else
1123 # edited by user - keep it
@@ -1112,7 +1125,7 @@ if [ ! -f "${NETDATA_PREFIX}/etc/netdata/.installer-cleanup-of-stock-configs-don
1125 fi
1126 fi
1127 fi
1115 - done < <(find -L "${NETDATA_PREFIX}/etc/netdata" -type f -not -path '*/\.*' -not -path "${NETDATA_PREFIX}/etc/netdata/orig/*" \( -name '*.conf.old' -o -name '*.conf' -o -name '*.conf.orig' -o -name '*.conf.installer_backup.*' \))
1128 + done
1129 fi
1130 touch "${NETDATA_PREFIX}/etc/netdata/.installer-cleanup-of-stock-configs-done"
1131
@@ -1131,7 +1144,7 @@ progress "Creating standard user and groups for netdata"
1144
1145 NETDATA_WANTED_GROUPS="docker nginx varnish haproxy adm nsd proxy squid ceph nobody"
1146 NETDATA_ADDED_TO_GROUPS=""
1134 -if [ "${UID}" -eq 0 ]; then
1147 +if [ "$(id -u)" -eq 0 ]; then
1148 progress "Adding group 'netdata'"
1149 portable_add_group netdata || :
1150
@@ -1161,7 +1174,9 @@ progress "Read installation options from netdata.conf"
1174
1175 # function to extract values from the config file
1176 config_option() {
1164 - local section="${1}" key="${2}" value="${3}"
1177 + section="${1}"
1178 + key="${2}"
1179 + value="${3}"
1180
1181 if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]; then
1182 "${NETDATA_PREFIX}/usr/sbin/netdata" \
@@ -1174,7 +1189,7 @@ config_option() {
1189 }
1190
1191 # the user netdata will run as
1177 -if [ "${UID}" = "0" ]; then
1192 +if [ "$(id -u)" = "0" ]; then
1193 NETDATA_USER="$(config_option "global" "run as user" "netdata")"
1194 ROOT_USER="root"
1195 else
@@ -1188,7 +1203,7 @@ echo >&2 "Netdata user and group is finally set to: ${NETDATA_USER}/${NETDATA_GR
1203 # the owners of the web files
1204 NETDATA_WEB_USER="$(config_option "web" "web files owner" "${NETDATA_USER}")"
1205 NETDATA_WEB_GROUP="${NETDATA_GROUP}"
1191 -if [ "${UID}" = "0" ] && [ "${NETDATA_USER}" != "${NETDATA_WEB_USER}" ]; then
1206 +if [ "$(id -u)" = "0" ] && [ "${NETDATA_USER}" != "${NETDATA_WEB_USER}" ]; then
1207 NETDATA_WEB_GROUP="$(id -g -n "${NETDATA_WEB_USER}")"
1208 [ -z "${NETDATA_WEB_GROUP}" ] && NETDATA_WEB_GROUP="${NETDATA_WEB_USER}"
1209 fi
@@ -1244,6 +1259,7 @@ fi
1259 [ ! -d "${NETDATA_STOCK_CONFIG_DIR}" ] && mkdir -p "${NETDATA_STOCK_CONFIG_DIR}"
1260
1261 helplink="000.-.USE.THE.orig.LINK.TO.COPY.AND.EDIT.STOCK.CONFIG.FILES"
1262 +# shellcheck disable=SC2031
1263 [ ${deleted_stock_configs} -eq 0 ] && helplink=""
1264 for link in "orig" "${helplink}"; do
1265 if [ -n "${link}" ]; then
@@ -1288,7 +1304,7 @@ run chmod 770 "${NETDATA_CLAIMING_DIR}"
1304
1305 # --- plugins ----
1306
1291 -if [ "${UID}" -eq 0 ]; then
1307 +if [ "$(id -u)" -eq 0 ]; then
1308 # find the admin group
1309 admin_group=
1310 test -z "${admin_group}" && getent group root > /dev/null 2>&1 && admin_group="root"
@@ -1299,6 +1315,7 @@ if [ "${UID}" -eq 0 ]; then
1315 run chown -R "root:${admin_group}" "${NETDATA_PREFIX}/usr/libexec/netdata"
1316 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type d -exec chmod 0755 {} \;
1317 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -exec chmod 0644 {} \;
1318 + # shellcheck disable=SC2086
1319 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chown :${NETDATA_GROUP} {} \;
1320 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.plugin -exec chmod 0750 {} \;
1321 run find "${NETDATA_PREFIX}/usr/libexec/netdata" -type f -a -name \*.sh -exec chmod 0755 {} \;
@@ -1331,29 +1348,29 @@ if [ "${UID}" -eq 0 ]; then
1348 fi
1349
1350 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin" ]; then
1334 - run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
1351 + run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
1352 run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/xenstat.plugin"
1353 fi
1354
1355 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin" ]; then
1339 - run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
1356 + run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
1357 run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin"
1358 run sh -c "setcap cap_perfmon+ep \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin\" || setcap cap_sys_admin+ep \"${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/perf.plugin\""
1359 fi
1360
1361 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin" ]; then
1345 - run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
1362 + run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
1363 run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
1364 run setcap cap_dac_read_search+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/slabinfo.plugin"
1365 fi
1366
1367 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping" ]; then
1351 - run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
1368 + run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
1369 run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ioping"
1370 fi
1371
1372 if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin" ]; then
1356 - run chown root:${NETDATA_GROUP} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin"
1373 + run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin"
1374 run chmod 4750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/ebpf.plugin"
1375 fi
1376
@@ -1383,6 +1400,8 @@ fi
1400 # 1 - version1 > version2
1401 # 2 - version2 > version1
1402 # 3 - error
1403 +
1404 +# shellcheck disable=SC2086
1405 govercomp() {
1406 # version in file:
1407 # - v0.14.0
@@ -1395,23 +1414,26 @@ govercomp() {
1414 # - go.d.plugin, version: v0.14.1-1-g4c5f98c-dirty
1415
1416 # we need to compare only MAJOR.MINOR.PATCH part
1398 - local ver1 ver2
1417 ver1=$(echo "$1" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+")
1418 ver2=$(echo "$2" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+")
1419
1402 - local IFS=.
1403 - read -ra ver1 <<< "$ver1"
1404 - read -ra ver2 <<< "$ver2"
1405 -
1406 - if [ ${#ver1[@]} -eq 0 ] || [ ${#ver2[@]} -eq 0 ]; then
1420 + if [ ${#ver1} -eq 0 ] || [ ${#ver2} -eq 0 ]; then
1421 return 3
1422 fi
1423
1410 - local i
1411 - for ((i = 0; i < ${#ver1[@]}; i++)); do
1412 - if [ "${ver1[i]}" -gt "${ver2[i]}" ]; then
1424 + num1=$(echo $ver1 | grep -o -E '\.' | wc -l)
1425 + num2=$(echo $ver2 | grep -o -E '\.' | wc -l)
1426 +
1427 + if [ ${num1} -ne ${num2} ]; then
1428 + return 3
1429 + fi
1430 +
1431 + for i in $(seq 1 $((num1+1))); do
1432 + x=$(echo $ver1 | cut -d'.' -f$i)
1433 + y=$(echo $ver2 | cut -d'.' -f$i)
1434 + if [ "${x}" -gt "${y}" ]; then
1435 return 1
1414 - elif [ "${ver2[i]}" -gt "${ver1[i]}" ]; then
1436 + elif [ "${y}" -gt "${x}" ]; then
1437 return 2
1438 fi
1439 done
@@ -1424,9 +1446,6 @@ should_install_go() {
1446 return 1
1447 fi
1448
1427 - local version_in_file
1428 - local binary_version
1429 -
1449 version_in_file="$(cat packaging/go.d.version 2> /dev/null)"
1450 binary_version=$("${NETDATA_PREFIX}"/usr/libexec/netdata/plugins.d/go.d.plugin -v 2> /dev/null)
1451
@@ -1447,22 +1466,22 @@ install_go() {
1466
1467 # When updating this value, ensure correct checksums in packaging/go.d.checksums
1468 GO_PACKAGE_VERSION="$(cat packaging/go.d.version)"
1450 - ARCH_MAP=(
1451 - 'i386::386'
1452 - 'i686::386'
1453 - 'x86_64::amd64'
1454 - 'aarch64::arm64'
1455 - 'armv64::arm64'
1456 - 'armv6l::arm'
1457 - 'armv7l::arm'
1458 - 'armv5tel::arm'
1459 - )
1469 + ARCH_MAP='
1470 + i386::386
1471 + i686::386
1472 + x86_64::amd64
1473 + aarch64::arm64
1474 + armv64::arm64
1475 + armv6l::arm
1476 + armv7l::arm
1477 + armv5tel::arm
1478 + '
1479
1480 progress "Install go.d.plugin"
1481 ARCH=$(uname -m)
1482 OS=$(uname -s | tr '[:upper:]' '[:lower:]')
1483
1465 - for index in "${ARCH_MAP[@]}"; do
1484 + for index in ${ARCH_MAP}; do
1485 KEY="${index%%::*}"
1486 VALUE="${index##*::}"
1487 if [ "$KEY" = "$ARCH" ]; then
@@ -1518,9 +1537,9 @@ install_go() {
1537 run tar -xf "${tmp}/config.tar.gz" -C "${NETDATA_STOCK_CONFIG_DIR}/"
1538 run chown -R "${ROOT_USER}:${ROOT_GROUP}" "${NETDATA_STOCK_CONFIG_DIR}"
1539
1521 - run tar xf "${tmp}/${GO_PACKAGE_BASENAME}"
1522 - run mv "${GO_PACKAGE_BASENAME/\.tar\.gz/}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
1523 - if [ "${UID}" -eq 0 ]; then
1540 + run tar -xf "${tmp}/${GO_PACKAGE_BASENAME}"
1541 + run mv "${GO_PACKAGE_BASENAME%.tar.gz}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
1542 + if [ "$(id -u)" -eq 0 ]; then
1543 run chown "root:${NETDATA_GROUP}" "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
1544 fi
1545 run chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/go.d.plugin"
@@ -1705,7 +1724,7 @@ if grep -q docker /proc/1/cgroup > /dev/null 2>&1; then
1724 is_systemd_running="$( (pgrep -q -f systemd && echo "1") || echo "NO")"
1725 fi
1726
1708 - if [ "${is_systemd_running}" == "1" ]; then
1727 + if [ "${is_systemd_running}" = "1" ]; then
1728 echo >&2 "Found systemd within the docker container, running install_netdata_service() method"
1729 install_netdata_service || run_failed "Cannot install netdata init service."
1730 else
@@ -1803,7 +1822,7 @@ if [ -f "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin" ]; then
1822 # -----------------------------------------------------------------------------
1823 progress "Check apps.plugin"
1824
1806 - if [ "${UID}" -ne 0 ]; then
1825 + if [ "$(id -u)" -ne 0 ]; then
1826 cat << SETUID_WARNING
1827
1828 ${TPUT_BOLD}apps.plugin needs privileges${TPUT_RESET}
@@ -1838,8 +1857,8 @@ if [ -f "${NETDATA_PREFIX}"/usr/libexec/netdata-uninstaller.sh ]; then
1857 rm -f "${NETDATA_PREFIX}"/usr/libexec/netdata-uninstaller.sh
1858 fi
1859
1841 -sed "s|ENVIRONMENT_FILE=\"/etc/netdata/.environment\"|ENVIRONMENT_FILE=\"${NETDATA_PREFIX}/etc/netdata/.environment\"|" packaging/installer/netdata-uninstaller.sh > ${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh
1842 -chmod 750 ${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh
1860 +sed "s|ENVIRONMENT_FILE=\"/etc/netdata/.environment\"|ENVIRONMENT_FILE=\"${NETDATA_PREFIX}/etc/netdata/.environment\"|" packaging/installer/netdata-uninstaller.sh > "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh"
1861 +chmod 750 "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-uninstaller.sh"
1862
1863 # -----------------------------------------------------------------------------
1864 progress "Basic netdata instructions"
@@ -1870,7 +1889,7 @@ install_netdata_updater || run_failed "Cannot install netdata updater tool."
1889
1890 progress "Check if we must enable/disable the netdata updater tool"
1891 if [ "${AUTOUPDATE}" = "1" ]; then
1873 - enable_netdata_updater ${AUTO_UPDATE_TYPE} || run_failed "Cannot enable netdata updater tool"
1892 + enable_netdata_updater "${AUTO_UPDATE_TYPE}" || run_failed "Cannot enable netdata updater tool"
1893 else
1894 disable_netdata_updater || run_failed "Cannot disable netdata updater tool"
1895 fi
@@ -1890,7 +1909,7 @@ NETDATA_TMPDIR="${TMPDIR}"
1909 NETDATA_PREFIX="${NETDATA_PREFIX}"
1910 NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS}"
1911 NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS}"
1893 -INSTALL_UID="${UID}"
1912 +INSTALL_UID="$(id -u)"
1913 NETDATA_GROUP="${NETDATA_GROUP}"
1914 REINSTALL_OPTIONS="${REINSTALL_OPTIONS}"
1915 RELEASE_CHANNEL="${RELEASE_CHANNEL}"
@@ -1911,9 +1930,11 @@ echo >&2
1930 progress "We are done!"
1931
1932 if [ ${started} -eq 1 ]; then
1914 - netdata_banner "is installed and running now!"
1933 + netdata_banner
1934 + progress "is installed and running now!"
1935 else
1916 - netdata_banner "is installed now!"
1936 + netdata_banner
1937 + progress "is installed now!"
1938 fi
1939
1940 echo >&2 " enjoy real-time performance and health monitoring..."
packaging/installer/functions.sh
+56 -72
@@ -1,10 +1,9 @@
1 -#!/bin/bash
1 +#!/bin/sh
2
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 # make sure we have a UID
6 [ -z "${UID}" ] && UID="$(id -u)"
7 -
7 # -----------------------------------------------------------------------------
8
9 setup_terminal() {
@@ -51,6 +50,7 @@ setup_terminal() {
50 TPUT_BLUE="$(tput setaf 4)"
51 # shellcheck disable=SC2034
52 TPUT_PURPLE="$(tput setaf 5)"
53 + # shellcheck disable=SC2034
54 TPUT_CYAN="$(tput setaf 6)"
55 TPUT_WHITE="$(tput setaf 7)"
56 # shellcheck disable=SC2034
@@ -129,11 +129,11 @@ download_file() {
129 # external component handling
130
131 fetch_and_verify() {
132 - local component=${1}
133 - local url=${2}
134 - local base_name=${3}
135 - local tmp=${4}
136 - local override=${5}
132 + component="${1}"
133 + url="${2}"
134 + base_name="${3}"
135 + tmp="${4}"
136 + override="${5}"
137
138 if [ -z "${override}" ]; then
139 download_file "${url}" "${tmp}/${base_name}" "${component}"
@@ -159,24 +159,20 @@ fetch_and_verify() {
159 # -----------------------------------------------------------------------------
160
161 netdata_banner() {
162 - local l1=" ^" \
162 + l1=" ^" \
163 l2=" |.-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-" \
164 - l3=" | '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' " \
164 l4=" +----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--->" \
166 - sp=" " \
167 - netdata="netdata" start end msg="${*}" chartcolor="${TPUT_DIM}"
168 -
169 - [ ${#msg} -lt ${#netdata} ] && msg="${msg}${sp:0:$((${#netdata} - ${#msg}))}"
170 - [ ${#msg} -gt $((${#l2} - 20)) ] && msg="${msg:0:$((${#l2} - 23))}..."
165 + space=" "
166 + l3f=" | '-' '-' '-' '-' '-'"
167 + l3e=" '-' '-' '-' '-' '-' "
168
172 - start="$((${#l2} / 2 - 4))"
173 - [ $((start + ${#msg} + 4)) -gt ${#l2} ] && start=$((${#l2} - ${#msg} - 4))
174 - end=$((start + ${#msg} + 4))
169 + netdata="netdata"
170 + chartcolor="${TPUT_DIM}"
171
172 echo >&2
173 echo >&2 "${chartcolor}${l1}${TPUT_RESET}"
178 - echo >&2 "${chartcolor}${l2:0:start}${sp:0:2}${TPUT_RESET}${TPUT_BOLD}${TPUT_GREEN}${netdata}${TPUT_RESET}${chartcolor}${sp:0:$((end - start - 2 - ${#netdata}))}${l2:end:$((${#l2} - end))}${TPUT_RESET}"
179 - echo >&2 "${chartcolor}${l3:0:start}${sp:0:2}${TPUT_RESET}${TPUT_BOLD}${TPUT_CYAN}${msg}${TPUT_RESET}${chartcolor}${sp:0:2}${l3:end:$((${#l2} - end))}${TPUT_RESET}"
174 + echo >&2 "${chartcolor}${l2%-. .-. .-. .-. .-. .-. .-. .-}${space}${TPUT_RESET}${TPUT_BOLD}${TPUT_GREEN}${netdata}${TPUT_RESET}${chartcolor}${l2# |.-. .-. .-. .-. .-. .-. .-. }${TPUT_RESET}"
175 + echo >&2 "${chartcolor}${l3f}${l3e}${TPUT_RESET}"
176 echo >&2 "${chartcolor}${l4}${TPUT_RESET}"
177 echo >&2
178 }
@@ -189,7 +185,8 @@ rcservice_cmd="$(command -v rc-service 2> /dev/null || true)"
185 systemctl_cmd="$(command -v systemctl 2> /dev/null || true)"
186 service() {
187
192 - local cmd="${1}" action="${2}"
188 + cmd="${1}"
189 + action="${2}"
190
191 if [ -n "${systemctl_cmd}" ]; then
192 run "${systemctl_cmd}" "${action}" "${cmd}"
@@ -208,7 +205,6 @@ service() {
205 # portable pidof
206
207 safe_pidof() {
211 - local pidof_cmd
208 pidof_cmd="$(command -v pidof 2> /dev/null)"
209 if [ -n "${pidof_cmd}" ]; then
210 ${pidof_cmd} "${@}"
@@ -234,7 +230,6 @@ find_processors() {
230 gnproc && return
231 fi
232
237 - local cpus
233 if [ -f "/proc/cpuinfo" ]; then
234 # linux
235 cpus=$(grep -c ^processor /proc/cpuinfo)
@@ -264,12 +259,12 @@ run_failed() {
259 }
260
261 ESCAPED_PRINT_METHOD=
267 -if printf "%q " test > /dev/null 2>&1; then
262 +if printf "%s " test > /dev/null 2>&1; then
263 ESCAPED_PRINT_METHOD="printfq"
264 fi
265 escaped_print() {
266 if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]; then
272 - printf "%q " "${@}"
267 + printf "%s " "${@}"
268 else
269 printf "%s" "${*}"
270 fi
@@ -278,14 +273,14 @@ escaped_print() {
273
274 run_logfile="/dev/null"
275 run() {
281 - local user="${USER--}" dir="${PWD}" info info_console
282 -
276 + local_user="${USER--}"
277 + local_dir="${PWD}"
278 if [ "${UID}" = "0" ]; then
284 - info="[root ${dir}]# "
285 - info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
279 + info="[root ${local_dir}]# "
280 + info_console="[${TPUT_DIM}${local_dir}${TPUT_RESET}]# "
281 else
287 - info="[${user} ${dir}]$ "
288 - info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ "
282 + info="[${local_user} ${local_dir}]$ "
283 + info_console="[${TPUT_DIM}${local_dir}${TPUT_RESET}]$ "
284 fi
285
286 {
@@ -300,7 +295,7 @@ run() {
295
296 "${@}"
297
303 - local ret=$?
298 + ret=$?
299 if [ ${ret} -ne 0 ]; then
300 run_failed
301 printf >> "${run_logfile}" "FAILED with exit code %s\n" "${ret}"
@@ -314,7 +309,6 @@ run() {
309
310 iscontainer() {
311 # man systemd-detect-virt
317 - local cmd
312 cmd=$(command -v systemd-detect-virt 2> /dev/null)
313 if [ -n "${cmd}" ] && [ -x "${cmd}" ]; then
314 "${cmd}" --container > /dev/null 2>&1 && return 0
@@ -322,7 +316,6 @@ iscontainer() {
316
317 # /proc/1/sched exposes the host's pid of our init !
318 # http://stackoverflow.com/a/37016302
325 - local pid
319 pid=$(head -n 1 /proc/1/sched 2> /dev/null | {
320 # shellcheck disable=SC2034
321 IFS='(),#:' read -r name pid th threads
@@ -353,18 +346,22 @@ iscontainer() {
346 get_os_key() {
347 if [ -f /etc/os-release ]; then
348 # shellcheck disable=SC1091
356 - source /etc/os-release || return 1
349 + . /etc/os-release || return 1
350 echo "${ID}-${VERSION_ID}"
351
352 elif [ -f /etc/redhat-release ]; then
360 - echo "$(< /etc/redhat-release)"
353 + cat /etc/redhat-release
354 else
355 echo "unknown"
356 fi
357 }
358
359 issystemd() {
367 - local pids p myns ns systemctl
360 + pids=''
361 + p=''
362 + myns=''
363 + ns=''
364 + systemctl=''
365
366 # if the directory /lib/systemd/system OR /usr/lib/systemd/system (SLES 12.x) does not exit, it is not systemd
367 if [ ! -d /lib/systemd/system ] && [ ! -d /usr/lib/systemd/system ]; then
@@ -398,47 +395,35 @@ issystemd() {
395 }
396
397 get_systemd_service_dir() {
401 - local SYSTEMD_DIRECTORY=""
402 - local key
403 - key="$(get_os_key)"
404 -
398 if [ -w "/lib/systemd/system" ]; then
406 - SYSTEMD_DIRECTORY="/lib/systemd/system"
399 + echo "/lib/systemd/system"
400 elif [ -w "/usr/lib/systemd/system" ]; then
408 - SYSTEMD_DIRECTORY="/usr/lib/systemd/system"
401 + echo "/usr/lib/systemd/system"
402 elif [ -w "/etc/systemd/system" ]; then
410 - SYSTEMD_DIRECTORY="/etc/systemd/system"
403 + echo "/etc/systemd/system"
404 fi
412 -
413 - if [[ ${key} =~ ^devuan* ]] || [ "${key}" = "debian-7" ] || [ "${key}" = "ubuntu-12.04" ] || [ "${key}" = "ubuntu-14.04" ]; then
414 - SYSTEMD_DIRECTORY="/etc/systemd/system"
415 - fi
416 -
417 - echo "${SYSTEMD_DIRECTORY}"
405 }
406
407 install_non_systemd_init() {
408 [ "${UID}" != 0 ] && return 1
422 -
423 - local key
409 key="$(get_os_key)"
410
411 if [ -d /etc/init.d ] && [ ! -f /etc/init.d/netdata ]; then
427 - if [[ ${key} =~ ^(gentoo|alpine).* ]]; then
412 + if expr "${key}" : "^(gentoo|alpine).*"; then
413 echo >&2 "Installing OpenRC init file..."
414 run cp system/netdata-openrc /etc/init.d/netdata &&
415 run chmod 755 /etc/init.d/netdata &&
416 run rc-update add netdata default &&
417 return 0
418
434 - elif [[ ${key} =~ ^devuan* ]] || [ "${key}" = "debian-7" ] || [ "${key}" = "ubuntu-12.04" ] || [ "${key}" = "ubuntu-14.04" ]; then
419 + elif expr "${key}" : "^devuan*" || [ "${key}" = "debian-7" ] || [ "${key}" = "ubuntu-12.04" ] || [ "${key}" = "ubuntu-14.04" ]; then
420 echo >&2 "Installing LSB init file..."
421 run cp system/netdata-lsb /etc/init.d/netdata &&
422 run chmod 755 /etc/init.d/netdata &&
423 run update-rc.d netdata defaults &&
424 run update-rc.d netdata enable &&
425 return 0
441 - elif [[ ${key} =~ ^(amzn-201[5678]|ol|CentOS release 6|Red Hat Enterprise Linux Server release 6|Scientific Linux CERN SLC release 6|CloudLinux Server release 6).* ]]; then
426 + elif expr "${key}" : "^(amzn-201[5678]|ol|CentOS release 6|Red Hat Enterprise Linux Server release 6|Scientific Linux CERN SLC release 6|CloudLinux Server release 6).*"; then
427 echo >&2 "Installing init.d file..."
428 run cp system/netdata-init-d /etc/init.d/netdata &&
429 run chmod 755 /etc/init.d/netdata &&
@@ -466,7 +451,6 @@ NETDATA_START_CMD="netdata"
451 NETDATA_INSTALLER_START_CMD=""
452
453 install_netdata_service() {
469 - local uname
454 uname="$(uname 2> /dev/null)"
455
456 if [ "${UID}" -eq 0 ]; then
@@ -512,7 +496,7 @@ install_netdata_service() {
496 if [ "${SYSTEMD_DIRECTORY}x" != "x" ]; then
497 ENABLE_NETDATA_IF_PREVIOUSLY_ENABLED="run systemctl enable netdata"
498 IS_NETDATA_ENABLED="$(systemctl is-enabled netdata 2> /dev/null || echo "Netdata not there")"
515 - if [ "${IS_NETDATA_ENABLED}" == "disabled" ]; then
499 + if [ "${IS_NETDATA_ENABLED}" = "disabled" ]; then
500 echo >&2 "Netdata was there and disabled, make sure we don't re-enable it ourselves"
501 ENABLE_NETDATA_IF_PREVIOUSLY_ENABLED="true"
502 fi
@@ -527,7 +511,7 @@ install_netdata_service() {
511 fi
512 else
513 install_non_systemd_init
530 - local ret=$?
514 + ret=$?
515
516 if [ ${ret} -eq 0 ]; then
517 if [ -n "${service_cmd}" ]; then
@@ -566,12 +550,14 @@ pidisnetdata() {
550 }
551
552 stop_netdata_on_pid() {
569 - local pid="${1}" ret=0 count=0
553 + pid="${1}"
554 + ret=0
555 + count=0
556
557 pidisnetdata "${pid}" || return 0
558
559 printf >&2 "Stopping netdata on pid %s ..." "${pid}"
574 - while [ -n "$pid" ] && [ ${ret} -eq 0 ]; do
560 + while [ -n "${pid}" ] && [ ${ret} -eq 0 ]; do
561 if [ ${count} -gt 24 ]; then
562 echo >&2 "Cannot stop the running netdata on pid ${pid}."
563 return 1
@@ -607,8 +593,6 @@ stop_netdata_on_pid() {
593 }
594
595 netdata_pids() {
610 - local p myns ns
611 -
596 myns="$(readlink /proc/self/ns/pid 2> /dev/null)"
597
598 for p in \
@@ -624,7 +608,6 @@ netdata_pids() {
608 }
609
610 stop_all_netdata() {
627 - local p uname
611
612 if [ "${UID}" -eq 0 ]; then
613 uname="$(uname 2> /dev/null)"
@@ -649,7 +632,7 @@ stop_all_netdata() {
632 fi
633 fi
634
652 - if [ -n "$(netdata_pids)" ] && [ -n "$(builtin type -P netdatacli)" ]; then
635 + if [ -n "$(netdata_pids)" ] && [ -n "$(type netdatacli)" ]; then
636 netdatacli shutdown-agent
637 sleep 20
638 fi
@@ -664,10 +647,10 @@ stop_all_netdata() {
647 # restart netdata
648
649 restart_netdata() {
667 - local netdata="${1}"
650 + netdata="${1}"
651 shift
652
670 - local started=0
653 + started=0
654
655 progress "Restarting netdata instance"
656
@@ -737,7 +720,8 @@ install_netdata_logrotate() {
720 # create netdata.conf
721
722 create_netdata_conf() {
740 - local path="${1}" url="${2}"
723 + path="${1}"
724 + url="${2}"
725
726 if [ -s "${path}" ]; then
727 return 0
@@ -778,7 +762,8 @@ create_netdata_conf() {
762 }
763
764 portable_add_user() {
781 - local username="${1}" homedir="${2}"
765 + username="${1}"
766 + homedir="${2}"
767
768 [ -z "${homedir}" ] && homedir="/tmp"
769
@@ -790,7 +775,6 @@ portable_add_user() {
775
776 echo >&2 "Adding ${username} user account with home ${homedir} ..."
777
793 - local nologin
778 nologin="$(command -v nologin || echo '/bin/false')"
779
780 # Linux
@@ -819,7 +803,7 @@ portable_add_user() {
803 }
804
805 portable_add_group() {
822 - local groupname="${1}"
806 + groupname="${1}"
807
808 # Check if group exist
809 if cut -d ':' -f 1 < /etc/group | grep "^${groupname}$" 1> /dev/null 2>&1; then
@@ -854,7 +838,8 @@ portable_add_group() {
838 }
839
840 portable_add_user_to_group() {
857 - local groupname="${1}" username="${2}"
841 + groupname="${1}"
842 + username="${2}"
843
844 # Check if group exist
845 if ! cut -d ':' -f 1 < /etc/group | grep "^${groupname}$" > /dev/null 2>&1; then
@@ -863,7 +848,7 @@ portable_add_user_to_group() {
848 fi
849
850 # Check if user is in group
866 - if [[ ",$(grep "^${groupname}:" < /etc/group | cut -d ':' -f 4)," =~ ,${username}, ]]; then
851 + if expr ",$(grep "^${groupname}:" < /etc/group | cut -d ':' -f 4)," : ",""${username}"","; then
852 # username is already there
853 echo >&2 "User '${username}' is already in group '${groupname}'."
854 return 0
@@ -984,7 +969,6 @@ cleanup_old_netdata_updater() {
969 }
970
971 enable_netdata_updater() {
987 - local updater_type
972
973 if [ -n "${1}" ] ; then
974 updater_type="${1}"