summaryrefslogtreecommitdiff
path: root/mk
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
commitab19d1bccead426b5e79a388f2194b096d3eebee (patch)
tree8f3702ac58d124d22cbcb68ba130bda59f106c37 /mk
parent5c6ea54f686eb83fb0923ce764cb8e5a2a808e9a (diff)
downloadpkgsrc-ab19d1bccead426b5e79a388f2194b096d3eebee.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')
-rwxr-xr-xmk/checksum/checksum87
-rw-r--r--mk/patch/patch.mk33
2 files changed, 70 insertions, 50 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
diff --git a/mk/patch/patch.mk b/mk/patch/patch.mk
index b799b691900..772eed5caef 100644
--- a/mk/patch/patch.mk
+++ b/mk/patch/patch.mk
@@ -1,4 +1,4 @@
-# $NetBSD: patch.mk,v 1.12 2007/08/14 13:21:57 rillig Exp $
+# $NetBSD: patch.mk,v 1.13 2007/08/14 21:25:10 jlam Exp $
#
# The following variables may be set in a package Makefile and control
# how pkgsrc patches are applied.
@@ -261,6 +261,11 @@ _PKGSRC_PATCHES+= ${PATCHDIR}/patch-*
_PKGSRC_PATCHES+= ${LOCALPATCHES}/${PKGPATH}/*
.endif
+_CHECKSUM_CMD= ${SETENV} DIGEST=${TOOLS_DIGEST:Q} CAT=${TOOLS_CAT:Q} \
+ ECHO=${TOOLS_ECHO:Q} SED=${TOOLS_SED:Q} \
+ TEST=${TOOLS_TEST:Q} \
+ ${SH} ${PKGSRCDIR}/mk/checksum/checksum
+
pkgsrc-patch-message:
@${STEP_MSG} "Applying pkgsrc patches for ${PKGNAME}"
@@ -287,22 +292,20 @@ do-pkgsrc-patch:
patch_warning "Ignoring patch file $$i: distinfo not found"; \
continue; \
fi; \
- filename=`${BASENAME} $$i`; \
- algsum=`${AWK} '(NF == 4) && ($$2 == "('$$filename')") && ($$3 == "=") {print $$1 " " $$4}' ${DISTINFO_FILE} || ${TRUE}`; \
- if ${TEST} -z "$$algsum"; then \
- patch_warning "Ignoring patch file $$i: no checksum found"; \
- continue; \
+ ${ECHO_PATCH_MSG} "Verifying $$i"; \
+ if ${_CHECKSUM_CMD} ${DISTINFO_FILE} $$i >/dev/null 2>&1; then \
+ cksum_result=0; \
+ else \
+ cksum_result=$$?; \
fi; \
- set -- $$algsum; \
- alg="$$1"; \
- recorded="$$2"; \
- calcsum=`${SED} -e '/\$$NetBSD.*/d' $$i | ${TOOLS_DIGEST} $$alg`; \
- ${ECHO_PATCH_MSG} "Verifying $$filename (using digest algorithm $$alg)"; \
- if ${TEST} "$$calcsum" != "$$recorded"; then \
- patch_warning "Ignoring patch file $$i: invalid checksum"; \
+ case "$$cksum_result" in \
+ 0) ;; \
+ 2) patch_warning "Ignoring patch file $$i: no checksum found"; \
+ continue ;; \
+ 1) patch_warning "Ignoring patch file $$i: invalid checksum"; \
fail="$$fail $$i"; \
- continue; \
- fi; \
+ continue ;; \
+ esac; \
;; \
esac; \
${ECHO_PATCH_MSG} "Applying pkgsrc patch $$i"; \