Subject: Re: The Lazy Bum's Metapackaging for Package Management (with patches)
To: None <tech-pkg@NetBSD.org>
From: J Chapman Flack <flack@cs.purdue.edu>
List: tech-pkg
Date: 03/20/2005 17:04:52
> [too much to read now]
> 
> Please re-post your patches in "diff -u" format.

Here goes....   -Chap

--- /usr/pkgsrc/mk/bsd.pkg.mk	2005-03-02 22:08:20.000000000 -0500
+++ /usr/pkgsrc/mk/bsd.pkg.mk	2005-03-20 16:47:13.000000000 -0500
@@ -1098,7 +1098,7 @@
 .    else
 DEPENDS_TARGET=	update
 .    endif
-.  elif make(bin-install)
+.  elif make(bin-install)  ||  make(real-su-bin-install)
 DEPENDS_TARGET=	bin-install
 .  else
 DEPENDS_TARGET=	reinstall
@@ -3825,6 +3825,15 @@
 
 # List of sites carrying binary pkgs. Variables "rel" and "arch" are
 # replaced with OS release ("1.5", ...) and architecture ("mipsel", ...)
+# XXX the way this variable is used in the shell script, all shell
+# metacharacters are active, not just variable substitution.  I first
+# changed it to do all substitution in make, just on the fixed tokens
+# ${rel} and ${arch}, and pass the result :Q-ed to the shell.  I liked
+# that much better, but realized it might change semantics for people who
+# already had funny stuff in their BINPKG_SITES and had had to figure out
+# how to quote it successfully.  So back to the original semantics - but
+# worth thinking about if a pure string substitution limited to arch and
+# rel would be less error prone.
 BINPKG_SITES?= \
 	ftp://ftp.NetBSD.org/pub/NetBSD/packages/$${rel}/$${arch}
 
@@ -3837,6 +3846,9 @@
 _BIN_INSTALL_FLAGS=	${BIN_INSTALL_FLAGS}
 _BIN_INSTALL_FLAGS+=	${PKG_ARGS_ADD}
 
+_SHORT_UNAME_R!=	uname -r
+_SHORT_UNAME_R:=	${_SHORT_UNAME_R:C@\.([0-9])*[_.].*@.\1@} # n.n[_.]anything => n.n
+
 # Install binary pkg, without strict uptodate-check first
 .PHONY: real-su-bin-install
 real-su-bin-install:
@@ -3848,32 +3860,25 @@
 		${SHCOMMENT} ${ECHO_MSG} "*** or use \`\`${MAKE} bin-update'' to upgrade it and all of its dependencies."; \
 		exit 1;							\
 	fi
-	@if [ -f ${PKGFILE} ] ; then 					\
-		${ECHO_MSG} "Installing from binary pkg ${PKGFILE}" ;	\
-		${PKG_ADD} ${_BIN_INSTALL_FLAGS} ${PKGFILE} ;		\
+	@rel=${_SHORT_UNAME_R:Q} ; \
+	arch=${MACHINE_ARCH:Q} ; \
+	pkgpath=${PKGREPOSITORY:Q} ; \
+	for i in ${BINPKG_SITES} ; do pkgpath="$$pkgpath;$$i/All" ; done ; \
+	${ECHO} "Trying $$pkgpath" ; 	\
+	if ${SETENV} PKG_PATH="$$pkgpath" ${PKG_ADD} ${BIN_INSTALL_FLAGS} ${PKGNAME_REQD:U${PKGNAME}:Q} ; then \
+		${ECHO} ${PKGNAME_REQD:U${PKGNAME}:Q} successfully installed.; \
+		break ; 				\
 	else 				 				\
-		rel=`${UNAME} -r | ${SED} 's@\.\([0-9]*\)[\._].*@\.\1@'`; \
-		arch=${MACHINE_ARCH}; 					\
-		for site in ${BINPKG_SITES} ; do 			\
-			${ECHO} Trying `eval ${ECHO} $$site`/All ; 	\
-			${SHCOMMENT} ${ECHO} ${SETENV} PKG_PATH="`eval ${ECHO} $$site`/All" ${PKG_ADD} ${_BIN_INSTALL_FLAGS} ${PKGNAME}${PKG_SUFX} ; \
-			if ${SETENV} PKG_PATH="`eval ${ECHO} $$site`/All" ${PKG_ADD} ${BIN_INSTALL_FLAGS} ${PKGNAME}${PKG_SUFX} ; then \
-				${ECHO} "${PKGNAME} successfully installed."; \
-				break ; 				\
-			fi ; 						\
-		done ; 							\
-		if ! ${PKG_INFO} -qe "${PKGNAME}" ; then 		\
-			${SHCOMMENT} Cycle through some FTP server here ;\
-			${ECHO_MSG} "Installing from source" ;		\
-			${MAKE} ${MAKEFLAGS} package 			\
-				DEPENDS_TARGET=${DEPENDS_TARGET:Q} &&	\
-			${MAKE} ${MAKEFLAGS} clean ;			\
-		fi ; \
+		${SHCOMMENT} Cycle through some FTP server here ;\
+		${ECHO_MSG} "Installing from source" ;		\
+		${MAKE} ${MAKEFLAGS} package 			\
+			DEPENDS_TARGET=${DEPENDS_TARGET:Q} &&	\
+		${MAKE} ${MAKEFLAGS} clean ;			\
 	fi
 
 .PHONY: bin-install
 bin-install:
-	@${ECHO_MSG} "${_PKGSRC_IN}> Binary install for ${PKGNAME}"
+	@${ECHO_MSG} "${_PKGSRC_IN}> Binary install for "${PKGNAME_REQD:U${PKGNAME}:Q}
 	${_PKG_SILENT}${_PKG_DEBUG}					\
 	realtarget="real-su-bin-install";				\
 	action="binary install";					\
@@ -3973,11 +3978,11 @@
 .    else	# !DEPENDS
 .      for dep in ${DEPENDS} ${BUILD_DEPENDS}
 	${_PKG_SILENT}${_PKG_DEBUG}					\
-	pkg="${dep:C/:.*//}";						\
-	dir="${dep:C/[^:]*://:C/:.*$//}";				\
+	pkg=${dep:C/:.*//:Q};						\
+	dir=${dep:C/[^:]*://:C/:.*$//:Q};				\
 	found=`${PKG_BEST_EXISTS} "$$pkg" || ${TRUE}`;			\
 	if [ "X$$REBUILD_DOWNLEVEL_DEPENDS" != "X" ]; then		\
-		pkgname=`cd $$dir ; ${MAKE} ${MAKEFLAGS} show-var VARNAME=PKGNAME`; \
+		pkgname=`cd "$$dir" ; ${MAKE} ${MAKEFLAGS} show-var VARNAME=PKGNAME`; \
 		if [ "X$$found" != "X" -a "X$$found" != "X$${pkgname}" ]; then \
 			${ECHO_MSG} "ignoring old installed package \"$$found\""; \
 			found="";					\
@@ -4002,11 +4007,11 @@
 		${ECHO_MSG} "${_PKGSRC_IN}> Required package $$pkg: NOT found"; \
 		target=${DEPENDS_TARGET:Q};				\
 		${ECHO_MSG} "${_PKGSRC_IN}> Verifying $$target for $$dir"; 	\
-		if [ ! -d $$dir ]; then					\
+		if [ ! -d "$$dir" ]; then					\
 			${ECHO_MSG} "=> No directory for $$dir.  Skipping.."; \
 		else							\
-			cd $$dir ;					\
-			${SETENV} _PKGSRC_DEPS=", ${PKGNAME}${_PKGSRC_DEPS}" ${MAKE} ${MAKEFLAGS} $$target PKGNAME_REQD=\'$$pkg\' || exit 1; \
+			cd "$$dir" ;					\
+			${SETENV} _PKGSRC_DEPS=", ${PKGNAME}${_PKGSRC_DEPS}" ${MAKE} ${MAKEFLAGS} $$target PKGNAME_REQD="$$pkg" || exit 1; \
 			${ECHO_MSG} "${_PKGSRC_IN}> Returning to build of ${PKGNAME}"; \
 		fi;							\
 	fi
@@ -4326,7 +4331,7 @@
 	| ${SORT} -u							\
 	| ${SED} -e "s/'/'\\\\''/g" -e "s/.*/'&'/"			\
 	| ${XARGS} -n 256 ${LS} -ld					\
-	| ${AWK} '{ s += $$5; } END { print s; }'			\
+	| ${AWK} '{ s += $$5; } END { print 0 + s; }'			\
 
 # Sizes of required pkgs (only)
 #