master
sh 2,105 lines 56.7 KB
Raw
1 #!/usr/bin/env bash
2 # shellcheck disable=SC2034
3 # We use lots of computed variable names in here, so we need to disable shellcheck 2034
4
5 export PATH="${PATH}:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
6 export LC_ALL=C
7
8 # Be nice on production environments
9 renice 19 $$ > /dev/null 2> /dev/null
10
11 ME="${0}"
12
13 if [ "${BASH_VERSINFO[0]}" -lt "4" ]; then
14 echo >&2 "Sorry! This script needs BASH version 4+, but you have BASH version ${BASH_VERSION}"
15 exit 1
16 fi
17
18 # These options control which packages we are going to install
19 # They can be pre-set, but also can be controlled with command line options
20 PACKAGES_NETDATA=${PACKAGES_NETDATA-1}
21 PACKAGES_NETDATA_PYTHON=${PACKAGES_NETDATA_PYTHON-0}
22 PACKAGES_NETDATA_PYTHON3=${PACKAGES_NETDATA_PYTHON3-1}
23 PACKAGES_DEBUG=${PACKAGES_DEBUG-0}
24 PACKAGES_IPRANGE=${PACKAGES_IPRANGE-0}
25 PACKAGES_FIREHOL=${PACKAGES_FIREHOL-0}
26 PACKAGES_FIREQOS=${PACKAGES_FIREQOS-0}
27 PACKAGES_UPDATE_IPSETS=${PACKAGES_UPDATE_IPSETS-0}
28 PACKAGES_NETDATA_DEMO_SITE=${PACKAGES_NETDATA_DEMO_SITE-0}
29 PACKAGES_NETDATA_SENSORS=${PACKAGES_NETDATA_SENSORS-0}
30 PACKAGES_NETDATA_DATABASE=${PACKAGES_NETDATA_DATABASE-1}
31 PACKAGES_NETDATA_STREAMING_COMPRESSION=${PACKAGES_NETDATA_STREAMING_COMPRESSION-0}
32 PACKAGES_NETDATA_EBPF=${PACKAGES_NETDATA_EBPF-1}
33
34 # needed commands
35 lsb_release=$(command -v lsb_release 2> /dev/null)
36
37 # Check which package managers are available
38 apk=$(command -v apk 2> /dev/null)
39 apt_get=$(command -v apt-get 2> /dev/null)
40 brew=$(command -v brew 2> /dev/null)
41 pkg=$(command -v pkg 2> /dev/null)
42 dnf=$(command -v dnf 2> /dev/null)
43 emerge=$(command -v emerge 2> /dev/null)
44 equo=$(command -v equo 2> /dev/null)
45 pacman=$(command -v pacman 2> /dev/null)
46 swupd=$(command -v swupd 2> /dev/null)
47 yum=$(command -v yum 2> /dev/null)
48 zypper=$(command -v zypper 2> /dev/null)
49
50 distribution=
51 release=
52 version=
53 codename=
54 package_installer=
55 tree=
56 detection=
57 NAME=
58 ID=
59 ID_LIKE=
60 VERSION=
61 VERSION_ID=
62
63 usage() {
64 cat << EOF
65 OPTIONS:
66
67 ${ME} [--dont-wait] [--non-interactive] \\
68 [distribution DD [version VV] [codename CN]] [installer IN] [packages]
69
70 Supported distributions (DD):
71
72 - arch (all Arch Linux derivatives)
73 - centos (all CentOS derivatives)
74 - gentoo (all Gentoo Linux derivatives)
75 - sabayon (all Sabayon Linux derivatives)
76 - debian, ubuntu (all Debian and Ubuntu derivatives)
77 - redhat, fedora (all Red Hat and Fedora derivatives)
78 - suse, opensuse (all SUSE and openSUSE derivatives)
79 - clearlinux (all Clear Linux derivatives)
80 - macos (Apple's macOS)
81
82 Supported installers (IN):
83
84 - apt-get all Debian / Ubuntu Linux derivatives
85 - dnf newer Red Hat / Fedora Linux
86 - emerge all Gentoo Linux derivatives
87 - equo all Sabayon Linux derivatives
88 - pacman all Arch Linux derivatives
89 - yum all Red Hat / Fedora / CentOS Linux derivatives
90 - zypper all SUSE Linux derivatives
91 - apk all Alpine derivatives
92 - swupd all Clear Linux derivatives
93 - brew macOS Homebrew
94 - pkg FreeBSD Ports
95
96 Supported packages (you can append many of them):
97
98 - netdata-all all packages required to install netdata
99 including python, sensors, etc
100
101 - netdata minimum packages required to install netdata
102 (includes python)
103
104 - python install python
105
106 - python3 install python3
107
108 - sensors install lm_sensors for monitoring h/w sensors
109
110 - firehol-all packages required for FireHOL, FireQOS, update-ipsets
111 - firehol packages required for FireHOL
112 - fireqos packages required for FireQOS
113 - update-ipsets packages required for update-ipsets
114
115 - demo packages required for running a netdata demo site
116 (includes nginx and various debugging tools)
117
118
119 If you don't supply the --dont-wait option, the program
120 will ask you before touching your system.
121
122 EOF
123 }
124
125 release2lsb_release() {
126 # loads the given /etc/x-release file
127 # this file is normally a single line containing something like
128 #
129 # X Linux release 1.2.3 (release-name)
130 #
131 # It attempts to parse it
132 # If it succeeds, it returns 0
133 # otherwise it returns 1
134
135 local file="${1}" x DISTRIB_ID="" DISTRIB_RELEASE="" DISTRIB_CODENAME=""
136 echo >&2 "Loading ${file} ..."
137
138 x="$(grep -v "^$" "${file}" | head -n 1)"
139
140 if [[ "${x}" =~ ^.*[[:space:]]+Linux[[:space:]]+release[[:space:]]+.*[[:space:]]+(.*)[[:space:]]*$ ]]; then
141 eval "$(echo "${x}" | sed "s|^\(.*\)[[:space:]]\+Linux[[:space:]]\+release[[:space:]]\+\(.*\)[[:space:]]\+(\(.*\))[[:space:]]*$|DISTRIB_ID=\"\1\"\nDISTRIB_RELEASE=\"\2\"\nDISTRIB_CODENAME=\"\3\"|g" | grep "^DISTRIB")"
142 elif [[ "${x}" =~ ^.*[[:space:]]+Linux[[:space:]]+release[[:space:]]+.*[[:space:]]+$ ]]; then
143 eval "$(echo "${x}" | sed "s|^\(.*\)[[:space:]]\+Linux[[:space:]]\+release[[:space:]]\+\(.*\)[[:space:]]*$|DISTRIB_ID=\"\1\"\nDISTRIB_RELEASE=\"\2\"|g" | grep "^DISTRIB")"
144 elif [[ "${x}" =~ ^.*[[:space:]]+release[[:space:]]+.*[[:space:]]+(.*)[[:space:]]*$ ]]; then
145 eval "$(echo "${x}" | sed "s|^\(.*\)[[:space:]]\+release[[:space:]]\+\(.*\)[[:space:]]\+(\(.*\))[[:space:]]*$|DISTRIB_ID=\"\1\"\nDISTRIB_RELEASE=\"\2\"\nDISTRIB_CODENAME=\"\3\"|g" | grep "^DISTRIB")"
146 elif [[ "${x}" =~ ^.*[[:space:]]+release[[:space:]]+.*[[:space:]]+$ ]]; then
147 eval "$(echo "${x}" | sed "s|^\(.*\)[[:space:]]\+release[[:space:]]\+\(.*\)[[:space:]]*$|DISTRIB_ID=\"\1\"\nDISTRIB_RELEASE=\"\2\"|g" | grep "^DISTRIB")"
148 fi
149
150 distribution="${DISTRIB_ID}"
151 version="${DISTRIB_RELEASE}"
152 codename="${DISTRIB_CODENAME}"
153
154 [ -z "${distribution}" ] && echo >&2 "Cannot parse this lsb-release: ${x}" && return 1
155 detection="${file}"
156 return 0
157 }
158
159 get_os_release() {
160 # Loads the /etc/os-release or /usr/lib/os-release file(s)
161 # Only the required fields are loaded
162 #
163 # If it manages to load a valid os-release, it returns 0
164 # otherwise it returns 1
165 #
166 # It searches the ID_LIKE field for a compatible distribution
167
168 os_release_file=
169 if [ -s "/etc/os-release" ]; then
170 os_release_file="/etc/os-release"
171 elif [ -s "/usr/lib/os-release" ]; then
172 os_release_file="/usr/lib/os-release"
173 else
174 echo >&2 "Cannot find an os-release file ..."
175 return 1
176 fi
177
178 local x
179 echo >&2 "Loading ${os_release_file} ..."
180
181 eval "$(grep -E "^(NAME|ID|ID_LIKE|VERSION|VERSION_ID)=" "${os_release_file}")"
182 for x in "${ID}" ${ID_LIKE}; do
183 case "${x,,}" in
184 almalinux | alpine | arch | centos | clear-linux-os | debian | fedora | gentoo | manjaro | opensuse-leap | opensuse-tumbleweed | ol | rhel | rocky | sabayon | sles | suse | ubuntu)
185 distribution="${x}"
186 if [[ "${ID}" = "opensuse-tumbleweed" ]]; then
187 version="tumbleweed"
188 codename="tumbleweed"
189 else
190 version="${VERSION_ID}"
191 codename="${VERSION}"
192 fi
193 detection="${os_release_file}"
194 break
195 ;;
196 *)
197 echo >&2 "Unknown distribution ID: ${x}"
198 ;;
199 esac
200 done
201 [[ -z "${distribution}" ]] && echo >&2 "Cannot find valid distribution in: \
202 ${ID} ${ID_LIKE}" && return 1
203
204 [[ -z "${distribution}" ]] && return 1
205 return 0
206 }
207
208 get_lsb_release() {
209 # Loads the /etc/lsb-release file
210 # If it fails, it attempts to run the command: lsb_release -a
211 # and parse its output
212 #
213 # If it manages to find the lsb-release, it returns 0
214 # otherwise it returns 1
215
216 if [ -f "/etc/lsb-release" ]; then
217 echo >&2 "Loading /etc/lsb-release ..."
218 local DISTRIB_ID="" DISTRIB_RELEASE="" DISTRIB_CODENAME=""
219 eval "$(grep -E "^(DISTRIB_ID|DISTRIB_RELEASE|DISTRIB_CODENAME)=" /etc/lsb-release)"
220 distribution="${DISTRIB_ID}"
221 version="${DISTRIB_RELEASE}"
222 codename="${DISTRIB_CODENAME}"
223 detection="/etc/lsb-release"
224 fi
225
226 if [ -z "${distribution}" ] && [ -n "${lsb_release}" ]; then
227 echo >&2 "Cannot find distribution with /etc/lsb-release"
228 echo >&2 "Running command: lsb_release ..."
229 eval "declare -A release=( $(lsb_release -a 2> /dev/null | sed -e "s|^\(.*\):[[:space:]]*\(.*\)$|[\1]=\"\2\"|g") )"
230 distribution="${release["Distributor ID"]}"
231 version="${release[Release]}"
232 codename="${release[Codename]}"
233 detection="lsb_release"
234 fi
235
236 [ -z "${distribution}" ] && echo >&2 "Cannot find valid distribution with lsb-release" && return 1
237 return 0
238 }
239
240 find_etc_any_release() {
241 # Check for any of the known /etc/x-release files
242 # If it finds one, it loads it and returns 0
243 # otherwise it returns 1
244
245 if [ -f "/etc/arch-release" ]; then
246 release2lsb_release "/etc/arch-release" && return 0
247 fi
248
249 if [ -f "/etc/centos-release" ]; then
250 release2lsb_release "/etc/centos-release" && return 0
251 fi
252
253 if [ -f "/etc/redhat-release" ]; then
254 release2lsb_release "/etc/redhat-release" && return 0
255 fi
256
257 if [ -f "/etc/SuSe-release" ]; then
258 release2lsb_release "/etc/SuSe-release" && return 0
259 fi
260
261 return 1
262 }
263
264 autodetect_distribution() {
265 # autodetection of distribution/OS
266 case "$(uname -s)" in
267 "Linux")
268 get_os_release || get_lsb_release || find_etc_any_release
269 ;;
270 "FreeBSD")
271 distribution="freebsd"
272 version="$(uname -r)"
273 detection="uname"
274 ;;
275 "Darwin")
276 distribution="macos"
277 version="$(uname -r)"
278 detection="uname"
279
280 if [ ${EUID} -eq 0 ]; then
281 echo >&2 "This script does not support running as EUID 0 on macOS. Please run it as a regular user."
282 exit 1
283 fi
284 ;;
285 *)
286 return 1
287 ;;
288 esac
289 }
290
291 user_picks_distribution() {
292 # let the user pick a distribution
293
294 echo >&2
295 echo >&2 "I NEED YOUR HELP"
296 echo >&2 "It seems I cannot detect your system automatically."
297
298 if [ "${NON_INTERACTIVE}" -eq 1 ]; then
299 echo >&2 "Running in non-interactive mode"
300 echo >&2 " > Bailing out..."
301 exit 1
302 fi
303
304 if [ -z "${equo}" ] && [ -z "${emerge}" ] && [ -z "${apt_get}" ] && [ -z "${yum}" ] && [ -z "${dnf}" ] && [ -z "${pacman}" ] && [ -z "${apk}" ] && [ -z "${swupd}" ]; then
305 echo >&2 "And it seems I cannot find a known package manager in this system."
306 echo >&2 "Please open a github issue to help us support your system too."
307 exit 1
308 fi
309
310 local opts=
311 echo >&2 "I found though that the following installers are available:"
312 echo >&2
313 [ -n "${apt_get}" ] && echo >&2 " - Debian/Ubuntu based (installer is: apt-get)" && opts="apt-get ${opts}"
314 [ -n "${yum}" ] && echo >&2 " - Red Hat/Fedora/CentOS based (installer is: yum)" && opts="yum ${opts}"
315 [ -n "${dnf}" ] && echo >&2 " - Red Hat/Fedora/CentOS based (installer is: dnf)" && opts="dnf ${opts}"
316 [ -n "${zypper}" ] && echo >&2 " - SuSe based (installer is: zypper)" && opts="zypper ${opts}"
317 [ -n "${pacman}" ] && echo >&2 " - Arch Linux based (installer is: pacman)" && opts="pacman ${opts}"
318 [ -n "${emerge}" ] && echo >&2 " - Gentoo based (installer is: emerge)" && opts="emerge ${opts}"
319 [ -n "${equo}" ] && echo >&2 " - Sabayon based (installer is: equo)" && opts="equo ${opts}"
320 [ -n "${apk}" ] && echo >&2 " - Alpine Linux based (installer is: apk)" && opts="apk ${opts}"
321 [ -n "${swupd}" ] && echo >&2 " - Clear Linux based (installer is: swupd)" && opts="swupd ${opts}"
322 [ -n "${brew}" ] && echo >&2 " - macOS based (installer is: brew)" && opts="brew ${opts}"
323 # XXX: This is being removed in another PR.
324 echo >&2
325
326 REPLY=
327 while [ -z "${REPLY}" ]; do
328 echo "To proceed please write one of these:"
329 echo "${opts// /, }"
330 if ! read -r -p ">" REPLY; then
331 continue
332 fi
333
334 if [ "${REPLY}" = "yum" ] && [ -z "${distribution}" ]; then
335 REPLY=
336 while [ -z "${REPLY}" ]; do
337 if ! read -r -p "yum in centos, rhel, ol or fedora? > "; then
338 continue
339 fi
340
341 case "${REPLY,,}" in
342 fedora | rhel)
343 distribution="rhel"
344 ;;
345 ol)
346 distribution="ol"
347 ;;
348 centos)
349 distribution="centos"
350 ;;
351 *)
352 echo >&2 "Please enter 'centos', 'fedora', 'ol' or 'rhel'."
353 REPLY=
354 ;;
355 esac
356 done
357 REPLY="yum"
358 fi
359 check_package_manager "${REPLY}" || REPLY=
360 done
361 }
362
363 detect_package_manager_from_distribution() {
364 case "${1,,}" in
365 arch* | manjaro*)
366 package_installer="install_pacman"
367 tree="arch"
368 if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${pacman}" ]; then
369 echo >&2 "command 'pacman' is required to install packages on a '${distribution} ${version}' system."
370 exit 1
371 fi
372 ;;
373
374 sabayon*)
375 package_installer="install_equo"
376 tree="sabayon"
377 if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${equo}" ]; then
378 echo >&2 "command 'equo' is required to install packages on a '${distribution} ${version}' system."
379 # Maybe offer to fall back on emerge? Both installers exist in Sabayon...
380 exit 1
381 fi
382 ;;
383
384 alpine*)
385 package_installer="install_apk"
386 tree="alpine"
387 if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${apk}" ]; then
388 echo >&2 "command 'apk' is required to install packages on a '${distribution} ${version}' system."
389 exit 1
390 fi
391 ;;
392
393 gentoo*)
394 package_installer="install_emerge"
395 tree="gentoo"
396 if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${emerge}" ]; then
397 echo >&2 "command 'emerge' is required to install packages on a '${distribution} ${version}' system."
398 exit 1
399 fi
400 ;;
401
402 debian* | ubuntu*)
403 package_installer="install_apt_get"
404 tree="debian"
405 if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${apt_get}" ]; then
406 echo >&2 "command 'apt-get' is required to install packages on a '${distribution} ${version}' system."
407 exit 1
408 fi
409 ;;
410
411 centos* | clearos* | rocky* | almalinux*)
412 package_installer=""
413 tree="centos"
414 [[ -n "${dnf}" ]] && package_installer="install_dnf"
415 [[ -n "${yum}" ]] && package_installer="install_yum"
416 if [[ "${IGNORE_INSTALLED}" -eq 0 ]] && [[ -z "${package_installer}" ]]; then
417 echo >&2 "command 'yum' or 'dnf' is required to install packages on a '${distribution} ${version}' system."
418 exit 1
419 fi
420 ;;
421
422 redhat* | red\ hat* | rhel*)
423 package_installer=
424 tree="rhel"
425 [[ -n "${dnf}" ]] && package_installer="install_dnf"
426 [[ -n "${yum}" ]] && package_installer="install_yum"
427 if [[ "${IGNORE_INSTALLED}" -eq 0 ]] && [[ -z "${package_installer}" ]]; then
428 echo >&2 "command 'yum' or 'dnf' is required to install packages on a '${distribution} ${version}' system."
429 exit 1
430 fi
431 ;;
432
433 fedora*)
434 package_installer="install_dnf"
435 tree="rhel"
436 if [[ "${IGNORE_INSTALLED}" -eq 0 ]] && [[ -z "${package_installer}" ]]; then
437 echo >&2 "command 'yum' or 'dnf' is required to install packages on a '${distribution} ${version}' system."
438 exit 1
439 fi
440 ;;
441
442
443 ol*)
444 package_installer=
445 tree="ol"
446 [ -n "${yum}" ] && package_installer="install_yum"
447 [ -n "${dnf}" ] && package_installer="install_dnf"
448 if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${package_installer}" ]; then
449 echo >&2 "command 'yum' or 'dnf' is required to install packages on a '${distribution} ${version}' system."
450 exit 1
451 fi
452 ;;
453
454 suse* | opensuse* | sles*)
455 package_installer="install_zypper"
456 tree="suse"
457 if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${zypper}" ]; then
458 echo >&2 "command 'zypper' is required to install packages on a '${distribution} ${version}' system."
459 exit 1
460 fi
461 ;;
462
463 clear-linux* | clearlinux*)
464 package_installer="install_swupd"
465 tree="clearlinux"
466 if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${swupd}" ]; then
467 echo >&2 "command 'swupd' is required to install packages on a '${distribution} ${version}' system."
468 exit 1
469 fi
470 ;;
471
472 freebsd)
473 package_installer="install_pkg"
474 tree="freebsd"
475 if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${pkg}" ]; then
476 echo >&2 "command 'pkg' is required to install packages on a '${distribution} ${version}' system."
477 exit 1
478 fi
479 ;;
480 macos)
481 package_installer="install_brew"
482 tree="macos"
483 if [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${brew}" ]; then
484 echo >&2 "command 'brew' is required to install packages on a '${distribution} ${version}' system. Get instructions at https://brew.sh/"
485 exit 1
486 fi
487 ;;
488
489 *)
490 # oops! unknown system
491 user_picks_distribution
492 ;;
493 esac
494 }
495
496 # XXX: This is being removed in another PR.
497 check_package_manager() {
498 # This is called only when the user is selecting a package manager
499 # It is used to verify the user selection is right
500
501 echo >&2 "Checking package manager: ${1}"
502
503 case "${1}" in
504 apt-get)
505 [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${apt_get}" ] && echo >&2 "${1} is not available." && return 1
506 package_installer="install_apt_get"
507 tree="debian"
508 detection="user-input"
509 return 0
510 ;;
511
512 dnf)
513 [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${dnf}" ] && echo >&2 "${1} is not available." && return 1
514 package_installer="install_dnf"
515 if [ "${distribution}" = "centos" ]; then
516 tree="centos"
517 elif [ "${distribution}" = "ol" ]; then
518 tree="ol"
519 else
520 tree="rhel"
521 fi
522 detection="user-input"
523 return 0
524 ;;
525
526 apk)
527 [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${apk}" ] && echo >&2 "${1} is not available." && return 1
528 package_installer="install_apk"
529 tree="alpine"
530 detection="user-input"
531 return 0
532 ;;
533
534 equo)
535 [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${equo}" ] && echo >&2 "${1} is not available." && return 1
536 package_installer="install_equo"
537 tree="sabayon"
538 detection="user-input"
539 return 0
540 ;;
541
542 emerge)
543 [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${emerge}" ] && echo >&2 "${1} is not available." && return 1
544 package_installer="install_emerge"
545 tree="gentoo"
546 detection="user-input"
547 return 0
548 ;;
549
550 pacman)
551 [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${pacman}" ] && echo >&2 "${1} is not available." && return 1
552 package_installer="install_pacman"
553 tree="arch"
554 detection="user-input"
555
556 return 0
557 ;;
558
559 zypper)
560 [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${zypper}" ] && echo >&2 "${1} is not available." && return 1
561 package_installer="install_zypper"
562 tree="suse"
563 detection="user-input"
564 return 0
565 ;;
566
567 yum)
568 [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${yum}" ] && echo >&2 "${1} is not available." && return 1
569 package_installer="install_yum"
570 if [ "${distribution}" = "centos" ]; then
571 tree="centos"
572 elif [ "${distribution}" = "ol" ]; then
573 tree="ol"
574 else
575 tree="rhel"
576 fi
577 detection="user-input"
578 return 0
579 ;;
580
581 swupd)
582 [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${swupd}" ] && echo >&2 "${1} is not available." && return 1
583 package_installer="install_swupd"
584 tree="clear-linux"
585 detection="user-input"
586 return 0
587 ;;
588
589 brew)
590 [ "${IGNORE_INSTALLED}" -eq 0 ] && [ -z "${brew}" ] && echo >&2 "${1} is not available." && return 1
591 package_installer="install_brew"
592 tree="macos"
593 detection="user-input"
594
595 return 0
596 ;;
597
598 *)
599 echo >&2 "Invalid package manager: '${1}'."
600 return 1
601 ;;
602 esac
603 }
604
605 require_cmd() {
606 # check if any of the commands given as argument
607 # are present on this system
608 # If any of them is available, it returns 0
609 # otherwise 1
610
611 [ "${IGNORE_INSTALLED}" -eq 1 ] && return 1
612
613 local wanted found
614 for wanted in "${@}"; do
615 if command -v "${wanted}" > /dev/null 2>&1; then
616 found="$(command -v "$wanted" 2> /dev/null)"
617 fi
618 [ -n "${found}" ] && [ -x "${found}" ] && return 0
619 done
620 return 1
621 }
622
623 declare -A pkg_find=(
624 ['gentoo']="sys-apps/findutils"
625 ['fedora']="findutils"
626 ['clearlinux']="findutils"
627 ['rhel']="findutils"
628 ['centos']="findutils"
629 ['macos']="NOTREQUIRED"
630 ['freebsd']="NOTREQUIRED"
631 ['default']="WARNING|"
632 )
633
634 declare -A pkg_awk=(
635 ['gentoo']="app-alternatives/awk"
636 ['default']="gawk"
637 )
638
639 declare -A pkg_distro_sdk=(
640 ['alpine']="alpine-sdk"
641 ['centos']="kernel-headers"
642 ['default']="NOTREQUIRED"
643 )
644
645 # bison and flex are required by libsensors
646 declare -A pkg_bison=(
647 ['default']="bison"
648 )
649 declare -A pkg_flex=(
650 ['default']="flex"
651 )
652
653 declare -A pkg_coreutils=(
654 ['alpine']="coreutils"
655 ['default']="NOTREQUIRED"
656 )
657
658 declare -A pkg_cmake=(
659 ['gentoo']="dev-util/cmake"
660 ['clearlinux']="c-basic"
661 ['default']="cmake"
662 )
663
664 # patch is required for vendoring Abseil
665 declare -A pkg_patch=(
666 ['default']="patch"
667 ['gentoo']="dev-util/patch"
668 )
669
670 declare -A pkg_json_c_dev=(
671 ['alpine']="json-c-dev"
672 ['arch']="json-c"
673 ['clearlinux']="devpkg-json-c"
674 ['debian']="libjson-c-dev"
675 ['gentoo']="dev-libs/json-c"
676 ['sabayon']="dev-libs/json-c"
677 ['suse']="libjson-c-devel"
678 ['freebsd']="json-c"
679 ['macos']="json-c"
680 ['default']="json-c-devel"
681 )
682
683 #TODO:: clearlinux ?
684 declare -A pkg_libyaml_dev=(
685 ['alpine']="yaml-dev"
686 ['arch']="libyaml"
687 ['clearlinux']="yaml-dev"
688 ['debian']="libyaml-dev"
689 ['gentoo']="dev-libs/libyaml"
690 ['sabayon']="dev-libs/libyaml"
691 ['suse']="libyaml-devel"
692 ['freebsd']="libyaml"
693 ['macos']="libyaml"
694 ['default']="libyaml-devel"
695 )
696
697 declare -A pkg_libatomic=(
698 ['arch']="NOTREQUIRED"
699 ['clearlinux']="NOTREQUIRED"
700 ['debian']="libatomic1"
701 ['freebsd']="NOTREQUIRED"
702 ['gentoo']="NOTREQUIRED"
703 ['macos']="NOTREQUIRED"
704 ['sabayon']="NOTREQUIRED"
705 ['suse']="libatomic1"
706 ['ubuntu']="libatomic1"
707 ['default']="libatomic"
708 )
709
710 declare -A pkg_libsystemd_dev=(
711 ['alpine']="NOTREQUIRED"
712 ['arch']="NOTREQUIRED" # inherently present on systems actually using systemd
713 ['clearlinux']="system-os-dev"
714 ['debian']="libsystemd-dev"
715 ['freebsd']="NOTREQUIRED"
716 ['gentoo']="NOTREQUIRED" # inherently present on systems actually using systemd
717 ['macos']="NOTREQUIRED"
718 ['sabayon']="NOTREQUIRED" # inherently present on systems actually using systemd
719 ['ubuntu']="libsystemd-dev"
720 ['default']="systemd-devel"
721 )
722
723 declare -A pkg_pcre2=(
724 ['alpine']="pcre2-dev"
725 ['arch']="pcre2"
726 ['centos']="pcre2-devel"
727 ['debian']="libpcre2-dev"
728 ['freebsd']="pcre2"
729 ['macos']="pcre2"
730 ['rhel']="pcre2-devel"
731 ['suse']="pcre2-devel"
732 ['ubuntu']="libpcre2-dev"
733 ['default']="NOTREQUIRED"
734 )
735
736 declare -A pkg_bridge_utils=(
737 ['gentoo']="net-misc/bridge-utils"
738 ['clearlinux']="network-basic"
739 ['macos']="WARNING|"
740 ['default']="bridge-utils"
741 )
742
743 declare -A pkg_curl=(
744 ['gentoo']="net-misc/curl"
745 ['sabayon']="net-misc/curl"
746 ['default']="curl"
747 )
748
749 declare -A pkg_gzip=(
750 ['gentoo']="app-alternatives/gzip"
751 ['macos']="NOTREQUIRED"
752 ['default']="gzip"
753 )
754
755 declare -A pkg_tar=(
756 ['gentoo']="app-alternatives/tar"
757 ['clearlinux']="os-core-update"
758 ['macos']="NOTREQUIRED"
759 ['freebsd']="NOTREQUIRED"
760 ['default']="tar"
761 )
762
763 declare -A pkg_git=(
764 ['gentoo']="dev-vcs/git"
765 ['default']="git"
766 )
767
768 declare -A pkg_gcc=(
769 ['gentoo']="sys-devel/gcc"
770 ['clearlinux']="c-basic"
771 ['macos']="NOTREQUIRED"
772 ['default']="gcc"
773 )
774
775 # g++, required for building protobuf
776 # All three cases of this not being required are systems that implicitly
777 # include g++ when installing gcc.
778 declare -A pkg_gxx=(
779 ['alpine']="g++"
780 ['arch']="NOTREQUIRED"
781 ['clearlinux']="c-basic"
782 ['debian']="g++"
783 ['gentoo']="NOTREQUIRED"
784 ['macos']="NOTREQUIRED"
785 ['ubuntu']="g++"
786 ['freebsd']="NOTREQUIRED"
787 ['default']="gcc-c++"
788 )
789
790 declare -A pkg_gdb=(
791 ['gentoo']="sys-devel/gdb"
792 ['macos']="NOTREQUIRED"
793 ['default']="gdb"
794 )
795
796 declare -A pkg_iotop=(
797 ['gentoo']="sys-process/iotop"
798 ['macos']="WARNING|"
799 ['default']="iotop"
800 )
801
802 declare -A pkg_iproute2=(
803 ['alpine']="iproute2"
804 ['debian']="iproute2"
805 ['gentoo']="sys-apps/iproute2"
806 ['sabayon']="sys-apps/iproute2"
807 ['clearlinux']="iproute2"
808 ['macos']="WARNING|"
809 ['default']="iproute"
810
811 # exceptions
812 ['ubuntu-12.04']="iproute"
813 )
814
815 declare -A pkg_ipset=(
816 ['gentoo']="net-firewall/ipset"
817 ['clearlinux']="network-basic"
818 ['macos']="WARNING|"
819 ['default']="ipset"
820 )
821
822 declare -A pkg_jq=(
823 ['gentoo']="app-misc/jq"
824 ['default']="jq"
825 )
826
827 declare -A pkg_iptables=(
828 ['gentoo']="net-firewall/iptables"
829 ['macos']="WARNING|"
830 ['default']="iptables"
831 )
832
833 declare -A pkg_libz_dev=(
834 ['alpine']="zlib-dev"
835 ['arch']="zlib"
836 ['centos']="zlib-devel"
837 ['debian']="zlib1g-dev"
838 ['gentoo']="sys-libs/zlib"
839 ['sabayon']="sys-libs/zlib"
840 ['rhel']="zlib-devel"
841 ['ol']="zlib-devel"
842 ['suse']="zlib-devel"
843 ['clearlinux']="devpkg-zlib"
844 ['macos']="NOTREQUIRED"
845 ['freebsd']="lzlib"
846 ['default']=""
847 )
848
849 declare -A pkg_libuuid_dev=(
850 ['alpine']="util-linux-dev"
851 ['arch']="util-linux"
852 ['centos']="libuuid-devel"
853 ['clearlinux']="devpkg-util-linux"
854 ['debian']="uuid-dev"
855 ['gentoo']="sys-apps/util-linux"
856 ['sabayon']="sys-apps/util-linux"
857 ['rhel']="libuuid-devel"
858 ['ol']="libuuid-devel"
859 ['suse']="libuuid-devel"
860 ['macos']="ossp-uuid"
861 ['freebsd']="libuuid"
862 ['default']=""
863 )
864
865 declare -A pkg_libcurl_dev=(
866 ['alpine']="curl-dev"
867 ['arch']="curl"
868 ['clearlinux']="devpkg-curl"
869 ['debian']="libcurl4-openssl-dev"
870 ['gentoo']="net-misc/curl"
871 ['ubuntu']="libcurl4-openssl-dev"
872 ['macos']="curl"
873 ['freebsd']="curl"
874 ['default']="libcurl-devel"
875 )
876
877 declare -A pkg_libmnl_dev=(
878 ['alpine']="libmnl-dev"
879 ['arch']="libmnl"
880 ['centos']="libmnl-devel"
881 ['debian']="libmnl-dev"
882 ['gentoo']="net-libs/libmnl"
883 ['sabayon']="net-libs/libmnl"
884 ['rhel']="libmnl-devel"
885 ['ol']="libmnl-devel"
886 ['suse']="libmnl-devel"
887 ['clearlinux']="devpkg-libmnl"
888 ['macos']="NOTREQUIRED"
889 ['default']=""
890 )
891
892 declare -A pkg_lm_sensors=(
893 ['alpine']="lm_sensors"
894 ['arch']="lm_sensors"
895 ['centos']="lm_sensors"
896 ['debian']="lm-sensors"
897 ['gentoo']="sys-apps/lm-sensors"
898 ['sabayon']="sys-apps/lm_sensors"
899 ['rhel']="lm_sensors"
900 ['suse']="sensors"
901 ['clearlinux']="lm-sensors"
902 ['macos']="WARNING|"
903 ['freebsd']="NOTREQUIRED"
904 ['default']="lm_sensors"
905 )
906
907 declare -A pkg_logwatch=(
908 ['gentoo']="sys-apps/logwatch"
909 ['clearlinux']="WARNING|"
910 ['macos']="WARNING|"
911 ['default']="logwatch"
912 )
913
914 declare -A pkg_lxc=(
915 ['gentoo']="app-emulation/lxc"
916 ['clearlinux']="WARNING|"
917 ['macos']="WARNING|"
918 ['default']="lxc"
919 )
920
921 declare -A pkg_mailutils=(
922 ['gentoo']="net-mail/mailutils"
923 ['clearlinux']="WARNING|"
924 ['macos']="WARNING|"
925 ['default']="mailutils"
926 )
927
928 declare -A pkg_make=(
929 ['gentoo']="sys-devel/make"
930 ['macos']="NOTREQUIRED"
931 ['freebsd']="gmake"
932 ['default']="make"
933 )
934
935 declare -A pkg_nginx=(
936 ['gentoo']="www-servers/nginx"
937 ['default']="nginx"
938 )
939
940 declare -A pkg_postfix=(
941 ['gentoo']="mail-mta/postfix"
942 ['macos']="WARNING|"
943 ['default']="postfix"
944 )
945
946 declare -A pkg_pkg_config=(
947 ['alpine']="pkgconf"
948 ['arch']="pkgconfig"
949 ['centos']="pkgconfig"
950 ['debian']="pkg-config"
951 ['gentoo']="virtual/pkgconfig"
952 ['sabayon']="virtual/pkgconfig"
953 ['rhel']="pkgconfig"
954 ['ol']="pkgconfig"
955 ['suse']="pkg-config"
956 ['freebsd']="pkgconf"
957 ['clearlinux']="c-basic"
958 ['default']="pkg-config"
959 )
960
961 declare -A pkg_python=(
962 ['gentoo']="dev-lang/python"
963 ['sabayon']="dev-lang/python:2.7"
964 ['clearlinux']="python-basic"
965 ['default']="python"
966
967 # Exceptions
968 ['macos']="WARNING|"
969 ['centos-8']="python2"
970 )
971
972 declare -A pkg_python_pip=(
973 ['alpine']="py-pip"
974 ['gentoo']="dev-python/pip"
975 ['sabayon']="dev-python/pip"
976 ['clearlinux']="python-basic"
977 ['macos']="WARNING|"
978 ['default']="python-pip"
979 )
980
981 declare -A pkg_python3_pip=(
982 ['alpine']="py3-pip"
983 ['arch']="python-pip"
984 ['gentoo']="dev-python/pip"
985 ['sabayon']="dev-python/pip"
986 ['clearlinux']="python3-basic"
987 ['macos']="NOTREQUIRED"
988 ['default']="python3-pip"
989 )
990
991 declare -A pkg_python_requests=(
992 ['alpine']="py-requests"
993 ['arch']="python2-requests"
994 ['centos']="python-requests"
995 ['debian']="python-requests"
996 ['gentoo']="dev-python/requests"
997 ['sabayon']="dev-python/requests"
998 ['rhel']="python-requests"
999 ['suse']="python-requests"
1000 ['clearlinux']="python-extras"
1001 ['macos']="WARNING|"
1002 ['default']="python-requests"
1003 ['alpine-3.1.4']="WARNING|"
1004 ['alpine-3.2.3']="WARNING|"
1005 )
1006
1007 declare -A pkg_python3_requests=(
1008 ['alpine']="py3-requests"
1009 ['arch']="python-requests"
1010 ['centos']="WARNING|"
1011 ['debian']="WARNING|"
1012 ['gentoo']="dev-python/requests"
1013 ['sabayon']="dev-python/requests"
1014 ['rhel']="WARNING|"
1015 ['suse']="WARNING|"
1016 ['clearlinux']="python-extras"
1017 ['macos']="WARNING|"
1018 ['default']="WARNING|"
1019
1020 ['centos-7']="python36-requests"
1021 ['centos-8']="python3-requests"
1022 ['rhel-7']="python36-requests"
1023 ['rhel-8']="python3-requests"
1024 ['ol-8']="python3-requests"
1025 )
1026
1027 declare -A pkg_lz4=(
1028 ['alpine']="lz4-dev"
1029 ['debian']="liblz4-dev"
1030 ['ubuntu']="liblz4-dev"
1031 ['suse']="liblz4-devel"
1032 ['gentoo']="app-arch/lz4"
1033 ['clearlinux']="devpkg-lz4"
1034 ['arch']="lz4"
1035 ['macos']="lz4"
1036 ['freebsd']="liblz4"
1037 ['default']="lz4-devel"
1038 )
1039
1040 declare -A pkg_zstd=(
1041 ['alpine']="zstd-dev"
1042 ['debian']="libzstd-dev"
1043 ['ubuntu']="libzstd-dev"
1044 ['gentoo']="app-arch/zstd"
1045 ['clearlinux']="zstd-devel"
1046 ['arch']="zstd"
1047 ['macos']="zstd"
1048 ['freebsd']="zstd"
1049 ['default']="libzstd-devel"
1050 )
1051
1052 declare -A pkg_libuv=(
1053 ['alpine']="libuv-dev"
1054 ['debian']="libuv1-dev"
1055 ['ubuntu']="libuv1-dev"
1056 ['gentoo']="dev-libs/libuv"
1057 ['arch']="libuv"
1058 ['clearlinux']="devpkg-libuv"
1059 ['macos']="libuv"
1060 ['freebsd']="libuv"
1061 ['default']="libuv-devel"
1062 )
1063
1064 declare -A pkg_openssl=(
1065 ['alpine']="openssl-dev"
1066 ['debian']="libssl-dev"
1067 ['ubuntu']="libssl-dev"
1068 ['suse']="libopenssl-devel"
1069 ['clearlinux']="devpkg-openssl"
1070 ['gentoo']="dev-libs/openssl"
1071 ['arch']="openssl"
1072 ['freebsd']="openssl"
1073 ['macos']="openssl"
1074 ['default']="openssl-devel"
1075 )
1076
1077 declare -A pkg_python3=(
1078 ['gentoo']="dev-lang/python"
1079 ['sabayon']="dev-lang/python:3.4"
1080 ['clearlinux']="python3-basic"
1081 ['macos']="python"
1082 ['default']="python3"
1083
1084 # exceptions
1085 ['centos-6']="WARNING|"
1086 )
1087
1088 declare -A pkg_screen=(
1089 ['gentoo']="app-misc/screen"
1090 ['sabayon']="app-misc/screen"
1091 ['clearlinux']="sysadmin-basic"
1092 ['default']="screen"
1093 )
1094
1095 declare -A pkg_sudo=(
1096 ['gentoo']="app-admin/sudo"
1097 ['macos']="NOTREQUIRED"
1098 ['default']="sudo"
1099 )
1100
1101 declare -A pkg_sysstat=(
1102 ['gentoo']="app-admin/sysstat"
1103 ['macos']="WARNING|"
1104 ['default']="sysstat"
1105 )
1106
1107 declare -A pkg_tcpdump=(
1108 ['gentoo']="net-analyzer/tcpdump"
1109 ['clearlinux']="network-basic"
1110 ['default']="tcpdump"
1111 )
1112
1113 declare -A pkg_traceroute=(
1114 ['alpine']=" "
1115 ['gentoo']="net-analyzer/traceroute"
1116 ['clearlinux']="network-basic"
1117 ['macos']="NOTREQUIRED"
1118 ['default']="traceroute"
1119 )
1120
1121 declare -A pkg_valgrind=(
1122 ['gentoo']="dev-util/valgrind"
1123 ['default']="valgrind"
1124 )
1125
1126 declare -A pkg_ulogd=(
1127 ['centos']="WARNING|"
1128 ['rhel']="WARNING|"
1129 ['ol']="WARNING|"
1130 ['clearlinux']="WARNING|"
1131 ['gentoo']="app-admin/ulogd"
1132 ['arch']="ulogd"
1133 ['macos']="WARNING|"
1134 ['default']="ulogd2"
1135 )
1136
1137 declare -A pkg_unzip=(
1138 ['gentoo']="app-arch/unzip"
1139 ['macos']="NOTREQUIRED"
1140 ['default']="unzip"
1141 )
1142
1143 declare -A pkg_zip=(
1144 ['gentoo']="app-arch/zip"
1145 ['macos']="NOTREQUIRED"
1146 ['default']="zip"
1147 )
1148
1149 declare -A pkg_libelf=(
1150 ['alpine']="elfutils-dev"
1151 ['arch']="libelf"
1152 ['gentoo']="virtual/libelf"
1153 ['sabayon']="virtual/libelf"
1154 ['debian']="libelf-dev"
1155 ['ubuntu']="libelf-dev"
1156 ['fedora']="elfutils-libelf-devel"
1157 ['centos']="elfutils-libelf-devel"
1158 ['rhel']="elfutils-libelf-devel"
1159 ['ol']="elfutils-libelf-devel"
1160 ['clearlinux']="devpkg-elfutils"
1161 ['suse']="libelf-devel"
1162 ['macos']="NOTREQUIRED"
1163 ['freebsd']="NOTREQUIRED"
1164 ['default']="libelf-devel"
1165
1166 # exceptions
1167 ['alpine-3.5']="libelf-dev"
1168 ['alpine-3.4']="libelf-dev"
1169 ['alpine-3.3']="libelf-dev"
1170 )
1171
1172 validate_package_trees() {
1173 if type -t validate_tree_${tree} > /dev/null; then
1174 validate_tree_${tree}
1175 fi
1176 }
1177
1178 validate_installed_package() {
1179 validate_${package_installer} "${p}"
1180 }
1181
1182 suitable_package() {
1183 local package="${1//-/_}" p="" v="${version//.*/}"
1184
1185 echo >&2 "Searching for ${package} ..."
1186
1187 eval "p=\${pkg_${package}['${distribution,,}-${version,,}']}"
1188 [ -z "${p}" ] && eval "p=\${pkg_${package}['${distribution,,}-${v,,}']}"
1189 [ -z "${p}" ] && eval "p=\${pkg_${package}['${distribution,,}']}"
1190 [ -z "${p}" ] && eval "p=\${pkg_${package}['${tree}-${version}']}"
1191 [ -z "${p}" ] && eval "p=\${pkg_${package}['${tree}-${v}']}"
1192 [ -z "${p}" ] && eval "p=\${pkg_${package}['${tree}']}"
1193 [ -z "${p}" ] && eval "p=\${pkg_${package}['default']}"
1194
1195 if [[ "${p/|*/}" =~ ^(ERROR|WARNING|INFO)$ ]]; then
1196 echo >&2 "${p/|*/}"
1197 echo >&2 "package ${1} is not available in this system."
1198 if [ -z "${p/*|/}" ]; then
1199 echo >&2 "You may try to install without it."
1200 else
1201 echo >&2 "${p/*|/}"
1202 fi
1203 echo >&2
1204 return 1
1205 elif [ "${p}" = "NOTREQUIRED" ]; then
1206 return 0
1207 elif [ -z "${p}" ]; then
1208 echo >&2 "WARNING"
1209 echo >&2 "package ${1} is not available in this system."
1210 echo >&2
1211 return 1
1212 else
1213 if [ "${IGNORE_INSTALLED}" -eq 0 ]; then
1214 validate_installed_package "${p}"
1215 else
1216 echo "${p}"
1217 fi
1218 return 0
1219 fi
1220 }
1221
1222 packages() {
1223 # detect the packages we need to install on this system
1224
1225 # -------------------------------------------------------------------------
1226 # basic build environment
1227
1228 suitable_package distro-sdk
1229 suitable_package coreutils
1230 suitable_package libatomic
1231
1232 require_cmd git || suitable_package git
1233 require_cmd find || suitable_package find
1234 require_cmd awk || suitable_package awk
1235
1236 require_cmd gcc || require_cmd clang ||
1237 require_cmd gcc-multilib || suitable_package gcc
1238 require_cmd g++ || require_cmd clang++ || suitable_package gxx
1239
1240 require_cmd pkg-config || suitable_package pkg-config
1241 require_cmd cmake || suitable_package cmake
1242 require_cmd make || suitable_package make
1243
1244 require_cmd flex || suitable_package flex
1245 require_cmd bison || suitable_package bison
1246
1247 # -------------------------------------------------------------------------
1248 # debugging tools for development
1249
1250 if [ "${PACKAGES_DEBUG}" -ne 0 ]; then
1251 require_cmd traceroute || suitable_package traceroute
1252 require_cmd tcpdump || suitable_package tcpdump
1253 require_cmd screen || suitable_package screen
1254
1255 if [ "${PACKAGES_NETDATA}" -ne 0 ]; then
1256 require_cmd gdb || suitable_package gdb
1257 require_cmd valgrind || suitable_package valgrind
1258 fi
1259 fi
1260
1261 # -------------------------------------------------------------------------
1262 # common command line tools
1263
1264 if [ "${PACKAGES_NETDATA}" -ne 0 ]; then
1265 require_cmd tar || suitable_package tar
1266 require_cmd curl || suitable_package curl
1267 require_cmd gzip || suitable_package gzip
1268 require_cmd patch || suitable_package patch
1269 fi
1270
1271 # -------------------------------------------------------------------------
1272 # firehol/fireqos/update-ipsets command line tools
1273
1274 if [ "${PACKAGES_FIREQOS}" -ne 0 ]; then
1275 require_cmd ip || suitable_package iproute2
1276 fi
1277
1278 if [ "${PACKAGES_FIREHOL}" -ne 0 ]; then
1279 require_cmd iptables || suitable_package iptables
1280 require_cmd ipset || suitable_package ipset
1281 require_cmd ulogd ulogd2 || suitable_package ulogd
1282 require_cmd traceroute || suitable_package traceroute
1283 require_cmd bridge || suitable_package bridge-utils
1284 fi
1285
1286 if [ "${PACKAGES_UPDATE_IPSETS}" -ne 0 ]; then
1287 require_cmd ipset || suitable_package ipset
1288 require_cmd zip || suitable_package zip
1289 require_cmd funzip || suitable_package unzip
1290 fi
1291
1292 # -------------------------------------------------------------------------
1293 # netdata libraries
1294
1295 if [ "${PACKAGES_NETDATA}" -ne 0 ]; then
1296 suitable_package libz-dev
1297 suitable_package libuuid-dev
1298 suitable_package libmnl-dev
1299 suitable_package json-c-dev
1300 suitable_package libyaml-dev
1301 suitable_package libsystemd-dev
1302 suitable_package pcre2
1303 suitable_package flex
1304 suitable_package libcurl-dev
1305 fi
1306
1307 # -------------------------------------------------------------------------
1308 # sensors
1309
1310 if [ "${PACKAGES_NETDATA_SENSORS}" -ne 0 ]; then
1311 require_cmd sensors || suitable_package lm_sensors
1312 fi
1313
1314 # -------------------------------------------------------------------------
1315 # netdata database
1316 if [ "${PACKAGES_NETDATA_DATABASE}" -ne 0 ]; then
1317 suitable_package libuv
1318 suitable_package lz4
1319 suitable_package openssl
1320 fi
1321
1322 if [ "${PACKAGES_NETDATA_STREAMING_COMPRESSION}" -ne 0 ]; then
1323 suitable_package zstd
1324 fi
1325
1326 # -------------------------------------------------------------------------
1327 # ebpf plugin
1328 if [ "${PACKAGES_NETDATA_EBPF}" -ne 0 ]; then
1329 suitable_package libelf
1330 fi
1331
1332 # -------------------------------------------------------------------------
1333 # python2
1334
1335 if [ "${PACKAGES_NETDATA_PYTHON}" -ne 0 ]; then
1336 require_cmd python || suitable_package python
1337 fi
1338
1339 # -------------------------------------------------------------------------
1340 # python3
1341
1342 if [ "${PACKAGES_NETDATA_PYTHON3}" -ne 0 ]; then
1343 require_cmd python3 || suitable_package python3
1344 fi
1345
1346 # -------------------------------------------------------------------------
1347 # applications needed for the netdata demo sites
1348
1349 if [ "${PACKAGES_NETDATA_DEMO_SITE}" -ne 0 ]; then
1350 require_cmd sudo || suitable_package sudo
1351 require_cmd jq || suitable_package jq
1352 require_cmd nginx || suitable_package nginx
1353 require_cmd postconf || suitable_package postfix
1354 require_cmd lxc-create || suitable_package lxc
1355 require_cmd logwatch || suitable_package logwatch
1356 require_cmd mail || suitable_package mailutils
1357 require_cmd iostat || suitable_package sysstat
1358 require_cmd iotop || suitable_package iotop
1359 fi
1360 }
1361
1362 DRYRUN=0
1363 run() {
1364
1365 printf >&2 "%q " "${@}"
1366 printf >&2 "\n"
1367
1368 if [ ! "${DRYRUN}" -eq 1 ]; then
1369 "${@}"
1370 return $?
1371 fi
1372 return 0
1373 }
1374
1375 sudo=
1376 if [ ${UID} -ne 0 ]; then
1377 sudo="sudo"
1378 fi
1379
1380 # -----------------------------------------------------------------------------
1381 # debian / ubuntu
1382
1383 validate_install_apt_get() {
1384 echo >&2 " > Checking if package '${*}' is installed..."
1385 [ "$(dpkg-query -W --showformat='${Status}\n' "${*}")" = "install ok installed" ] || echo "${*}"
1386 }
1387
1388 install_apt_get() {
1389 local opts=""
1390 if [ "${NON_INTERACTIVE}" -eq 1 ]; then
1391 echo >&2 "Running in non-interactive mode"
1392 # http://serverfault.com/questions/227190/how-do-i-ask-apt-get-to-skip-any-interactive-post-install-configuration-steps
1393 export DEBIAN_FRONTEND="noninteractive"
1394 opts="${opts} -yq"
1395 fi
1396
1397 read -r -a apt_opts <<< "$opts"
1398
1399 # update apt repository caches
1400
1401 echo >&2 "NOTE: Running apt-get update and updating your APT caches ..."
1402 if [ "${version}" = 8 ]; then
1403 echo >&2 "WARNING: You seem to be on Debian 8 (jessie) which is old enough we have to disable Check-Valid-Until checks"
1404 if ! cat /etc/apt/sources.list /etc/apt/sources.list.d/* 2> /dev/null | grep -q jessie-backports; then
1405 echo >&2 "We also have to enable the jessie-backports repository"
1406 if prompt "Is this okay?"; then
1407 ${sudo} /bin/sh -c 'echo "deb http://archive.debian.org/debian/ jessie-backports main contrib non-free" >> /etc/apt/sources.list.d/99-archived.list'
1408 fi
1409 fi
1410 run ${sudo} apt-get "${apt_opts[@]}" -o Acquire::Check-Valid-Until=false update
1411 else
1412 run ${sudo} apt-get "${apt_opts[@]}" update
1413 fi
1414
1415 # install the required packages
1416 run ${sudo} apt-get "${apt_opts[@]}" install "${@}"
1417 }
1418
1419 # -----------------------------------------------------------------------------
1420 # centos / rhel
1421
1422 prompt() {
1423 if [ "${NON_INTERACTIVE}" -eq 1 ]; then
1424 echo >&2 "Running in non-interactive mode, assuming yes (y)"
1425 echo >&2 " > Would have prompted for ${1} ..."
1426 return 0
1427 fi
1428
1429 while true; do
1430 read -r -p "${1} [y/n] " yn
1431 case $yn in
1432 [Yy]*) return 0 ;;
1433 [Nn]*) return 1 ;;
1434 *) echo >&2 "Please answer with yes (y) or no (n)." ;;
1435 esac
1436 done
1437 }
1438
1439 validate_tree_freebsd() {
1440 local opts=
1441 if [ "${NON_INTERACTIVE}" -eq 1 ]; then
1442 echo >&2 "Running in non-interactive mode"
1443 opts="-y"
1444 fi
1445
1446 echo >&2 " > FreeBSD Version: ${version} ..."
1447
1448 make="make"
1449 echo >&2 " > Checking for gmake ..."
1450 if ! pkg query %n-%v | grep -q gmake; then
1451 if prompt "gmake is required to build on FreeBSD and is not installed. Shall I install it?"; then
1452 # shellcheck disable=2086
1453 run ${sudo} pkg install ${opts} gmake
1454 fi
1455 fi
1456 }
1457
1458 validate_tree_ol() {
1459 local opts=
1460 if [ "${NON_INTERACTIVE}" -eq 1 ]; then
1461 echo >&2 "Running in non-interactive mode"
1462 opts="-y"
1463 fi
1464
1465 if [[ "${version}" =~ ^8(\..*)?$ ]]; then
1466 echo " > Checking for CodeReady Builder ..."
1467 if ! run ${sudo} dnf repolist | grep -q codeready; then
1468 if prompt "CodeReady Builder not found, shall I install it?"; then
1469 cat > /etc/yum.repos.d/ol8_codeready.repo <<-EOF
1470 [ol8_codeready_builder]
1471 name=Oracle Linux \$releasever CodeReady Builder (\$basearch)
1472 baseurl=http://yum.oracle.com/repo/OracleLinux/OL8/codeready/builder/\$basearch
1473 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
1474 gpgcheck=1
1475 enabled=1
1476 EOF
1477 fi
1478 fi
1479 elif [[ "${version}" =~ ^9(\..*)?$ ]]; then
1480 echo " > Checking for CodeReady Builder ..."
1481 if ! run ${sudo} dnf repolist enabled | grep -q codeready; then
1482 if prompt "CodeReady Builder not enabled, shall I enable it?"; then
1483 run ${sudo} dnf config-manager --set-enabled ol9_codeready_builder
1484 fi
1485 fi
1486 fi
1487 }
1488
1489 validate_tree_centos() {
1490 local opts=
1491 if [ "${NON_INTERACTIVE}" -eq 1 ]; then
1492 echo >&2 "Running in non-interactive mode"
1493 opts="-y"
1494 fi
1495
1496 echo >&2 " > CentOS Version: ${version} ..."
1497
1498 if [[ "${version}" =~ ^(9|10)(\..*)?$ ]]; then
1499 echo >&2 " > Checking for config-manager ..."
1500 if ! run ${sudo} dnf config-manager --help; then
1501 if prompt "config-manager not found, shall I install it?"; then
1502 # shellcheck disable=2086
1503 run ${sudo} dnf ${opts} install 'dnf-command(config-manager)'
1504 fi
1505 fi
1506
1507 echo >&2 " > Checking for CRB ..."
1508 # shellcheck disable=2086
1509 if ! run ${sudo} dnf repolist | grep CRB; then
1510 if prompt "CRB not found, shall I install it?"; then
1511 # shellcheck disable=2086
1512 run ${sudo} dnf ${opts} config-manager --set-enabled crb
1513 fi
1514 fi
1515 elif [[ "${version}" =~ ^8(\..*)?$ ]]; then
1516 echo >&2 " > Checking for config-manager ..."
1517 if ! run ${sudo} yum config-manager --help; then
1518 if prompt "config-manager not found, shall I install it?"; then
1519 # shellcheck disable=2086
1520 run ${sudo} yum ${opts} install 'dnf-command(config-manager)'
1521 fi
1522 fi
1523
1524 echo >&2 " > Checking for PowerTools ..."
1525 # shellcheck disable=2086
1526 if ! run ${sudo} yum repolist | grep PowerTools; then
1527 if prompt "PowerTools not found, shall I install it?"; then
1528 # shellcheck disable=2086
1529 run ${sudo} yum ${opts} config-manager --set-enabled powertools
1530 fi
1531 fi
1532
1533 echo >&2 " > Updating libarchive ..."
1534 # shellcheck disable=2086
1535 run ${sudo} yum ${opts} install libarchive
1536
1537 elif [[ "${version}" =~ ^7(\..*)?$ ]]; then
1538 echo >&2 " > Checking for EPEL ..."
1539 if ! rpm -qa | grep epel-release > /dev/null; then
1540 if prompt "EPEL not found, shall I install it?"; then
1541 # shellcheck disable=2086
1542 run ${sudo} yum ${opts} install epel-release
1543 fi
1544 fi
1545 elif [[ "${version}" =~ ^6\..*$ ]]; then
1546 echo >&2 " > Detected CentOS 6.x ..."
1547 echo >&2 " > Checking for Okay ..."
1548 if ! rpm -qa | grep okay > /dev/null; then
1549 if prompt "okay not found, shall I install it?"; then
1550 # shellcheck disable=2086
1551 run ${sudo} yum ${opts} install http://repo.okay.com.mx/centos/6/x86_64/release/okay-release-1-3.el6.noarch.rpm
1552 fi
1553 fi
1554
1555 fi
1556 }
1557
1558 validate_install_yum() {
1559 echo >&2 " > Checking if package '${*}' is installed..."
1560 yum list installed "${*}" > /dev/null 2>&1 || echo "${*}"
1561 }
1562
1563 install_yum() {
1564 # download the latest package info
1565 if [ "${DRYRUN}" -eq 1 ]; then
1566 echo >&2 " >> IMPORTANT << "
1567 echo >&2 " Please make sure your system is up to date"
1568 echo >&2 " by running: ${sudo} yum update "
1569 echo >&2
1570 fi
1571
1572 local opts=
1573 if [ "${NON_INTERACTIVE}" -eq 1 ]; then
1574 echo >&2 "Running in non-interactive mode"
1575 # http://unix.stackexchange.com/questions/87822/does-yum-have-an-equivalent-to-apt-aptitudes-debian-frontend-noninteractive
1576 opts="-y"
1577 fi
1578
1579 read -r -a yum_opts <<< "${opts}"
1580
1581 # install the required packages
1582 run ${sudo} yum "${yum_opts[@]}" install "${@}"
1583 }
1584
1585 # -----------------------------------------------------------------------------
1586 # fedora
1587
1588 validate_install_dnf() {
1589 echo >&2 " > Checking if package '${*}' is installed..."
1590 dnf list --installed "${*}" > /dev/null 2>&1 || echo "${*}"
1591 }
1592
1593 install_dnf() {
1594 # download the latest package info
1595 if [ "${DRYRUN}" -eq 1 ]; then
1596 echo >&2 " >> IMPORTANT << "
1597 echo >&2 " Please make sure your system is up to date"
1598 echo >&2 " by running: ${sudo} dnf update "
1599 echo >&2
1600 fi
1601
1602 local opts=
1603 if [ "${NON_INTERACTIVE}" -eq 1 ]; then
1604 echo >&2 "Running in non-interactive mode"
1605 # man dnf
1606 opts="-y"
1607 fi
1608
1609 # install the required packages
1610 # --setopt=strict=0 allows dnf to proceed
1611 # installing whatever is available
1612 # even if a package is not found
1613 opts="$opts --setopt=strict=0"
1614 read -r -a dnf_opts <<< "$opts"
1615 run ${sudo} dnf "${dnf_opts[@]}" install "${@}"
1616 }
1617
1618 # -----------------------------------------------------------------------------
1619 # gentoo
1620
1621 validate_install_emerge() {
1622 echo "${*}"
1623 }
1624
1625 install_emerge() {
1626 # download the latest package info
1627 # we don't do this for emerge - it is very slow
1628 # and most users are expected to do this daily
1629 # emerge --sync
1630 if [ "${DRYRUN}" -eq 1 ]; then
1631 echo >&2 " >> IMPORTANT << "
1632 echo >&2 " Please make sure your system is up to date"
1633 echo >&2 " by running: ${sudo} emerge --sync or ${sudo} eix-sync "
1634 echo >&2
1635 fi
1636
1637 local opts="--ask"
1638 if [ "${NON_INTERACTIVE}" -eq 1 ]; then
1639 echo >&2 "Running in non-interactive mode"
1640 opts=""
1641 fi
1642
1643 read -r -a emerge_opts <<< "$opts"
1644
1645 # install the required packages
1646 run ${sudo} emerge "${emerge_opts[@]}" -v --noreplace "${@}"
1647 }
1648
1649 # -----------------------------------------------------------------------------
1650 # alpine
1651
1652 validate_install_apk() {
1653 echo "${*}"
1654 }
1655
1656 install_apk() {
1657 # download the latest package info
1658 if [ "${DRYRUN}" -eq 1 ]; then
1659 echo >&2 " >> IMPORTANT << "
1660 echo >&2 " Please make sure your system is up to date"
1661 echo >&2 " by running: ${sudo} apk update "
1662 echo >&2
1663 fi
1664
1665 local opts="--force-broken-world"
1666 if [ "${NON_INTERACTIVE}" -eq 1 ]; then
1667 echo >&2 "Running in non-interactive mode"
1668 else
1669 opts="${opts} -i"
1670 fi
1671
1672 read -r -a apk_opts <<< "$opts"
1673
1674 # install the required packages
1675 run ${sudo} apk add "${apk_opts[@]}" "${@}"
1676 }
1677
1678 # -----------------------------------------------------------------------------
1679 # sabayon
1680
1681 validate_install_equo() {
1682 echo >&2 " > Checking if package '${*}' is installed..."
1683 equo s --installed "${*}" > /dev/null 2>&1 || echo "${*}"
1684 }
1685
1686 install_equo() {
1687 # download the latest package info
1688 if [ "${DRYRUN}" -eq 1 ]; then
1689 echo >&2 " >> IMPORTANT << "
1690 echo >&2 " Please make sure your system is up to date"
1691 echo >&2 " by running: ${sudo} equo up "
1692 echo >&2
1693 fi
1694
1695 local opts="-av"
1696 if [ "${NON_INTERACTIVE}" -eq 1 ]; then
1697 echo >&2 "Running in non-interactive mode"
1698 opts="-v"
1699 fi
1700
1701 read -r -a equo_opts <<< "$opts"
1702
1703 # install the required packages
1704 run ${sudo} equo i "${equo_opts[@]}" "${@}"
1705 }
1706
1707 # -----------------------------------------------------------------------------
1708 # arch
1709
1710 PACMAN_DB_SYNCED=0
1711 validate_install_pacman() {
1712
1713 if [ "${PACMAN_DB_SYNCED}" -eq 0 ]; then
1714 echo >&2 " > Running pacman -Sy to sync the database"
1715 local x
1716 x=$(pacman -Sy)
1717 [ -z "${x}" ] && echo "${*}"
1718 PACMAN_DB_SYNCED=1
1719 fi
1720 echo >&2 " > Checking if package '${*}' is installed..."
1721
1722 # In pacman, you can utilize alternative flags to exactly match package names,
1723 # but is highly likely we require pattern matching too in this so we keep -s and match
1724 # the exceptional cases like so
1725 local x=""
1726 case "${package}" in
1727 "gcc")
1728 # Temporary workaround: In archlinux, default installation includes runtime libs under package "gcc"
1729 # These are not sufficient for netdata install, so we need to make sure that the appropriate libraries are there
1730 # by ensuring devel libs are available
1731 x=$(pacman -Qs "${*}" | grep "base-devel")
1732 ;;
1733 "tar")
1734 x=$(pacman -Qs "${*}" | grep "local/tar")
1735 ;;
1736 "make")
1737 x=$(pacman -Qs "${*}" | grep "local/make ")
1738 ;;
1739 *)
1740 x=$(pacman -Qs "${*}")
1741 ;;
1742 esac
1743
1744 [ -z "${x}" ] && echo "${*}"
1745 }
1746
1747 install_pacman() {
1748 # download the latest package info
1749 if [ "${DRYRUN}" -eq 1 ]; then
1750 echo >&2 " >> IMPORTANT << "
1751 echo >&2 " Please make sure your system is up to date"
1752 echo >&2 " by running: ${sudo} pacman -Syu "
1753 echo >&2
1754 fi
1755
1756 # install the required packages
1757 if [ "${NON_INTERACTIVE}" -eq 1 ]; then
1758 echo >&2 "Running in non-interactive mode"
1759 # http://unix.stackexchange.com/questions/52277/pacman-option-to-assume-yes-to-every-question/52278
1760 # Try the noconfirm option, if that fails, go with the legacy way for non-interactive
1761 run ${sudo} pacman --noconfirm --needed -S "${@}" || yes | run ${sudo} pacman --needed -S "${@}"
1762 else
1763 run ${sudo} pacman --needed -S "${@}"
1764 fi
1765 }
1766
1767 # -----------------------------------------------------------------------------
1768 # suse / opensuse
1769
1770 validate_install_zypper() {
1771 rpm -q "${*}" > /dev/null 2>&1 || echo "${*}"
1772 }
1773
1774 install_zypper() {
1775 # download the latest package info
1776 if [ "${DRYRUN}" -eq 1 ]; then
1777 echo >&2 " >> IMPORTANT << "
1778 echo >&2 " Please make sure your system is up to date"
1779 echo >&2 " by running: ${sudo} zypper update "
1780 echo >&2
1781 fi
1782
1783 local opts="--ignore-unknown"
1784 local install_opts="--allow-downgrade"
1785 if [ "${NON_INTERACTIVE}" -eq 1 ]; then
1786 echo >&2 "Running in non-interactive mode"
1787 # http://unix.stackexchange.com/questions/82016/how-to-use-zypper-in-bash-scripts-for-someone-coming-from-apt-get
1788 opts="${opts} --non-interactive"
1789 fi
1790
1791 read -r -a zypper_opts <<< "$opts"
1792 # install the required packages
1793 run ${sudo} zypper "${zypper_opts[@]}" install "${install_opts}" "${@}"
1794 }
1795
1796 # -----------------------------------------------------------------------------
1797 # clearlinux
1798
1799 validate_install_swupd() {
1800 swupd bundle-list | grep -q "${*}" || echo "${*}"
1801 }
1802
1803 install_swupd() {
1804 # download the latest package info
1805 if [ "${DRYRUN}" -eq 1 ]; then
1806 echo >&2 " >> IMPORTANT << "
1807 echo >&2 " Please make sure your system is up to date"
1808 echo >&2 " by running: ${sudo} swupd update "
1809 echo >&2
1810 fi
1811
1812 run ${sudo} swupd bundle-add "${@}"
1813 }
1814
1815 # -----------------------------------------------------------------------------
1816 # macOS
1817
1818 validate_install_pkg() {
1819 pkg query %n-%v | grep -q "${*}" || echo "${*}"
1820 }
1821
1822 validate_install_brew() {
1823 brew list | grep -q "${*}" || echo "${*}"
1824 }
1825
1826 install_pkg() {
1827 # download the latest package info
1828 if [ "${DRYRUN}" -eq 1 ]; then
1829 echo >&2 " >> IMPORTANT << "
1830 echo >&2 " Please make sure your system is up to date"
1831 echo >&2 " by running: pkg update "
1832 echo >&2
1833 fi
1834
1835 local opts=
1836 if [ "${NON_INTERACTIVE}" -eq 1 ]; then
1837 echo >&2 "Running in non-interactive mode"
1838 opts="-y"
1839 fi
1840
1841 read -r -a pkg_opts <<< "${opts}"
1842
1843 run ${sudo} pkg install "${pkg_opts[@]}" "${@}"
1844 }
1845
1846 install_brew() {
1847 # download the latest package info
1848 if [ "${DRYRUN}" -eq 1 ]; then
1849 echo >&2 " >> IMPORTANT << "
1850 echo >&2 " Please make sure your system is up to date"
1851 echo >&2 " by running: brew upgrade "
1852 echo >&2
1853 fi
1854
1855 run brew install "${@}"
1856 }
1857
1858 # -----------------------------------------------------------------------------
1859
1860 install_failed() {
1861 local ret="${1}"
1862 cat << EOF
1863
1864
1865
1866 We are very sorry!
1867
1868 Installation of required packages failed.
1869
1870 What to do now:
1871
1872 1. Make sure your system is updated.
1873 Most of the times, updating your system will resolve the issue.
1874
1875 2. If the error message is about a specific package, try removing
1876 that package from the command and run it again.
1877 Depending on the broken package, you may be able to continue.
1878
1879 3. Let us know. We may be able to help.
1880 Open a github issue with the above log, at:
1881
1882 https://github.com/netdata/netdata/issues
1883
1884
1885 EOF
1886 remote_log "FAILED" "${ret}"
1887 exit 1
1888 }
1889
1890 remote_log() {
1891 # log success or failure on our system
1892 # to help us solve installation issues
1893 curl > /dev/null 2>&1 -Ss --max-time 3 "https://registry.my-netdata.io/log/installer?status=${1}&error=${2}&distribution=${distribution}&version=${version}&installer=${package_installer}&tree=${tree}&detection=${detection}&netdata=${PACKAGES_NETDATA}&python=${PACKAGES_NETDATA_PYTHON}&python3=${PACKAGES_NETDATA_PYTHON3}&sensors=${PACKAGES_NETDATA_SENSORS}&database=${PACKAGES_NETDATA_DATABASE}&ebpf=${PACKAGES_NETDATA_EBPF}&firehol=${PACKAGES_FIREHOL}&fireqos=${PACKAGES_FIREQOS}&iprange=${PACKAGES_IPRANGE}&update_ipsets=${PACKAGES_UPDATE_IPSETS}&demo=${PACKAGES_NETDATA_DEMO_SITE}"
1894 }
1895
1896 if [ -z "${1}" ]; then
1897 usage
1898 exit 1
1899 fi
1900
1901 pv=$(python --version 2>&1)
1902 if [ "${tree}" = macos ]; then
1903 pv=3
1904 elif [[ "${pv}" =~ ^Python\ 2.* ]]; then
1905 pv=2
1906 elif [[ "${pv}" =~ ^Python\ 3.* ]]; then
1907 pv=3
1908 elif [[ "${tree}" == "centos" ]] && [ "${version}" -lt 8 ]; then
1909 pv=2
1910 else
1911 pv=3
1912 fi
1913
1914 # parse command line arguments
1915 DONT_WAIT=0
1916 NON_INTERACTIVE=0
1917 IGNORE_INSTALLED=0
1918 while [ -n "${1}" ]; do
1919 case "${1}" in
1920 distribution)
1921 distribution="${2}"
1922 shift
1923 ;;
1924
1925 version)
1926 version="${2}"
1927 shift
1928 ;;
1929
1930 codename)
1931 codename="${2}"
1932 shift
1933 ;;
1934
1935 installer)
1936 check_package_manager "${2}" || exit 1
1937 shift
1938 ;;
1939
1940 dont-wait | --dont-wait | -n)
1941 DONT_WAIT=1
1942 ;;
1943
1944 non-interactive | --non-interactive | -y)
1945 NON_INTERACTIVE=1
1946 ;;
1947
1948 ignore-installed | --ignore-installed | -i)
1949 IGNORE_INSTALLED=1
1950 ;;
1951
1952 netdata-all)
1953 PACKAGES_NETDATA=1
1954 if [ "${pv}" -eq 2 ]; then
1955 PACKAGES_NETDATA_PYTHON=1
1956 else
1957 PACKAGES_NETDATA_PYTHON3=1
1958 fi
1959 PACKAGES_NETDATA_SENSORS=1
1960 PACKAGES_NETDATA_DATABASE=1
1961 PACKAGES_NETDATA_EBPF=1
1962 PACKAGES_NETDATA_STREAMING_COMPRESSION=1
1963 ;;
1964
1965 netdata)
1966 PACKAGES_NETDATA=1
1967 PACKAGES_NETDATA_PYTHON3=1
1968 PACKAGES_NETDATA_DATABASE=1
1969 PACKAGES_NETDATA_EBPF=1
1970 PACKAGES_NETDATA_STREAMING_COMPRESSION=1
1971 ;;
1972
1973 python | netdata-python)
1974 PACKAGES_NETDATA_PYTHON=1
1975 ;;
1976
1977 python3 | netdata-python3)
1978 PACKAGES_NETDATA_PYTHON3=1
1979 ;;
1980
1981 sensors | netdata-sensors)
1982 PACKAGES_NETDATA=1
1983 PACKAGES_NETDATA_PYTHON3=1
1984 PACKAGES_NETDATA_SENSORS=1
1985 PACKAGES_NETDATA_DATABASE=1
1986 ;;
1987
1988 firehol | update-ipsets | firehol-all | fireqos)
1989 PACKAGES_IPRANGE=1
1990 PACKAGES_FIREHOL=1
1991 PACKAGES_FIREQOS=1
1992 PACKAGES_IPRANGE=1
1993 PACKAGES_UPDATE_IPSETS=1
1994 ;;
1995
1996 demo | all)
1997 PACKAGES_NETDATA=1
1998 if [ "${pv}" -eq 2 ]; then
1999 PACKAGES_NETDATA_PYTHON=1
2000 else
2001 PACKAGES_NETDATA_PYTHON3=1
2002 fi
2003 PACKAGES_DEBUG=1
2004 PACKAGES_IPRANGE=1
2005 PACKAGES_FIREHOL=1
2006 PACKAGES_FIREQOS=1
2007 PACKAGES_UPDATE_IPSETS=1
2008 PACKAGES_NETDATA_DEMO_SITE=1
2009 PACKAGES_NETDATA_DATABASE=1
2010 PACKAGES_NETDATA_EBPF=1
2011 ;;
2012
2013 help | -h | --help)
2014 usage
2015 exit 1
2016 ;;
2017
2018 *)
2019 echo >&2 "ERROR: Cannot understand option '${1}'"
2020 echo >&2
2021 usage
2022 exit 1
2023 ;;
2024 esac
2025 shift
2026 done
2027
2028 # Check for missing core commands like grep, warn the user to install it and bail out cleanly
2029 if ! command -v grep > /dev/null 2>&1; then
2030 echo >&2
2031 echo >&2 "ERROR: 'grep' is required for the install to run correctly and was not found on the system."
2032 echo >&2 "Please install grep and run the installer again."
2033 echo >&2
2034 exit 1
2035 fi
2036
2037 if [ -z "${package_installer}" ] || [ -z "${tree}" ]; then
2038 if [ -z "${distribution}" ]; then
2039 # we dont know the distribution
2040 autodetect_distribution || user_picks_distribution
2041 fi
2042
2043 # When no package installer is detected, try again from distro info if any
2044 if [ -z "${package_installer}" ]; then
2045 detect_package_manager_from_distribution "${distribution}"
2046 fi
2047
2048 # Validate package manager trees
2049 validate_package_trees
2050 fi
2051
2052 [ "${detection}" = "/etc/os-release" ] && cat << EOF
2053
2054 /etc/os-release information:
2055 NAME : ${NAME}
2056 VERSION : ${VERSION}
2057 ID : ${ID}
2058 ID_LIKE : ${ID_LIKE}
2059 VERSION_ID : ${VERSION_ID}
2060 EOF
2061
2062 cat << EOF
2063
2064 We detected these:
2065 Distribution : ${distribution}
2066 Version : ${version}
2067 Codename : ${codename}
2068 Package Manager : ${package_installer}
2069 Packages Tree : ${tree}
2070 Detection Method: ${detection}
2071 Default Python v: ${pv} $([ ${pv} -eq 2 ] && [ "${PACKAGES_NETDATA_PYTHON3}" -eq 1 ] && echo "(will install python3 too)")
2072
2073 EOF
2074
2075 mapfile -t PACKAGES_TO_INSTALL < <(packages | sort -u)
2076
2077 if [ ${#PACKAGES_TO_INSTALL[@]} -gt 0 ]; then
2078 echo >&2
2079 echo >&2 "The following command will be run:"
2080 echo >&2
2081 DRYRUN=1
2082 "${package_installer}" "${PACKAGES_TO_INSTALL[@]}"
2083 DRYRUN=0
2084 echo >&2
2085 echo >&2
2086
2087 if [ "${DONT_WAIT}" -eq 0 ] && [ "${NON_INTERACTIVE}" -eq 0 ]; then
2088 read -r -p "Press ENTER to run it > " || exit 1
2089 fi
2090
2091 "${package_installer}" "${PACKAGES_TO_INSTALL[@]}" || install_failed $?
2092
2093 echo >&2
2094 echo >&2 "All Done! - Now proceed to the next step."
2095 echo >&2
2096
2097 else
2098 echo >&2
2099 echo >&2 "All required packages are already installed. Now proceed to the next step."
2100 echo >&2
2101 fi
2102
2103 remote_log "OK"
2104
2105 exit 0