freebsd.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #!/usr/bin/env bash
  2. # Package tree used for installing netdata on distribution:
  3. # << FreeBSD >>
  4. set -e
  5. NON_INTERACTIVE=0
  6. DONT_WAIT=0
  7. package_tree="
  8. cmake
  9. curl
  10. e2fsprogs-libuuid
  11. git
  12. gzip
  13. json-c
  14. liblz4
  15. libuv
  16. libyaml
  17. lzlib
  18. openssl
  19. pkgconf
  20. python3
  21. "
  22. prompt() {
  23. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  24. echo >&2 "Running in non-interactive mode, assuming yes (y)"
  25. echo >&2 " > Would have prompted for ${1} ..."
  26. return 0
  27. fi
  28. while true; do
  29. read -r -p "${1} [y/n] " yn
  30. case $yn in
  31. [Yy]*) return 0 ;;
  32. [Nn]*) return 1 ;;
  33. *) echo >&2 "Please answer with yes (y) or no (n)." ;;
  34. esac
  35. done
  36. }
  37. usage() {
  38. cat << EOF
  39. OPTIONS:
  40. [--dont-wait] [--non-interactive] [ ]
  41. EOF
  42. }
  43. check_flags() {
  44. while [ -n "${1}" ]; do
  45. case "${1}" in
  46. dont-wait | --dont-wait | -n)
  47. DONT_WAIT=1
  48. ;;
  49. non-interactive | --non-interactive | -y)
  50. NON_INTERACTIVE=1
  51. ;;
  52. help | -h | --help)
  53. usage
  54. exit 1
  55. ;;
  56. *)
  57. echo >&2 "ERROR: Cannot understand option '${1}'"
  58. echo >&2
  59. usage
  60. exit 1
  61. ;;
  62. esac
  63. shift
  64. done
  65. if [ "${DONT_WAIT}" -eq 0 ] && [ "${NON_INTERACTIVE}" -eq 0 ]; then
  66. read -r -p "Press ENTER to run it > " || exit 1
  67. fi
  68. }
  69. validate_tree_freebsd() {
  70. opts=
  71. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  72. echo >&2 "Running in non-interactive mode"
  73. opts="-y"
  74. fi
  75. echo >&2 " > Checking for gmake ..."
  76. if ! pkg query %n-%v | grep -q gmake; then
  77. if prompt "gmake is required to build on FreeBSD and is not installed. Shall I install it?"; then
  78. pkg install ${opts} gmake
  79. fi
  80. fi
  81. }
  82. enable_repo () {
  83. if ! dnf repolist | grep -q codeready; then
  84. cat >> /etc/yum.repos.d/oracle-linux-ol8.repo <<-EOF
  85. [ol8_codeready_builder]
  86. name=Oracle Linux \$releasever CodeReady Builder (\$basearch)
  87. baseurl=http://yum.oracle.com/repo/OracleLinux/OL8/codeready/builder/\$basearch
  88. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
  89. gpgcheck=1
  90. enabled=1
  91. EOF
  92. else
  93. echo "Something went wrong!"
  94. exit 1
  95. fi
  96. }
  97. # shellcheck disable=SC2068
  98. check_flags ${@}
  99. validate_tree_freebsd
  100. packages_to_install=
  101. for package in $package_tree; do
  102. if pkg info -Ix "$package" &> /dev/null; then
  103. echo "Package '${package}' is installed"
  104. else
  105. echo "Package '${package}' is NOT installed"
  106. packages_to_install="$packages_to_install $package"
  107. fi
  108. done
  109. if [[ -z "$packages_to_install" ]]; then
  110. echo "All required packages are already installed. Skipping .."
  111. else
  112. echo "packages_to_install:" "$packages_to_install"
  113. opts=
  114. if [ "${NON_INTERACTIVE}" -eq 1 ]; then
  115. echo >&2 "Running in non-interactive mode"
  116. opts="-y"
  117. fi
  118. # shellcheck disable=SC2086
  119. pkg install ${opts} $packages_to_install
  120. fi