feat: allow sha512sums ans sha256sums
This commit is contained in:
54
leaf
54
leaf
@@ -600,12 +600,40 @@ leaf_phase_try() {
|
|||||||
|
|
||||||
|
|
||||||
leaf_prepare_package() {
|
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}"
|
distdir="${DIST_DIR}"
|
||||||
filedir="${PKGBUILD_DIR}/${PKG_PREFIX}/${PKG_NAME}"
|
filedir="${PKGBUILD_DIR}/${PKG_PREFIX}/${PKG_NAME}"
|
||||||
mkdir -pv -- "${distdir}"
|
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}"
|
pushd "${distdir}" >/dev/null || leaf_error "cannot enter distdir: ${distdir}"
|
||||||
|
|
||||||
for index in "${!sources[@]}"; do
|
for index in "${!sources[@]}"; do
|
||||||
@@ -618,12 +646,17 @@ leaf_prepare_package() {
|
|||||||
|
|
||||||
if [ -f "${sourcefile}" ]; then
|
if [ -f "${sourcefile}" ]; then
|
||||||
echo "${sourcefile} exists, checking..."
|
echo "${sourcefile} exists, checking..."
|
||||||
_md5sum="$(md5sum -- "${sourcefile}" | awk '{print $1}')"
|
case "${checksum_algo}" in
|
||||||
if [ "${_md5sum}" = "${md5sums[$index]}" ]; then
|
sha512) _sum="$(sha512sum -- "${sourcefile}" | awk '{print $1}')" ;;
|
||||||
echo "md5sum match, skip ${sourcefile}."
|
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
|
continue
|
||||||
fi
|
fi
|
||||||
echo "md5sum does not match, refetching..."
|
echo "${checksum_algo}sum does not match, refetching..."
|
||||||
rm -f -- "${sourcefile}"
|
rm -f -- "${sourcefile}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -640,9 +673,14 @@ leaf_prepare_package() {
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
_md5sum="$(md5sum -- "${sourcefile}" | awk '{print $1}')"
|
case "${checksum_algo}" in
|
||||||
if [ "${_md5sum}" != "${md5sums[$index]}" ]; then
|
sha512) _sum="$(sha512sum -- "${sourcefile}" | awk '{print $1}')" ;;
|
||||||
leaf_error "md5sums of ${sourcefile}(${_md5sum}) does not match with ${md5sums[$index]}!"
|
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
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user