updpkgsums: add more error checking before replacement

Re-add some paranoia which was inadvertently lost with 768b65e934. In
case 'makepkg -g' fails to generate new sums (e.g. when a remote
resource cannot be fetched), or awk fails to write the new file (i have
no idea when this would happen), bail out with an error.

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Dave Reisner 2014-12-18 23:20:22 -05:00 committed by Allan McRae
parent bc6ada0877
commit 565c931e2c

View file

@ -86,7 +86,7 @@ newbuildfile=$(mktemp --tmpdir updpkgsums.XXXXXX)
# $newbuildfile as garbage in $TMPDIR. This fails silently if the replacement # $newbuildfile as garbage in $TMPDIR. This fails silently if the replacement
# succeeds. # succeeds.
trap "rm -rf '$BUILDDIR' '$newbuildfile'" EXIT trap "rm -rf '$BUILDDIR' '$newbuildfile'" EXIT
newsums=$(makepkg -g -p "$buildfile") && newsums=$(makepkg -g -p "$buildfile") || die 'Failed to generate new checksums'
awk -v newsums="$newsums" ' awk -v newsums="$newsums" '
/^[[:blank:]]*(md|sha)[[:digit:]]+sums(_[^=]+)?=/,/\)[[:blank:]]*(#.*)?$/ { /^[[:blank:]]*(md|sha)[[:digit:]]+sums(_[^=]+)?=/,/\)[[:blank:]]*(#.*)?$/ {
if (!w) { if (!w) {
@ -98,7 +98,7 @@ awk -v newsums="$newsums" '
1 1
END { if (!w) print newsums } END { if (!w) print newsums }
' "$buildfile" > "$newbuildfile" ' "$buildfile" > "$newbuildfile" || die 'Failed to write new PKGBUILD'
# Replace the original buildfile. # Replace the original buildfile.
if ! mv -- "$newbuildfile" "$buildfile"; then if ! mv -- "$newbuildfile" "$buildfile"; then