Date: Tue, 30 Jun 2009 09:20:43 +0000 (UTC) From: Nick Hibma <n_hibma@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org Subject: svn commit: r195184 - stable/7/tools/tools/nanobsd Message-ID: <200906300920.n5U9KhHB073782@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: n_hibma Date: Tue Jun 30 09:20:43 2009 New Revision: 195184 URL: http://svn.freebsd.org/changeset/base/195184 Log: MFC all changes up to 194958: 194288: Fix NanoBSD when the data partition size is defined as a negative number. 194431: Allow building world into a separate dir (for reuse in multiple images). 194437: Reverse some stuff I accidentally committed in the previous commit. 194440: Cleanups. 194958: Make pprint print through fd 3 so pprint can be used in customise functions. Prefix each log line with the running time. Modified: stable/7/tools/tools/nanobsd/nanobsd.sh (contents, props changed) Modified: stable/7/tools/tools/nanobsd/nanobsd.sh ============================================================================== --- stable/7/tools/tools/nanobsd/nanobsd.sh Tue Jun 30 09:14:09 2009 (r195183) +++ stable/7/tools/tools/nanobsd/nanobsd.sh Tue Jun 30 09:20:43 2009 (r195184) @@ -51,7 +51,6 @@ NANO_PACKAGE_LIST="*" # Object tree directory # default is subdir of /usr/obj -# XXX: MAKEOBJDIRPREFIX handling... ? #NANO_OBJ="" # The directory to put the final images @@ -147,21 +146,19 @@ NANO_ARCH=i386 clean_build ( ) ( pprint 2 "Clean and create object directory (${MAKEOBJDIRPREFIX})" - if rm -rf ${MAKEOBJDIRPREFIX} > /dev/null 2>&1 ; then - true - else + if ! rm -rf ${MAKEOBJDIRPREFIX} > /dev/null 2>&1 ; then chflags -R noschg ${MAKEOBJDIRPREFIX} - rm -rf ${MAKEOBJDIRPREFIX} + rm -r ${MAKEOBJDIRPREFIX} fi mkdir -p ${MAKEOBJDIRPREFIX} printenv > ${MAKEOBJDIRPREFIX}/_.env ) make_conf_build ( ) ( - pprint 2 "Construct build make.conf ($NANO_MAKE_CONF)" + pprint 2 "Construct build make.conf ($NANO_MAKE_CONF_BUILD)" - echo "${CONF_WORLD}" > ${NANO_MAKE_CONF} - echo "${CONF_BUILD}" >> ${NANO_MAKE_CONF} + echo "${CONF_WORLD}" > ${NANO_MAKE_CONF_BUILD} + echo "${CONF_BUILD}" >> ${NANO_MAKE_CONF_BUILD} ) build_world ( ) ( @@ -170,7 +167,7 @@ build_world ( ) ( cd ${NANO_SRC} env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} \ - __MAKE_CONF=${NANO_MAKE_CONF} buildworld \ + __MAKE_CONF=${NANO_MAKE_CONF_BUILD} buildworld \ > ${MAKEOBJDIRPREFIX}/_.bw 2>&1 ) @@ -188,62 +185,70 @@ build_kernel ( ) ( unset TARGET_CPUTYPE unset TARGET_BIG_ENDIAN env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} buildkernel \ - __MAKE_CONF=${NANO_MAKE_CONF} KERNCONF=`basename ${NANO_KERNEL}` \ + __MAKE_CONF=${NANO_MAKE_CONF_BUILD} KERNCONF=`basename ${NANO_KERNEL}` \ > ${MAKEOBJDIRPREFIX}/_.bk 2>&1 ) ) clean_world ( ) ( - pprint 2 "Clean and create world directory (${NANO_WORLDDIR})" - if rm -rf ${NANO_WORLDDIR}/ > /dev/null 2>&1 ; then - true + if [ "${NANO_OBJ}" != "${MAKEOBJDIRPREFIX}" ]; then + pprint 2 "Clean and create object directory (${NANO_OBJ})" + if ! rm -rf ${NANO_OBJ} > /dev/null 2>&1 ; then + chflags -R noschg ${NANO_OBJ} + rm -r ${NANO_OBJ} + fi + mkdir -p ${NANO_OBJ} ${NANO_WORLDDIR} + printenv > ${NANO_OBJ}/_.env else - chflags -R noschg ${NANO_WORLDDIR}/ - rm -rf ${NANO_WORLDDIR}/ + pprint 2 "Clean and create world directory (${NANO_WORLDDIR})" + if ! rm -rf ${NANO_WORLDDIR}/ > /dev/null 2>&1 ; then + chflags -R noschg ${NANO_WORLDDIR} + rm -rf ${NANO_WORLDDIR} + fi + mkdir -p ${NANO_WORLDDIR} fi - mkdir -p ${NANO_WORLDDIR}/ ) make_conf_install ( ) ( - pprint 2 "Construct install make.conf ($NANO_MAKE_CONF)" + pprint 2 "Construct install make.conf ($NANO_MAKE_CONF_INSTALL)" - echo "${CONF_WORLD}" > ${NANO_MAKE_CONF} - echo "${CONF_INSTALL}" >> ${NANO_MAKE_CONF} + echo "${CONF_WORLD}" > ${NANO_MAKE_CONF_INSTALL} + echo "${CONF_INSTALL}" >> ${NANO_MAKE_CONF_INSTALL} ) install_world ( ) ( pprint 2 "installworld" - pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.iw" + pprint 3 "log: ${NANO_OBJ}/_.iw" cd ${NANO_SRC} env TARGET_ARCH=${NANO_ARCH} \ - ${NANO_PMAKE} __MAKE_CONF=${NANO_MAKE_CONF} installworld \ + ${NANO_PMAKE} __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} installworld \ DESTDIR=${NANO_WORLDDIR} \ - > ${MAKEOBJDIRPREFIX}/_.iw 2>&1 + > ${NANO_OBJ}/_.iw 2>&1 chflags -R noschg ${NANO_WORLDDIR} ) install_etc ( ) ( pprint 2 "install /etc" - pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.etc" + pprint 3 "log: ${NANO_OBJ}/_.etc" cd ${NANO_SRC} env TARGET_ARCH=${NANO_ARCH} \ - ${NANO_PMAKE} __MAKE_CONF=${NANO_MAKE_CONF} distribution \ + ${NANO_PMAKE} __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} distribution \ DESTDIR=${NANO_WORLDDIR} \ - > ${MAKEOBJDIRPREFIX}/_.etc 2>&1 + > ${NANO_OBJ}/_.etc 2>&1 ) install_kernel ( ) ( pprint 2 "install kernel" - pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.ik" + pprint 3 "log: ${NANO_OBJ}/_.ik" cd ${NANO_SRC} env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} installkernel \ DESTDIR=${NANO_WORLDDIR} \ - __MAKE_CONF=${NANO_MAKE_CONF} KERNCONF=`basename ${NANO_KERNEL}` \ - > ${MAKEOBJDIRPREFIX}/_.ik 2>&1 + __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} KERNCONF=`basename ${NANO_KERNEL}` \ + > ${NANO_OBJ}/_.ik 2>&1 ) run_customize() ( @@ -252,9 +257,9 @@ run_customize() ( for c in $NANO_CUSTOMIZE do pprint 2 "customize \"$c\"" - pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.cust.$c" + pprint 3 "log: ${NANO_OBJ}/_.cust.$c" pprint 4 "`type $c`" - ( $c ) > ${MAKEOBJDIRPREFIX}/_.cust.$c 2>&1 + ( $c ) > ${NANO_OBJ}/_.cust.$c 2>&1 done ) @@ -264,15 +269,15 @@ run_late_customize() ( for c in $NANO_LATE_CUSTOMIZE do pprint 2 "late customize \"$c\"" - pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.late_cust.$c" + pprint 3 "log: ${NANO_OBJ}/_.late_cust.$c" pprint 4 "`type $c`" - ( $c ) > ${MAKEOBJDIRPREFIX}/_.late_cust.$c 2>&1 + ( $c ) > ${NANO_OBJ}/_.late_cust.$c 2>&1 done ) setup_nanobsd ( ) ( pprint 2 "configure nanobsd setup" - pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.dl" + pprint 3 "log: ${NANO_OBJ}/_.dl" ( cd ${NANO_WORLDDIR} @@ -312,7 +317,7 @@ setup_nanobsd ( ) ( rm tmp || true ln -s var/tmp tmp - ) > ${MAKEOBJDIRPREFIX}/_.dl 2>&1 + ) > ${NANO_OBJ}/_.dl 2>&1 ) setup_nanobsd_etc ( ) ( @@ -348,7 +353,7 @@ prune_usr() ( create_i386_diskimage ( ) ( pprint 2 "build diskimage" - pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.di" + pprint 3 "log: ${NANO_OBJ}/_.di" ( echo $NANO_MEDIASIZE $NANO_IMAGES \ @@ -417,10 +422,10 @@ create_i386_diskimage ( ) ( # for booting the image from a USB device to work. print "a 1" } - ' > ${MAKEOBJDIRPREFIX}/_.fdisk + ' > ${NANO_OBJ}/_.fdisk IMG=${NANO_DISKIMGDIR}/${NANO_IMGNAME} - MNT=${MAKEOBJDIRPREFIX}/_.mnt + MNT=${NANO_OBJ}/_.mnt mkdir -p ${MNT} if [ "${NANO_MD_BACKING}" = "swap" ] ; then @@ -436,7 +441,7 @@ create_i386_diskimage ( ) ( trap "df -i ${MNT} ; umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT - fdisk -i -f ${MAKEOBJDIRPREFIX}/_.fdisk ${MD} + fdisk -i -f ${NANO_OBJ}/_.fdisk ${MD} fdisk ${MD} # XXX: params # XXX: pick up cached boot* files, they may not be in image anymore. @@ -452,8 +457,8 @@ create_i386_diskimage ( ) ( ( cd ${NANO_WORLDDIR} && find . -print | cpio -dump ${MNT} ) df -i ${MNT} echo "Generating mtree..." - ( cd ${MNT} && mtree -c ) > ${MAKEOBJDIRPREFIX}/_.mtree - ( cd ${MNT} && du -k ) > ${MAKEOBJDIRPREFIX}/_.du + ( cd ${MNT} && mtree -c ) > ${NANO_OBJ}/_.mtree + ( cd ${MNT} && du -k ) > ${NANO_OBJ}/_.du umount ${MNT} if [ $NANO_IMAGES -gt 1 -a $NANO_INIT_IMG2 -gt 0 ] ; then @@ -466,7 +471,6 @@ create_i386_diskimage ( ) ( sed -i "" "s/${NANO_DRIVE}s1/${NANO_DRIVE}s2/g" $f done umount ${MNT} - fi # Create Config slice @@ -480,21 +484,21 @@ create_i386_diskimage ( ) ( fi if [ "${NANO_MD_BACKING}" = "swap" ] ; then - echo "Writing out _.disk.full..." + echo "Writing out ${NANO_IMGNAME}..." dd if=/dev/${MD} of=${IMG} bs=64k fi echo "Writing out _.disk.image..." dd if=/dev/${MD}s1 of=${NANO_DISKIMGDIR}/_.disk.image bs=64k mdconfig -d -u $MD - ) > ${MAKEOBJDIRPREFIX}/_.di 2>&1 + ) > ${NANO_OBJ}/_.di 2>&1 ) last_orders () ( # Redefine this function with any last orders you may have # after the build completed, for instance to copy the finished # image to a more convenient place: - # cp ${MAKEOBJDIRPREFIX}/_.disk.image /home/ftp/pub/nanobsd.disk + # cp ${NANO_DISKIMGDIR}/_.disk.image /home/ftp/pub/nanobsd.disk ) ####################################################################### @@ -660,7 +664,8 @@ late_customize_cmd () { # Print $2 at level $1. pprint() { if [ "$1" -le $PPLEVEL ]; then - printf "%.${1}s %s\n" "#####" "$2" + runtime=$(( `date +%s` - $NANO_STARTTIME )) + printf "%s %.${1}s %s\n" "`date -u -r $runtime +%H:%M:%S`" "#####" "$2" 1>&3 fi } @@ -751,19 +756,13 @@ fi ####################################################################### # Setup and Export Internal variables # -if [ "x${NANO_OBJ}" = "x" ] ; then - MAKEOBJDIRPREFIX=/usr/obj/nanobsd.${NANO_NAME}/ - NANO_OBJ=${MAKEOBJDIRPREFIX} -else - MAKEOBJDIRPREFIX=${NANO_OBJ} -fi - -if [ "x${NANO_DISKIMGDIR}" = "x" ] ; then - NANO_DISKIMGDIR=${MAKEOBJDIRPREFIX} -fi - -NANO_WORLDDIR=${MAKEOBJDIRPREFIX}/_.w -NANO_MAKE_CONF=${MAKEOBJDIRPREFIX}/make.conf +test -n "${NANO_OBJ}" || NANO_OBJ=/usr/obj/nanobsd.${NANO_NAME}/ +test -n "${MAKEOBJDIRPREFIX}" || MAKEOBJDIRPREFIX=${NANO_OBJ} +test -n "${NANO_DISKIMGDIR}" || NANO_DISKIMGDIR=${NANO_OBJ} + +NANO_WORLDDIR=${NANO_OBJ}/_.w +NANO_MAKE_CONF_BUILD=${MAKEOBJDIRPREFIX}/make.conf.build +NANO_MAKE_CONF_INSTALL=${NANO_OBJ}/make.conf.install if [ -d ${NANO_TOOLS} ] ; then true @@ -791,7 +790,8 @@ export NANO_DRIVE export NANO_HEADS export NANO_IMAGES export NANO_IMGNAME -export NANO_MAKE_CONF +export NANO_MAKE_CONF_BUILD +export NANO_MAKE_CONF_INSTALL export NANO_MEDIASIZE export NANO_NAME export NANO_NEWFS @@ -807,6 +807,10 @@ export NANO_BOOTLOADER ####################################################################### # And then it is as simple as that... +# File descriptor 3 is used for logging output, see pprint +exec 3>&1 + +NANO_STARTTIME=`date +%s` pprint 1 "NanoBSD image ${NANO_NAME} build starting" if $do_world ; then @@ -840,7 +844,6 @@ prune_usr run_late_customize if $do_image ; then create_${NANO_ARCH}_diskimage - echo "# Created NanoBSD disk image: ${MAKEOBJDIRPREFIX}/${NANO_IMGNAME}" else pprint 2 "Skipping image build (as instructed)" fi
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906300920.n5U9KhHB073782>