Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 21 Jun 2012 20:03:20 +0100 (BST)
From:      Chris Rees <crees@FreeBSD.org>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   ports/169300: [PATCH] bsd.pkgng.mk Allow deinstall as user and make clean after non-root install
Message-ID:  <20120621190321.08D1FB0B9@pegasus.bayofrum.net>
Resent-Message-ID: <201206211910.q5LJA55a081935@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         169300
>Category:       ports
>Synopsis:       [PATCH] bsd.pkgng.mk Allow deinstall as user and make clean after non-root install
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 21 19:10:05 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator:     Chris Rees
>Release:        FreeBSD 9.0-RELEASE amd64
>Organization:
>Environment:
System: FreeBSD pegasus.bayofrum.net 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Sun Apr 29 12:29:02 BST 2012 root@pegasus.bayofrum.net:/usr/obj/usr/src/sys/PEGASUS amd64


	
>Description:
	If WITH_PKGNG is set in /etc/make.conf, the install sequence is changed to use pkgng.  The SUSEQ part works great while installing, but if the user is not root then deinstall does not work, and neither does a make clean after a make install.

	The former problem is solved as the current pkg_install deinstall target is implemented, but UID is not defined at the time, so it must be enumerated in the target rather than using a make .if construct.
>How-To-Repeat:
	% grep WITH_PKGNG /etc/make.conf
	WITH_PKGNG=	yes
	% cd /usr/ports/textproc/atom
	% make install
# Works great, performs su etc and installs

	% make clean
	===>  Cleaning for atom-1.0
	rm: /usr/obj/ports/usr/ports/textproc/atom/work/.metadir/+DESC: Permission denied
	rm: /usr/obj/ports/usr/ports/textproc/atom/work/.metadir/+MANIFEST: Permission denied
	rm: /usr/obj/ports/usr/ports/textproc/atom/work/.metadir/+MTREE_DIRS: Permission denied
	rm: /usr/obj/ports/usr/ports/textproc/atom/work/.metadir: Directory not empty
	rm: /usr/obj/ports/usr/ports/textproc/atom/work: Directory not empty
	*** Error code 1

	% make deinstall
	===>  Deinstalling for textproc/atom
	===>   Deinstalling atom-1.0
	pkg: deleting packages can only be done as root
	*** Error code 77
>Fix:

	Both problems solved here; feels a little clumsy adding another target before SUSEQ, but I don't see another clean method for creating METADIR before su.

--- bsd-pkgng-mk-allow-user-de-install.diff begins here ---
Index: bsd.port.mk
===================================================================
RCS file: /exports/cvsroot-freebsd/ports/Mk/bsd.port.mk,v
retrieving revision 1.725
diff -u -r1.725 bsd.port.mk
--- bsd.port.mk	6 Jun 2012 14:23:17 -0000	1.725
+++ bsd.port.mk	21 Jun 2012 18:51:46 -0000
@@ -3977,6 +3977,11 @@
 .endif
 .endif
 
+.if !target(create-metadir)
+create-metadir:
+	@${DO_NADA}
+.endif
+
 .if !target(check-umask)
 check-umask:
 	@if [ `${SH} -c umask` != 0022 ]; then \
@@ -4276,8 +4281,9 @@
 _BUILD_SEQ=		build-message pre-build pre-build-script do-build \
 				post-build post-build-script
 _INSTALL_DEP=	build
-_INSTALL_SEQ=	install-message check-install-conflicts run-depends lib-depends apply-slist pre-install \
-				pre-install-script generate-plist check-already-installed
+_INSTALL_SEQ=	install-message check-install-conflicts run-depends \
+				lib-depends apply-slist pre-install pre-install-script \
+				generate-plist check-already-installed create-metadir
 _INSTALL_SUSEQ= check-umask install-mtree pre-su-install \
 				pre-su-install-script create-users-groups do-install \
 				install-desktop-entries install-license install-rc-script \
Index: bsd.pkgng.mk
===================================================================
RCS file: /exports/cvsroot-freebsd/ports/Mk/bsd.pkgng.mk,v
retrieving revision 1.6
diff -u -r1.6 bsd.pkgng.mk
--- bsd.pkgng.mk	3 Jun 2012 14:49:52 -0000	1.6
+++ bsd.pkgng.mk	21 Jun 2012 18:49:33 -0000
@@ -27,6 +27,12 @@
 	fi
 
 
+# Create before SUSEQ, or make clean will fail unless root
+.if !target(create-metadir)
+create-metadir:
+	@${MKDIR} ${METADIR}
+.endif
+
 .if !target(fake-pkg)
 fake-pkg:
 .if !defined(NO_PKG_REGISTER)
@@ -263,15 +269,22 @@
 
 .if !target(deinstall)
 deinstall:
-	@${ECHO_MSG} "===>  Deinstalling for ${PKGORIGIN}"
-	@if ${PKG_INFO} -e ${PKGORIGIN}; then \
-		p=`${PKG_INFO} -q ${PKGORIGIN}`; \
-		${ECHO_MSG} "===>   Deinstalling $${p}"; \
-		${PKG_DELETE} -f ${PKGORIGIN} ; \
+	@if [ ${UID} != 0 ]; then \
+		${ECHO_MSG} "===> Switching to root credentials for '${.TARGET}' target" ; \
+		cd ${.CURDIR} && \
+			${SU_CMD} "${MAKE} ${.TARGET}"; \
+		${ECHO_MSG} "===> Returning to user credentials"; \
 	else \
-		${ECHO_MSG} "===>   ${PKGBASE} not installed, skipping"; \
+		${ECHO_MSG} "===>  Deinstalling for ${PKGORIGIN}"; \
+		if ${PKG_INFO} -e ${PKGORIGIN}; then \
+			p=`${PKG_INFO} -q ${PKGORIGIN}`; \
+			${ECHO_MSG} "===>   Deinstalling $${p}"; \
+			${PKG_DELETE} -f ${PKGORIGIN} ; \
+		else \
+			${ECHO_MSG} "===>   ${PKGBASE} not installed, skipping"; \
+		fi; \
+		${RM} -f ${INSTALL_COOKIE} ${PACKAGE_COOKIE}; \
 	fi
-	@${RM} -f ${INSTALL_COOKIE} ${PACKAGE_COOKIE}
 .endif
 
 .endif # defined(_POSTMKINCLUDED)
--- bsd-pkgng-mk-allow-user-de,install.diff ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120621190321.08D1FB0B9>