summaryrefslogtreecommitdiff
path: root/mk/checksum
diff options
context:
space:
mode:
authorjlam <jlam@pkgsrc.org>2007-08-14 21:25:09 +0000
committerjlam <jlam@pkgsrc.org>2007-08-14 21:25:09 +0000
commit701b13909a92de00bd3f399d00e83ebbcf763efd (patch)
tree8f3702ac58d124d22cbcb68ba130bda59f106c37 /mk/checksum
parent8e144a7e42a8dd3ac68117ad4e4d8e9563fca6fc (diff)
downloadpkgsrc-701b13909a92de00bd3f399d00e83ebbcf763efd.tar.gz
Teach the pkgsrc/mk/checksum/checksum script how to verify patches by
first stripping them of NetBSD RCS ID tags. Use the checksum script in the patch module to verify patch checksums instead of hand-coding a miniature version of the checksum script in the do-pkgsrc-patches target.
Diffstat (limited to 'mk/checksum')
-rwxr-xr-xmk/checksum/checksum87
1 files changed, 52 insertions, 35 deletions
diff --git a/mk/checksum/checksum b/mk/checksum/checksum
index eb40c498d27..4b8d770640a 100755
--- a/mk/checksum/checksum
+++ b/mk/checksum/checksum
@@ -1,8 +1,8 @@
#!/bin/sh
#
-# $NetBSD: checksum,v 1.10 2006/12/15 13:15:06 martti Exp $
+# $NetBSD: checksum,v 1.11 2007/08/14 21:25:09 jlam Exp $
#
-# Copyright (c) 2006 The NetBSD Foundation, Inc.
+# Copyright (c) 2006, 2007 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
@@ -47,7 +47,20 @@
#
# DESCRIPTION
# checksum will verify the checksums in the distinfo file for each
-# of the files specified.
+# of the files specified. If the file is a patch (named patch-*),
+# then strip out any lines containing NetBSD RCS ID tags before
+# computing the checksum for comparison the one in the distinfo
+# file.
+#
+# The checksum utility exits with one of the following values:
+#
+# 0 All of the file checksums verify.
+#
+# 1 At least one of the file checksums did not match.
+#
+# 2 At least one of the files is missing any checksum.
+#
+# >2 An error occurred.
#
# OPTIONS
# -a algorithm Only verify checksums for the specified algorithm.
@@ -61,6 +74,7 @@ set -e # exit on errors
: ${DIGEST:=digest}
: ${CAT:=cat}
: ${ECHO:=echo}
+: ${SED:=sed}
: ${TEST:=test}
self="${0##*/}"
@@ -79,20 +93,21 @@ while ${TEST} $# -gt 0; do
--) shift; break ;;
-*) ${ECHO} 1>&2 "$self: unknown option -- ${1#-}"
usage
- exit 1
+ exit 128
;;
*) break ;;
esac
done
# Process required arguments
-${TEST} $# -gt 0 || { usage; exit 1; }
+${TEST} $# -gt 0 || { usage; exit 128; }
distinfo="$1"; shift
files="$@"
+files_left="$@"
if ${TEST} ! -f "$distinfo"; then
${ECHO} 1>&2 "$self: distinfo file missing: $distinfo"
- exit 1
+ exit 128
fi
digestcmd=
@@ -116,7 +131,7 @@ esac
if ${TEST} -z "$digestcmd"; then
${ECHO} 1>&2 "$self: \`\`${DIGEST}'' is missing"
- exit 1
+ exit 128
fi
{ exitcode=0
@@ -132,26 +147,24 @@ fi
${TEST} "$d_alg" = "$algorithm" || continue
fi
- eval "tmp=\"\$_alg_${d_alg}\""
- ${TEST} -n "$tmp" || eval "_alg_${d_alg}=\"$files\""
-
for file in $files; do
sfile="${file%$suffix}"
+ case $file in
+ patch-*|*/patch-*) sfile="${sfile##*/}" ;;
+ esac
${TEST} "$d_file" = "($sfile)" || continue
- eval "tmp=\"\$_alg_${d_alg}\""
- case "$tmp" in
- "$file"|"$file "*) tmp_pre= ;;
- *" $file") tmp_pre="${tmp%% $file}" ;;
- *) tmp_pre="${tmp%% $file *} " ;;
+ case "$files_left" in
+ "$file"|"$file "*) pre= ;;
+ *" $file") pre="${files_left%% $file}" ;;
+ *) pre="${files_left%% $file *} " ;;
esac
- case "$tmp" in
- "$file"|*" $file") tmp_post= ;;
- "$file "*) tmp_post="${tmp##$file }" ;;
- *) tmp_post="${tmp##* $file }" ;;
+ case "$files_left" in
+ "$file"|*" $file") post= ;;
+ "$file "*) post="${files_left##$file }" ;;
+ *) post="${files_left##* $file }" ;;
esac
- tmp="${tmp_pre}${tmp_post}"
- eval "_alg_${d_alg}=\"$tmp\""
+ files_left="${pre}${post}"
if ${TEST} "$d_checksum" = "IGNORE"; then
${ECHO} 1>&2 "$self: Ignoring checksum for $sfile"
@@ -159,29 +172,33 @@ fi
fi
if ${TEST} ! -f $file; then
${ECHO} 1>&2 "$self: $file does not exist"
- exit 1
+ exit 128
fi
- checksum=`${DIGEST} $d_alg < $file`
+ case $file in
+ patch-*|*/patch-*)
+ checksum=`${SED} -e '/[$]NetBSD.*/d' $file | ${DIGEST} $d_alg`
+ ;;
+ *)
+ checksum=`${DIGEST} $d_alg < $file`
+ ;;
+ esac
if ${TEST} "$d_checksum" = "$checksum"; then
${ECHO} "=> Checksum $d_alg OK for $sfile"
else
${ECHO} 1>&2 "$self: Checksum $d_alg mismatch for $sfile"
- exitcode=1
+ exit 1
fi
break
done
-
- eval "tmp=\"\$_alg_${d_alg}\""
- ${TEST} -n "$tmp" || eval "_alg_${d_alg}=DONE"
done
- if ${TEST} -n "$algorithm"; then
- eval "tmp=\"\$_alg_${algorithm}\""
- ${TEST} -n "$tmp" || tmp="$files"
- if ${TEST} "$tmp" != DONE; then
- for file in $tmp; do
+ if ${TEST} -n "$files_left"; then
+ for file in $files_left; do
+ if ${TEST} -n "$algorithm"; then
${ECHO} 1>&2 "$self: No $algorithm checksum recorded for $file"
- exitcode=1
- done
- fi
+ else
+ ${ECHO} 1>&2 "$self: No checksum recorded for $file"
+ fi
+ exitcode=2
+ done
fi
exit $exitcode; } < $distinfo