1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-08-13 17:03:46 -04:00

makepkg: break out check_checksums to reasonably sized functions

This commit is contained in:
Dave Reisner 2014-08-06 22:01:41 -04:00 committed by Allan McRae
parent b52ed49d75
commit a3d7230e4d

View File

@ -1176,53 +1176,66 @@ generate_checksums() {
done
}
verify_integrity_one() {
local source_name=$1 integ=$2 expectedsum=$3
local file="$(get_filename "$source_name")"
printf ' %s ... ' "$file" >&2
if [[ $expectedsum = 'SKIP' ]]; then
printf '%s\n' "$(gettext "Skipped")" >&2
return
fi
if ! file="$(get_filepath "$file")"; then
printf '%s\n' "$(gettext "NOT FOUND")" >&2
return 1
fi
local realsum="$(openssl dgst -${integ} "$file")"
realsum="${realsum##* }"
if [[ ${expectedsum,,} = "$realsum" ]]; then
printf '%s\n' "$(gettext "Passed")" >&2
else
printf '%s\n' "$(gettext "FAILED")" >&2
return 1
fi
return 0
}
verify_integrity_sums() {
local integ=$1 integrity_sums
array_build integrity_sums "${integ}sums"
if (( ${#integrity_sums[@]} == ${#source[@]} )); then
msg "$(gettext "Validating source files with %s...")" "${integ}sums"
local idx errors=0
for (( idx = 0; idx < ${#source[*]}; idx++ )); do
verify_integrity_one "${source[idx]}" "$integ" "${integrity_sums[idx]}" || errors=1
done
if (( errors )); then
error "$(gettext "One or more files did not pass the validity check!")"
exit 1 # TODO: error code
fi
elif (( ${#integrity_sums[@]} )); then
error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ"
exit 1 # TODO: error code
else
return 1
fi
}
check_checksums() {
(( SKIPCHECKSUMS )) && return 0
(( ! ${#source[@]} )) && return 0
local correlation=0
local integ required
local integ
for integ in "${known_hash_algos[@]}"; do
local sumname="${integ}sums[@]"
local integrity_sums=("${!sumname}")
if (( ${#integrity_sums[@]} == ${#source[@]} )); then
msg "$(gettext "Validating source files with %s...")" "${integ}sums"
correlation=1
local idx errors=0
for (( idx = 0; idx < ${#source[*]}; idx++ )); do
local file="$(get_filename "${source[idx]}")"
printf ' %s ... ' "$file" >&2
if [[ ${integrity_sums[idx]} = 'SKIP' ]]; then
printf '%s\n' "$(gettext "Skipped")" >&2
continue
fi
if ! file="$(get_filepath "$file")"; then
printf '%s\n' "$(gettext "NOT FOUND")" >&2
errors=1
continue
fi
local expectedsum="${integrity_sums[idx],,}"
local realsum="$(openssl dgst -${integ} "$file")"
realsum="${realsum##* }"
if [[ $expectedsum = "$realsum" ]]; then
printf '%s\n' "$(gettext "Passed")" >&2
else
printf '%s\n' "$(gettext "FAILED")" >&2
errors=1
fi
done
if (( errors )); then
error "$(gettext "One or more files did not pass the validity check!")"
exit 1 # TODO: error code
fi
elif (( ${#integrity_sums[@]} )); then
error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ"
exit 1 # TODO: error code
fi
verify_integrity_sums "$integ" && correlation=1
done
if (( ! correlation )); then