build-deb.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/sh
  2. set -e
  3. SRC_DIR="$(CDPATH='' cd -- "$(dirname -- "${0}")" && pwd -P)"
  4. BUILD_DIR=/build
  5. DISTRO="$(awk -F'=' '/^ID=/ {print $2}' /etc/os-release)"
  6. DISTRO_VERSION="$(awk -F'"' '/VERSION_ID=/ {print $2}' /etc/os-release)"
  7. # Needed because dpkg is stupid and tries to configure things interactively if it sees a terminal.
  8. export DEBIAN_FRONTEND=noninteractive
  9. echo "::group::Installing Build Dependencies"
  10. apt update
  11. apt upgrade -y
  12. apt install -y --no-install-recommends ca-certificates cmake ninja-build curl gnupg
  13. echo "::endgroup::"
  14. echo "::group::Building Packages"
  15. cmake -S "${SRC_DIR}" -B "${BUILD_DIR}" -G Ninja
  16. cmake --build "${BUILD_DIR}"
  17. cd "${BUILD_DIR}"
  18. cpack -G DEB
  19. echo "::endgroup::"
  20. [ -d "${SRC_DIR}/artifacts" ] || mkdir -p "${SRC_DIR}/artifacts"
  21. # Embed distro info in package name.
  22. # This is required to make the repo actually standards compliant wthout packagecloud's hacks.
  23. distid="${DISTRO}${DISTRO_VERSION}"
  24. for pkg in "${BUILD_DIR}"/packages/*.deb; do
  25. extension="${pkg##*.}"
  26. pkgname="$(basename "${pkg}" "${extension}")"
  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="${SRC_DIR}/artifacts/${name}_${version}+${distid}_${arch}${extension}"
  31. mv "${pkg}" "${newname}"
  32. done
  33. # Correct ownership of the artifacts.
  34. # Without this, the artifacts directory and it's contents end up owned
  35. # by root instead of the local user on Linux boxes
  36. chown -R --reference="${SRC_DIR}" "${SRC_DIR}/artifacts"