pkg-test.sh 3.9 KB

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