3 # Copyright (c) 2005 Poul-Henning Kamp.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #######################################################################
34 # Setup default values for all controlling variables.
35 # These values can be overridden from the config file(s)
37 #######################################################################
39 # Name of this NanoBSD build. (Used to construct workdir names)
42 # Source tree directory
45 # Where nanobsd additional files live under the source tree
46 NANO_TOOLS=tools/tools/nanobsd
48 # Where cust_pkg() finds packages to install
49 NANO_PACKAGE_DIR=${NANO_SRC}/${NANO_TOOLS}/Pkg
52 # Object tree directory
53 # default is subdir of /usr/obj
56 # The directory to put the final images
57 # default is ${NANO_OBJ}
60 # Make & parallel Make
62 NANO_PMAKE="make -j 3"
64 # The default name for any image we create.
65 NANO_IMGNAME="_.disk.full"
67 # Options to put in make.conf during buildworld only
70 # Options to put in make.conf during installworld only
73 # Options to put in make.conf during both build- & installworld.
76 # Kernel config file to use
79 # Kernel modules to build; default is none
85 # Late customize commands.
86 NANO_LATE_CUSTOMIZE=""
88 # Newfs paramters to use
89 NANO_NEWFS="-b 4096 -f 512 -i 8192 -U"
91 # The drive name of the media at runtime
94 # Target media size in 512 bytes sectors
95 NANO_MEDIASIZE=1500000
97 # Number of code images on media (1 or 2)
100 # 0 -> Leave second image all zeroes so it compresses better.
101 # 1 -> Initialize second image with a copy of the first
104 # Size of code file system in 512 bytes sectors
105 # If zero, size will be as large as possible.
108 # Size of configuration file system in 512 bytes sectors
112 # Size of data file system in 512 bytes sectors
113 # If zero: no partition configured.
114 # If negative: max size possible
117 # Size of the /etc ramdisk in 512 bytes sectors
118 NANO_RAM_ETCSIZE=10240
120 # Size of the /tmp+/var ramdisk in 512 bytes sectors
121 NANO_RAM_TMPVARSIZE=10240
123 # Media geometry, only relevant if bios doesn't understand LBA.
127 # boot0 flags/options and configuration
128 NANO_BOOT0CFG="-o packet -s 1 -m 3"
129 NANO_BOOTLOADER="boot/boot0sio"
131 # boot2 flags/options
132 # default force serial console
135 # Backing type of md(4) device
136 # Can be "file" or "swap"
137 NANO_MD_BACKING="file"
139 # for swap type md(4) backing, write out the mbr only
140 NANO_IMAGE_MBRONLY=true
142 # Progress Print level
145 # Set NANO_LABEL to non-blank to form the basis for using /dev/ufs/label
146 # in preference to /dev/${NANO_DRIVE}
147 # Root partition will be ${NANO_LABEL}s{1,2}
148 # /cfg partition will be ${NANO_LABEL}s3
149 # /data partition will be ${NANO_LABEL}s4
152 #######################################################################
153 # Architecture to build. Corresponds to TARGET_ARCH in a buildworld.
154 # Unfortunately, there's no way to set TARGET at this time, and it
155 # conflates the two, so architectures where TARGET != TARGET_ARCH do
156 # not work. This defaults to the arch of the current machine.
160 # Directory to populate /cfg from
163 # Directory to populate /data from
166 # src.conf to use when building the image. Defaults to /dev/null for the sake
168 SRCCONF=${SRCCONF:=/dev/null}
170 #######################################################################
172 # The functions which do the real work.
173 # Can be overridden from the config file(s)
175 #######################################################################
178 if [ $? -ne 0 ]; then
179 echo "Error encountered. Check for errors in last log file." 1>&2
185 pprint 2 "Clean and create object directory (${MAKEOBJDIRPREFIX})"
187 if ! rm -rf ${MAKEOBJDIRPREFIX} > /dev/null 2>&1 ; then
188 chflags -R noschg ${MAKEOBJDIRPREFIX}
189 rm -r ${MAKEOBJDIRPREFIX}
191 mkdir -p ${MAKEOBJDIRPREFIX}
192 printenv > ${MAKEOBJDIRPREFIX}/_.env
195 make_conf_build ( ) (
196 pprint 2 "Construct build make.conf ($NANO_MAKE_CONF_BUILD)"
198 echo "${CONF_WORLD}" > ${NANO_MAKE_CONF_BUILD}
199 echo "${CONF_BUILD}" >> ${NANO_MAKE_CONF_BUILD}
203 pprint 2 "run buildworld"
204 pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bw"
207 env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} \
209 __MAKE_CONF=${NANO_MAKE_CONF_BUILD} buildworld \
210 > ${MAKEOBJDIRPREFIX}/_.bw 2>&1
216 pprint 2 "build kernel ($NANO_KERNEL)"
217 pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bk"
220 if [ -f ${NANO_KERNEL} ] ; then
221 extra="KERNCONFDIR=$(realpath $(dirname ${NANO_KERNEL}))"
222 kernconf=$(basename ${NANO_KERNEL})
224 kernconf=${NANO_KERNEL}
228 # unset these just in case to avoid compiler complaints
229 # when cross-building
231 # Note: We intentionally build all modules, not only the ones in
232 # NANO_MODULES so the built world can be reused by multiple images.
233 env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} buildkernel \
235 ${extra} __MAKE_CONF=${NANO_MAKE_CONF_BUILD} \
237 ) > ${MAKEOBJDIRPREFIX}/_.bk 2>&1
241 if [ "${NANO_OBJ}" != "${MAKEOBJDIRPREFIX}" ]; then
242 pprint 2 "Clean and create object directory (${NANO_OBJ})"
243 if ! rm -rf ${NANO_OBJ} > /dev/null 2>&1 ; then
244 chflags -R noschg ${NANO_OBJ}
247 mkdir -p ${NANO_OBJ} ${NANO_WORLDDIR}
248 printenv > ${NANO_OBJ}/_.env
250 pprint 2 "Clean and create world directory (${NANO_WORLDDIR})"
251 if ! rm -rf ${NANO_WORLDDIR}/ > /dev/null 2>&1 ; then
252 chflags -R noschg ${NANO_WORLDDIR}
253 rm -rf ${NANO_WORLDDIR}
255 mkdir -p ${NANO_WORLDDIR}
259 make_conf_install ( ) (
260 pprint 2 "Construct install make.conf ($NANO_MAKE_CONF_INSTALL)"
262 echo "${CONF_WORLD}" > ${NANO_MAKE_CONF_INSTALL}
263 echo "${CONF_INSTALL}" >> ${NANO_MAKE_CONF_INSTALL}
267 pprint 2 "installworld"
268 pprint 3 "log: ${NANO_OBJ}/_.iw"
271 env TARGET_ARCH=${NANO_ARCH} \
272 ${NANO_MAKE} SRCCONF=${SRCCONF} \
273 __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} installworld \
274 DESTDIR=${NANO_WORLDDIR} \
275 > ${NANO_OBJ}/_.iw 2>&1
276 chflags -R noschg ${NANO_WORLDDIR}
281 pprint 2 "install /etc"
282 pprint 3 "log: ${NANO_OBJ}/_.etc"
285 env TARGET_ARCH=${NANO_ARCH} \
286 ${NANO_MAKE} SRCCONF=${SRCCONF} \
287 __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} distribution \
288 DESTDIR=${NANO_WORLDDIR} \
289 > ${NANO_OBJ}/_.etc 2>&1
290 # make.conf doesn't get created by default, but some ports need it
291 # so they can spam it.
292 cp /dev/null ${NANO_WORLDDIR}/etc/make.conf
298 pprint 2 "install kernel ($NANO_KERNEL)"
299 pprint 3 "log: ${NANO_OBJ}/_.ik"
302 if [ -f ${NANO_KERNEL} ] ; then
303 extra="KERNCONFDIR=$(realpath $(dirname ${NANO_KERNEL}))"
304 kernconf=$(basename ${NANO_KERNEL})
306 kernconf=${NANO_KERNEL}
310 env TARGET_ARCH=${NANO_ARCH} ${NANO_MAKE} installkernel \
311 DESTDIR=${NANO_WORLDDIR} \
313 ${extra} __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} \
314 KERNCONF=${kernconf} \
315 MODULES_OVERRIDE="${NANO_MODULES}"
316 ) > ${NANO_OBJ}/_.ik 2>&1
321 pprint 2 "run customize scripts"
322 for c in $NANO_CUSTOMIZE
324 pprint 2 "customize \"$c\""
325 pprint 3 "log: ${NANO_OBJ}/_.cust.$c"
327 ( set -x ; $c ) > ${NANO_OBJ}/_.cust.$c 2>&1
331 run_late_customize() (
333 pprint 2 "run late customize scripts"
334 for c in $NANO_LATE_CUSTOMIZE
336 pprint 2 "late customize \"$c\""
337 pprint 3 "log: ${NANO_OBJ}/_.late_cust.$c"
339 ( set -x ; $c ) > ${NANO_OBJ}/_.late_cust.$c 2>&1
344 pprint 2 "configure nanobsd setup"
345 pprint 3 "log: ${NANO_OBJ}/_.dl"
350 # Move /usr/local/etc to /etc/local so that the /cfg stuff
351 # can stomp on it. Otherwise packages like ipsec-tools which
352 # have hardcoded paths under ${prefix}/etc are not tweakable.
353 if [ -d usr/local/etc ] ; then
357 find . -print | cpio -dumpl ../../../etc/local
360 ln -s ../../etc/local etc
366 # link /$d under /conf
367 # we use hard links so we have them both places.
368 # the files in /$d will be hidden by the mount.
369 # XXX: configure /$d ramdisk size
370 mkdir -p conf/base/$d conf/default/$d
371 find $d -print | cpio -dumpl conf/base/
374 echo "$NANO_RAM_ETCSIZE" > conf/base/etc/md_size
375 echo "$NANO_RAM_TMPVARSIZE" > conf/base/var/md_size
377 # pick up config files from the special partition
378 echo "mount -o ro /dev/${NANO_DRIVE}s3" > conf/default/etc/remount
380 # Put /tmp on the /var ramdisk (could be symlink already)
381 test -d tmp && rmdir tmp || rm -f tmp
384 ) > ${NANO_OBJ}/_.dl 2>&1
387 setup_nanobsd_etc ( ) (
388 pprint 2 "configure nanobsd /etc"
393 # create diskless marker file
396 # Make root filesystem R/O by default
397 echo "root_rw_mount=NO" >> etc/defaults/rc.conf
399 # save config file for scripts
400 echo "NANO_DRIVE=${NANO_DRIVE}" > etc/nanobsd.conf
402 echo "/dev/${NANO_DRIVE}s1a / ufs ro 1 1" > etc/fstab
403 echo "/dev/${NANO_DRIVE}s3 /cfg ufs rw,noauto 2 2" >> etc/fstab
410 # Remove all empty directories in /usr
411 find ${NANO_WORLDDIR}/usr -type d -depth -print |
414 rmdir $d > /dev/null 2>&1 || true
423 echo newfs ${NANO_NEWFS} ${NANO_LABEL:+-L${NANO_LABEL}${lbl}} ${dev}
424 newfs ${NANO_NEWFS} ${NANO_LABEL:+-L${NANO_LABEL}${lbl}} ${dev}
425 mount -o async ${dev} ${mnt}
429 local dev dir mnt lbl
434 echo "Creating ${dev} (mounting on ${mnt})"
435 newfs_part ${dev} ${mnt} ${lbl}
436 if [ -n "${dir}" -a -d "${dir}" ]; then
437 echo "Populating ${lbl} from ${dir}"
439 find . -print | grep -Ev '/(CVS|\.svn)' | cpio -dumpv ${mnt}
445 populate_cfg_slice ( ) (
446 populate_slice "$1" "$2" "$3" "$4"
449 populate_data_slice ( ) (
450 populate_slice "$1" "$2" "$3" "$4"
453 create_i386_diskimage ( ) (
454 pprint 2 "build diskimage"
455 pprint 3 "log: ${NANO_OBJ}/_.di"
458 echo $NANO_MEDIASIZE $NANO_IMAGES \
459 $NANO_SECTS $NANO_HEADS \
460 $NANO_CODESIZE $NANO_CONFSIZE $NANO_DATASIZE |
465 # size of cylinder in sectors
468 # number of full cylinders on media
471 # output fdisk geometry spec, truncate cyls to 1023
473 print "g c" cyl " h" $4 " s" $3
475 print "g c" 1023 " h" $4 " s" $3
478 # size of data partition in full cylinders
479 dsl = int (($7 + cs - 1) / cs)
484 # size of config partition in full cylinders
485 csl = int (($6 + cs - 1) / cs)
488 # size of image partition(s) in full cylinders
489 isl = int ((cyl - dsl - csl) / $2)
491 isl = int (($5 + cs - 1) / cs)
494 # First image partition start at second track
495 print "p 1 165 " $3, isl * cs - $3
498 # Second image partition (if any) also starts offset one
499 # track to keep them identical.
501 print "p 2 165 " $3 + c, isl * cs - $3
505 # Config partition starts at cylinder boundary.
506 print "p 3 165 " c, csl * cs
509 # Data partition (if any) starts at cylinder boundary.
511 print "p 4 165 " c, dsl * cs
512 } else if ($7 < 0 && $1 > c) {
513 print "p 4 165 " c, $1 - c
515 print "Disk space overcommitted by", \
516 c - $1, "sectors" > "/dev/stderr"
520 # Force slice 1 to be marked active. This is necessary
521 # for booting the image from a USB device to work.
524 ' > ${NANO_OBJ}/_.fdisk
526 IMG=${NANO_DISKIMGDIR}/${NANO_IMGNAME}
527 MNT=${NANO_OBJ}/_.mnt
530 if [ "${NANO_MD_BACKING}" = "swap" ] ; then
531 MD=`mdconfig -a -t swap -s ${NANO_MEDIASIZE} -x ${NANO_SECTS} \
534 echo "Creating md backing file..."
536 dd if=/dev/zero of=${IMG} seek=${NANO_MEDIASIZE} count=0
537 MD=`mdconfig -a -t vnode -f ${IMG} -x ${NANO_SECTS} \
541 trap "echo 'Running exit trap code' ; df -i ${MNT} ; umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT
543 fdisk -i -f ${NANO_OBJ}/_.fdisk ${MD}
546 # XXX: pick up cached boot* files, they may not be in image anymore.
547 boot0cfg -B -b ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ${NANO_BOOT0CFG} ${MD}
548 bsdlabel -w -B -b ${NANO_WORLDDIR}/boot/boot ${MD}s1
552 populate_slice /dev/${MD}s1a ${NANO_WORLDDIR} ${MNT} "s1a"
553 mount /dev/${MD}s1a ${MNT}
554 echo "Generating mtree..."
555 ( cd ${MNT} && mtree -c ) > ${NANO_OBJ}/_.mtree
556 ( cd ${MNT} && du -k ) > ${NANO_OBJ}/_.du
559 if [ $NANO_IMAGES -gt 1 -a $NANO_INIT_IMG2 -gt 0 ] ; then
560 # Duplicate to second image (if present)
561 echo "Duplicating to second image..."
562 dd conv=sparse if=/dev/${MD}s1 of=/dev/${MD}s2 bs=64k
563 mount /dev/${MD}s2a ${MNT}
564 for f in ${MNT}/etc/fstab ${MNT}/conf/base/etc/fstab
566 sed -i "" "s=${NANO_DRIVE}s1=${NANO_DRIVE}s2=g" $f
569 # Override the label from the first partition so we
570 # don't confuse glabel with duplicates.
571 if [ ! -z ${NANO_LABEL} ]; then
572 tunefs -L ${NANO_LABEL}"s2a" /dev/${MD}s2a
576 # Create Config slice
577 populate_cfg_slice /dev/${MD}s3 "${NANO_CFGDIR}" ${MNT} "s3"
579 # Create Data slice, if any.
580 if [ $NANO_DATASIZE -ne 0 ] ; then
581 populate_data_slice /dev/${MD}s4 "${NANO_DATADIR}" ${MNT} "s4"
584 if [ "${NANO_MD_BACKING}" = "swap" ] ; then
585 if [ ${NANO_IMAGE_MBRONLY} ]; then
586 echo "Writing out _.disk.mbr..."
587 dd if=/dev/${MD} of=${NANO_DISKIMGDIR}/_.disk.mbr bs=512 count=1
589 echo "Writing out ${NANO_IMGNAME}..."
590 dd if=/dev/${MD} of=${IMG} bs=64k
593 echo "Writing out ${NANO_IMGNAME}..."
594 dd conv=sparse if=/dev/${MD} of=${IMG} bs=64k
597 if ${do_copyout_partition} ; then
598 echo "Writing out _.disk.image..."
599 dd conv=sparse if=/dev/${MD}s1 of=${NANO_DISKIMGDIR}/_.disk.image bs=64k
604 trap nano_cleanup EXIT
606 ) > ${NANO_OBJ}/_.di 2>&1
609 # i386 and amd64 are identical for disk images
610 create_amd64_diskimage ( ) (
611 create_i386_diskimage
615 # Redefine this function with any last orders you may have
616 # after the build completed, for instance to copy the finished
617 # image to a more convenient place:
618 # cp ${NANO_DISKIMGDIR}/_.disk.image /home/ftp/pub/nanobsd.disk
622 #######################################################################
624 # Optional convenience functions.
626 #######################################################################
628 #######################################################################
629 # Common Flash device geometries
633 if [ -d ${NANO_TOOLS} ] ; then
634 . ${NANO_TOOLS}/FlashDevice.sub
636 . ${NANO_SRC}/${NANO_TOOLS}/FlashDevice.sub
638 sub_FlashDevice $1 $2
641 #######################################################################
642 # USB device geometries
645 # UsbDevice Generic 1000 # a generic flash key sold as having 1GB
647 # This function will set NANO_MEDIASIZE, NANO_HEADS and NANO_SECTS for you.
649 # Note that the capacity of a flash key is usually advertised in MB or
650 # GB, *not* MiB/GiB. As such, the precise number of cylinders available
651 # for C/H/S geometry may vary depending on the actual flash geometry.
653 # The following generic device layouts are understood:
654 # generic An alias for generic-hdd.
655 # generic-hdd 255H 63S/T xxxxC with no MBR restrictions.
656 # generic-fdd 64H 32S/T xxxxC with no MBR restrictions.
658 # The generic-hdd device is preferred for flash devices larger than 1GB.
662 a1=`echo $1 | tr '[:upper:]' '[:lower:]'`
667 NANO_MEDIASIZE=$(( $2 * 1000 * 1000 / 512 ))
672 NANO_MEDIASIZE=$(( $2 * 1000 * 1000 / 512 ))
675 echo "Unknown USB flash device"
681 #######################################################################
682 # Setup serial console
685 # Enable getty on console
686 sed -i "" -e /tty[du]0/s/off/on/ ${NANO_WORLDDIR}/etc/ttys
688 # Disable getty on syscons devices
689 sed -i "" -e '/^ttyv[0-8]/s/ on/ off/' ${NANO_WORLDDIR}/etc/ttys
691 # Tell loader to use serial console early.
692 echo "${NANO_BOOT2CFG}" > ${NANO_WORLDDIR}/boot.config
695 #######################################################################
696 # Allow root login via ssh
698 cust_allow_ssh_root () (
699 sed -i "" -e '/PermitRootLogin/s/.*/PermitRootLogin yes/' \
700 ${NANO_WORLDDIR}/etc/ssh/sshd_config
703 #######################################################################
704 # Install the stuff under ./Files
706 cust_install_files () (
707 cd ${NANO_TOOLS}/Files
708 find . -print | grep -Ev '/(CVS|\.svn)' | cpio -Ldumpv ${NANO_WORLDDIR}
711 #######################################################################
712 # Install packages from ${NANO_PACKAGE_DIR}
716 # If the package directory doesn't exist, we're done.
717 if [ ! -d ${NANO_PACKAGE_DIR} ]; then
718 echo "DONE 0 packages"
722 # Copy packages into chroot
723 mkdir -p ${NANO_WORLDDIR}/Pkg
725 cd ${NANO_PACKAGE_DIR}
726 find ${NANO_PACKAGE_LIST} -print |
727 cpio -Ldumpv ${NANO_WORLDDIR}/Pkg
730 # Count & report how many we have to install
731 todo=`ls ${NANO_WORLDDIR}/Pkg | wc -l`
732 echo "=== TODO: $todo"
733 ls ${NANO_WORLDDIR}/Pkg
737 # Record how many we have now
738 have=`ls ${NANO_WORLDDIR}/var/db/pkg | wc -l`
740 # Attempt to install more packages
741 # ...but no more than 200 at a time due to pkg_add's internal
743 chroot ${NANO_WORLDDIR} sh -c \
744 'ls Pkg/*tbz | xargs -n 200 pkg_add -F' || true
746 # See what that got us
747 now=`ls ${NANO_WORLDDIR}/var/db/pkg | wc -l`
749 ls ${NANO_WORLDDIR}/var/db/pkg
753 if [ $now -eq $todo ] ; then
754 echo "DONE $now packages"
756 elif [ $now -eq $have ] ; then
757 echo "FAILED: Nothing happened on this pass"
761 rm -rf ${NANO_WORLDDIR}/Pkg
766 # If the package directory doesn't exist, we're done.
767 if [ ! -d ${NANO_PACKAGE_DIR} ]; then
768 echo "DONE 0 packages"
772 # Find a pkg-* package
773 for x in `find -s ${NANO_PACKAGE_DIR} -iname 'pkg-*'`; do
774 _NANO_PKG_PACKAGE=`basename "$x"`
776 if [ -z "${_NANO_PKG_PACKAGE}" -o ! -f "${NANO_PACKAGE_DIR}/${_NANO_PKG_PACKAGE}" ]; then
777 echo "FAILED: need a pkg/ package for bootstrapping"
781 # Copy packages into chroot
782 mkdir -p ${NANO_WORLDDIR}/Pkg
784 cd ${NANO_PACKAGE_DIR}
785 find ${NANO_PACKAGE_LIST} -print |
786 cpio -Ldumpv ${NANO_WORLDDIR}/Pkg
790 chroot ${NANO_WORLDDIR} sh -c \
791 "env ASSUME_ALWAYS_YES=YES SIGNATURE_TYPE=none /usr/sbin/pkg add /Pkg/${_NANO_PKG_PACKAGE}"
792 chroot ${NANO_WORLDDIR} sh -c "pkg -N >/dev/null 2>&1;"
793 if [ "$?" -ne "0" ]; then
794 echo "FAILED: pkg bootstrapping faied"
797 rm -f ${NANO_WORLDDIR}/Pkg/pkg-*
799 # Count & report how many we have to install
800 todo=`ls ${NANO_WORLDDIR}/Pkg | /usr/bin/wc -l`
801 todo=$(expr $todo + 1) # add one for pkg since it is installed already
802 echo "=== TODO: $todo"
803 ls ${NANO_WORLDDIR}/Pkg
807 # Record how many we have now
808 have=`chroot ${NANO_WORLDDIR} sh -c \
809 'env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg info | /usr/bin/wc -l'`
811 # Attempt to install more packages
813 chroot ${NANO_WORLDDIR} sh -c \
814 'ls Pkg/*txz | xargs env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg add ' || true
816 # See what that got us
817 now=`chroot ${NANO_WORLDDIR} sh -c \
818 'env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg info | /usr/bin/wc -l'`
820 chroot ${NANO_WORLDDIR} sh -c \
821 'env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg info'
823 if [ $now -eq $todo ] ; then
824 echo "DONE $now packages"
826 elif [ $now -eq $have ] ; then
827 echo "FAILED: Nothing happened on this pass"
831 rm -rf ${NANO_WORLDDIR}/Pkg
834 #######################################################################
835 # Convenience function:
836 # Register all args as customize function.
839 NANO_CUSTOMIZE="$NANO_CUSTOMIZE $*"
842 #######################################################################
843 # Convenience function:
844 # Register all args as late customize function to run just before
847 late_customize_cmd () {
848 NANO_LATE_CUSTOMIZE="$NANO_LATE_CUSTOMIZE $*"
851 #######################################################################
853 # All set up to go...
855 #######################################################################
858 # Print $2 at level $1.
860 if [ "$1" -le $PPLEVEL ]; then
861 runtime=$(( `date +%s` - $NANO_STARTTIME ))
862 printf "%s %.${1}s %s\n" "`date -u -r $runtime +%H:%M:%S`" "#####" "$2" 1>&3
868 echo "Usage: $0 [-bfiknqvw] [-c config_file]"
869 echo " -b suppress builds (both kernel and world)"
870 echo " -f suppress code slice extraction"
871 echo " -i suppress disk image build"
872 echo " -k suppress buildkernel"
873 echo " -n add -DNO_CLEAN to buildworld, buildkernel, etc"
874 echo " -q make output more quiet"
875 echo " -v make output more verbose"
876 echo " -w suppress buildworld"
877 echo " -c specify config file"
882 #######################################################################
889 do_copyout_partition=true
892 args=`getopt bc:fhiknqvw $*`
893 if [ $? -ne 0 ] ; then
919 do_copyout_partition=false
934 PPLEVEL=$(($PPLEVEL - 1))
938 PPLEVEL=$(($PPLEVEL + 1))
951 if [ $# -gt 0 ] ; then
952 echo "$0: Extraneous arguments supplied"
956 trap nano_cleanup EXIT
958 #######################################################################
959 # Setup and Export Internal variables
961 test -n "${NANO_OBJ}" || NANO_OBJ=/usr/obj/nanobsd.${NANO_NAME}/
962 test -n "${MAKEOBJDIRPREFIX}" || MAKEOBJDIRPREFIX=${NANO_OBJ}
963 test -n "${NANO_DISKIMGDIR}" || NANO_DISKIMGDIR=${NANO_OBJ}
965 NANO_WORLDDIR=${NANO_OBJ}/_.w
966 NANO_MAKE_CONF_BUILD=${MAKEOBJDIRPREFIX}/make.conf.build
967 NANO_MAKE_CONF_INSTALL=${NANO_OBJ}/make.conf.install
969 if [ -d ${NANO_TOOLS} ] ; then
971 elif [ -d ${NANO_SRC}/${NANO_TOOLS} ] ; then
972 NANO_TOOLS=${NANO_SRC}/${NANO_TOOLS}
974 echo "NANO_TOOLS directory does not exist" 1>&2
981 NANO_MAKE="${NANO_MAKE} -DNO_CLEAN"
982 NANO_PMAKE="${NANO_PMAKE} -DNO_CLEAN"
985 # Override user's NANO_DRIVE if they specified a NANO_LABEL
986 if [ ! -z "${NANO_LABEL}" ]; then
987 NANO_DRIVE=ufs/${NANO_LABEL}
990 export MAKEOBJDIRPREFIX
995 export NANO_CUSTOMIZE
1002 export NANO_MAKE_CONF_BUILD
1003 export NANO_MAKE_CONF_INSTALL
1004 export NANO_MEDIASIZE
1012 export NANO_WORLDDIR
1013 export NANO_BOOT0CFG
1014 export NANO_BOOTLOADER
1017 #######################################################################
1018 # And then it is as simple as that...
1020 # File descriptor 3 is used for logging output, see pprint
1023 NANO_STARTTIME=`date +%s`
1024 pprint 1 "NanoBSD image ${NANO_NAME} build starting"
1030 pprint 2 "Using existing build tree (as instructed)"
1035 pprint 2 "Skipping buildworld (as instructed)"
1038 if $do_kernel ; then
1039 if ! $do_world ; then
1044 pprint 2 "Skipping buildkernel (as instructed)"
1059 create_${NANO_ARCH}_diskimage
1061 pprint 2 "Skipping image build (as instructed)"
1065 pprint 1 "NanoBSD image ${NANO_NAME} completed"