rockylinux.sh 3.4 KB

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