makepkg: unify list of known hash algorithms

Unifying this list makes adding new algorithms easier. There's also
some menial cleanup in this patch to avoid use of eval and properly
treat lists of data as array instead of simple strings.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Dave Reisner 2013-09-02 15:53:33 -04:00 committed by Allan McRae
parent aade18cf3b
commit b370f0ca42

View file

@ -54,6 +54,8 @@ splitpkg_overrides=('pkgver' 'pkgrel' 'epoch' 'pkgdesc' 'arch' 'url' 'license' \
'replaces' 'backup' 'options' 'install' 'changelog') 'replaces' 'backup' 'options' 'install' 'changelog')
readonly -a packaging_options other_options splitpkg_overrides readonly -a packaging_options other_options splitpkg_overrides
known_hash_algos=('md5' 'sha1' 'sha256' 'sha384' 'sha512')
# Options # Options
ASDEPS=0 ASDEPS=0
NEEDED=0 NEEDED=0
@ -1107,10 +1109,10 @@ get_integlist() {
local integ local integ
local integlist=() local integlist=()
for integ in md5 sha1 sha256 sha384 sha512; do for integ in "${known_hash_algos[@]}"; do
local integrity_sums=($(eval echo "\${${integ}sums[@]}")) local sumname="${integ}sums[@]"
if [[ -n "$integrity_sums" ]]; then if [[ -n ${!sumname} ]]; then
integlist=(${integlist[@]} $integ) integlist+=("$integ")
fi fi
done done
@ -1131,19 +1133,17 @@ generate_checksums() {
local integlist local integlist
if (( $# == 0 )); then if (( $# == 0 )); then
integlist=$(get_integlist) IFS=$'\n' read -ra integlist < <(get_integlist)
else else
integlist=$@ integlist=("$@")
fi fi
local integ local integ
for integ in ${integlist[@]}; do for integ in "${integlist[@]}"; do
case "$integ" in if ! in_array "$integ" "${known_hash_algos[@]}"; then
md5|sha1|sha256|sha384|sha512) : ;; error "$(gettext "Invalid integrity algorithm '%s' specified.")" "$integ"
*) exit 1 # $E_CONFIG_ERROR
error "$(gettext "Invalid integrity algorithm '%s' specified.")" "$integ" fi
exit 1;; # $E_CONFIG_ERROR
esac
local ct=0 local ct=0
local numsrc=${#source[@]} local numsrc=${#source[@]}
@ -1192,8 +1192,9 @@ check_checksums() {
local correlation=0 local correlation=0
local integ required local integ required
for integ in md5 sha1 sha256 sha384 sha512; do for integ in "${known_hash_algos[@]}"; do
local integrity_sums=($(eval echo "\${${integ}sums[@]}")) local sumname="${integ}sums[@]"
local integrity_sums=("${!sumname}")
if (( ${#integrity_sums[@]} == ${#source[@]} )); then if (( ${#integrity_sums[@]} == ${#source[@]} )); then
msg "$(gettext "Validating source files with %s...")" "${integ}sums" msg "$(gettext "Validating source files with %s...")" "${integ}sums"
correlation=1 correlation=1