Subject: Re: Unpriviledged installs (was Re: CVS commit: sharesrc)
To: None <tech-install@netbsd.org>
From: Simon Burge <simonb@netbsd.org>
List: tech-install
Date: 08/16/1999 12:12:55
Simon Burge wrote:

> I think there's a slightly better way of doing this.  In bsd.README:
> 
> 	UNPRIVILEDGED   If defined, don't set the owner/group/mode when installing
> 			files or directories (incomplete).
> 
> and then in <bsd.own.mk>
> 
> 	.if defined(UNPRIVILEDGED)
> 	INSTPRIV?=      -U
> 	.endif
> 
> and use ${INSTPRIV} in the ${INSTALL} lines.  This was UNPRIVILEDGED can
> be used to tweak a class of things (mtree comes to mind - I'll look at
> that next).

How does the following look?  I've done a "make install" as me in
/usr/src/lib, and ok so far...  I'll commit this to the main line if
no-one has a problem with it (and I don't get any problems after the
world finishes building)...

Index: bsd.README
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/bsd.README,v
retrieving revision 1.51
diff -u -p -r1.51 bsd.README
--- bsd.README	1999/07/26 02:01:47	1.51
+++ bsd.README	1999/08/16 02:07:53
@@ -72,6 +72,9 @@ UPDATE 		If defined, 'make install' only
 		more recently modified in the source directories that their
 		installed counterparts.
 
+UNPRIVILEDGED	If defined, don't set the owner/group/mode when installing
+		files or directories (incomplete).
+
 MKCATPAGES	If "no", don't build or install the catman pages.
 
 MKDOC		If "no", don't build or install the documentation.
Index: bsd.doc.mk
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/bsd.doc.mk,v
retrieving revision 1.41
diff -u -p -r1.41 bsd.doc.mk
--- bsd.doc.mk	1999/02/12 01:10:06	1.41
+++ bsd.doc.mk	1999/08/16 02:07:53
@@ -61,8 +61,8 @@ ${DESTDIR}${DOCDIR}/${DIR}/${F}: .MADE
 
 .PRECIOUS: ${DESTDIR}${DOCDIR}/${DIR}/${F}
 ${DESTDIR}${DOCDIR}/${DIR}/${F}: ${F}
-	${INSTALL} ${RENAME} ${PRESERVE} -c -o ${DOCOWN} -g ${DOCGRP} \
-		-m ${DOCMODE} ${.ALLSRC} ${.TARGET}
+	${INSTALL} ${PRESERVE} ${INSTPRIV} -r -c -o ${DOCOWN} -g ${DOCGRP} \
+	    -m ${DOCMODE} ${.ALLSRC} ${.TARGET}
 .endfor
 .endif
 
Index: bsd.files.mk
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/bsd.files.mk,v
retrieving revision 1.8
diff -u -p -r1.8 bsd.files.mk
--- bsd.files.mk	1999/02/11 13:25:42	1.8
+++ bsd.files.mk	1999/08/16 02:07:53
@@ -31,8 +31,8 @@ ${DESTDIR}${FILESDIR_${F}}/${FILESNAME_$
 
 .PRECIOUS: ${DESTDIR}${FILESDIR_${F}}/${FILESNAME_${F}}
 ${DESTDIR}${FILESDIR_${F}}/${FILESNAME_${F}}: ${F}
-	${INSTALL} ${RENAME} ${PRESERVE} ${COPY} -o ${FILESOWN_${F}} \
-		-g ${FILESGRP_${F}} -m ${FILESMODE_${F}} ${.ALLSRC} ${.TARGET}
+	${INSTALL} ${PRESERVE} ${COPY} ${INSTPRIV} -r -o ${FILESOWN_${F}} \
+	    -g ${FILESGRP_${F}} -m ${FILESMODE_${F}} ${.ALLSRC} ${.TARGET}
 .endfor
 .endif
 
Index: bsd.inc.mk
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/bsd.inc.mk,v
retrieving revision 1.12
diff -u -p -r1.12 bsd.inc.mk
--- bsd.inc.mk	1999/02/04 11:58:30	1.12
+++ bsd.inc.mk	1999/08/16 02:07:53
@@ -13,10 +13,10 @@ incinstall:: ${DESTDIR}${INCSDIR}/$I
 .endif
 ${DESTDIR}${INCSDIR}/$I: $I
 	@cmp -s ${.ALLSRC} ${.TARGET} > /dev/null 2>&1 || \
-	    (echo "${INSTALL} ${RENAME} ${PRESERVE} -c -o ${BINOWN} \
+	    (echo "${INSTALL} ${PRESERVE} ${INSTPRIV} -r -c -o ${BINOWN} \
 		-g ${BINGRP} -m ${NONBINMODE} ${.ALLSRC} ${.TARGET}" && \
-	     ${INSTALL} ${RENAME} ${PRESERVE} -c -o ${BINOWN} -g ${BINGRP} \
-		-m ${NONBINMODE} ${.ALLSRC} ${.TARGET})
+	     ${INSTALL} ${PRESERVE} ${INSTPRIV} -r -c -o ${BINOWN} \
+		 -g ${BINGRP} -m ${NONBINMODE} ${.ALLSRC} ${.TARGET})
 .endfor
 .endif
 
Index: bsd.kinc.mk
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/bsd.kinc.mk,v
retrieving revision 1.5
diff -u -p -r1.5 bsd.kinc.mk
--- bsd.kinc.mk	1999/02/04 11:58:30	1.5
+++ bsd.kinc.mk	1999/08/16 02:07:54
@@ -70,7 +70,8 @@ ${DESTDIR}${INCSDIR}:
 	@if [ ! -d ${.TARGET} ] || [ -L ${.TARGET} ] ; then \
 		echo creating ${.TARGET}; \
 		/bin/rm -rf ${.TARGET}; \
-		${INSTALL} -d -o ${BINOWN} -g ${BINGRP} -m 755 ${.TARGET}; \
+		${INSTALL} ${INSTPRIV} -d -o ${BINOWN} -g ${BINGRP} -m 755 \
+		    ${.TARGET}; \
 	fi
 
 incinstall:: ${DESTDIR}${INCSDIR}
@@ -85,10 +86,10 @@ incinstall:: ${DESTDIR}${INCSDIR}/$I
 .endif
 ${DESTDIR}${INCSDIR}/$I: ${DESTDIR}${INCSDIR} $I 
 	@cmp -s ${.CURDIR}/$I ${.TARGET} > /dev/null 2>&1 || \
-	    (echo "${INSTALL} ${RENAME} ${PRESERVE} -c -o ${BINOWN} \
+	    (echo "${INSTALL} ${PRESERVE} ${INSTPRIV} -r -c -o ${BINOWN} \
 		-g ${BINGRP} -m ${NONBINMODE} ${.CURDIR}/$I ${.TARGET}" && \
-	     ${INSTALL} ${RENAME} ${PRESERVE} -c -o ${BINOWN} -g ${BINGRP} \
-		-m ${NONBINMODE} ${.CURDIR}/$I ${.TARGET})
+	     ${INSTALL} ${PRESERVE} ${INSTPRIV} -r -c -o ${BINOWN} \
+		-g ${BINGRP} -m ${NONBINMODE} ${.CURDIR}/$I ${.TARGET})
 .endfor
 .endif
 
@@ -102,9 +103,9 @@ incinstall:: ${DESTDIR}${INCSDIR}/$I
 .endif
 ${DESTDIR}${INCSDIR}/$I: ${DESTDIR}${INCSDIR} $I 
 	@cmp -s $I ${.TARGET} > /dev/null 2>&1 || \
-	    (echo "${INSTALL} ${RENAME} ${PRESERVE} -c -o ${BINOWN} \
-		-g ${BINGRP} -m ${NONBINMODE} $I ${.TARGET}" && \
-	     ${INSTALL} ${RENAME} ${PRESERVE} -c -o ${BINOWN} -g ${BINGRP} \
+	    (echo "${INSTALL} ${PRESERVE} -r -c -o ${BINOWN} -g ${BINGRP} \
+		-m ${NONBINMODE} $I ${.TARGET}" && \
+	     ${INSTALL} ${PRESERVE} -r -c -o ${BINOWN} -g ${BINGRP} \
 		-m ${NONBINMODE} $I ${.TARGET})
 .endfor
 .endif
Index: bsd.kmod.mk
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/bsd.kmod.mk,v
retrieving revision 1.30
diff -u -p -r1.30 bsd.kmod.mk
--- bsd.kmod.mk	1999/03/10 06:34:19	1.30
+++ bsd.kmod.mk	1999/08/16 02:07:54
@@ -68,8 +68,8 @@ ${DESTDIR}${KMODDIR}/${PROG}: .MADE
 
 .PRECIOUS: ${DESTDIR}${KMODDIR}/${PROG}
 ${DESTDIR}${KMODDIR}/${PROG}: ${PROG}
-	${INSTALL} ${RENAME} ${PRESERVE} ${COPY} -o ${KMODOWN} -g ${KMODGRP} \
-		-m ${KMODMODE} ${.ALLSRC} ${.TARGET}
+	${INSTALL} ${PRESERVE} ${COPY} ${INSTPRIV} -r -o ${KMODOWN} \
+	    -g ${KMODGRP} -m ${KMODMODE} ${.ALLSRC} ${.TARGET}
 .endif
 
 lint: ${LOBJS}
Index: bsd.lib.mk
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/bsd.lib.mk,v
retrieving revision 1.155
diff -u -p -r1.155 bsd.lib.mk
--- bsd.lib.mk	1999/07/14 20:18:07	1.155
+++ bsd.lib.mk	1999/08/16 02:07:54
@@ -252,8 +252,8 @@ __archivebuild: .USE
 	${RANLIB} ${.TARGET}
 
 __archiveinstall: .USE
-	${INSTALL} ${RENAME} ${PRESERVE} ${COPY} -o ${LIBOWN} -g ${LIBGRP} \
-		-m 600 ${.ALLSRC} ${.TARGET}
+	${INSTALL} ${PRESERVE} ${COPY} ${INSTPRIV} -r -o ${LIBOWN} \
+	    -g ${LIBGRP} -m 600 ${.ALLSRC} ${.TARGET}
 	${RANLIB} -t ${.TARGET}
 	chmod ${LIBMODE} ${.TARGET}
 
@@ -377,8 +377,8 @@ ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB
 
 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
 ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
-	${INSTALL} ${RENAME} ${PRESERVE} ${COPY} -o ${LIBOWN} -g ${LIBGRP} \
-		-m ${LIBMODE} ${.ALLSRC} ${.TARGET}
+	${INSTALL} ${PRESERVE} ${COPY} ${INSTPRIV} -r -o ${LIBOWN} \
+	    -g ${LIBGRP} -m ${LIBMODE} ${.ALLSRC} ${.TARGET}
 .if ${OBJECT_FMT} == "a.out" && !defined(DESTDIR)
 	/sbin/ldconfig -m ${LIBDIR}
 .endif
@@ -405,8 +405,8 @@ ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln:
 
 .PRECIOUS: ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln
 ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln: llib-l${LIB}.ln
-	${INSTALL} ${RENAME} ${PRESERVE} ${COPY} -o ${LIBOWN} -g ${LIBGRP} \
-		-m ${LIBMODE} ${.ALLSRC} ${DESTDIR}${LINTLIBDIR}
+	${INSTALL} ${PRESERVE} ${COPY} ${INSTPRIV} -r -o ${LIBOWN} \
+	    -g ${LIBGRP} -m ${LIBMODE} ${.ALLSRC} ${DESTDIR}${LINTLIBDIR}
 .endif
 .endif
 
Index: bsd.man.mk
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/bsd.man.mk,v
retrieving revision 1.46
diff -u -p -r1.46 bsd.man.mk
--- bsd.man.mk	1999/04/16 18:56:19	1.46
+++ bsd.man.mk	1999/08/16 02:07:54
@@ -48,8 +48,8 @@ MANPAGES=	${MAN}
 CATPAGES=	${MANPAGES:C/(.*).([1-9])/\1.cat\2/}
 .endif
 
-MINSTALL=	${INSTALL} ${RENAME} ${PRESERVE} ${COPY} -o ${MANOWN} \
-			-g ${MANGRP} -m ${MANMODE}
+MINSTALL=	${INSTALL} ${PRESERVE} ${COPY} ${INSTPRIV} -r -o ${MANOWN} \
+		    -g ${MANGRP} -m ${MANMODE}
 
 .if defined(MANZ)
 # chown and chmod are done afterward automatically
Index: bsd.nls.mk
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/bsd.nls.mk,v
retrieving revision 1.17
diff -u -p -r1.17 bsd.nls.mk
--- bsd.nls.mk	1999/02/12 12:38:45	1.17
+++ bsd.nls.mk	1999/08/16 02:07:54
@@ -51,9 +51,9 @@ ${DESTDIR}${NLSDIR}/${F:T:R}/${NLSNAME}.
 
 .PRECIOUS: ${DESTDIR}${NLSDIR}/${F:T:R}/${NLSNAME}.cat
 ${DESTDIR}${NLSDIR}/${F:T:R}/${NLSNAME}.cat: ${F}
-	${INSTALL} -d ${.TARGET:H}
-	${INSTALL} ${RENAME} ${PRESERVE} ${COPY} -o ${NLSOWN} -g ${NLSGRP} \
-		-m ${NLSMODE} ${.ALLSRC} ${.TARGET}
+	${INSTALL} ${INSTPRIV} -d -o ${NLSOWN} -g ${NLSGRP} ${.TARGET:H}
+	${INSTALL} ${PRESERVE} ${COPY} ${INSTPRIV} -r -o ${NLSOWN} \
+	    -g ${NLSGRP} -m ${NLSMODE} ${.ALLSRC} ${.TARGET}
 .endfor
 .else
 cleannls:
Index: bsd.own.mk
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/bsd.own.mk,v
retrieving revision 1.124
diff -u -p -r1.124 bsd.own.mk
--- bsd.own.mk	1999/07/05 09:13:04	1.124
+++ bsd.own.mk	1999/08/16 02:07:54
@@ -69,7 +69,9 @@ PRESERVE?=	-p
 .else
 PRESERVE?=
 .endif
-RENAME?=
+.if defined(UNPRIVILEDGED)
+INSTPRIV?=	-U
+.endif
 STRIPFLAG?=	-s
 
 # Define SYS_INCLUDE to indicate whether you want symbolic links to the system
Index: bsd.prog.mk
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/bsd.prog.mk,v
retrieving revision 1.101
diff -u -p -r1.101 bsd.prog.mk
--- bsd.prog.mk	1999/07/01 20:19:18	1.101
+++ bsd.prog.mk	1999/08/16 02:07:55
@@ -143,8 +143,8 @@ ${DESTDIR}${BINDIR}/${PROGNAME}: .MADE
 
 .PRECIOUS: ${DESTDIR}${BINDIR}/${PROGNAME}
 ${DESTDIR}${BINDIR}/${PROGNAME}: ${PROG}
-	${INSTALL} ${RENAME} ${PRESERVE} ${COPY} ${STRIPFLAG} -o ${BINOWN} \
-	    -g ${BINGRP} -m ${BINMODE} ${.ALLSRC} ${.TARGET}
+	${INSTALL} ${PRESERVE} ${COPY} ${STRIPFLAG} ${INSTPRIV} -r \
+	    -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} ${.ALLSRC} ${.TARGET}
 .endif
 
 .if !target(proginstall)
@@ -177,8 +177,8 @@ ${DESTDIR}${SCRIPTSDIR_${S}}/${SCRIPTSNA
 
 .PRECIOUS: ${DESTDIR}${SCRIPTSDIR_${S}}/${SCRIPTSNAME_${S}}
 ${DESTDIR}${SCRIPTSDIR_${S}}/${SCRIPTSNAME_${S}}: ${S}
-	${INSTALL} ${RENAME} ${PRESERVE} ${COPY} -o ${SCRIPTSOWN_${S}} -g \
-	    ${SCRIPTSGRP_${S}} -m ${SCRIPTSMODE_${S}} ${.ALLSRC} ${.TARGET}
+	${INSTALL} ${PRESERVE} ${COPY} ${INSTPRIV} -r -o ${SCRIPTSOWN_${S}} \
+	    -g ${SCRIPTSGRP_${S}} -m ${SCRIPTSMODE_${S}} ${.ALLSRC} ${.TARGET}
 .endfor
 .endif