Subject: Re: pkgsrc installing binary packages
To: Jeremy C. Reed <reed@reedmedia.net>
From: Hubert Feyrer <hubert.feyrer@informatik.fh-regensburg.de>
List: tech-pkg
Date: 05/03/2001 23:46:15
OK, next round on teaching bin-install FTP, including docs & stuff. Please
test, review, and let me know if this is ok to commit, or if there's
something fundamental missing.


 - Hubert

P.S.: Our docs are really redundant - adding a variable needs changes in
      ways to many places. Anyone wanting to fix that? IMHO most
      overlappings between packages.7 and mk.conf.examples should move
      to one of the two files (or one should be generated from the other). 
      Any takers?


Index: mk/bsd.pkg.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/bsd.pkg.mk,v
retrieving revision 1.730
diff -u -r1.730 bsd.pkg.mk
--- mk/bsd.pkg.mk	2001/04/26 08:35:38	1.730
+++ mk/bsd.pkg.mk	2001/05/03 21:33:02
@@ -2606,17 +2606,39 @@
 .endif
 
 
+
+# List of sites carrying binary pkgs. Variables "rel" and "arch" are
+# replaced with OS release ("1.5", ...) and architecture ("mipsel", ...)
+BINPKG_SITE?= \
+	ftp://ftp.netbsd.org/pub/NetBSD/packages/$${rel}/$${arch} \
+	ftp://ftp.de.netbsd.org/pub/NetBSD/packages/$${rel}/$${arch} \
+	ftp://smaug.fh-regensburg.de/pub/NetBSD/packages/$${arch} \
+
+# List of flags to pass to pkg_add(8) for bin-install:
+BIN_INSTALL_FLAGS?= 	# -v
+
 # Install binary pkg, without strict uptodate-check first
-# (XXX should be able to snarf via FTP. Later...)
 bin-install:
 	@if [ -f ${PKGFILE} ] ; then 					\
 		${ECHO_MSG} "Installing from binary pkg ${PKGFILE}" ;	\
 		${PKG_ADD} ${PKGFILE} ; 				\
 	else 				 				\
-		${SHCOMMENT} Cycle through some FTP server here ;\
-		${ECHO_MSG} "Installing from source" ;			\
-		${MAKE} ${MAKEFLAGS} package &&				\
-		${MAKE} ${MAKEFLAGS} clean ;				\
+		rel=`uname -r | sed 's@\.\([0-9]*\)[\._].*@\.\1@'`; 	\
+		arch=`sysctl -n hw.machine_arch`; 			\
+		for site in ${BINPKG_SITE} ; 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 &&			\
+			${MAKE} ${MAKEFLAGS} clean ;			\
+		fi ; \
 	fi
 
 
Index: mk/mk.conf.example
===================================================================
RCS file: /cvsroot/pkgsrc/mk/mk.conf.example,v
retrieving revision 1.204
diff -u -r1.204 mk.conf.example
--- mk/mk.conf.example	2001/04/30 14:39:41	1.204
+++ mk/mk.conf.example	2001/05/03 21:33:03
@@ -280,6 +280,20 @@
 # Possible: defined, not defined
 # Default: not defined
 
+#BINPKG_SITE=...
+# Whitespace seperated list of URLs for binary packages. Directories
+# "All" etc. are expected in the named place, variables "rel" and
+# "arch" are replaced with OS release ("1.5", ...) and architecture
+# ("mipsel", ...)
+# Possible: any ftp url, see above.
+# Default: ftp://ftp.netbsd.org/pub/NetBSD/packages/$${rel}/$${arch}
+
+#BIN_INSTALL_FLAGS=
+# List of flags passed to pkg_add(8) in the bin_install package.
+# Possible: -v, -f, etc. See pkg_add(8)
+# Default: (no option)
+
+
 #
 #	Definitions used only in the packages collection
 #
Index: Packages.txt
===================================================================
RCS file: /cvsroot/pkgsrc/Packages.txt,v
retrieving revision 1.155
diff -u -r1.155 Packages.txt
--- Packages.txt	2001/05/01 16:06:27	1.155
+++ Packages.txt	2001/05/03 21:33:05
@@ -273,10 +273,13 @@
 to remember to set them each time you want to use pkgsrc.
 
 If you want to deinstall and re-install a binary package that you've
-created (see next section) or that you put into pkgsrc/packages
-manually, you can use the the "bin-install" target, which will
-install a binary package - if available - via pkg_add, and do a "make
-package" else.
+created (see next section), that you put into pkgsrc/packages manually or
+that's available on a FTP server, you can use the the "bin-install" target,
+which will install a binary package - if available - via pkg_add, looking
+in the local machine's pkgsrc/packages directory first, and trying the FTP
+servers listed in BINPKG_SITES next. If no binary package is found, a
+"make package" is done. See packages(7) and pkgsrc/mk/mk.conf.examples for
+more information on the "bin-install" target. 
 
 A final word of warning: If you setup a system that has a non-standard
 setting for LOCALBASE (or X11BASE, for that matter), be sure to set that
Index: packages.7
===================================================================
RCS file: /cvsroot/sharesrc/share/man/man7/packages.7,v
retrieving revision 1.50
diff -u -r1.50 packages.7
--- packages.7	2001/04/29 05:56:20	1.50
+++ packages.7	2001/05/03 21:37:27
@@ -4,7 +4,7 @@
 .\"
 .\"	This file is in the public domain.
 .\"
-.Dd October 22, 2000
+.Dd May 3rd, 2001
 .Dt PACKAGES 7
 .Os
 .Sh NAME
@@ -91,6 +91,17 @@
 .It USE_GLX 
 Says that if Mesa is requested, a package should preferably use a
 GLX (hardware-accelerated) version of the Mesa library.
+.It BINPKG_SITES
+List of sites carrying binary pkgs. Variables
+.Dq rel
+and
+.Dq arch
+are
+replaced with OS release (
+.Dq 1.5 ,
+etc.) and architecture (
+.Dq mipsel ,
+etc.). 
 .El
 .Sh PACKAGE SPECIFIC VARIABLES
 This section documents variables that typically apply to an individual
@@ -696,9 +707,16 @@
 .It install	
 Install the results of a build.
 .It bin-install	
-Install a binary package if available, do a 
+Install a binary package from local disk and via FTP from a list
+of sites (see
+.Dq BINPKG_LIST
+variable), and do a 
 .Dq make package
-else.
+if no binary package is available anywhere. The arguments given to
+.Xr pkg_add
+can be set via
+.Dq BIN_INSTALL_FLAGS ,
+e.g. to do verbose operation, etc. 
 .It reinstall	
 Install the results of a build, ignoring
 .Dq already installed
@@ -753,12 +771,13 @@
 targets unless you want to open a major can of worms.
 .Sh SEE ALSO
 .Xr make 1 ,
-.Xr mk.conf 5
+.Xr mk.conf 5 ,
+.Pa ${PKGSRCDIR}/mk/mk.conf.examples
 and
 .Rs
 .%T "Documentation on the NetBSD Package System"
-.Re
-.Pa ${PKGSRCDIR}/Packages.txt
+.Re 
+.Pa ${PKGSRCDIR}/Packages.txt 
 .Sh HISTORY
 This manual page is based upon the comments in the
 .Pa bsd.pkg.mk

-- 
Hubert Feyrer <hubert.feyrer@informatik.fh-regensburg.de>