pkg-test.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #!/bin/sh
  2. SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)"
  3. install_debian_like() {
  4. # This is needed to ensure package installs don't prompt for any user input.
  5. export DEBIAN_FRONTEND=noninteractive
  6. if apt-cache show netcat 2>&1 | grep -q "No packages found"; then
  7. netcat="netcat-traditional"
  8. else
  9. netcat="netcat"
  10. fi
  11. apt-get update
  12. # Install Netdata
  13. # Strange quoting is required here so that glob matching works.
  14. # shellcheck disable=SC2046
  15. apt-get install -y $(find /netdata/artifacts -type f -name 'netdata*.deb' \
  16. ! -name '*dbgsym*' ! -name '*cups*' ! -name '*freeipmi*') || exit 3
  17. # Install testing tools
  18. apt-get install -y --no-install-recommends curl dpkg-dev "${netcat}" jq || exit 1
  19. dpkg-architecture --equal amd64 || NETDATA_SKIP_EBPF=1
  20. }
  21. install_fedora_like() {
  22. # Using a glob pattern here because I can't reliably determine what the
  23. # resulting package name will be (TODO: There must be a better way!)
  24. PKGMGR="$( (command -v dnf > /dev/null && echo "dnf") || echo "yum")"
  25. if [ "${PKGMGR}" = "dnf" ]; then
  26. opts="--allowerasing"
  27. fi
  28. # Install Netdata
  29. # Strange quoting is required here so that glob matching works.
  30. "${PKGMGR}" install -y /netdata/artifacts/netdata*.rpm || exit 1
  31. # Install testing tools
  32. "${PKGMGR}" install -y curl nc jq || exit 1
  33. [ "$(rpm --eval '%{_build_arch}')" = "x86_64" ] || NETDATA_SKIP_EBPF=1
  34. }
  35. install_centos() {
  36. # Using a glob pattern here because I can't reliably determine what the
  37. # resulting package name will be (TODO: There must be a better way!)
  38. PKGMGR="$( (command -v dnf > /dev/null && echo "dnf") || echo "yum")"
  39. if [ "${PKGMGR}" = "dnf" ]; then
  40. opts="--allowerasing"
  41. fi
  42. # Install EPEL (needed for `jq`
  43. "${PKGMGR}" install -y epel-release || exit 1
  44. # Install Netdata
  45. # Strange quoting is required here so that glob matching works.
  46. "${PKGMGR}" install -y /netdata/artifacts/netdata*.rpm || exit 1
  47. # Install testing tools
  48. # shellcheck disable=SC2086
  49. "${PKGMGR}" install -y ${opts} curl nc jq || exit 1
  50. [ "$(rpm --eval '%{_build_arch}')" = "x86_64" ] || NETDATA_SKIP_EBPF=1
  51. }
  52. install_amazon_linux() {
  53. PKGMGR="$( (command -v dnf > /dev/null && echo "dnf") || echo "yum")"
  54. if [ "${PKGMGR}" = "dnf" ]; then
  55. opts="--allowerasing"
  56. fi
  57. # Install Netdata
  58. # Strange quoting is required here so that glob matching works.
  59. "${PKGMGR}" install -y /netdata/artifacts/netdata*.rpm || exit 1
  60. # Install testing tools
  61. # shellcheck disable=SC2086
  62. "${PKGMGR}" install -y ${opts} curl nc jq || exit 1
  63. [ "$(rpm --eval '%{_build_arch}')" = "x86_64" ] || NETDATA_SKIP_EBPF=1
  64. }
  65. install_suse_like() {
  66. # Using a glob pattern here because I can't reliably determine what the
  67. # resulting package name will be (TODO: There must be a better way!)
  68. # Install Netdata
  69. # Strange quoting is required here so that glob matching works.
  70. zypper install -y --allow-downgrade --allow-unsigned-rpm /netdata/artifacts/netdata*.rpm || exit 1
  71. # Install testing tools
  72. zypper install -y --allow-downgrade --no-recommends curl netcat-openbsd jq || exit 1
  73. [ "$(rpm --eval '%{_build_arch}')" = "x86_64" ] || NETDATA_SKIP_EBPF=1
  74. }
  75. dump_log() {
  76. cat ./netdata.log
  77. }
  78. case "${DISTRO}" in
  79. debian | ubuntu)
  80. install_debian_like
  81. ;;
  82. fedora | oraclelinux)
  83. install_fedora_like
  84. ;;
  85. centos | centos-stream | rockylinux | almalinux)
  86. install_centos
  87. ;;
  88. amazonlinux)
  89. install_amazon_linux
  90. ;;
  91. opensuse)
  92. install_suse_like
  93. ;;
  94. *)
  95. printf "ERROR: unsupported distro: %s_%s\n" "${DISTRO}" "${DISTRO_VERSION}"
  96. exit 1
  97. ;;
  98. esac
  99. trap dump_log EXIT
  100. export NETDATA_LIBEXEC_PREFIX=/usr/libexec/netdata
  101. export NETDATA_SKIP_LIBEXEC_PARTS="freeipmi|xenstat|nfacct|cups"
  102. if [ -n "${NETDATA_SKIP_EBPF}" ]; then
  103. export NETDATA_SKIP_LIBEXEC_PARTS="${NETDATA_SKIP_LIBEXEC_PARTS}|ebpf"
  104. fi
  105. /usr/sbin/netdata -D > ./netdata.log 2>&1 &
  106. "${SCRIPT_DIR}/../../packaging/runtime-check.sh" || exit 1
  107. trap - EXIT