ci/buildroot/install-buildroot.sh
#!/bin/bash
set -euo pipefail

# This is invoked by Dockerfile

dnf -y install dnf-plugins-core
# We want to avoid a 7 day cycle for e.g. new ostree etc.
dnf config-manager setopt updates-testing.enabled=1

dn=$(dirname "$0")
tmpd=$(mktemp -d) && trap 'rm -rf ${tmpd}' EXIT

arch=$(arch)

echo "Installing base build requirements"
dnf -y install /usr/bin/xargs 'dnf-command(builddep)'
deps=$(grep -v '^#' "${dn}"/buildroot-reqs.txt)
if [ -f "${dn}/buildroot-reqs-${arch}.txt" ]; then
  deps+=" "
  deps+=$(grep -v '^#' "${dn}/buildroot-reqs-${arch}.txt")
fi
echo "${deps}" | xargs dnf -y install

echo "Installing build dependencies of primary packages"
brs=$(grep -v '^#' "${dn}"/buildroot-buildreqs.txt)
(cd "${tmpd}" && mkdir rpmbuild
 echo "${brs}" | xargs dnf download --source
 # rebuild the SRPM for this arch; see
 # https://bugzilla.redhat.com/show_bug.cgi?id=1402784#c6
 # Add workaround if on F42 for https://github.com/coreos/fedora-coreos-tracker/issues/1901
 source /etc/os-release
 workaround=""
 if [ "${VERSION_ID}" == "42" ]; then
    workaround="--noclean"
 fi
 find . -name '*.src.rpm' -print0 | xargs -0n 1 rpmbuild -rs --nodeps \
    -D "%_topdir $PWD/rpmbuild" -D "%_tmppath %{_topdir}/tmp" ${workaround}
 dnf builddep -y rpmbuild/SRPMS/*.src.rpm)
rm -rf "${tmpd:?}"/*

echo "Installing build dependencies from canonical spec files"
specs=$(grep -v '^#' "${dn}"/buildroot-specs.txt)
(cd "${tmpd}" && echo "${specs}" | xargs curl -L --remote-name-all)
(cd "${tmpd}" && find . -type f -print0 | xargs -0 dnf -y builddep)
rm -rf "${tmpd:?}"/*

echo "Installing test dependencies from canonical upstream files"
testdep_urls=$(grep -v '^#' "${dn}"/testdeps.txt)
(cd "${tmpd}" && echo "${testdep_urls}" | xargs curl -L --remote-name-all)
grep -hrv '^#' "${tmpd}" | xargs dnf -y install
rm -rf "${tmpd:?}"/*

echo 'Done!'
