build-deb.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/sh
  2. # Extract distro info from /etc/os-release
  3. DISTVERS="$(awk -F'"' '/VERSION_ID=/ {print $2}' /etc/os-release)"
  4. DISTNAME="$(awk -F'=' '/^ID=/ {print $2}' /etc/os-release)"
  5. # Needed because dpkg is stupid and tries to configure things interactively if it sees a terminal.
  6. export DEBIAN_FRONTEND=noninteractive
  7. # Pull in our dependencies
  8. apt update || exit 1
  9. apt upgrade -y || exit 1
  10. apt install -y build-essential debhelper curl gnupg || exit 1
  11. # Run the builds in an isolated source directory.
  12. # This removes the need for cleanup, and ensures anything the build does
  13. # doesn't muck with the user's sources.
  14. cp -a /netdata/packaging/repoconfig /usr/src || exit 1
  15. cd /usr/src/repoconfig || exit 1
  16. # pre/post options are after 1.18.8, is simpler to just check help for their existence than parsing version
  17. if dpkg-buildpackage --help | grep "\-\-post\-clean" 2> /dev/null > /dev/null; then
  18. dpkg-buildpackage --post-clean --pre-clean -b -us -uc || exit 1
  19. else
  20. dpkg-buildpackage -b -us -uc || exit 1
  21. fi
  22. # Embed distro info in package name.
  23. # This is required to make the repo actually standards compliant wthout packageclouds hacks.
  24. distid="${DISTNAME}${DISTVERS}"
  25. for pkg in /usr/src/*.deb; do
  26. pkgname="$(basename "${pkg}" .deb)"
  27. name="$(echo "${pkgname}" | cut -f 1 -d '_')"
  28. version="$(echo "${pkgname}" | cut -f 2 -d '_')"
  29. arch="$(echo "${pkgname}" | cut -f 3 -d '_')"
  30. newname="$(dirname "${pkg}")/${name}_${version}+${distid}_${arch}.deb"
  31. mv "${pkg}" "${newname}"
  32. done
  33. # Copy the built packages to /netdata/artifacts (which may be bind-mounted)
  34. # Also ensure /netdata/artifacts exists and create it if it doesn't
  35. [ -d /netdata/artifacts ] || mkdir -p /netdata/artifacts
  36. cp -a /usr/src/*.deb /netdata/artifacts/ || exit 1
  37. # Correct ownership of the artifacts.
  38. # Without this, the artifacts directory and it's contents end up owned
  39. # by root instead of the local user on Linux boxes
  40. chown -R --reference=/netdata /netdata/artifacts