rockylinux.sh 3.4 KB

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