2024-06-12 08:44:04 -04:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
## SPDX-FileCopyrightText: 2024 Benjamin Grande M. S. <ben.grande.b@gmail.com>
|
|
|
|
##
|
|
|
|
## SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
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-13 07:14:41 -04:00
|
|
|
|
2024-06-12 08:44:04 -04:00
|
|
|
template=".qubesbuilder.template"
|
|
|
|
target=".qubesbuilder"
|
|
|
|
intended_target="${target}"
|
|
|
|
if test "${1-}" = "test"; then
|
|
|
|
tmpdir="$(mktemp -d)"
|
|
|
|
target="${tmpdir}/.qubesbuilder"
|
2024-07-06 16:25:54 -04:00
|
|
|
# shellcheck disable=SC2154
|
2024-07-10 08:36:05 -04:00
|
|
|
trap 'ec="$?"; rm -rf -- "${tmpdir}"; exit "${ec}"' EXIT INT HUP QUIT ABRT
|
2024-06-12 08:44:04 -04:00
|
|
|
fi
|
2024-06-21 11:00:06 -04:00
|
|
|
ignored="$(git ls-files --exclude-standard --others --ignored salt/)"
|
|
|
|
untracked="$(git ls-files --exclude-standard --others salt/)"
|
2024-08-06 11:04:16 -04:00
|
|
|
unwanted="$(printf '%s\n%s\n' "${ignored}" "${untracked}" |
|
|
|
|
grep -e "^salt/\S\+/README.md" | cut -d "/" -f2 | sort -u)"
|
2024-06-12 08:44:04 -04:00
|
|
|
group="$(./scripts/spec-get.sh dom0 group)"
|
2024-07-09 11:42:07 -04:00
|
|
|
projects="$(find salt/ -mindepth 1 -maxdepth 1 -type d | sort -d |
|
2024-08-06 11:04:16 -04:00
|
|
|
sed -e "s|^salt/\(\S\+\)| - rpm_spec/${group}-\1.spec|")"
|
2024-06-12 08:44:04 -04:00
|
|
|
for unwanted_project in ${unwanted}; do
|
2024-08-06 12:15:24 -04:00
|
|
|
projects="$(printf '%s\n' "${projects}" |
|
2024-08-06 11:04:16 -04:00
|
|
|
sed -e "\@rpm_spec/${group}-${unwanted_project}.spec@d")"
|
2024-06-12 08:44:04 -04:00
|
|
|
done
|
|
|
|
|
2024-06-13 07:14:41 -04:00
|
|
|
if test "${1-}" = "print"; then
|
2024-08-06 12:15:24 -04:00
|
|
|
printf '%s\n' "${projects}"
|
2024-06-13 07:14:41 -04:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2024-08-06 11:04:16 -04:00
|
|
|
sed -e "/@SPEC@/d" -- "${template}" | tee -- "${target}" >/dev/null
|
2024-08-06 12:15:24 -04:00
|
|
|
printf '%s\n' "${projects}" | tee -a -- "${target}" >/dev/null
|
2024-06-12 08:44:04 -04:00
|
|
|
if test "${1-}" = "test"; then
|
2024-08-06 11:04:16 -04:00
|
|
|
if ! cmp -s -- "${target}" "${intended_target}"; then
|
2024-08-06 12:15:24 -04:00
|
|
|
err_msg="${0##*/}: error: File ${intended_target} is not up to date"
|
|
|
|
printf '%s\n' "${err_msg}" >&2
|
|
|
|
err_msg="${0##*/}: error: Update the builder file with: ${0##/*}"
|
|
|
|
printf '%s\n' "${err_msg}" >&2
|
2024-06-12 08:44:04 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|