master
sh 97 lines 1.7 KB
Raw
1 #!/usr/bin/env bash
2 # Package tree used for installing netdata on distribution:
3 # << ArchLinux: [base] [base-devel] >> | << Manjaro >>
4
5 set -e
6
7 NON_INTERACTIVE=0
8 DONT_WAIT=0
9
10 declare -a package_tree=(
11 binutils
12 bison
13 cmake
14 curl
15 flex
16 gcc
17 git
18 gzip
19 json-c
20 libelf
21 libmnl
22 libuv
23 libyaml
24 lz4
25 make
26 openssl
27 pkgconfig
28 python3
29 tar
30 util-linux
31 zlib
32 )
33
34 usage() {
35 cat << EOF
36 OPTIONS:
37 [--dont-wait] [--non-interactive] [ ]
38 EOF
39 }
40
41 check_flags() {
42 while [ -n "${1}" ]; do
43 case "${1}" in
44 dont-wait | --dont-wait | -n)
45 DONT_WAIT=1
46 ;;
47
48 non-interactive | --non-interactive | -y)
49 NON_INTERACTIVE=1
50 ;;
51
52 help | -h | --help)
53 usage
54 exit 1
55 ;;
56 *)
57 echo >&2 "ERROR: Cannot understand option '${1}'"
58 echo >&2
59 usage
60 exit 1
61 ;;
62 esac
63 shift
64 done
65
66 if [ "${DONT_WAIT}" -eq 0 ] && [ "${NON_INTERACTIVE}" -eq 0 ]; then
67 read -r -p "Press ENTER to run it > " || exit 1
68 fi
69 }
70
71 # shellcheck disable=SC2068
72 check_flags ${@}
73
74 packages_to_install=
75
76 # shellcheck disable=SC2068
77 for package in ${package_tree[@]}; do
78 if pacman -Qn "$package" &> /dev/null; then
79 echo "Package '${package}' is installed"
80 else
81 echo "Package '$package' is NOT installed"
82 packages_to_install="$packages_to_install $package"
83 fi
84 done
85
86 if [[ -z $packages_to_install ]]; then
87 echo "All required packages are already installed. Skipping .."
88 else
89 echo "packages_to_install: " "${packages_to_install[@]}"
90 opts=
91 if [ "${NON_INTERACTIVE}" -eq 1 ]; then
92 echo >&2 "Running in non-interactive mode"
93 opts="--noconfirm"
94 fi
95 # shellcheck disable=SC2068
96 pacman -Sy ${opts} ${packages_to_install[@]}
97 fi