[Midnightbsd-cvs] src [9379] trunk: Introduce a new option -DNO_ROOT that allows install and distribution
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat Mar 4 15:33:14 EST 2017
Revision: 9379
http://svnweb.midnightbsd.org/src/?rev=9379
Author: laffer1
Date: 2017-03-04 15:33:14 -0500 (Sat, 04 Mar 2017)
Log Message:
-----------
Introduce a new option -DNO_ROOT that allows install and distribution
targets to be run without root privilege.
Information about ownership, group, flags, and suid bits are stored in
the file specified by METALOG which defaults to ${DESTDIR}/METALOG.
This file can be used in conjunction with bsdtar or makefs to generate
archives or file system images with correct permissions.
Modified Paths:
--------------
trunk/Makefile.inc1
trunk/etc/Makefile
Modified: trunk/Makefile.inc1
===================================================================
--- trunk/Makefile.inc1 2017-03-04 20:27:37 UTC (rev 9378)
+++ trunk/Makefile.inc1 2017-03-04 20:33:14 UTC (rev 9379)
@@ -4,6 +4,8 @@
# Make command line options:
# -DNO_CLEANDIR run ${MAKE} clean, instead of ${MAKE} cleandir
# -DNO_CLEAN do not clean at all
+# -DDB_FROM_SRC use the user/group databases in src/etc instead of
+# the system database when installing.
# -DNO_SHARE do not go into share subdir
# -DKERNFAST define NO_KERNEL{CONFIG,CLEAN,DEPEND,OBJ}
# -DNO_KERNELCONFIG do not run config in ${MAKE} buildkernel
@@ -11,13 +13,14 @@
# -DNO_KERNELDEPEND do not run ${MAKE} depend in ${MAKE} buildkernel
# -DNO_KERNELOBJ do not run ${MAKE} obj in ${MAKE} buildkernel
# -DNO_PORTSUPDATE do not update ports in ${MAKE} update
+# -DNO_ROOT install without using root privilege
# -DNO_DOCUPDATE do not update doc in ${MAKE} update
-# -DDB_FROM_SRC use the user/group databases in src/etc instead of
-# the system database when installing.
# -DNO_CTF do not run the DTrace CTF conversion tools on built objects
# LOCAL_DIRS="list of dirs" to add additional dirs to the SUBDIR list
# LOCAL_MTREE="list of mtree files" to process to allow local directories
# to be created before files are installed
+# METALOG="path to metadata log" to write permission and ownership
+# when NO_ROOT is set. (default: ${DESTDIR}/METALOG)
# TARGET="machine" to crossbuild world for a different machine type
# TARGET_ARCH= may be required when a TARGET supports multiple endians
@@ -347,9 +350,20 @@
IMAKEENV+= PATH=${TMPPATH}:${INSTALLTMP}
.endif
.if defined(DB_FROM_SRC)
-IMAKE_INSTALL= INSTALL="install -N ${.CURDIR}/etc"
-IMAKE_MTREE= MTREE_CMD="nmtree -N ${.CURDIR}/etc"
+INSTALLFLAGS+= -N ${.CURDIR}/etc
+MTREEFLAGS+= -N ${.CURDIR}/etc
.endif
+.if defined(NO_ROOT)
+METALOG?= ${DESTDIR}/${DISTDIR}/METALOG
+IMAKE+= -DNO_ROOT METALOG=${METALOG}
+INSTALL_DDIR= ${DESTDIR}/${DISTDIR}
+INSTALLFLAGS+= -U -M ${METALOG} -D ${INSTALL_DDIR:S://:/:g:C:/$::}
+MTREEFLAGS+= -W
+.endif
+.if defined(DB_FROM_SRC) || defined(NO_ROOT)
+IMAKE_INSTALL= INSTALL="install ${INSTALLFLAGS}"
+IMAKE_MTREE= MTREE_CMD="nmtree ${MTREEFLAGS}"
+.endif
# kernel stage
KMAKEENV= ${WMAKEENV}
@@ -387,7 +401,7 @@
rm -f ${OBJTREE}${.CURDIR}/usr.bin/truss/ioctl.c
.endif
.for _dir in \
- lib usr legacy/usr legacy/usr/bin legacy/usr/sbin
+ lib usr legacy/bin legacy/usr legacy/usr/bin legacy/usr/sbin
mkdir -p ${WORLDTMP}/${_dir}
.endfor
mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \
@@ -653,7 +667,7 @@
.endif
ITOOLS= [ awk cap_mkdb cat chflags chmod chown \
- date echo egrep find grep ${_install-info} \
+ date echo egrep find grep id install ${_install-info} \
ln lockf make mkdir mtree ${_nmtree_itools} mv pwd_mkdb \
rm sed sh sysctl test true uname wc ${_zoneinfo}
@@ -676,6 +690,8 @@
EXTRA_DISTRIBUTIONS+= lib32
.endif
+MTREE_MAGIC?= mtree 2.0
+
distributeworld installworld: installcheck installcheck_UGID
mkdir -p ${INSTALLTMP}
progs=$$(for prog in ${ITOOLS}; do \
@@ -698,6 +714,9 @@
done); \
cp $$libs $$progs ${INSTALLTMP}
cp -R $${PATH_LOCALE:-"/usr/share/locale"} ${INSTALLTMP}/locale
+.if defined(NO_ROOT)
+ echo "#${MTREE_MAGIC}" > ${METALOG}
+.endif
.if make(distributeworld)
.for dist in ${EXTRA_DISTRIBUTIONS}
-mkdir ${DESTDIR}/${DISTDIR}/${dist}
@@ -707,10 +726,20 @@
-p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
-p ${DESTDIR}/${DISTDIR}/${dist}/usr/include >/dev/null
+.if defined(NO_ROOT)
+ ${IMAKEENV} nmtree -C -f ${.CURDIR}/etc/mtree/BSD.root.dist | \
+ sed -e 's#^\./#./${dist}/#' >> ${METALOG}
+ ${IMAKEENV} nmtree -C -f ${.CURDIR}/etc/mtree/BSD.usr.dist | \
+ sed -e 's#^\./#./${dist}/usr/#' >> ${METALOG}
+ ${IMAKEENV} nmtree -C -f ${.CURDIR}/etc/mtree/BSD.include.dist | \
+ sed -e 's#^\./#./${dist}/usr/include/#' >> ${METALOG}
+.endif
.endfor
-mkdir ${DESTDIR}/${DISTDIR}/base
- ${_+_}cd ${.CURDIR}; ${IMAKE} distrib-dirs \
- LOCAL_MTREE=${LOCAL_MTREE} DESTDIR=${DESTDIR}/${DISTDIR}/base
+ cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
+ METALOG=${METALOG} ${IMAKE_INSTALL} ${IMAKE_MTREE} \
+ DISTBASE=/base DESTDIR=${DESTDIR}/${DISTDIR}/base \
+ LOCAL_MTREE=${LOCAL_MTREE} distrib-dirs
.endif
${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}; \
${IMAKEENV} rm -rf ${INSTALLTMP}
@@ -718,12 +747,30 @@
.for dist in ${EXTRA_DISTRIBUTIONS}
find ${DESTDIR}/${DISTDIR}/${dist} -empty -delete
.endfor
+.if defined(NO_ROOT)
+.for dist in base ${EXTRA_DISTRIBUTIONS}
+ @# For each file that exists in this dist, print the corresponding
+ @# line from the METALOG. This relies on the fact that
+ @# a line containing only the filename will sort immediatly before
+ @# the relevant mtree line.
+ cd ${DESTDIR}/${DISTDIR}; \
+ find ./${dist} | sort -u ${METALOG} - | \
+ awk 'BEGIN { print "#${MTREE_MAGIC}" } !/ type=/ { file = $$1 } / type=/ { if ($$1 == file) { sub(/^\.\/${dist}\//, "./"); print } }' > \
+ ${DESTDIR}/${DISTDIR}/${dist}.meta
+.endfor
.endif
+.endif
packageworld:
.for dist in base ${EXTRA_DISTRIBUTIONS}
+.if defined(NO_ROOT)
${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
+ tar cvJf ${DESTDIR}/${DISTDIR}/${dist}.txz \
+ @${DESTDIR}/${DISTDIR}/${dist}.meta
+.else
+ ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \
tar cvJf ${DESTDIR}/${DISTDIR}/${dist}.txz .
+.endif
.endfor
#
@@ -760,7 +807,7 @@
distrib-dirs distribution:
cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} \
- ${IMAKE_INSTALL} ${IMAKE_MTREE} ${.TARGET}
+ ${IMAKE_INSTALL} ${IMAKE_MTREE} METALOG=${METALOG} ${.TARGET}
#
# buildkernel and installkernel
@@ -1114,6 +1161,7 @@
${_ar} \
${_dtc} \
${_awk} \
+ ${_cat} \
usr.bin/lorder \
usr.bin/makewhatis \
${_mklocale} \
@@ -1249,7 +1297,12 @@
# hierarchy - ensure that all the needed directories are present
#
hierarchy:
+.if defined(NO_ROOT)
+ cd ${.CURDIR}/etc; ${MAKE} LOCAL_MTREE=${LOCAL_MTREE} \
+ -DNO_ROOT METALOG=${METALOG} distrib-dirs
+.else
cd ${.CURDIR}/etc; ${MAKE} LOCAL_MTREE=${LOCAL_MTREE} distrib-dirs
+.endif
#
# libraries - build all libraries, and install them under ${DESTDIR}.
Modified: trunk/etc/Makefile
===================================================================
--- trunk/etc/Makefile 2017-03-04 20:27:37 UTC (rev 9378)
+++ trunk/etc/Makefile 2017-03-04 20:33:14 UTC (rev 9379)
@@ -151,6 +151,9 @@
# Special top level files for FreeBSD
FREEBSD=COPYRIGHT
+# Sanitize DESTDIR
+DESTDIR:= ${DESTDIR:C://*:/:g}
+
afterinstall:
.if ${MK_MAN} != "no"
${_+_}cd ${.CURDIR}/../share/man; ${MAKE} makedb
@@ -172,6 +175,10 @@
PWD_MKDB_ENDIAN?=
.endif
+.if defined(NO_ROOT)
+METALOG.add?= cat -l >> ${METALOG}
+.endif
+
distribution:
.if !defined(DESTDIR)
@echo "set DESTDIR before running \"make ${.TARGET}\""
@@ -198,6 +205,14 @@
.endif
pwd_mkdb ${PWD_MKDB_ENDIAN} -i -p -d ${DESTDIR}/etc \
${DESTDIR}/etc/master.passwd
+.if defined(NO_ROOT)
+ ( \
+ echo "./etc/login.conf.db type=file mode=0644 uname=root gname=wheel"; \
+ echo "./etc/passwd type=file mode=0644 uname=root gname=wheel"; \
+ echo "./etc/pwd.db type=file mode=0644 uname=root gname=wheel"; \
+ echo "./etc/spwd.db type=file mode=0600 uname=root gname=wheel"; \
+ ) | ${METALOG.add}
+.endif
.if ${MK_BLUETOOTH} != "no"
${_+_}cd ${.CURDIR}/bluetooth; ${MAKE} install
.endif
@@ -323,6 +338,21 @@
-f $$m -p $$d; \
${MTREE_CMD} -deU ${MTREE_FOLLOWS_SYMLINKS} -f $$m -p $$d; \
done; true
+.if defined(NO_ROOT)
+ @set ${MTREES}; \
+ while test $$# -ge 2; do \
+ m=${.CURDIR}/$$1; \
+ shift; \
+ d=$$1; \
+ test "$$d" == "/" && d=""; \
+ d=${DISTBASE}$$d; \
+ shift; \
+ ${ECHO} "${MTREE_CMD:N-W} -C -f $$m -K uname,gname | " \
+ "sed s#^\.#.$$d# | ${METALOG.add}" ; \
+ ${MTREE_CMD:N-W} -C -f $$m -K uname,gname | sed s#^\.#.$$d# | \
+ ${METALOG.add} ; \
+ done; true
+.endif
${INSTALL_SYMLINK} usr/src/sys ${DESTDIR}/sys
cd ${DESTDIR}/usr/share/man; \
for mandir in man*; do \
More information about the Midnightbsd-cvs
mailing list