Subject: Re: pkg_install BIG problem
To: NetBSD Packages Technical Discussion List <tech-pkg@NetBSD.ORG>
From: Greg A. Woods <woods@weird.com>
List: tech-pkg
Date: 12/10/2004 13:57:41
[ On Friday, December 10, 2004 at 01:30:19 (-0600), Eric Haszlakiewicz wrote: ]
> Subject: Re: pkg_install BIG problem
>
> 	yes that works, but it has the unfortunate drawback that a binary
> package of pkg_install can't be created, thus making it more difficult 
> than necessary to update a machine w/o pkgsrc sources installed.  

A binary package of pkg_install _can_ be created, provided one is
willing to make this small adjustment to the pkgsrc Makefile:

Index: pkgtools/pkg_install/Makefile
===================================================================
RCS file: /cvs/master/m-NetBSD/main/pkgsrc/pkgtools/pkg_install/Makefile,v
retrieving revision 1.103
diff -u -r1.103 Makefile
--- pkgtools/pkg_install/Makefile	14 Aug 2004 02:33:51 -0000	1.103
+++ pkgtools/pkg_install/Makefile	28 Sep 2004 18:51:47 -0000
@@ -28,9 +28,10 @@
 NO_BUILDLINK=		# defined
 NO_CHECKSUM=		# defined
 NO_MTREE=		# defined
-NO_PKG_REGISTER=	# defined
-NO_PACKAGE=		Deinstallation is not permitted
+#NO_PKG_REGISTER=	# defined
+#NO_PACKAGE=		Deinstallation is not permitted
 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
@@ -56,28 +57,37 @@
 
 .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.
+#
+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"
 
 .include "../../pkgtools/libnbcompat/inplace.mk"
 .include "../../mk/bsd.pkg.mk"

There is no problem whatsoever any more with using the resulting binary
package -- it installs over top of the existing one just fine.

> 	As I understand it, the original reason for that flag was to
> keep packages from being deleted.  The better replacement for doing that
> is the PKG_PRESERVE flag.  As you discovered, it still has a few quirks
> to be ironed out. :)

Most of the wrinkles go away with this little INSTALL script:

#! /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


-- 
						Greg A. Woods

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