2023-11-13 09:33:28 -05:00
|
|
|
#!/bin/sh
|
|
|
|
|
2024-06-12 08:44:04 -04:00
|
|
|
## SPDX-FileCopyrightText: 2023 - 2024 Benjamin Grande M. S. <ben.grande.b@gmail.com>
|
2023-11-13 09:33:28 -05:00
|
|
|
##
|
|
|
|
## SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
usage(){
|
2024-08-06 12:15:24 -04:00
|
|
|
printf '%s\n' "Usage: ${0##*/} PROJECT [PROJECT ...]" >&2
|
2023-11-13 09:33:28 -05:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2024-06-12 08:44:04 -04:00
|
|
|
build_rpm(){
|
|
|
|
counter=$((counter+1))
|
|
|
|
project="${1}"
|
|
|
|
group="$(${spec_get} "${project}" group)"
|
|
|
|
version="$(${spec_get} "${project}" version)"
|
|
|
|
spec="rpm_spec/${group}-${project}.spec"
|
2023-11-13 09:33:28 -05:00
|
|
|
|
2024-06-12 08:44:04 -04:00
|
|
|
"${spec_gen}" "${project}"
|
2023-11-13 09:33:28 -05:00
|
|
|
|
2024-06-12 08:44:04 -04:00
|
|
|
## All specs have the same format, only lint the first one.
|
|
|
|
if test "${counter}" = "1"; then
|
|
|
|
rpmlint "${spec}"
|
|
|
|
fi
|
2023-11-13 09:33:28 -05:00
|
|
|
|
2024-08-06 11:04:16 -04:00
|
|
|
if grep -q -e "^BuildRequires: " -- "${spec}"; then
|
2024-06-12 08:44:04 -04:00
|
|
|
sudo dnf build-dep "${spec}"
|
|
|
|
fi
|
2023-11-13 09:33:28 -05:00
|
|
|
|
2024-08-06 11:04:16 -04:00
|
|
|
mkdir -p -- \
|
2024-06-12 08:44:04 -04:00
|
|
|
"${build_dir}/BUILD/${group}-${project}/LICENSES/" \
|
|
|
|
"${build_dir}/SOURCES/${group}-${project}/LICENSES"
|
2023-11-13 09:33:28 -05:00
|
|
|
|
2024-06-24 02:24:48 -04:00
|
|
|
## TODO: generate tarball to sources.
|
2024-08-06 11:04:16 -04:00
|
|
|
cp -r -- . "${build_dir}/BUILD/${group}-${project}/"
|
|
|
|
cp -r -- . "${build_dir}/SOURCES/${group}-${project}/"
|
2024-06-12 08:44:04 -04:00
|
|
|
|
|
|
|
## TODO: use qubes-builderv2 with mock or qubes executor
|
2024-06-13 08:03:16 -04:00
|
|
|
rpmbuild -ba --quiet --clean -- "${spec}"
|
2024-06-12 08:44:04 -04:00
|
|
|
if test -n "${key_id}"; then
|
|
|
|
rpm_basename="${build_dir}/RPMS/noarch/${group}-${project}-${version}-"
|
|
|
|
rpm_suffix=".noarch.rpm"
|
|
|
|
## TODO: target only the latest release
|
|
|
|
rpmsign --key-id="${key_id}" --digest-algo=sha512 --addsign \
|
|
|
|
-- "${rpm_basename}"*"${rpm_suffix}" </dev/null
|
|
|
|
gpg="$(git config --get gpg.program)" || gpg="gpg"
|
|
|
|
dbpath="$(mktemp -d)"
|
|
|
|
trap 'rm -rf -- "${dbpath}"' EXIT INT HUP QUIT ABRT
|
|
|
|
tmp_file="${dbpath}/${key_id}.asc"
|
2024-08-06 11:04:16 -04:00
|
|
|
"${gpg}" --export --armor "${key_id}" | tee -- "${tmp_file}" >/dev/null
|
2024-06-12 08:44:04 -04:00
|
|
|
rpmkeys --dbpath="${dbpath}" --import "${tmp_file}"
|
2024-07-06 16:25:54 -04:00
|
|
|
## TODO: target only the latest release
|
2024-06-14 13:22:43 -04:00
|
|
|
rpmkeys --dbpath="${dbpath}" --checksig --verbose \
|
2024-06-12 08:44:04 -04:00
|
|
|
-- "${rpm_basename}"*"${rpm_suffix}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
case "${1-}" in
|
|
|
|
-h|--?help) usage;;
|
2024-07-10 08:36:05 -04:00
|
|
|
*) ;;
|
2024-06-12 08:44:04 -04:00
|
|
|
esac
|
|
|
|
|
2024-08-06 12:15:24 -04:00
|
|
|
command -v git >/dev/null ||
|
|
|
|
{ printf '%s\n' "Missing program: git" >&2; exit 1; }
|
2024-07-10 08:36:05 -04:00
|
|
|
repo_toplevel="$(git rev-parse --show-toplevel)"
|
|
|
|
test -d "${repo_toplevel}" || exit 1
|
2024-07-19 09:29:17 -04:00
|
|
|
cd "${repo_toplevel}"
|
2024-07-10 08:36:05 -04:00
|
|
|
unset repo_toplevel
|
2024-06-12 08:44:04 -04:00
|
|
|
./scripts/requires-program.sh dnf rpmlint rpmbuild rpmsign
|
|
|
|
build_dir="${HOME}/rpmbuild"
|
2023-11-13 09:33:28 -05:00
|
|
|
|
|
|
|
if command -v rpmdev-setuptree >/dev/null; then
|
|
|
|
rpmdev-setuptree
|
|
|
|
else
|
2024-08-06 11:04:16 -04:00
|
|
|
mkdir -p -- \
|
2024-06-12 08:44:04 -04:00
|
|
|
"${build_dir}/BUILD" "${build_dir}/BUILDROOT" "${build_dir}/RPMS" \
|
|
|
|
"${build_dir}/SOURCES" "${build_dir}/SPECS" "${build_dir}/SRPMS"
|
2023-11-13 09:33:28 -05:00
|
|
|
fi
|
|
|
|
|
2024-06-12 08:44:04 -04:00
|
|
|
key_id="$(git config --get user.signingKey)" || true
|
|
|
|
spec_gen="./scripts/spec-gen.sh"
|
|
|
|
spec_get="./scripts/spec-get.sh"
|
2023-11-13 09:33:28 -05:00
|
|
|
|
2024-06-12 08:44:04 -04:00
|
|
|
if test -z "${1-}"; then
|
2024-07-10 08:36:05 -04:00
|
|
|
# shellcheck disable=SC2046,SC2312
|
2024-06-12 08:44:04 -04:00
|
|
|
set -- $(find salt/ -mindepth 1 -maxdepth 1 -type d -printf '%f\n' \
|
2024-07-08 11:26:34 -04:00
|
|
|
| sort -d | tr "\n" " ")
|
2023-11-13 09:33:28 -05:00
|
|
|
fi
|
2024-06-12 08:44:04 -04:00
|
|
|
counter=0
|
2024-07-10 08:36:05 -04:00
|
|
|
for p in "${@}"; do
|
2024-06-12 08:44:04 -04:00
|
|
|
build_rpm "${p}"
|
|
|
|
done
|