pkg-test.sh 2.9 KB

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