pkg-test.sh 3.8 KB

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