pkg-test.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #!/bin/sh
  2. install_debian_like() {
  3. # This is needed to ensure package installs don't prompt for any user input.
  4. export DEBIAN_FRONTEND=noninteractive
  5. if apt-cache show netcat 2>&1 | grep -q "No packages found"; then
  6. netcat="netcat-traditional"
  7. else
  8. netcat="netcat"
  9. fi
  10. apt-get update
  11. # Install Netdata
  12. apt-get install -y /netdata/artifacts/netdata_"${VERSION}"*_*.deb || exit 1
  13. # Install testing tools
  14. apt-get install -y --no-install-recommends curl "${netcat}" jq || exit 1
  15. }
  16. install_fedora_like() {
  17. # Using a glob pattern here because I can't reliably determine what the
  18. # resulting package name will be (TODO: There must be a better way!)
  19. PKGMGR="$( (command -v dnf > /dev/null && echo "dnf") || echo "yum")"
  20. pkg_version="$(echo "${VERSION}" | tr - .)"
  21. # Install Netdata
  22. "$PKGMGR" install -y /netdata/artifacts/netdata-"${pkg_version}"-*.rpm
  23. # Install testing tools
  24. "$PKGMGR" install -y curl nc jq || exit 1
  25. }
  26. install_centos() {
  27. # Using a glob pattern here because I can't reliably determine what the
  28. # resulting package name will be (TODO: There must be a better way!)
  29. PKGMGR="$( (command -v dnf > /dev/null && echo "dnf") || echo "yum")"
  30. pkg_version="$(echo "${VERSION}" | tr - .)"
  31. if [ "${PKGMGR}" = "dnf" ]; then
  32. opts="--allowerasing"
  33. fi
  34. # Install EPEL (needed for `jq`
  35. "$PKGMGR" install -y epel-release || exit 1
  36. # Install Netdata
  37. "$PKGMGR" install -y /netdata/artifacts/netdata-"${pkg_version}"-*.rpm
  38. # Install testing tools
  39. "$PKGMGR" install -y ${opts} curl nc jq || exit 1
  40. }
  41. install_suse_like() {
  42. # Using a glob pattern here because I can't reliably determine what the
  43. # resulting package name will be (TODO: There must be a better way!)
  44. pkg_version="$(echo "${VERSION}" | tr - .)"
  45. # Install Netdata
  46. zypper install -y --allow-unsigned-rpm /netdata/artifacts/netdata-"${pkg_version}"-*.rpm
  47. # Install testing tools
  48. zypper install -y --no-recommends curl netcat-openbsd jq || exit 1
  49. }
  50. dump_log() {
  51. cat ./netdata.log
  52. }
  53. wait_for() {
  54. host="${1}"
  55. port="${2}"
  56. name="${3}"
  57. timeout="30"
  58. if command -v nc > /dev/null ; then
  59. netcat="nc"
  60. elif command -v netcat > /dev/null ; then
  61. netcat="netcat"
  62. else
  63. printf "Unable to find a usable netcat command.\n"
  64. return 1
  65. fi
  66. printf "Waiting for %s on %s:%s ... " "${name}" "${host}" "${port}"
  67. sleep 30
  68. i=0
  69. while ! ${netcat} -z "${host}" "${port}"; do
  70. sleep 1
  71. if [ "$i" -gt "$timeout" ]; then
  72. printf "Timed out!\n"
  73. return 1
  74. fi
  75. i="$((i + 1))"
  76. done
  77. printf "OK\n"
  78. }
  79. case "${DISTRO}" in
  80. debian | ubuntu)
  81. install_debian_like
  82. ;;
  83. fedora | oraclelinux)
  84. install_fedora_like
  85. ;;
  86. centos | rockylinux | almalinux)
  87. install_centos
  88. ;;
  89. opensuse)
  90. install_suse_like
  91. ;;
  92. *)
  93. printf "ERROR: unsupported distro: %s_%s\n" "${DISTRO}" "${DISTRO_VERSION}"
  94. exit 1
  95. ;;
  96. esac
  97. trap dump_log EXIT
  98. /usr/sbin/netdata -D > ./netdata.log 2>&1 &
  99. wait_for localhost 19999 netdata || exit 1
  100. curl -sS http://127.0.0.1:19999/api/v1/info > ./response || exit 1
  101. cat ./response
  102. jq '.version' ./response || exit 1
  103. trap - EXIT