rockylinux.sh 3.4 KB

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