Index: tools/tools/nanobsd/nanobsd.sh =================================================================== --- tools/tools/nanobsd/nanobsd.sh (revision 229271) +++ tools/tools/nanobsd/nanobsd.sh (working copy) @@ -58,7 +58,7 @@ #NANO_DISKIMGDIR="" # Parallel Make -NANO_PMAKE="make -j 3" +NANO_PMAKE="make" # The default name for any image we create. NANO_IMGNAME="_.disk.full" @@ -76,7 +76,7 @@ NANO_KERNEL=GENERIC # Kernel modules to build; default is none -NANO_MODULES= +NANO_MODULES="" # Customize commands. NANO_CUSTOMIZE="" @@ -146,12 +146,14 @@ NANO_LABEL="" ####################################################################### -# Architecture to build. Corresponds to TARGET_ARCH in a buildworld. -# Unfortunately, there's no way to set TARGET at this time, and it -# conflates the two, so architectures where TARGET != TARGET_ARCH do -# not work. This defaults to the arch of the current machine. +# Architecture to build. Corresponds to TARGET:TARGET_ARCH in +# buildworld. +# This defaults to the architecture and processor of the current machine. +# +# This accepts just the architecture though (for select architectures like +# amd64, i386, etc where there isn't a different processor). -NANO_ARCH=`uname -p` +: ${NANO_ARCH=$(uname -m):$(uname -p)} # Directory to populate /cfg from NANO_CFGDIR="" @@ -159,6 +161,16 @@ # Directory to populate /data from NANO_DATADIR="" +# src.conf to use when building the image. Defaults to /dev/null for the sake +# of determinism. +SRCCONF=${SRCCONF:=/dev/null} + +# Where to put the obj files. Defaults to /usr/obj. +MAKEOBJDIRPREFIX=/usr/obj + +# Files to exclude via find(1) +NANO_IGNORE_FILES_EXPR='/(CVS|\.git|\.svn)' + ####################################################################### # # The functions which do the real work. @@ -182,7 +194,6 @@ echo "${CONF_WORLD}" > ${NANO_MAKE_CONF_BUILD} echo "${CONF_BUILD}" >> ${NANO_MAKE_CONF_BUILD} - echo "SRCCONF=/dev/null" >> ${NANO_MAKE_CONF_BUILD} ) build_world ( ) ( @@ -190,7 +201,11 @@ pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bw" cd ${NANO_SRC} - env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} \ + env \ + TARGET=${NANO_ARCH%:*} \ + TARGET_ARCH=${NANO_ARCH##*:} \ + ${NANO_PMAKE} \ + SRCCONF=${SRCCONF} \ __MAKE_CONF=${NANO_MAKE_CONF_BUILD} buildworld \ > ${MAKEOBJDIRPREFIX}/_.bw 2>&1 ) @@ -214,10 +229,16 @@ unset TARGET_BIG_ENDIAN # Note: We intentionally build all modules, not only the ones in # NANO_MODULES so the built world can be reused by multiple images. - env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} buildkernel \ + env \ + TARGET=${NANO_ARCH%:*} \ + TARGET_ARCH=${NANO_ARCH##*:} \ + ${NANO_PMAKE} \ + buildkernel \ + ${kernconfdir:+"KERNCONFDIR="}${kernconfdir} \ + KERNCONF=${kernconf} \ + MODULES_OVERRIDE="${NANO_MODULES}" \ + SRCCONF=${SRCCONF} \ __MAKE_CONF=${NANO_MAKE_CONF_BUILD} \ - ${kernconfdir:+"KERNCONFDIR="}${kernconfdir} \ - KERNCONF=${kernconf} ) > ${MAKEOBJDIRPREFIX}/_.bk 2>&1 ) @@ -245,7 +266,6 @@ echo "${CONF_WORLD}" > ${NANO_MAKE_CONF_INSTALL} echo "${CONF_INSTALL}" >> ${NANO_MAKE_CONF_INSTALL} - echo "SRCCONF=/dev/null" >> ${NANO_MAKE_CONF_INSTALL} ) install_world ( ) ( @@ -253,9 +273,14 @@ pprint 3 "log: ${NANO_OBJ}/_.iw" cd ${NANO_SRC} - env TARGET_ARCH=${NANO_ARCH} \ - ${NANO_PMAKE} __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} installworld \ + env \ + TARGET=${NANO_ARCH%:*} \ + TARGET_ARCH=${NANO_ARCH##*:} \ + ${NANO_PMAKE} \ + installworld \ DESTDIR=${NANO_WORLDDIR} \ + SRCCONF=${SRCCONF} \ + __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} \ > ${NANO_OBJ}/_.iw 2>&1 chflags -R noschg ${NANO_WORLDDIR} ) @@ -266,9 +291,14 @@ pprint 3 "log: ${NANO_OBJ}/_.etc" cd ${NANO_SRC} - env TARGET_ARCH=${NANO_ARCH} \ - ${NANO_PMAKE} __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} distribution \ + env \ + TARGET=${NANO_ARCH%:*} \ + TARGET_ARCH=${NANO_ARCH##*:} \ + ${NANO_PMAKE} \ + distribution \ DESTDIR=${NANO_WORLDDIR} \ + SRCCONF=${SRCCONF} \ + __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} \ > ${NANO_OBJ}/_.etc 2>&1 # make.conf doesn't get created by default, but some ports need it # so they can spam it. @@ -288,36 +318,53 @@ fi cd ${NANO_SRC} - env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} installkernel \ + env \ + TARGET=${NANO_ARCH%:*} \ + TARGET_ARCH=${NANO_ARCH##*:} \ + ${NANO_PMAKE} \ + installkernel \ DESTDIR=${NANO_WORLDDIR} \ - __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} \ ${kernconfdir:+"KERNCONFDIR="}${kernconfdir} \ KERNCONF=${kernconf} \ MODULES_OVERRIDE="${NANO_MODULES}" + SRCCONF=${SRCCONF} \ + __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} \ ) > ${NANO_OBJ}/_.ik 2>&1 ) run_customize() ( pprint 2 "run customize scripts" - for c in $NANO_CUSTOMIZE + set -- $NANO_CUSTOMIZE + i=1 + num_steps=$# + while [ $i -le $num_steps ] do - pprint 2 "customize \"$c\"" + c=$1 + pprint 2 "[$i/$num_steps] customize \"$c\"" pprint 3 "log: ${NANO_OBJ}/_.cust.$c" pprint 4 "`type $c`" ( set -x ; $c ) > ${NANO_OBJ}/_.cust.$c 2>&1 + shift + : $(( i += 1 )) done ) run_late_customize() ( pprint 2 "run late customize scripts" - for c in $NANO_LATE_CUSTOMIZE + set -- $NANO_LATE_CUSTOMIZE + i=1 + num_steps=$# + while [ $i -le $num_steps ] do - pprint 2 "late customize \"$c\"" + c=$1 + pprint 2 "[$i/$num_steps] late customize \"$c\"" pprint 3 "log: ${NANO_OBJ}/_.late_cust.$c" pprint 4 "`type $c`" ( set -x ; $c ) > ${NANO_OBJ}/_.late_cust.$c 2>&1 + shift + : $(( i += 1 )) done ) @@ -335,7 +382,7 @@ ( mkdir -p etc/local cd usr/local/etc - find . -print | cpio -dumpl ../../../etc/local + find . | cpio -R root:wheel -dumpl ../../../etc/local cd .. rm -rf etc ln -s ../../etc/local etc @@ -349,7 +396,7 @@ # the files in /$d will be hidden by the mount. # XXX: configure /$d ramdisk size mkdir -p conf/base/$d conf/default/$d - find $d -print | cpio -dumpl conf/base/ + find $d | cpio -R root:wheel -dumpl conf/base/ done echo "$NANO_RAM_ETCSIZE" > conf/base/etc/md_size @@ -359,8 +406,8 @@ echo "mount -o ro /dev/${NANO_DRIVE}s3" > conf/default/etc/remount # Put /tmp on the /var ramdisk (could be symlink already) - rmdir tmp || true - rm tmp || true + rm -f tmp || : + rm -Rf tmp ln -s var/tmp tmp ) > ${NANO_OBJ}/_.dl 2>&1 @@ -390,7 +437,7 @@ prune_usr() ( # Remove all empty directories in /usr - find ${NANO_WORLDDIR}/usr -type d -depth -print | + find ${NANO_WORLDDIR}/usr -type d -depth | while read d do rmdir $d > /dev/null 2>&1 || true @@ -418,7 +465,7 @@ echo "Creating ${dev} with ${dir} (mounting on ${mnt})" newfs_part $dev $mnt $lbl cd ${dir} - find . -print | grep -Ev '/(CVS|\.svn)' | cpio -dumpv ${mnt} + find . \! -regex "$NANO_IGNORE_FILES_EXPR" | cpio -R root:wheel -dumpv ${mnt} df -i ${mnt} umount ${mnt} ) @@ -588,6 +635,8 @@ # after the build completed, for instance to copy the finished # image to a more convenient place: # cp ${NANO_DISKIMGDIR}/_.disk.image /home/ftp/pub/nanobsd.disk + # The following line is needed to keep bash from barfing on the file. + : ) ####################################################################### @@ -676,7 +725,8 @@ cust_install_files () ( cd ${NANO_TOOLS}/Files - find . -print | grep -Ev '/(CVS|\.svn)' | cpio -Ldumpv ${NANO_WORLDDIR} + find . \! -regex "${NANO_IGNORE_FILES_EXPR}" | \ + cpio -R root:wheel -Ldumpv ${NANO_WORLDDIR} ) ####################################################################### @@ -694,8 +744,8 @@ mkdir -p ${NANO_WORLDDIR}/Pkg ( cd ${NANO_PACKAGE_DIR} - find ${NANO_PACKAGE_LIST} -print | - cpio -Ldumpv ${NANO_WORLDDIR}/Pkg + find ${NANO_PACKAGE_LIST} | \ + cpio -R root:wheel -Ldumpv ${NANO_WORLDDIR}/Pkg ) # Count & report how many we have to install @@ -758,105 +808,112 @@ # Progress Print # Print $2 at level $1. pprint() { - if [ "$1" -le $PPLEVEL ]; then - runtime=$(( `date +%s` - $NANO_STARTTIME )) - printf "%s %.${1}s %s\n" "`date -u -r $runtime +%H:%M:%S`" "#####" "$2" 1>&3 - fi + if [ "$1" -le $PPLEVEL ]; then + runtime=$(( $(date +'%s') - ${NANO_STARTTIME} )) + printf "%s %.${1}s %s\n" "$(date -u -r $runtime +%H:%M:%S)" "#####" "$2" >&3 + fi } usage () { - ( - echo "Usage: $0 [-bfiknqvw] [-c config_file]" - echo " -b suppress builds (both kernel and world)" - echo " -f suppress code slice extraction" - echo " -i suppress disk image build" - echo " -k suppress buildkernel" - echo " -n add -DNO_CLEAN to buildworld, buildkernel, etc" - echo " -q make output more quiet" - echo " -v make output more verbose" - echo " -w suppress buildworld" - echo " -c specify config file" - ) 1>&2 + cat >&2 <