pkg-test.sh 4.0 KB

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