rockylinux.sh 3.4 KB

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