| 1 | #!/usr/bin/env bash |
| 2 | # Package tree used for installing netdata on distribution: |
| 3 | # << opeSUSE >> |
| 4 | # supported versions: leap/15.3 and tumbleweed |
| 5 | # it may work with SLES as well, although we have not tested with it |
| 6 | |
| 7 | set -e |
| 8 | |
| 9 | NON_INTERACTIVE=0 |
| 10 | DONT_WAIT=0 |
| 11 | |
| 12 | declare -a package_tree=( |
| 13 | bison |
| 14 | cmake |
| 15 | curl |
| 16 | flex |
| 17 | gcc |
| 18 | gcc-c++ |
| 19 | git |
| 20 | gzip |
| 21 | libatomic1 |
| 22 | libelf-devel |
| 23 | libjson-c-devel |
| 24 | liblz4-devel |
| 25 | libmnl-devel |
| 26 | libopenssl-devel |
| 27 | libuuid-devel |
| 28 | libuv-devel |
| 29 | libyaml-devel |
| 30 | make |
| 31 | pkg-config |
| 32 | python3 |
| 33 | systemd-devel |
| 34 | tar |
| 35 | zlib-devel |
| 36 | ) |
| 37 | |
| 38 | usage() { |
| 39 | cat << EOF |
| 40 | OPTIONS: |
| 41 | [--dont-wait] [--non-interactive] [ ] |
| 42 | EOF |
| 43 | } |
| 44 | |
| 45 | check_flags() { |
| 46 | while [ -n "${1}" ]; do |
| 47 | case "${1}" in |
| 48 | dont-wait | --dont-wait | -n) |
| 49 | DONT_WAIT=1 |
| 50 | ;; |
| 51 | |
| 52 | non-interactive | --non-interactive | -y) |
| 53 | NON_INTERACTIVE=1 |
| 54 | ;; |
| 55 | |
| 56 | help | -h | --help) |
| 57 | usage |
| 58 | exit 1 |
| 59 | ;; |
| 60 | *) |
| 61 | echo >&2 "ERROR: Cannot understand option '${1}'" |
| 62 | echo >&2 |
| 63 | usage |
| 64 | exit 1 |
| 65 | ;; |
| 66 | esac |
| 67 | shift |
| 68 | done |
| 69 | |
| 70 | if [ "${DONT_WAIT}" -eq 0 ] && [ "${NON_INTERACTIVE}" -eq 0 ]; then |
| 71 | read -r -p "Press ENTER to run it > " || exit 1 |
| 72 | fi |
| 73 | } |
| 74 | |
| 75 | # shellcheck disable=SC2068 |
| 76 | check_flags ${@} |
| 77 | |
| 78 | packages_to_install= |
| 79 | |
| 80 | # shellcheck disable=SC2068 |
| 81 | for package in ${package_tree[@]}; do |
| 82 | if zypper search -i "$package" &> /dev/null; then |
| 83 | echo "Package '${package}' is installed" |
| 84 | else |
| 85 | echo "Package '$package' is NOT installed" |
| 86 | packages_to_install="$packages_to_install $package" |
| 87 | fi |
| 88 | done |
| 89 | |
| 90 | if [[ -z $packages_to_install ]]; then |
| 91 | echo "All required packages are already installed. Skipping .." |
| 92 | else |
| 93 | echo "packages_to_install:" "${packages_to_install[@]}" |
| 94 | opts="--ignore-unknown" |
| 95 | if [ "${NON_INTERACTIVE}" -eq 1 ]; then |
| 96 | echo >&2 "Running in non-interactive mode" |
| 97 | opts="--non-interactive" |
| 98 | fi |
| 99 | # shellcheck disable=SC2068 |
| 100 | zypper ${opts} install ${packages_to_install[@]} |
| 101 | fi |