scripts/makepkg.in: Clean up gen/check checksum code.
Signed-off-by: Andrew Fyfe <andrew@neptune-one.net> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
7f153b729f
commit
6f183cb984
1 changed files with 66 additions and 67 deletions
|
@ -1071,88 +1071,87 @@ else
|
||||||
unset netfile file dlclient ret
|
unset netfile file dlclient ret
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$GENINTEG" = "1" ]; then
|
||||||
|
msg "$(gettext "Generating checksums for source files...")"
|
||||||
|
plain ""
|
||||||
|
|
||||||
|
for integ in ${INTEGRITY_CHECK[@]}; do
|
||||||
|
integ="$(echo $integ | tr [:upper:] [:lower:])"
|
||||||
|
case "$integ" in
|
||||||
|
md5|sha1|sha256|sha384|sha512) : ;;
|
||||||
|
*) error "$(gettext "Invalid integrity algorithm '%s' specified.")" "$integ"; exit 1;; # $E_CONFIG_ERROR
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ ! $(type -p "${integ}sum") ]; then
|
||||||
|
error "$(gettext "Cannot fin the '%s' program.")" "${integ}sum"
|
||||||
|
exit 1 # $E_MISSING_PROGRAM
|
||||||
|
fi
|
||||||
|
|
||||||
|
ct=0
|
||||||
|
numsrc=${#source[@]}
|
||||||
|
echo -n "${integ}sums=("
|
||||||
|
i=0; indent=''
|
||||||
|
while [ $i -lt $((${#integ}+6)) ]; do
|
||||||
|
indent="$indent "
|
||||||
|
i=$(($i+1))
|
||||||
|
done
|
||||||
|
|
||||||
|
for netfile in ${source[@]}; do
|
||||||
|
file="$(strip_url "$netfile")"
|
||||||
|
sum="$(${integ}sum "$file" | cut -d ' ' -f 1)"
|
||||||
|
[ $ct -gt 0 ] && echo -n "$indent"
|
||||||
|
echo -n "'$sum'"
|
||||||
|
ct=$(($ct+1))
|
||||||
|
[ $ct -lt $numsrc ] && echo
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ")"
|
||||||
|
done
|
||||||
|
|
||||||
|
exit 0 # $E_OK
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$NOEXTRACT" = "1" -o "$REPKG" = "1" ]; then
|
if [ "$NOEXTRACT" = "1" -o "$REPKG" = "1" ]; then
|
||||||
warning "$(gettext "Skipping source integrity checks -- using existing src/ tree")"
|
warning "$(gettext "Skipping source integrity checks -- using existing src/ tree")"
|
||||||
else
|
else
|
||||||
# TODO we end up checking $GENINTEG 3 times, could probably be refactored
|
|
||||||
if [ "$GENINTEG" = "1" ]; then
|
|
||||||
msg "$(gettext "Generating checksums for source files")"
|
|
||||||
plain ""
|
|
||||||
fi
|
|
||||||
|
|
||||||
for integ in ${INTEGRITY_CHECK[@]}; do
|
for integ in ${INTEGRITY_CHECK[@]}; do
|
||||||
integ="$(echo $integ | tr A-Z a-z)"
|
integ="$(echo $integ | tr [:upper:] [:lower:])"
|
||||||
case "$integ" in
|
case "$integ" in
|
||||||
md5) integrity_name="md5sum" ;;
|
md5|sha1|sha256|sha384|sha512) : ;;
|
||||||
sha1) integrity_name="sha1sum" ;;
|
*) error "$(gettext "Invalid integrity algorithm '%s' specified")" "$integ"; exit 1;; # $E_CONFIG_ERROR
|
||||||
sha256) integrity_name="sha256sum" ;;
|
|
||||||
sha384) integrity_name="sha384sum" ;;
|
|
||||||
sha512) integrity_name="sha512sum" ;;
|
|
||||||
*) error "$(gettext "Invalid integrity algorithm '%s' specified")" "$integ"; exit 1;;
|
|
||||||
esac
|
esac
|
||||||
if [ ! $(type -p $integrity_name) ]; then
|
|
||||||
error "$(gettext "Cannot find the %s program.")" "$integrity_name"
|
if [ ! $(type -p "${integ}sum") ]; then
|
||||||
exit 1
|
error "$(gettext "Cannot find the %s program.")" "${integ}sum"
|
||||||
|
exit 1 # $E_MISSING_PROGRAM
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Generate integrity checks
|
integrity_sums=($(eval echo \${${integ}sums[@]}))
|
||||||
if [ "$GENINTEG" = "1" ]; then
|
|
||||||
ct=0
|
|
||||||
numsrc=${#source[@]}
|
|
||||||
for netfile in "${source[@]}"; do
|
|
||||||
file=$(strip_url "$netfile")
|
|
||||||
sum=$(eval "$integrity_name '$file' | cut -d' ' -f 1")
|
|
||||||
if [ $ct -eq 0 ]; then
|
|
||||||
echo -n "${integrity_name}s=("
|
|
||||||
else
|
|
||||||
indent=0
|
|
||||||
while [ $indent -lt $((${#integrity_name}+3)) ]; do
|
|
||||||
echo -n " "
|
|
||||||
indent=$(($indent+1))
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
echo -n "'$sum'"
|
|
||||||
ct=$(($ct+1))
|
|
||||||
if [ $ct -eq $numsrc ]; then
|
|
||||||
echo ')'
|
|
||||||
else
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
#Validate integrity checks
|
|
||||||
else
|
|
||||||
integrity_sums=($(eval echo \${${integrity_name}s[@]}))
|
|
||||||
|
|
||||||
if [ ${#integrity_sums[@]} -eq ${#source[@]} ]; then
|
if [ ${#integrity_sums[@]} -eq ${#source[@]} ]; then
|
||||||
msg "$(gettext "Validating source files with %s")" "${integrity_name}s"
|
msg "$(gettext "Validating source files with %s")" "${integ}sums"
|
||||||
errors=0
|
errors=0
|
||||||
idx=0
|
idx=0
|
||||||
for netfile in "${source[@]}"; do
|
for file in "${source[@]}"; do
|
||||||
file=$(strip_url "$netfile")
|
file="$(strip_url "$file")"
|
||||||
echo -n " $file ... " >&2
|
echo -n " $file ... " >&2
|
||||||
echo "${integrity_sums[$idx]} $file" | $integrity_name -c - >/dev/null 2>&1
|
if echo "${integrity_sums[$idx]} $file" | ${integ}sum --status -c - &>/dev/null; then
|
||||||
if [ $? -ne 0 ]; then
|
echo "$(gettext "Passed")" >&2
|
||||||
|
else
|
||||||
echo "$(gettext "FAILED")" >&2
|
echo "$(gettext "FAILED")" >&2
|
||||||
errors=1
|
errors=1
|
||||||
else
|
|
||||||
echo "$(gettext "Passed")" >&2
|
|
||||||
fi
|
fi
|
||||||
idx=$(($idx+1))
|
idx=$(($idx+1))
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ $errors -gt 0 ]; then
|
if [ $errors -gt 0 ]; then
|
||||||
error "$(gettext "One or more files did not pass the validity check!")"
|
error "$(gettext "One or more files did not pass the validity check!")"
|
||||||
exit 1
|
exit 1 # TODO: error code
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
warning "$(gettext "Integrity checks (%s) are missing or incomplete.")" "$integ"
|
warning "$(gettext "Integrity checks (%s) are missing or incomplete.")" "$integ"
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
unset integ integrity_sums errors idx file
|
||||||
if [ "$GENINTEG" = "1" ]; then
|
|
||||||
plain ""
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Extract sources
|
#Extract sources
|
||||||
|
|
Loading…
Add table
Reference in a new issue