coverity-scan.sh 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env bash
  2. # shellcheck disable=SC2235
  3. # To run this script you need to provide API token. This can be done either by:
  4. # - Putting token in ".coverity-token" file
  5. # - Assigning token value to COVERITY_SCAN_TOKEN environment variable
  6. # Additionally script can install coverity tool on your computer. To do this just set environment variable INSTALL_COVERITY to "true"
  7. cpus=$(grep -c ^processor </proc/cpuinfo)
  8. [ -z "${cpus}" ] && cpus=1
  9. token="${COVERITY_SCAN_TOKEN}"
  10. ([ -z "${token}" ] && [ -f .coverity-token ]) && token="$(<.coverity-token)"
  11. if [ -z "${token}" ]; then
  12. echo >&2 "Save the coverity token to .coverity-token or export it as COVERITY_SCAN_TOKEN."
  13. exit 1
  14. fi
  15. # shellcheck disable=SC2230
  16. covbuild="$(which cov-build 2>/dev/null || command -v cov-build 2>/dev/null)"
  17. ([ -z "${covbuild}" ] && [ -f .coverity-build ]) && covbuild="$(<.coverity-build)"
  18. if [ -z "${covbuild}" ]; then
  19. echo "Cannot find 'cov-build' binary in \$PATH."
  20. if [ "${INSTALL_COVERITY}" != "" ]; then
  21. echo "Installing coverity..."
  22. mkdir /tmp/coverity
  23. curl -SL --data "token=${token}&project=netdata%2Fnetdata" https://scan.coverity.com/download/linux64 > /tmp/coverity_tool.tar.gz
  24. tar -x -C /tmp/coverity/ -f /tmp/coverity_tool.tar.gz
  25. sudo mv /tmp/coverity/cov-analysis-linux64-2017.07 /opt/coverity
  26. export PATH=${PATH}:/opt/coverity/bin/
  27. # shellcheck disable=SC2230
  28. covbuild="$(which cov-build 2>/dev/null || command -v cov-build 2>/dev/null)"
  29. else
  30. echo "Save command the full filename of cov-build in .coverity-build"
  31. exit 1
  32. fi
  33. fi
  34. if [ ! -x "${covbuild}" ]; then
  35. echo "The command ${covbuild} is not executable. Save command the full filename of cov-build in .coverity-build"
  36. exit 1
  37. fi
  38. version="$(grep "^#define PACKAGE_VERSION" config.h | cut -d '"' -f 2)"
  39. echo >&2 "Working on netdata version: ${version}"
  40. echo >&2 "Cleaning up old builds..."
  41. make clean || echo "Nothing to clean"
  42. [ -d "cov-int" ] && rm -rf "cov-int"
  43. [ -f netdata-coverity-analysis.tgz ] && rm netdata-coverity-analysis.tgz
  44. autoreconf -ivf
  45. ./configure --enable-plugin-nfacct --enable-plugin-freeipmi
  46. "${covbuild}" --dir cov-int make -j${cpus} || exit 1
  47. echo >&2 "Compressing data..."
  48. tar czvf netdata-coverity-analysis.tgz cov-int || exit 1
  49. echo >&2 "Sending analysis for version ${version} ..."
  50. curl --progress-bar --form token="${token}" \
  51. --form email=costa@tsaousis.gr \
  52. --form file=@netdata-coverity-analysis.tgz \
  53. --form version="${version}" \
  54. --form description="netdata, real-time performance monitoring, done right." \
  55. https://scan.coverity.com/builds?project=netdata%2Fnetdata