Subject: pkg_chk for remote binary packages
To: None <tech-pkg@NetBSD.org>
From: Dieter Baron <dillo@danbala.tuwien.ac.at>
List: tech-pkg
Date: 12/05/2005 23:31:56
--LTeJQqWS0MN7I/qa
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

hi,

the attached patch allows pkg_chk to work on remote binary packages.
On the machine that holds the packages, run
	pkg_chk -S -b <binary_package_directory>
to create a summary file, which is fetched by pkg_chk when working
with remote packages.

  Please review and test.  I would like to get this committed before
the branch.

					yours,
					dillo


--LTeJQqWS0MN7I/qa
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="pkg_chk.diff"

Index: Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_chk/Makefile,v
retrieving revision 1.20
diff -u -r1.20 Makefile
--- Makefile	27 Sep 2005 17:13:03 -0000	1.20
+++ Makefile	5 Dec 2005 22:03:52 -0000
@@ -1,6 +1,6 @@
 # $NetBSD: Makefile,v 1.20 2005/09/27 17:13:03 abs Exp $
 
-DISTNAME=	pkg_chk-1.62
+DISTNAME=	pkg_chk-1.63
 CATEGORIES=	pkgtools
 MASTER_SITES=	# empty
 DISTFILES=	# empty
Index: files/pkg_chk.8
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_chk/files/pkg_chk.8,v
retrieving revision 1.13
diff -u -r1.13 pkg_chk.8
--- files/pkg_chk.8	30 Sep 2005 12:10:44 -0000	1.13
+++ files/pkg_chk.8	5 Dec 2005 22:03:52 -0000
@@ -10,7 +10,7 @@
 .Nd check, and optionally update, installed packages
 .Sh SYNOPSIS
 .Nm
-.Op Fl aBbcfhiklNnrsuv
+.Op Fl aBbcfhiklNnrsSuv
 .Op Fl C Ar conf
 .Op Fl D Ar tags
 .Op Fl L Ar file
@@ -126,6 +126,9 @@
 Recursively delete any mismatched packages found.
 Use with care, this does not record which packages were installed
 for later update.
+.It Fl S
+Create summary file of binary packages.  If you are using binary
+packages remotely, this file has to be created on the server.
 .It Fl s
 Building missing packages from source.
 If DEPENDS_TARGET=package is set in
Index: files/pkg_chk.sh
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_chk/files/pkg_chk.sh,v
retrieving revision 1.21
diff -u -r1.21 pkg_chk.sh
--- files/pkg_chk.sh	2 Oct 2005 02:05:29 -0000	1.21
+++ files/pkg_chk.sh	5 Dec 2005 22:03:52 -0000
@@ -5,10 +5,31 @@
 # TODO: Make -g check dependencies and tsort
 # TODO: Variation of -g which only lists top level packages
 # TODO: List top level packages installed but not in config
-# TODO: Generate list files so -u can work against a remote URL
 
 PATH=/usr/sbin:/usr/bin:${PATH}
 
+SUMMARY_FILE=pkg_chk-summary
+
+is_binary_available()
+    {
+    if [ -n "$PKGDB" ]; then
+	for iba_pkg in $PKGDB; do
+	    case $iba_pkg in
+		*:"$1")
+		    return 0;
+		;;
+	    esac
+        done
+	return 1;
+    else
+	if [ -f "$PACKAGES/$1.tgz" ]; then
+	    return 0;
+	else
+	    return 1;
+	fi
+    fi
+    }
+
 check_packages_installed()
     {
     MISSING_TODO=
@@ -37,7 +58,7 @@
 		msg_n "missing"
 		MISSING_TODO="$MISSING_TODO $PKGNAME $pkgdir"
 	    fi
-	    if [ -f $PACKAGES/$PKGNAME.tgz ] ;then
+	    if is_binary_available $PKGNAME ;then
 		msg_n " (binary package available)"
 	    fi
 	    msg
@@ -191,7 +212,7 @@
 get_build_ver()
     {
     if [ -n "$opt_b" -a -z "$opt_s" ] ; then
-	${PKG_INFO} -. -b $PACKAGES/$PKGNAME.tgz | tail +4 | ${SED} "s|^[^:]*/[^:]*:||" | ${GREP} .
+	${PKG_INFO} -. -q -b $PACKAGES/$PKGNAME.tgz | ${SED} "s|^[^:]*/[^:]*:||" | ${GREP} .
 	return
     fi
     files=""
@@ -227,7 +248,9 @@
 	if [ -z "$PKGNAME" ]; then
 	    continue
 	fi
-	if [ ! -f $PACKAGES/$PKGNAME.tgz ] ;then
+	if is_binary_available $PKGNAME; then
+	    :
+	else
 	    fatal_maybe " ** $PKGNAME - binary package missing"
 	    continue
 	fi
@@ -240,16 +263,20 @@
     while [ "$CHECKLIST" != ' ' ]; do
 	NEXTCHECK=' '
 	for pkg in $CHECKLIST ; do
-	    if [ ! -f $PACKAGES/$pkg.tgz ] ; then
+	    if is_binary_available $pkg; then
+		:
+	    else
 		fatal_maybe " ** $pkg.tgz - binary package dependency missing"
 		continue
 	    fi
-	    DEPLIST="$(${PKG_INFO} -. -N $PACKAGES/$pkg.tgz | ${SED} '1,/Built using:/d' | ${GREP} .. || true)"
+	    DEPLIST="$(${PKG_INFO} -. -q -N $PACKAGES/$pkg.tgz | ${GREP} .. || true)"
 	    if [ -z "$DEPLIST" ] ; then
 		PAIRLIST="${PAIRLIST}$pkg.tgz $pkg.tgz\n"
 	    fi
 	    for dep in $DEPLIST ; do
-		if [ ! -f $PACKAGES/$dep.tgz ] ; then
+		if is_binary_available $pkg; then
+		    :
+		else
 		    fatal_maybe " ** $dep.tgz - dependency missing for $pkg"
 		    break 2
 		fi
@@ -433,12 +460,11 @@
 
     if [ -d $PKG_DBDIR/$PKGNAME ];then
 	msg "$PKGNAME installed in previous stage"
-    elif [ -n "$opt_b" -a -f $PACKAGES/$PKGNAME.tgz ] ; then
+    elif [ -n "$opt_b" ] && is_binary_available $PKGNAME; then
 	if [ -n "$saved_PKG_PATH" ] ; then
 	    export PKG_PATH=$saved_PKG_PATH
 	fi
-	cd $PACKAGES
-	run_cmd "${PKG_ADD} $PKGNAME.tgz"
+	run_cmd "${PKG_ADD} $PACKAGES/$PKGNAME.tgz"
 	if [ -n "$saved_PKG_PATH" ] ; then
 	    unset PKG_PATH
 	fi
@@ -499,7 +525,8 @@
     {
     arg=$1
     case $arg in
-	/*)	echo $arg ;;
+	http://*|ftp://*|/*)">ftp://*|/*)">http://*|ftp://*|/*)
+		echo $arg ;;
 	*)	echo $basedir/$arg ;;
     esac
     }
@@ -528,6 +555,7 @@
 	-n	Display actions that would be taken, but do not perform them
 	-P dir  Set PACKAGES dir (overrides any other setting)
 	-r	Recursively remove mismatches (use with care) (implies -i)
+	-S	Create summary of binary packages
 	-s      Install packages by building from source
 	-U tags Comma separated list of pkgchk.conf tags to unset
 	-u      Update all mismatched packages (implies -i)
@@ -551,7 +579,7 @@
     fi
     }
 
-args=$(getopt BC:D:L:P:U:abcfghiklNnrsuv $*)
+args=$(getopt BC:D:L:P:U:abcfghiklNnrsSuv $*)
 if [ $? != 0 ]; then
     opt_h=1
 fi
@@ -575,6 +603,7 @@
 	-n )	opt_n=1 ;;
 	-P )	opt_P="$2" ; shift;;
 	-r )	opt_r=1 ; opt_i=1 ;;
+	-S )	opt_S=1 ;;
 	-s )	opt_s=1 ;;
 	-U )	opt_U="$2" ; shift;;
 	-u )	opt_u=1 ; opt_i=1 ;;
@@ -588,9 +617,9 @@
     opt_b=1; opt_s=1;
 fi
 
-if [ -z "$opt_a" -a -z "$opt_c" -a -z "$opt_g" -a -z "$opt_i" -a -z "$opt_N" -a -z "$opt_l" ];
+if [ -z "$opt_a" -a -z "$opt_c" -a -z "$opt_g" -a -z "$opt_i" -a -z "$opt_N" -a -z "$opt_l" -a -z "$opt_S" ];
 then
-    usage "Must specify at least one of -a, -c, -g, -i, -l, -N, or -u";
+    usage "Must specify at least one of -a, -c, -g, -i, -l, -N, -S, or -u";
 fi
 
 if [ -n "$opt_h" -o $# != 0 ];then
@@ -665,15 +694,27 @@
 	done
 fi
 
-if [ -n "$opt_b" -a -z "$opt_s" -a -d $PACKAGES ] ; then
-    msg_progress Scan $PACKAGES
-    cd $PACKAGES
-    for f in `ls -t *.tgz` ; do # Sort by time to pick up newest first
-	PKGDIR=`${PKG_INFO} -. -B $PACKAGES/$f|${AWK} -F= '$1=="PKGPATH"{print $2}'`
-	PKGNAME=`echo $f | ${SED} 's/\.tgz$//'`
-	PKGDB="${PKGDB} $PKGDIR:$PKGNAME"
-    done
-    PKGSRCDIR=NONE
+if [ -n "$opt_b" -o -n "$opt_S" -a -z "$opt_s" ] ; then
+    case $PACKAGES in
+	http://*|ftp://*)">ftp://*)">http://*|ftp://*)
+	    PKGDB=`ftp -o - $PACKAGES/$SUMMARY_FILE`;;
+	*)
+	    if [ -d "$PACKAGES" ] ; then
+		msg_progress Scan $PACKAGES
+		cd $PACKAGES
+		for f in `ls -t *.tgz` ; do # Sort by time to pick up newest first
+		    PKGDIR=`${PKG_INFO} -. -B $PACKAGES/$f|${AWK} -F= '$1=="PKGPATH"{print $2}'`
+		    PKGNAME=`echo $f | ${SED} 's/\.tgz$//'`
+		    PKGDB="${PKGDB} $PKGDIR:$PKGNAME"
+		done
+		PKGSRCDIR=NONE
+	    fi;;
+    esac
+fi
+
+if [ -n "$opt_S" ]; then
+    msg_progress "Write $PACKGES/$SUMMARY_FILE"
+    echo "$PKGDB" | tr ' ' '\012' > $PACKAGES/$SUMMARY_FILE
 fi
 
 if [ -n "$opt_g" ]; then

--LTeJQqWS0MN7I/qa--