ol.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #!/usr/bin/env bash
  2. # Package tree used for installing netdata on distribution:
  3. # << Oracle Linux: [8, 9] >>
  4. set -e
  5. NON_INTERACTIVE=0
  6. DONT_WAIT=0
  7. declare -a package_tree=(
  8. cmake
  9. curl
  10. elfutils-libelf-devel
  11. gcc
  12. gcc-c++
  13. git
  14. gzip
  15. json-c-devel
  16. libatomic
  17. libmnl-devel
  18. libuuid-devel
  19. libuv-devel
  20. libyaml-devel
  21. lz4-devel
  22. make
  23. openssl-devel
  24. pkgconfig
  25. python3
  26. systemd-devel
  27. tar
  28. zlib-devel
  29. )
  30. prompt() {
  31. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  32. echo >&2 "Running in non-interactive mode, assuming yes (y)"
  33. echo >&2 " > Would have prompted for ${1} ..."
  34. return 0
  35. fi
  36. while true; do
  37. read -r -p "${1} [y/n] " yn
  38. case $yn in
  39. [Yy]*) return 0 ;;
  40. [Nn]*) return 1 ;;
  41. *) echo >&2 "Please answer with yes (y) or no (n)." ;;
  42. esac
  43. done
  44. }
  45. usage() {
  46. cat << EOF
  47. OPTIONS:
  48. [--dont-wait] [--non-interactive] [ ]
  49. EOF
  50. }
  51. check_flags() {
  52. while [ -n "${1}" ]; do
  53. case "${1}" in
  54. dont-wait | --dont-wait | -n)
  55. DONT_WAIT=1
  56. ;;
  57. non-interactive | --non-interactive | -y)
  58. NON_INTERACTIVE=1
  59. ;;
  60. help | -h | --help)
  61. usage
  62. exit 1
  63. ;;
  64. *)
  65. echo >&2 "ERROR: Cannot understand option '${1}'"
  66. echo >&2
  67. usage
  68. exit 1
  69. ;;
  70. esac
  71. shift
  72. done
  73. if [ "${DONT_WAIT}" -eq 0 ] && [ "${NON_INTERACTIVE}" -eq 0 ]; then
  74. read -r -p "Press ENTER to run it > " || exit 1
  75. fi
  76. }
  77. validate_tree_ol() {
  78. opts=
  79. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  80. echo >&2 "Running in non-interactive mode"
  81. opts="-y"
  82. fi
  83. # shellcheck disable=SC1091
  84. source /etc/os-release
  85. # shellcheck disable=SC2153
  86. version="$(echo "${VERSION}" | cut -f 1 -d '.')"
  87. echo >&2 " > Checking for config-manager ..."
  88. if ! dnf config-manager &> /dev/null; then
  89. if prompt "config-manager not found, shall I install it?"; then
  90. dnf ${opts} install 'dnf-command(config-manager)'
  91. fi
  92. fi
  93. echo " > Checking for CodeReady Builder ..."
  94. if [[ "${version}" =~ ^8(\..*)?$ ]]; then
  95. if ! dnf repolist enabled | grep ol8_codeready_builder; then
  96. if prompt "CodeReadyBuilder not found, shall I install it?"; then
  97. dnf ${opts} config-manager --set-enabled ol8_codeready_builder || enable_repo
  98. fi
  99. fi
  100. elif [[ "${version}" =~ ^9(\..*)?$ ]]; then
  101. if ! dnf repolist enabled | grep ol9_codeready_builder; then
  102. if prompt "CodeReadyBuilder not found, shall I install it?"; then
  103. dnf ${opts} config-manager --set-enabled ol9_codeready_builder || enable_repo
  104. fi
  105. fi
  106. fi
  107. dnf makecache --refresh
  108. }
  109. # shellcheck disable=SC2068
  110. check_flags ${@}
  111. validate_tree_ol
  112. packages_to_install=
  113. # shellcheck disable=SC2068
  114. for package in ${package_tree[@]}; do
  115. if rpm -q "$package" &> /dev/null; then
  116. echo "Package '${package}' is installed"
  117. else
  118. echo "Package '$package' is NOT installed"
  119. packages_to_install="$packages_to_install $package"
  120. fi
  121. done
  122. if [[ -z $packages_to_install ]]; then
  123. echo "All required packages are already installed. Skipping .."
  124. else
  125. opts=
  126. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  127. echo >&2 "Running in non-interactive mode"
  128. opts="-y"
  129. fi
  130. echo "packages_to_install:" "${packages_to_install[@]}"
  131. # shellcheck disable=SC2068
  132. dnf install ${opts} ${packages_to_install[@]}
  133. fi