rockylinux.sh 3.4 KB

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