arch.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/usr/bin/env bash
  2. # Package tree used for installing netdata on distribution:
  3. # << ArchLinux: [base] [base-devel] >> | << Manjaro >>
  4. set -e
  5. NON_INTERACTIVE=0
  6. DONT_WAIT=0
  7. declare -a package_tree=(
  8. gcc
  9. make
  10. autoconf
  11. autoconf-archive
  12. autogen
  13. automake
  14. libtool
  15. cmake
  16. zlib
  17. util-linux
  18. libmnl
  19. json-c
  20. libuv
  21. lz4
  22. openssl
  23. libelf
  24. git
  25. pkgconfig
  26. tar
  27. curl
  28. gzip
  29. python3
  30. binutils
  31. )
  32. usage() {
  33. cat << EOF
  34. OPTIONS:
  35. [--dont-wait] [--non-interactive] [ ]
  36. EOF
  37. }
  38. check_flags() {
  39. while [ -n "${1}" ]; do
  40. case "${1}" in
  41. dont-wait | --dont-wait | -n)
  42. DONT_WAIT=1
  43. ;;
  44. non-interactive | --non-interactive | -y)
  45. NON_INTERACTIVE=1
  46. ;;
  47. help | -h | --help)
  48. usage
  49. exit 1
  50. ;;
  51. *)
  52. echo >&2 "ERROR: Cannot understand option '${1}'"
  53. echo >&2
  54. usage
  55. exit 1
  56. ;;
  57. esac
  58. shift
  59. done
  60. if [ "${DONT_WAIT}" -eq 0 ] && [ "${NON_INTERACTIVE}" -eq 0 ]; then
  61. read -r -p "Press ENTER to run it > " || exit 1
  62. fi
  63. }
  64. # shellcheck disable=SC2068
  65. check_flags ${@}
  66. packages_to_install=
  67. # shellcheck disable=SC2068
  68. for package in ${package_tree[@]}; do
  69. if pacman -Qn "$package" &> /dev/null; then
  70. echo "Package '${package}' is installed"
  71. else
  72. echo "Package '$package' is NOT installed"
  73. packages_to_install="$packages_to_install $package"
  74. fi
  75. done
  76. if [[ -z $packages_to_install ]]; then
  77. echo "All required packages are already installed. Skipping .."
  78. else
  79. echo "packages_to_install: " "${packages_to_install[@]}"
  80. opts=
  81. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  82. echo >&2 "Running in non-interactive mode"
  83. opts="--noconfirm"
  84. fi
  85. # shellcheck disable=SC2068
  86. pacman -Sy ${opts} ${packages_to_install[@]}
  87. fi