arch.sh 1.7 KB

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