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,43 +1176,44 @@ generate_checksums() {
done done
} }
check_checksums() { verify_integrity_one() {
(( SKIPCHECKSUMS )) && return 0 local source_name=$1 integ=$2 expectedsum=$3
(( ! ${#source[@]} )) && return 0
local correlation=0 local file="$(get_filename "$source_name")"
local integ required
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 printf ' %s ... ' "$file" >&2
if [[ ${integrity_sums[idx]} = 'SKIP' ]]; then if [[ $expectedsum = 'SKIP' ]]; then
printf '%s\n' "$(gettext "Skipped")" >&2 printf '%s\n' "$(gettext "Skipped")" >&2
continue return
fi fi
if ! file="$(get_filepath "$file")"; then if ! file="$(get_filepath "$file")"; then
printf '%s\n' "$(gettext "NOT FOUND")" >&2 printf '%s\n' "$(gettext "NOT FOUND")" >&2
errors=1 return 1
continue
fi fi
local expectedsum="${integrity_sums[idx],,}"
local realsum="$(openssl dgst -${integ} "$file")" local realsum="$(openssl dgst -${integ} "$file")"
realsum="${realsum##* }" realsum="${realsum##* }"
if [[ $expectedsum = "$realsum" ]]; then if [[ ${expectedsum,,} = "$realsum" ]]; then
printf '%s\n' "$(gettext "Passed")" >&2 printf '%s\n' "$(gettext "Passed")" >&2
else else
printf '%s\n' "$(gettext "FAILED")" >&2 printf '%s\n' "$(gettext "FAILED")" >&2
errors=1 return 1
fi 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 done
if (( errors )); then if (( errors )); then
@ -1222,7 +1223,19 @@ check_checksums() {
elif (( ${#integrity_sums[@]} )); then elif (( ${#integrity_sums[@]} )); then
error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ" error "$(gettext "Integrity checks (%s) differ in size from the source array.")" "$integ"
exit 1 # TODO: error code exit 1 # TODO: error code
else
return 1
fi fi
}
check_checksums() {
(( SKIPCHECKSUMS )) && return 0
(( ! ${#source[@]} )) && return 0
local correlation=0
local integ
for integ in "${known_hash_algos[@]}"; do
verify_integrity_sums "$integ" && correlation=1
done done
if (( ! correlation )); then if (( ! correlation )); then