2023-11-13 09:33:28 -05:00
|
|
|
#!/bin/sh
|
|
|
|
|
2024-07-08 05:41:45 -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
|
|
|
|
|
|
|
|
# shellcheck disable=SC2034
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
usage(){
|
2024-06-12 08:44:04 -04:00
|
|
|
names="$(find salt/ -mindepth 1 -maxdepth 1 -type d -printf '%f\n' \
|
2024-07-08 11:26:34 -04:00
|
|
|
| sort -d | tr "\n" " ")"
|
2024-08-06 12:15:24 -04:00
|
|
|
keys_trimmed="$(printf '%s\n' "${keys}" | tr "\n" " ")"
|
|
|
|
printf '%s\n' "Usage: ${0##*/} <NAME> <KEY>"
|
|
|
|
printf '%s\n' "Example: ${0##*/} qubes-builder description"
|
|
|
|
printf '%s\n' "Names: ${names}"
|
|
|
|
printf '%s\n' "Keys: ${keys_trimmed}"
|
2023-11-13 09:33:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
block_max_chars(){
|
|
|
|
char_key="${1}"
|
|
|
|
char_value="${2}"
|
|
|
|
less_than="${3}"
|
|
|
|
if test "${#char_value}" -ge "${less_than}"; then
|
2024-08-06 12:15:24 -04:00
|
|
|
err_msg="Error: ${char_key} is too long. Must be <${less_than} chars."
|
|
|
|
printf '%s\n' "${err_msg}" >&2
|
|
|
|
printf '%s\n' "Key contents: ${char_value}" >&2
|
2023-11-13 09:33:28 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-07-09 11:42:07 -04:00
|
|
|
keys="name
|
|
|
|
branch
|
|
|
|
group
|
|
|
|
file_roots
|
|
|
|
requires
|
|
|
|
packager
|
|
|
|
vendor
|
|
|
|
url
|
|
|
|
bug_url
|
|
|
|
version
|
|
|
|
project
|
|
|
|
project_dir
|
|
|
|
changelog
|
|
|
|
readme
|
|
|
|
license_csv
|
|
|
|
license
|
|
|
|
description
|
|
|
|
summary
|
|
|
|
saltfiles"
|
2023-11-13 09:33:28 -05:00
|
|
|
|
2024-06-12 08:44:04 -04:00
|
|
|
name=""
|
|
|
|
key=""
|
2023-11-13 09:33:28 -05:00
|
|
|
case "${1-}" in
|
|
|
|
"") usage; exit 1;;
|
|
|
|
-h|--?help) usage; exit 0;;
|
2024-06-12 08:44:04 -04:00
|
|
|
*) name="${1}"; shift;;
|
2023-11-13 09:33:28 -05:00
|
|
|
esac
|
2024-06-12 08:44:04 -04:00
|
|
|
case "${1-}" in
|
2023-11-13 09:33:28 -05:00
|
|
|
"") usage; exit 1;;
|
2024-06-12 08:44:04 -04:00
|
|
|
*) key="${1}"; shift;;
|
2023-11-13 09:33:28 -05:00
|
|
|
esac
|
2024-06-12 08:44:04 -04:00
|
|
|
if test -z "${key##* }"; then
|
2024-08-06 12:15:24 -04:00
|
|
|
printf '%s\n' "Key was not given" >&2
|
2024-06-12 08:44:04 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
2023-11-13 09:33:28 -05:00
|
|
|
|
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 reuse
|
|
|
|
|
|
|
|
if test "${key}" = "branch"; then
|
|
|
|
branch="$(git branch --show-current)"
|
|
|
|
fi
|
2023-11-13 09:33:28 -05:00
|
|
|
|
2024-06-21 11:00:06 -04:00
|
|
|
toplevel="$(git rev-parse --show-toplevel)"
|
|
|
|
group="${toplevel##*/}"
|
2023-11-13 09:33:28 -05:00
|
|
|
block_max_chars group "${group}" 70
|
|
|
|
file_roots="/srv/salt/${group}"
|
2024-06-21 11:00:06 -04:00
|
|
|
vendor="${SPEC_VENDOR:-"$(git config --get user.name)"}"
|
2024-06-24 02:24:48 -04:00
|
|
|
packager="${SPEC_PACKAGER:-"${vendor} <$(git config --get user.email)>"}"
|
2024-06-21 11:00:06 -04:00
|
|
|
url="${SPEC_URL:-"https://github.com/ben-grande/qusal"}"
|
|
|
|
bug_url="${SPEC_BUGURL:-"${url}/issues"}"
|
2023-11-13 09:33:28 -05:00
|
|
|
|
2024-06-22 06:23:46 -04:00
|
|
|
if test -z "${group}" || test -z "${vendor}" || test -z "${packager}" \
|
|
|
|
|| test -z "${url}" || test -z "${bug_url}"
|
|
|
|
then
|
2024-08-06 12:15:24 -04:00
|
|
|
err_msg="At least one empty var: group, vendor, packager, url, bug_url"
|
|
|
|
printf '%s\n' "${err_msg}" >&2
|
2024-06-22 06:23:46 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2023-11-13 09:33:28 -05:00
|
|
|
project="${group}-${name}"
|
|
|
|
project_dir="salt/${name}"
|
|
|
|
|
|
|
|
if ! test -d "${project_dir}"; then
|
2024-08-06 12:15:24 -04:00
|
|
|
printf '%s\n' "Project doesn't exist: ${project_dir}" >&2
|
2023-11-13 09:33:28 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-06-21 11:00:06 -04:00
|
|
|
# shellcheck disable=SC2094
|
|
|
|
read -r version <"${project_dir}/version"
|
2023-11-13 09:33:28 -05:00
|
|
|
readme="${project_dir}/README.md"
|
|
|
|
if ! test -f "${readme}"; then
|
2024-08-06 12:15:24 -04:00
|
|
|
printf '%s\n' "Project ${name} does not have README.md" >&2
|
2023-11-13 09:33:28 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-06-12 08:44:04 -04:00
|
|
|
if test "${key}" = "license" || test "${key}" = "license_csv"; then
|
|
|
|
license_csv="$(reuse --root "${project_dir}" lint |
|
2024-07-08 13:08:01 -04:00
|
|
|
awk -F ':' '/^\* Used licenses:/{print $2}' | tr " " "\n" | tr -d "," |
|
|
|
|
sort -d | tr -s "\n" "," | sed "s/^\,//;s/\,$//")"
|
2024-08-06 12:15:24 -04:00
|
|
|
license="$(printf '%s\n' "${license_csv}" | sed "s/\,/ AND /g")"
|
2023-11-13 09:33:28 -05:00
|
|
|
fi
|
|
|
|
|
2024-06-12 08:44:04 -04:00
|
|
|
## The macro %autochangelog prints logs of all projects and we separate a
|
|
|
|
## project per directory. The disadvantage of the changelog below is it
|
|
|
|
# #doesn't differentiate commits per version and release, but per commit id.
|
|
|
|
if test "${key}" = "changelog"; then
|
2024-07-09 11:42:07 -04:00
|
|
|
changelog="$(TZ=UTC0 git log -n 50 \
|
|
|
|
--format=format:"* %cd %an <%ae> - %h%n- %s%n" \
|
|
|
|
--date=format:"%a %b %d %Y" -- "${project_dir}" | \
|
|
|
|
sed -re "s/^- +- */- /")"
|
2024-06-12 08:44:04 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
if test "${key}" = "description"; then
|
2024-06-14 13:22:43 -04:00
|
|
|
description="$(sed -n '/^## Description/,/^## /p' -- "${readme}" |
|
2024-06-12 08:44:04 -04:00
|
|
|
sed '1d;$d' | sed "1{/^$/d}")"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test "${key}" = "summary"; then
|
2024-07-08 11:26:34 -04:00
|
|
|
summary="$(sed -n -e \
|
|
|
|
"/^# ${name}$/,/^## Table of Contents$/{
|
2024-09-25 14:14:24 -04:00
|
|
|
/^$/d; /^#/d; /^SPDX/d; /^<!--/d; /^-->/d; s/\.$//; p}" \
|
2024-07-08 11:26:34 -04:00
|
|
|
-- "${readme}")"
|
2024-06-12 08:44:04 -04:00
|
|
|
block_max_chars summary "${summary}" 70
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test "${key}" = "saltfiles" || test "${key}" = "requires"; then
|
|
|
|
saltfiles="$(find "${project_dir}" -maxdepth 1 -name "*.sls")"
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
if test -n "${saltfiles}"; then
|
2024-08-06 11:04:16 -04:00
|
|
|
requires="$(sed -n -e '/^include:$/,/^\s*$/p' -- ${saltfiles} |
|
|
|
|
sed -e "/^\s*- \./d;/{/d" | grep -e "^\s*- " | cut -d "." -f1 |
|
|
|
|
sort -u | sed -e "s/- //")"
|
|
|
|
if grep -qrn -e "{%-\? from \('\|\"\)utils" ${saltfiles}; then
|
2024-06-12 08:44:04 -04:00
|
|
|
if test -n "${requires}"; then
|
|
|
|
requires="${requires} utils"
|
|
|
|
else
|
|
|
|
requires="utils"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
requires=""
|
|
|
|
fi
|
|
|
|
requires_valid=""
|
2024-08-06 11:04:16 -04:00
|
|
|
for r in $(printf '%s' "${requires}" | tr " " "\n"); do
|
2024-06-12 08:44:04 -04:00
|
|
|
if ! test -d "salt/${r}"; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
requires_valid="${requires_valid} ${r}"
|
|
|
|
done
|
|
|
|
requires="${requires_valid}"
|
|
|
|
unset requires_valid
|
2023-11-13 09:33:28 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
case "${key}" in
|
2024-08-06 12:15:24 -04:00
|
|
|
branch) printf '%s\n' "${branch}";;
|
|
|
|
changelog) printf '%s\n' "${changelog}";;
|
|
|
|
description) printf '%s\n' "${description}";;
|
|
|
|
file_roots) printf '%s\n' "${file_roots}";;
|
|
|
|
group) printf '%s\n' "${group}";;
|
|
|
|
license_csv) printf '%s\n' "${license_csv}";;
|
|
|
|
license) printf '%s\n' "${license}";;
|
|
|
|
name) printf '%s\n' "${name}";;
|
|
|
|
project) printf '%s\n' "${project}";;
|
|
|
|
project_dir) printf '%s\n' "${project_dir}";;
|
|
|
|
readme) printf '%s\n' "${readme}";;
|
|
|
|
requires) printf '%s\n' "${requires}";;
|
|
|
|
saltfiles) printf '%s\n' "${saltfiles}";;
|
|
|
|
summary) printf '%s\n' "${summary}";;
|
|
|
|
url) printf '%s\n' "${url}";;
|
|
|
|
bug_url) printf '%s\n' "${bug_url}";;
|
|
|
|
vendor) printf '%s\n' "${vendor}";;
|
|
|
|
packager) printf '%s\n' "${packager}";;
|
|
|
|
version) printf '%s\n' "${version}";;
|
2024-07-10 08:36:05 -04:00
|
|
|
"") exit 1;;
|
2024-08-06 12:15:24 -04:00
|
|
|
*) printf '%s\n' "Unsupported key" >&2; exit 1;;
|
2023-11-13 09:33:28 -05:00
|
|
|
esac
|