master
sh 162 lines 3.38 KB
Raw
1 #!/usr/bin/env bash
2 # Package tree used for installing netdata on distribution:
3 # << Rocky Linux:[8.5] >>
4
5 set -e
6
7 NON_INTERACTIVE=0
8 DONT_WAIT=0
9
10 declare -a package_tree=(
11 bison
12 cmake
13 curl
14 elfutils-libelf-devel
15 findutils
16 flex
17 gcc
18 gcc-c++
19 git
20 gzip
21 json-c-devel
22 libatomic
23 libmnl-devel
24 libuuid-devel
25 libuv-devel
26 libyaml-devel
27 lz4-devel
28 make
29 openssl-devel
30 pkgconfig
31 python3
32 systemd-devel
33 tar
34 zlib-devel
35 )
36
37 prompt() {
38 if [ "${NON_INTERACTIVE}" -eq 1 ]; then
39 echo >&2 "Running in non-interactive mode, assuming yes (y)"
40 echo >&2 " > Would have prompted for ${1} ..."
41 return 0
42 fi
43
44 while true; do
45 read -r -p "${1} [y/n] " yn
46 case $yn in
47 [Yy]*) return 0 ;;
48 [Nn]*) return 1 ;;
49 *) echo >&2 "Please answer with yes (y) or no (n)." ;;
50 esac
51 done
52 }
53
54 usage() {
55 cat << EOF
56 OPTIONS:
57 [--dont-wait] [--non-interactive] [ ]
58 EOF
59 }
60
61 check_flags() {
62 while [ -n "${1}" ]; do
63 case "${1}" in
64 dont-wait | --dont-wait | -n)
65 DONT_WAIT=1
66 ;;
67
68 non-interactive | --non-interactive | -y)
69 NON_INTERACTIVE=1
70 ;;
71
72 help | -h | --help)
73 usage
74 exit 1
75 ;;
76 *)
77 echo >&2 "ERROR: Cannot understand option '${1}'"
78 echo >&2
79 usage
80 exit 1
81 ;;
82 esac
83 shift
84 done
85
86 if [ "${DONT_WAIT}" -eq 0 ] && [ "${NON_INTERACTIVE}" -eq 0 ]; then
87 read -r -p "Press ENTER to run it > " || exit 1
88 fi
89 }
90
91 validate_tree_rockylinux() {
92 local opts=
93 if [ "${NON_INTERACTIVE}" -eq 1 ]; then
94 echo >&2 "Running in non-interactive mode"
95 opts="-y"
96 fi
97
98 echo >&2 " > Checking for config-manager ..."
99 if ! dnf config-manager; then
100 if prompt "config-manager not found, shall I install it?"; then
101 dnf ${opts} install 'dnf-command(config-manager)'
102 fi
103 fi
104
105 echo >&2 " > Checking for PowerTools ..."
106 if ! dnf repolist | grep PowerTools; then
107 if prompt "PowerTools not found, shall I install it?"; then
108 dnf ${opts} config-manager --set-enabled powertools || enable_powertools_repo
109 fi
110 fi
111
112 echo >&2 " > Updating libarchive ..."
113 dnf ${opts} install libarchive
114
115 dnf makecache --refresh
116 }
117
118 enable_powertools_repo() {
119 if ! dnf repolist | grep -q powertools; then
120 cat > /etc/yum.repos.d/powertools.repo <<-EOF
121 [powertools]
122 name=Rocky Linux \$releasever - PowerTools
123 mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=\$basearch&repo=PowerTools-\$releasever
124 #baseurl=http://dl.rockylinux.org/\$contentdir/\$releasever/PowerTools/\$basearch/os/
125 gpgcheck=1
126 enabled=1
127 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial
128 EOF
129 else
130 echo "Something went wrong!"
131 exit 1
132 fi
133 }
134
135 # shellcheck disable=SC2068
136 check_flags ${@}
137 validate_tree_rockylinux
138
139 packages_to_install=
140
141 # shellcheck disable=SC2068
142 for package in ${package_tree[@]}; do
143 if rpm -q "$package" &> /dev/null; then
144 echo "Package '${package}' is installed"
145 else
146 echo "Package '$package' is NOT installed"
147 packages_to_install="$packages_to_install $package"
148 fi
149 done
150
151 if [[ -z $packages_to_install ]]; then
152 echo "All required packages are already installed. Skipping .."
153 else
154 echo "packages_to_install:" "${packages_to_install[@]}"
155 opts=
156 if [ "${NON_INTERACTIVE}" -eq 1 ]; then
157 echo >&2 "Running in non-interactive mode"
158 opts="-y"
159 fi
160 # shellcheck disable=SC2068
161 dnf install ${opts} ${packages_to_install[@]}
162 fi