pkg-test.sh 3.0 KB

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