From 3baaafe11351dface3d1a25d02ecb6f2007a312a Mon Sep 17 00:00:00 2001 From: Dirk Vogt Date: Tue, 1 May 2012 16:32:15 +0200 Subject: [PATCH] When MKUNPRIV is set do not require root privilege --- etc/Makefile | 46 +++++++++++++++++++++++++--------------------- etc/mtree.sh | 27 ++++++++++++++++----------- 2 files changed, 41 insertions(+), 32 deletions(-) diff --git a/etc/Makefile b/etc/Makefile index 23e5eef8b..8fddd0b74 100644 --- a/etc/Makefile +++ b/etc/Makefile @@ -1,12 +1,14 @@ -ETC=/etc/ -USR=/usr/ -USRETC=/usr/etc/ -DEFAULTS=/etc/defaults +.include +ETC=${DESTDIR}/etc/ +USR=${DESTDIR}/usr/ +USRETC=${DESTDIR}/usr/etc/ +DEFAULTS=${ETC}/defaults # # FILES1 are installed in /etc *before* the tree hierarchy is created # and can therefore not rely on /etc/groups and /etc/passwd being # present. + FILES1=group hostname.file inet.conf motd.install mtab profile \ protocols rc services termcap utmp rc.cd \ syslog.conf rc.daemons.dist \ @@ -26,53 +28,55 @@ FILES3=daily dhcptags.conf rc DEFAULTFILES=rc.conf minix.rc.conf USRFILES=Makefile -TOOL_PWD_MKDB= pwd_mkdb +TOOL_PWD_MKDB?= pwd_mkdb clean:: -install:: installpw # installpw needed to bootstrap pw db +install: installpw # installpw needed to bootstrap pw db @echo "Installing /etc, /usr/etc and /usr/lib.." mkdir -p $(ETC) $(USRLIB) mkdir -p $(ETC)/devmand/scripts + @echo "Making hierarchy.." + sh mtree.sh mtree/minix.tree ${TOOL_AWK} ${TOOL_STAT} ${DESTDIR} ${MKUNPRIVED} @for f in $(FILES1); do if [ -f $(ETC)/$$f ]; then :; else cp $$f $(ETC)/$$f; chmod 755 $(ETC)/$$f; fi; done @for f in $(USRFILES); do cp usr/$$f $(USR)/$$f; chmod 644 $(USR)/$$f; done - @echo "Making hierarchy.." - sh mtree.sh mtree/minix.tree @for f in $(FILES3); do if [ -f $(USRETC)/$$f ]; then :; else cp usr/$$f $(USRETC); chmod 755 $(USRETC)/$$f; fi; done for f in $(DEFAULTFILES); do cp defaults/$$f $(DEFAULTS)/; chmod 644 $(DEFAULTS)/$$f; done @echo "Making devices.." - p=`pwd` && cd /dev && sh $$p/../commands/MAKEDEV/MAKEDEV.sh null - p=`pwd` && cd /dev && sh $$p/../commands/MAKEDEV/MAKEDEV.sh std 2>/dev/null - install -o root -g operator -m 755 crontab /usr/lib + if [ ${MKUNPRIVED} != yes ] ;then \ + cd ${DESTDIR}/dev && sh ${NETBSDSRCDIR}/commands/MAKEDEV/MAKEDEV.sh null ;\ + cd ${DESTDIR}/dev && sh ${NETBSDSRCDIR}/commands/MAKEDEV/MAKEDEV.sh std 2>/dev/null ;\ + fi + ${INSTALL_FILE} -o root -g operator -m 755 crontab ${DESTDIR}/usr/lib @echo "Making user homedirs.." - for u in /usr/ast ~root; do cp ast/.[aepv]* $$u ; done + for u in ${DESTDIR}/usr/ast ${DESTDIR}/root; do mkdir -p $$u; cp ast/.[aepv]* $$u ; done @echo "Installing fonts.." - install -m 644 -o root -g operator fonts/*.fnt /usr/lib/fonts/ + ${INSTALL_FILE} -m 644 -o root -g operator fonts/*.fnt ${DESTDIR}/usr/lib/fonts/ installforce:: $(ETC)/rc $(ETC)/rs.inet $(ETC)/rs.single $(ETC)/system.conf $(ETC)/rc.subr.minix $(USRETC)/rc $(USR)/Makefile installpw installpw:: if [ ! -d $(ETC) ]; then mkdir $(ETC); chmod 755 $(ETC); fi @for f in $(PWFILES); do if [ -f $(ETC)/$$f ]; then :; else cp $$f $(ETC)/$$f; chmod 600 $(ETC)/$$f; fi; done - touch /etc/pwd.db; touch /etc/spwd.db; ${TOOL_PWD_MKDB} -p -V 0 /etc/master.passwd + touch ${ETC}/pwd.db; touch ${ETC}/spwd.db; ${TOOL_PWD_MKDB} -d ${ETC}/.. -p -V 0 ${ETC}/master.passwd $(ETC)/rc: rc .PHONY - install -m 755 -o root -g operator $> $@ + ${INSTALL_FILE} -m 755 -o root -g operator $> $@ $(ETC)/rs.inet: rs.inet .PHONY - install -m 755 -o root -g operator $> $@ + ${INSTALL_FILE} -m 755 -o root -g operator $> $@ $(ETC)/rs.single: rs.single .PHONY - install -m 755 -o root -g operator $> $@ + ${INSTALL_FILE} -m 755 -o root -g operator $> $@ $(ETC)/system.conf: system.conf .PHONY - install -m 644 -o root -g operator $> $@ + ${INSTALL_FILE} -m 644 -o root -g operator $> $@ $(ETC)/rc.subr.minix: rc.subr.minix .PHONY - install -m 644 -o root -g operator $> $@ + ${INSTALL_FILE} -m 644 -o root -g operator $> $@ $(USRETC)/rc: usr/rc .PHONY - install -m 755 -o root -g operator $> $@ + ${INSTALL_FILE} -m 755 -o root -g operator $> $@ $(USR)/Makefile: usr/Makefile .PHONY - install -m 644 -o root -g operator $> $@ + ${INSTALL_FILE} -m 644 -o root -g operator $> $@ diff --git a/etc/mtree.sh b/etc/mtree.sh index 36e6767c8..0f38a8621 100755 --- a/etc/mtree.sh +++ b/etc/mtree.sh @@ -1,30 +1,35 @@ #!/bin/sh set -e -if [ $# -ne 1 ] -then echo "Usage: $0 mtreefile" +if [ $# -ne 5 ] +then echo "Usage: $0 mtreefile TOOL_AWK TOOL_STAT DEST_DIR UNPRIV" exit 1 fi +AWK=$2 +STAT=$3 +DESTDIR=$4 +UNPRIV=$5 cat "$1" | while read line do - NF="`echo $line | awk '{ print NF }'`" + NF="`echo $line | ${AWK} '{ print NF }'`" if [ $NF = 4 ] - then mode="`echo $line | awk '{ print $1 }'`" - owner="`echo $line | awk '{ print $2 }'`" - group="`echo $line | awk '{ print $3 }'`" - dir="`echo $line | awk '{ print $4 }'`" + then mode="`echo $line | ${AWK} '{ print $1 }'`" + owner="`echo $line | ${AWK} '{ print $2 }'`" + group="`echo $line | ${AWK} '{ print $3 }'`" + dir="${DESTDIR}`echo $line | ${AWK} '{ print $4 }'`" mkdir -p $dir - targetdev="`stat -f %d $dir/.`" + targetdev="`${STAT} -f %d $dir/.`" if [ $targetdev -lt 256 ] then echo "skipping non-dev $dir properties" - else chown $owner $dir + elif [ $UNPRIV != yes] + then chown $owner $dir chmod $mode $dir chgrp $group $dir fi elif [ $NF = 3 ] - then target="`echo $line | awk '{ print $3 }'`" - linkfile="`echo $line | awk '{ print $1 }'`" + then target="`echo $line | ${AWK} '{ print $3 }'`" + linkfile="${DESTDIR}`echo $line | ${AWK} '{ print $1 }'`" rm -f $linkfile ln -s $target $linkfile else echo odd line. -- 2.44.0