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