Subject: Unprivileged builds
To: None <tech-pkg@NetBSD.org>
From: Julio M. Merino Vidal <jmmv84@gmail.com>
List: tech-pkg
Date: 05/28/2005 18:18:17
--=-nUmC55DYLiLxltRy5YpZ
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi all,

what about adding a PKGSRC_UNPRIVED variable to make it easy for end
users to use pkgsrc without root privileges?

The attached patch implements it, setting multiple variables to use the
current user/group pair and disables some features that may break
builds.  It also changes bootstrap to benefit from it.

Cheers,

-- 
Julio M. Merino Vidal <jmmv84@gmail.com>
http://www.livejournal.com/users/jmmv/
The NetBSD Project - http://www.NetBSD.org/

--=-nUmC55DYLiLxltRy5YpZ
Content-Disposition: attachment; filename=patch.diff
Content-Type: text/x-patch; name=patch.diff; charset=UTF-8
Content-Transfer-Encoding: 7bit

Index: bootstrap/bootstrap
===================================================================
RCS file: /cvsroot/pkgsrc/bootstrap/bootstrap,v
retrieving revision 1.37
diff -u -r1.37 bootstrap
--- bootstrap/bootstrap	14 May 2005 02:12:48 -0000	1.37
+++ bootstrap/bootstrap	28 May 2005 16:09:08 -0000
@@ -715,6 +715,10 @@
 # opsys specific fiddling
 opsys_finish
 
+if [ $ignoreusercheck = "yes" ]; then
+	echo "PKGSRC_UNPRIVED=yes" >> ${MKCONF_EXAMPLE}
+fi
+
 echo "" >> ${MKCONF_EXAMPLE}
 echo ".endif			# end pkgsrc settings" >> ${MKCONF_EXAMPLE}
 
Index: mk/bsd.pkg.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/bsd.pkg.mk,v
retrieving revision 1.1678
diff -u -r1.1678 bsd.pkg.mk
--- mk/bsd.pkg.mk	26 May 2005 11:15:30 -0000	1.1678
+++ mk/bsd.pkg.mk	28 May 2005 16:09:10 -0000
@@ -90,6 +90,28 @@
 SHLIB_HANDLING?=	YES	# do automatic shared lib handling
 CREATE_WRKDIR_SYMLINK?=	yes	# create a symlink to WRKOBJDIR
 
+##### Unprivileged builds
+
+.if defined(PKGSRC_UNPRIVED) && !empty(PKGSRC_UNPRIVED:M[Yy][Ee][Ss])
+ROOT_USER=		${PKGSRC_UNPRIVED_USER}
+ROOT_GROUP=		${PKGSRC_UNPRIVED_GROUP}
+
+BINOWN=			${PKGSRC_UNPRIVED_USER}
+BINGRP=			${PKGSRC_UNPRIVED_GROUP}
+GAMEOWN=		${PKGSRC_UNPRIVED_USER}
+GAMEGRP=		${PKGSRC_UNPRIVED_GROUP}
+MANOWN=			${PKGSRC_UNPRIVED_USER}
+MANGRP=			${PKGSRC_UNPRIVED_GROUP}
+SHAREOWN=		${PKGSRC_UNPRIVED_USER}
+SHAREGRP=		${PKGSRC_UNPRIVED_GROUP}
+
+NO_MTREE=		# defined
+SU_CMD=			${SH} -c
+PKG_CREATE_USERGROUP?=	NO
+PKG_DBDIR?=		${VARBASE}/db/pkg
+VARBASE?=		${PREFIX}/var
+.endif
+
 ##### Variant spellings
 
 .if defined(LICENCE) && !defined(LICENSE)
@@ -902,6 +924,18 @@
 
 .include "../../mk/wrapper/bsd.wrapper.mk"
 
+# Set default user/group values for unprivileged builds.  This needs to go
+# at this point because we need to run the 'id' command, defined by the
+# tools framework.
+.if defined(PKGSRC_UNPRIVED) && !empty(PKGSRC_UNPRIVED:M[Yy][Ee][Ss])
+.  if !defined(PKGSRC_UNPRIVED_USER) || empty(PKGSRC_UNPRIVED_USER)
+PKGSRC_UNPRIVED_USER!=	${ID} -n -u
+.  endif
+.  if !defined(PKGSRC_UNPRIVED_GROUP) || empty(PKGSRC_UNPRIVED_GROUP)
+PKGSRC_UNPRIVED_GROUP!=	${ID} -n -g
+.  endif
+.endif
+
 .if defined(RECOMMENDED)
 .  if !empty(IGNORE_RECOMMENDED:M[nN][oO])
 DEPENDS+=		${RECOMMENDED}

--=-nUmC55DYLiLxltRy5YpZ--