feat: allow sha512sums ans sha256sums

This commit is contained in:
2026-01-11 05:08:00 -05:00
parent 4ff79cfdd6
commit 618ad9222a

54
leaf
View File

@@ -600,12 +600,40 @@ leaf_phase_try() {
leaf_prepare_package() {
local url sourcefile index _md5sum local_src
local url sourcefile index _sum local_src
local checksum_algo checksum_arr_name
local decl
distdir="${DIST_DIR}"
filedir="${PKGBUILD_DIR}/${PKG_PREFIX}/${PKG_NAME}"
mkdir -pv -- "${distdir}"
# choose checksum type (sha512 -> sha256 -> md5)
if declare -p sha512sums &>/dev/null; then
decl="$(declare -p sha512sums 2>/dev/null)"
[[ "${decl}" == "declare -a "* || "${decl}" == "declare -a"* ]] \
|| leaf_error "sha512sums is defined but is not an array"
checksum_algo="sha512"
checksum_arr_name="sha512sums"
elif declare -p sha256sums &>/dev/null; then
decl="$(declare -p sha256sums 2>/dev/null)"
[[ "${decl}" == "declare -a "* || "${decl}" == "declare -a"* ]] \
|| leaf_error "sha256sums is defined but is not an array"
checksum_algo="sha256"
checksum_arr_name="sha256sums"
elif declare -p md5sums &>/dev/null; then
decl="$(declare -p md5sums 2>/dev/null)"
[[ "${decl}" == "declare -a "* || "${decl}" == "declare -a"* ]] \
|| leaf_error "md5sums is defined but is not an array"
checksum_algo="md5"
checksum_arr_name="md5sums"
else
leaf_error "no checksum list defined: need one of sha512sums/sha256sums/md5sums"
fi
local -n checksums_ref="${checksum_arr_name}"
# enter ${distdir}
pushd "${distdir}" >/dev/null || leaf_error "cannot enter distdir: ${distdir}"
for index in "${!sources[@]}"; do
@@ -618,12 +646,17 @@ leaf_prepare_package() {
if [ -f "${sourcefile}" ]; then
echo "${sourcefile} exists, checking..."
_md5sum="$(md5sum -- "${sourcefile}" | awk '{print $1}')"
if [ "${_md5sum}" = "${md5sums[$index]}" ]; then
echo "md5sum match, skip ${sourcefile}."
case "${checksum_algo}" in
sha512) _sum="$(sha512sum -- "${sourcefile}" | awk '{print $1}')" ;;
sha256) _sum="$(sha256sum -- "${sourcefile}" | awk '{print $1}')" ;;
md5) _sum="$(md5sum -- "${sourcefile}" | awk '{print $1}')" ;;
*) leaf_error "internal error: unknown checksum algo: ${checksum_algo}" ;;
esac
if [ "${_sum}" = "${checksums_ref[$index]}" ]; then
echo "${checksum_algo}sum match, skip ${sourcefile}."
continue
fi
echo "md5sum does not match, refetching..."
echo "${checksum_algo}sum does not match, refetching..."
rm -f -- "${sourcefile}"
fi
@@ -640,9 +673,14 @@ leaf_prepare_package() {
;;
esac
_md5sum="$(md5sum -- "${sourcefile}" | awk '{print $1}')"
if [ "${_md5sum}" != "${md5sums[$index]}" ]; then
leaf_error "md5sums of ${sourcefile}(${_md5sum}) does not match with ${md5sums[$index]}!"
case "${checksum_algo}" in
sha512) _sum="$(sha512sum -- "${sourcefile}" | awk '{print $1}')" ;;
sha256) _sum="$(sha256sum -- "${sourcefile}" | awk '{print $1}')" ;;
md5) _sum="$(md5sum -- "${sourcefile}" | awk '{print $1}')" ;;
*) leaf_error "internal error: unknown checksum algo: ${checksum_algo}" ;;
esac
if [ "${_sum}" != "${checksums_ref[$index]}" ]; then
leaf_error "${checksum_algo}sum of ${sourcefile}(${_sum}) does not match with ${checksums_ref[$index]}!"
fi
done