Subject: Re: pkg tools problem
To: Jeremy C. Reed <reed@reedmedia.net>
From: Greg A. Woods <woods@weird.com>
List: tech-pkg
Date: 02/10/2005 20:24:55
[ On Friday, February 4, 2005 at 15:40:26 (-0800), Jeremy C. Reed wrote: ]
> Subject: Re: pkg tools problem
>
> My own pkg_install/Makefile has:
> +# Removing this package would break pkgsrc, so allow this package to
> +# reinstall over itself.
> +# XXX need to figure out a way not to have multiple pkg entries for old ones.
> +FORCE_PKG_REGISTER=    # defined
> 
> This is messy because I end up with:
> 
> drwxr-xr-x  2 root root 4096 Apr  8  2004 /var/db/pkg/pkg_install-20040330
> drwxr-xr-x  2 root root 4096 Apr  9  2004 /var/db/pkg/pkg_install-20040409
> drwxr-xr-x  2 root root 4096 May 26  2004 /var/db/pkg/pkg_install-20040508
> drwxr-xr-x  2 root root 4096 Jul 22  2004 /var/db/pkg/pkg_install-20040508nb1
> drwxr-xr-x  2 root root 4096 Jul 22  2004 /var/db/pkg/pkg_install-20040508nb2
> drwxr-xr-x  2 root root 4096 Jan  7 10:02 /var/db/pkg/pkg_install-20050106

That's very easy to fix, even in a way that works properly with binary
packages:

Index: pkgtools/pkg_install/INSTALL
===================================================================
RCS file: pkgtools/pkg_install/INSTALL
diff -N pkgtools/pkg_install/INSTALL
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ pkgtools/pkg_install/INSTALL	25 Aug 2003 00:15:31 -0000
@@ -0,0 +1,22 @@
+#! /bin/sh
+# -*- sh -*-
+#
+#ident "@(#)$NetBSD"
+#
+
+# De-installation of this package is not (supposed to be) possible, so
+# to avoid confusion we just remove the record of previous installs
+# having been done.
+
+PKGNAME=$1
+STAGE=$2
+
+PKGBASE=${PKGNAME%-[0-9]*}
+
+: ${PKG_DBDIR:=/var/db/pkg}
+
+case ${STAGE} in
+PRE-INSTALL)
+	rm -rf ${PKG_DBDIR}/${PKGBASE}-[0-9]*
+	;;
+esac
Index: pkgtools/pkg_install/Makefile
===================================================================
RCS file: /cvs/master/m-NetBSD/main/pkgsrc/pkgtools/pkg_install/Makefile,v
retrieving revision 1.106
diff -u -r1.106 Makefile
--- pkgtools/pkg_install/Makefile	9 Dec 2004 21:29:06 -0000	1.106
+++ pkgtools/pkg_install/Makefile	11 Feb 2005 01:20:22 -0000
@@ -29,6 +29,7 @@
 NO_CHECKSUM=		# defined
 NO_MTREE=		# defined
 PKG_PRESERVE=		# defined
+FORCE_PKG_REGISTER=	YES
 
 # These are needed to solve a chicken-and-egg problem where pkgsrc uses
 # newer features of pkg_install, but older NetBSD installations won't
@@ -57,19 +58,34 @@
 
 .include "../../mk/bsd.prefs.mk"
 
+LOCALBASE:=		${PKG_TOOLS_BIN:C|/[^/]?bin$||}
+
 VERSION!=		${AWK} -F '"' '/PKGTOOLS_VERSION/ {print $$2}' \
 			${FILESDIR}/lib/version.h
 
 do-extract:
 	@${CP} -Rp ${FILESDIR} ${WRKSRC}
 
+# Note we need to run the INSTALL script as this doesn't happen
+# automagically from pkgsrc unless USE_PKGINSTALL=YES, but there's no
+# need for all that machinery in this simple case.
+#
+pre-install:
+	${SETENV} ${SCRIPTS_ENV} ${SHELL} ${INSTALL_FILE} ${PKGNAME} PRE-INSTALL
+
 post-install:
-	if [ ! -f ${PKG_DBDIR}/pkgdb.byfile.db ]; then			\
-		if [ ! -d ${PKG_DBDIR} ]; then				\
-			${INSTALL_DATA_DIR} ${PKG_DBDIR};		\
-		fi;							\
-		${PKG_ADMIN} rebuild;					\
+	@if [ ! -d ${PKG_DBDIR} ]; then				\
+		${ECHO} "${INSTALL_DATA_DIR} ${PKG_DBDIR}";	\
+		${INSTALL_DATA_DIR} ${PKG_DBDIR};		\
 	fi
+	${PKG_ADMIN} rebuild
+
+# Use the following to update these sources from -current
+#
+NBSRC =	/usr/src-current
+update-sources:
+	${SH} ../../pkgtools/libnbcompat/files/src2nbcompat ${NBSRC}/usr.sbin/pkg_install ${.CURDIR}/files
+	${ECHO} "Remember to fix files/lib/version.h"
 
 # XXX Reverse the order that update does things since
 # XXX we need pkg_delete built before we can deinstall.

-- 
						Greg A. Woods

H:+1 416 218-0098  W:+1 416 489-5852 x122  VE3TCP  RoboHack <woods@robohack.ca>
Planix, Inc. <woods@planix.com>          Secrets of the Weird <woods@weird.com>