arch.sh 1.7 KB

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