ports/56641: [PATCH] bsd.port.mk: support for SHA1 and other algorithms in distinfo
Oliver Eikemeier
eikemeier at fillmore-labs.com
Tue Sep 9 16:10:03 UTC 2003
>Number: 56641
>Category: ports
>Synopsis: [PATCH] bsd.port.mk: support for SHA1 and other algorithms in distinfo
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-ports-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Tue Sep 09 09:10:01 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator: Oliver Eikemeier
>Release: FreeBSD 4.8-STABLE i386
>Organization:
Fillmore Labs - http://www.fillmore-labs.com
>Environment:
System: FreeBSD nuuk.fillmore-labs.com 4.8-STABLE
>Description:
NetBSD uses SHA1, OpenBSD SHA1, RMD160 and MD5 in distinfo.
Enable FreeBSD to handle these.
>How-To-Repeat:
>Fix:
included is a patch for bsd.port.mk that:
- adds FETCH_DEPENDS on the security/digest port, this is
the NetBSD digest tool, completely self contained in
the ports tree (the sources are in ${FILESDIR})
- modify makesum and checksum to use this tool, fallback
to md5 if it can not be found
- make the used algorithms tunable via
DISTINFO_ALGORITHMS and CHECKSUM_ALGORITHMS
- activate the size recording checked in at
http://www.freebsd.org/cgi/cvsweb.cgi/ports/Mk/bsd.port.mk#rev1.291
(the size is currently unused, but it can be checked or
users can be notified how many bytes must be fetched)
- try to re-get distfiles only if it makes sense
- minor cleanup: be more specific looking for files in distinfo
(fetch accepted "afile" and "file" if only "afile" was in distinfo)
--- bsd.port.mk.patch begins here ---
--- ports/Mk/bsd.port.mk.orig Tue Sep 9 15:44:13 2003
+++ ports/Mk/bsd.port.mk Tue Sep 9 17:32:50 2003
@@ -2252,6 +2252,17 @@
_IGNOREFILES?= ${IGNOREFILES}
.endif
+# Used for generating distinfo.
+DISTINFO_ALGORITHMS?= SHA1 MD5
+
+# acceptable algorithms
+CHECKSUM_ALGORITHMS?= SHA1 RMD160 MD5
+
+.if !defined(NO_CHECKSUM) && !empty(CKSUMFILES) && ${CHECKSUM_ALGORITHMS} != "MD5"
+FETCH_DEPENDS+= ${LOCALBASE}/bin/digest:${PORTSDIR}/security/digest
+DIGEST?= ${LOCALBASE}/bin/digest
+.endif
+
# This is what is actually going to be extracted, and is overridable
# by user.
EXTRACT_ONLY?= ${_DISTFILES}
@@ -2720,6 +2731,7 @@
fi; \
done; \
if [ ! -f $$file -a ! -f $$filebasename -o "$$force_fetch" = "true" ]; then \
+ DIR=${DIST_SUBDIR}; \
if [ -L $$file -o -L $$filebasename ]; then \
${ECHO_MSG} ">> ${_DISTDIR}/$$file is a broken symlink."; \
${ECHO_MSG} ">> Perhaps a filesystem (most likely a CD) isn't mounted?"; \
@@ -2727,10 +2739,17 @@
exit 1; \
fi ; \
if [ -f ${MD5_FILE} -a "x${NO_CHECKSUM}" = "x" ]; then \
- if ! ${GREP} -q "^MD5 (.*$$file)" ${MD5_FILE}; then \
- ${ECHO_MSG} ">> $$file is not in ${MD5_FILE}."; \
+ found=0; \
+ for alg in ${CHECKSUM_ALGORITHMS:U}; do \
+ if ${GREP} -q "^$${alg} ($${DIR:+$$DIR/}$$file)" ${MD5_FILE}; then \
+ found=1; \
+ break; \
+ fi; \
+ done; \
+ if [ "$$found" = 0 ]; then \
+ ${ECHO_MSG} ">> $${DIR:+$$DIR/}$$file is not in ${MD5_FILE}."; \
${ECHO_MSG} ">> Either ${MD5_FILE} is out of date, or"; \
- ${ECHO_MSG} ">> $$file is spelled incorrectly."; \
+ ${ECHO_MSG} ">> $${DIR:+$$DIR/}$$file is spelled incorrectly."; \
exit 1; \
fi; \
fi; \
@@ -2754,7 +2773,6 @@
fi ; \
for site in `eval $$SORTED_MASTER_SITES_CMD_TMP`; do \
${ECHO_MSG} ">> Attempting to fetch from $${site}."; \
- DIR=${DIST_SUBDIR}; \
CKSIZE=`${GREP} "^SIZE ($${DIR:+$$DIR/}$$file)" ${MD5_FILE} | ${AWK} '{print $$4}'`; \
case $${file} in \
*/*) ${MKDIR} $${file%/*}; \
@@ -3708,42 +3726,66 @@
@if [ -f ${MD5_FILE} ]; then ${CAT} /dev/null > ${MD5_FILE}; fi
@(cd ${DISTDIR}; \
for file in ${_CKSUMFILES}; do \
- ${MD5} $$file >> ${MD5_FILE}; \
+ for alg in ${DISTINFO_ALGORITHMS}; do \
+ if [ -n "${DIGEST}" -a -x "${DIGEST}" ]; then \
+ ${DIGEST} $$alg $$file >> ${MD5_FILE}; \
+ elif [ "$$alg" = "MD5" ]; then \
+ ${MD5} $$file >> ${MD5_FILE}; \
+ else \
+ ${ECHO_CMD} "Can not calculate $$alg checksum, port security/digest not installed"; \
+ exit 1; \
+ fi; \
+ done; \
+ echo "SIZE ($$file) = "`${LS} -ALln $$file | ${AWK} '{print $$5}'` >> ${MD5_FILE}; \
done)
@for file in ${_IGNOREFILES}; do \
${ECHO_CMD} "MD5 ($$file) = IGNORE" >> ${MD5_FILE}; \
done
.endif
-# this line goes after the ${MD5} above
-# echo "SIZE ($$file) = "`wc -c < $$file` >> ${MD5_FILE}; \
.if !target(checksum)
checksum: fetch
@if [ ! -f ${MD5_FILE} ]; then \
- ${ECHO_MSG} ">> No MD5 checksum file."; \
+ ${ECHO_MSG} ">> No distinfo file (${MD5_FILE})."; \
else \
(cd ${DISTDIR}; OK="true"; \
for file in ${_CKSUMFILES}; do \
- CKSUM=`${MD5} < $$file`; \
- CKSUM2=`${GREP} "^MD5 ($$file)" ${MD5_FILE} | ${AWK} '{print $$4}'`; \
- if [ "$$CKSUM2" = "" ]; then \
+ CKSUM=""; \
+ CKSUM2=""; \
+ for alg in ${CHECKSUM_ALGORITHMS:U}; do \
+ CKSUM2=`${GREP} "^$$alg ($$file)" ${MD5_FILE} | ${AWK} '{print $$4}'`; \
+ if [ -n "$$CKSUM2" ]; then \
+ if [ -n "${DIGEST}" -a -x "${DIGEST}" ]; then \
+ CKSUM=`${DIGEST} $$alg < $$file`; \
+ break; \
+ elif [ "$$alg" = "MD5" ]; then \
+ CKSUM=`${MD5} < $$file`; \
+ break; \
+ fi; \
+ fi; \
+ done; \
+ if [ -z "$$CKSUM2" ]; then \
${ECHO_MSG} ">> No checksum recorded for $$file."; \
OK="false"; \
+ elif [ -z "$$CKSUM" ]; then \
+ ${ECHO_MSG} ">> Can not calculate checksum for $$file,"; \
+ ${ECHO_MSG} " port security/digest not installed?"; \
+ OK="false"; \
elif [ "$$CKSUM2" = "IGNORE" ]; then \
${ECHO_MSG} ">> Checksum for $$file is set to IGNORE in distinfo file even though"; \
${ECHO_MSG} " the file is not in the "'$$'"{IGNOREFILES} list."; \
OK="false"; \
- elif ${EXPR} "$$CKSUM2" : ".*$$CKSUM" > /dev/null; then \
+ elif [ "$$CKSUM2" = "$$CKSUM" ]; then \
${ECHO_MSG} ">> Checksum OK for $$file."; \
else \
${ECHO_MSG} ">> Checksum mismatch for $$file."; \
refetchlist="$$refetchlist$$file "; \
- OK="false"; \
+ OK="retry"; \
fi; \
done; \
for file in ${_IGNOREFILES}; do \
- CKSUM2=`${GREP} "($$file)" ${MD5_FILE} | ${AWK} '{print $$4}'`; \
+ CKSUM2=`${GREP} "($$file)" ${MD5_FILE} | ${AWK} '{if(NR<2)print $$4}'`; \
if [ "$$CKSUM2" = "" ]; then \
${ECHO_MSG} ">> No checksum recorded for $$file, file is in "'$$'"{IGNOREFILES} list."; \
OK="false"; \
@@ -3753,7 +3795,7 @@
OK="false"; \
fi; \
done; \
- if [ "$$OK" != "true" ] && [ ${FETCH_REGET} -gt 0 ]; then \
+ if [ "$$OK" = "retry" ] && [ ${FETCH_REGET} -gt 0 ]; then \
${ECHO_MSG} "===> Refetch for ${FETCH_REGET} more times files: $$refetchlist"; \
if ( cd ${.CURDIR} && \
${MAKE} ${.MAKEFLAGS} FORCE_FETCH="$$refetchlist" FETCH_REGET="`expr ${FETCH_REGET} - 1`" fetch); then \
--- bsd.port.mk.patch ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-ports-bugs
mailing list