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 # where package metadata gets placed
53 NANO_PKG_META_BASE=/var/db
55 # Object tree directory
56 # default is subdir of /usr/obj
59 # The directory to put the final images
60 # default is ${NANO_OBJ}
63 # Make & parallel Make
65 NANO_PMAKE="make -j 3"
67 # The default name for any image we create.
68 NANO_IMGNAME="_.disk.full"
70 # Options to put in make.conf during buildworld only
73 # Options to put in make.conf during installworld only
76 # Options to put in make.conf during both build- & installworld.
79 # Kernel config file to use
82 # Kernel modules to install. If empty, no modules are installed.
83 # Use "default" to install all built modules.
89 # Late customize commands.
90 NANO_LATE_CUSTOMIZE=""
92 # Newfs paramters to use
93 NANO_NEWFS="-b 4096 -f 512 -i 8192 -U"
95 # The drive name of the media at runtime
98 # Target media size in 512 bytes sectors
99 NANO_MEDIASIZE=2000000
101 # Number of code images on media (1 or 2)
104 # 0 -> Leave second image all zeroes so it compresses better.
105 # 1 -> Initialize second image with a copy of the first
108 # Size of code file system in 512 bytes sectors
109 # If zero, size will be as large as possible.
112 # Size of configuration file system in 512 bytes sectors
116 # Size of data file system in 512 bytes sectors
117 # If zero: no partition configured.
118 # If negative: max size possible
121 # Size of the /etc ramdisk in 512 bytes sectors
122 NANO_RAM_ETCSIZE=10240
124 # Size of the /tmp+/var ramdisk in 512 bytes sectors
125 NANO_RAM_TMPVARSIZE=10240
127 # Media geometry, only relevant if bios doesn't understand LBA.
131 # boot0 flags/options and configuration
132 NANO_BOOT0CFG="-o packet -s 1 -m 3"
133 NANO_BOOTLOADER="boot/boot0sio"
135 # boot2 flags/options
136 # default force serial console
139 # Backing type of md(4) device
140 # Can be "file" or "swap"
141 NANO_MD_BACKING="file"
143 # for swap type md(4) backing, write out the mbr only
144 NANO_IMAGE_MBRONLY=true
146 # Progress Print level
149 # Set NANO_LABEL to non-blank to form the basis for using /dev/ufs/label
150 # in preference to /dev/${NANO_DRIVE}
151 # Root partition will be ${NANO_LABEL}s{1,2}
152 # /cfg partition will be ${NANO_LABEL}s3
153 # /data partition will be ${NANO_LABEL}s4
156 #######################################################################
157 # Architecture to build. Corresponds to TARGET_ARCH in a buildworld.
158 # Unfortunately, there's no way to set TARGET at this time, and it
159 # conflates the two, so architectures where TARGET != TARGET_ARCH do
160 # not work. This defaults to the arch of the current machine.
164 # Directory to populate /cfg from
167 # Directory to populate /data from
170 # src.conf to use when building the image. Defaults to /dev/null for the sake
172 SRCCONF=${SRCCONF:=/dev/null}
174 #######################################################################
176 # The functions which do the real work.
177 # Can be overridden from the config file(s)
179 #######################################################################
181 # rm doesn't know -x prior to FreeBSD 10, so cope with a variety of build
190 # run in the world chroot, errors fatal
193 chroot ${NANO_WORLDDIR} /bin/sh -exc "$*"
196 # run in the world chroot, errors not fatal
199 chroot ${NANO_WORLDDIR} /bin/sh -c "$*" || true
203 if [ $? -ne 0 ]; then
204 echo "Error encountered. Check for errors in last log file." 1>&2
210 pprint 2 "Clean and create object directory (${MAKEOBJDIRPREFIX})"
212 if ! nano_rm -rf ${MAKEOBJDIRPREFIX}/ > /dev/null 2>&1 ; then
213 chflags -R noschg ${MAKEOBJDIRPREFIX}/
214 nano_rm -r ${MAKEOBJDIRPREFIX}/
218 make_conf_build ( ) (
219 pprint 2 "Construct build make.conf ($NANO_MAKE_CONF_BUILD)"
221 mkdir -p ${MAKEOBJDIRPREFIX}
222 printenv > ${MAKEOBJDIRPREFIX}/_.env
224 echo "${CONF_WORLD}" > ${NANO_MAKE_CONF_BUILD}
225 echo "${CONF_BUILD}" >> ${NANO_MAKE_CONF_BUILD}
229 pprint 2 "run buildworld"
230 pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bw"
233 env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} \
235 __MAKE_CONF=${NANO_MAKE_CONF_BUILD} buildworld \
236 > ${MAKEOBJDIRPREFIX}/_.bw 2>&1
242 pprint 2 "build kernel ($NANO_KERNEL)"
243 pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bk"
246 if [ -f ${NANO_KERNEL} ] ; then
247 kernconfdir_arg="KERNCONFDIR='$(realpath $(dirname ${NANO_KERNEL}))'"
248 kernconf=$(basename ${NANO_KERNEL})
250 kernconf=${NANO_KERNEL}
254 # unset these just in case to avoid compiler complaints
255 # when cross-building
257 # Note: We intentionally build all modules, not only the ones in
258 # NANO_MODULES so the built world can be reused by multiple images.
259 eval "TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} buildkernel \
260 SRCCONF='${SRCCONF}' \
261 __MAKE_CONF='${NANO_MAKE_CONF_BUILD}' \
262 ${kernconfdir_arg} KERNCONF=${kernconf}"
263 ) > ${MAKEOBJDIRPREFIX}/_.bk 2>&1
267 if [ "${NANO_OBJ}" != "${MAKEOBJDIRPREFIX}" ]; then
268 pprint 2 "Clean and create object directory (${NANO_OBJ})"
269 if ! nano_rm -rf ${NANO_OBJ}/ > /dev/null 2>&1 ; then
270 chflags -R noschg ${NANO_OBJ}
271 nano_rm -r ${NANO_OBJ}/
273 mkdir -p ${NANO_OBJ} ${NANO_WORLDDIR}
274 printenv > ${NANO_OBJ}/_.env
276 pprint 2 "Clean and create world directory (${NANO_WORLDDIR})"
277 if ! nano_rm -rf ${NANO_WORLDDIR}/ > /dev/null 2>&1 ; then
278 chflags -R noschg ${NANO_WORLDDIR}
279 nano_rm -rf ${NANO_WORLDDIR}/
281 mkdir -p ${NANO_WORLDDIR}
285 make_conf_install ( ) (
286 pprint 2 "Construct install make.conf ($NANO_MAKE_CONF_INSTALL)"
288 echo "${CONF_WORLD}" > ${NANO_MAKE_CONF_INSTALL}
289 echo "${CONF_INSTALL}" >> ${NANO_MAKE_CONF_INSTALL}
293 pprint 2 "installworld"
294 pprint 3 "log: ${NANO_OBJ}/_.iw"
297 env TARGET_ARCH=${NANO_ARCH} \
298 ${NANO_MAKE} SRCCONF=${SRCCONF} \
299 __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} installworld \
300 DESTDIR=${NANO_WORLDDIR} \
301 > ${NANO_OBJ}/_.iw 2>&1
302 chflags -R noschg ${NANO_WORLDDIR}
307 pprint 2 "install /etc"
308 pprint 3 "log: ${NANO_OBJ}/_.etc"
311 env TARGET_ARCH=${NANO_ARCH} \
312 ${NANO_MAKE} SRCCONF=${SRCCONF} \
313 __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} distribution \
314 DESTDIR=${NANO_WORLDDIR} \
315 > ${NANO_OBJ}/_.etc 2>&1
316 # make.conf doesn't get created by default, but some ports need it
317 # so they can spam it.
318 cp /dev/null ${NANO_WORLDDIR}/etc/make.conf
324 pprint 2 "install kernel ($NANO_KERNEL)"
325 pprint 3 "log: ${NANO_OBJ}/_.ik"
328 if [ -f ${NANO_KERNEL} ] ; then
329 kernconfdir_arg="KERNCONFDIR='$(realpath $(dirname ${NANO_KERNEL}))'"
330 kernconf=$(basename ${NANO_KERNEL})
332 kernconf=${NANO_KERNEL}
335 # Install all built modules if NANO_MODULES=default,
336 # else install only listed modules (none if NANO_MODULES is empty).
337 if [ "${NANO_MODULES}" != "default" ]; then
338 modules_override_arg="MODULES_OVERRIDE='${NANO_MODULES}'"
342 eval "TARGET_ARCH=${NANO_ARCH} ${NANO_MAKE} installkernel \
343 DESTDIR='${NANO_WORLDDIR}' \
344 SRCCONF='${SRCCONF}' \
345 __MAKE_CONF='${NANO_MAKE_CONF_INSTALL}' \
346 ${kernconfdir_arg} KERNCONF=${kernconf} \
347 ${modules_override_arg}"
348 ) > ${NANO_OBJ}/_.ik 2>&1
352 print 2 "Installing the optimized native build tools for cross env"
353 pprint 3 "log: ${NANO_OBJ}/_.native_xtools"
356 env TARGET_ARCH=${NANO_ARCH} \
357 ${NANO_MAKE} SRCCONF=${SRCCONF} \
358 __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} native-xtools \
359 DESTDIR=${NANO_WORLDDIR} \
360 > ${NANO_OBJ}/_.native_xtools 2>&1
365 pprint 2 "run customize scripts"
366 for c in $NANO_CUSTOMIZE
368 pprint 2 "customize \"$c\""
369 pprint 3 "log: ${NANO_OBJ}/_.cust.$c"
371 ( set -x ; $c ) > ${NANO_OBJ}/_.cust.$c 2>&1
375 run_late_customize() (
377 pprint 2 "run late customize scripts"
378 for c in $NANO_LATE_CUSTOMIZE
380 pprint 2 "late customize \"$c\""
381 pprint 3 "log: ${NANO_OBJ}/_.late_cust.$c"
383 ( set -x ; $c ) > ${NANO_OBJ}/_.late_cust.$c 2>&1
388 pprint 2 "configure nanobsd setup"
389 pprint 3 "log: ${NANO_OBJ}/_.dl"
394 # Move /usr/local/etc to /etc/local so that the /cfg stuff
395 # can stomp on it. Otherwise packages like ipsec-tools which
396 # have hardcoded paths under ${prefix}/etc are not tweakable.
397 if [ -d usr/local/etc ] ; then
401 find . -print | cpio -dumpl ../../../etc/local
404 ln -s ../../etc/local etc
410 # link /$d under /conf
411 # we use hard links so we have them both places.
412 # the files in /$d will be hidden by the mount.
413 # XXX: configure /$d ramdisk size
414 mkdir -p conf/base/$d conf/default/$d
415 find $d -print | cpio -dumpl conf/base/
418 echo "$NANO_RAM_ETCSIZE" > conf/base/etc/md_size
419 echo "$NANO_RAM_TMPVARSIZE" > conf/base/var/md_size
421 # pick up config files from the special partition
422 echo "mount -o ro /dev/${NANO_DRIVE}s3" > conf/default/etc/remount
424 # Put /tmp on the /var ramdisk (could be symlink already)
428 ) > ${NANO_OBJ}/_.dl 2>&1
431 setup_nanobsd_etc ( ) (
432 pprint 2 "configure nanobsd /etc"
437 # create diskless marker file
440 # Make root filesystem R/O by default
441 echo "root_rw_mount=NO" >> etc/defaults/rc.conf
443 # save config file for scripts
444 echo "NANO_DRIVE=${NANO_DRIVE}" > etc/nanobsd.conf
446 echo "/dev/${NANO_DRIVE}s1a / ufs ro 1 1" > etc/fstab
447 echo "/dev/${NANO_DRIVE}s3 /cfg ufs rw,noauto 2 2" >> etc/fstab
454 # Remove all empty directories in /usr
455 find ${NANO_WORLDDIR}/usr -type d -depth -print |
458 rmdir $d > /dev/null 2>&1 || true
467 echo newfs ${NANO_NEWFS} ${NANO_LABEL:+-L${NANO_LABEL}${lbl}} ${dev}
468 newfs ${NANO_NEWFS} ${NANO_LABEL:+-L${NANO_LABEL}${lbl}} ${dev}
469 mount -o async ${dev} ${mnt}
472 # Convenient spot to work around any umount issues that your build environment
473 # hits by overriding this method.
479 local dev dir mnt lbl
484 echo "Creating ${dev} (mounting on ${mnt})"
485 newfs_part ${dev} ${mnt} ${lbl}
486 if [ -n "${dir}" -a -d "${dir}" ]; then
487 echo "Populating ${lbl} from ${dir}"
489 find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)' | cpio -dumpv ${mnt}
495 populate_cfg_slice ( ) (
496 populate_slice "$1" "$2" "$3" "$4"
499 populate_data_slice ( ) (
500 populate_slice "$1" "$2" "$3" "$4"
503 create_diskimage ( ) (
504 pprint 2 "build diskimage"
505 pprint 3 "log: ${NANO_OBJ}/_.di"
508 echo $NANO_MEDIASIZE $NANO_IMAGES \
509 $NANO_SECTS $NANO_HEADS \
510 $NANO_CODESIZE $NANO_CONFSIZE $NANO_DATASIZE |
515 # size of cylinder in sectors
518 # number of full cylinders on media
521 # output fdisk geometry spec, truncate cyls to 1023
523 print "g c" cyl " h" $4 " s" $3
525 print "g c" 1023 " h" $4 " s" $3
528 # size of data partition in full cylinders
529 dsl = int (($7 + cs - 1) / cs)
534 # size of config partition in full cylinders
535 csl = int (($6 + cs - 1) / cs)
538 # size of image partition(s) in full cylinders
539 isl = int ((cyl - dsl - csl) / $2)
541 isl = int (($5 + cs - 1) / cs)
544 # First image partition start at second track
545 print "p 1 165 " $3, isl * cs - $3
548 # Second image partition (if any) also starts offset one
549 # track to keep them identical.
551 print "p 2 165 " $3 + c, isl * cs - $3
555 # Config partition starts at cylinder boundary.
556 print "p 3 165 " c, csl * cs
559 # Data partition (if any) starts at cylinder boundary.
561 print "p 4 165 " c, dsl * cs
562 } else if ($7 < 0 && $1 > c) {
563 print "p 4 165 " c, $1 - c
565 print "Disk space overcommitted by", \
566 c - $1, "sectors" > "/dev/stderr"
570 # Force slice 1 to be marked active. This is necessary
571 # for booting the image from a USB device to work.
574 ' > ${NANO_OBJ}/_.fdisk
576 IMG=${NANO_DISKIMGDIR}/${NANO_IMGNAME}
577 MNT=${NANO_OBJ}/_.mnt
580 if [ "${NANO_MD_BACKING}" = "swap" ] ; then
581 MD=`mdconfig -a -t swap -s ${NANO_MEDIASIZE} -x ${NANO_SECTS} \
584 echo "Creating md backing file..."
586 dd if=/dev/zero of=${IMG} seek=${NANO_MEDIASIZE} count=0
587 MD=`mdconfig -a -t vnode -f ${IMG} -x ${NANO_SECTS} \
591 trap "echo 'Running exit trap code' ; df -i ${MNT} ; nano_umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT
593 fdisk -i -f ${NANO_OBJ}/_.fdisk ${MD}
596 # XXX: pick up cached boot* files, they may not be in image anymore.
597 if [ -f ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ]; then
598 boot0cfg -B -b ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ${NANO_BOOT0CFG} ${MD}
600 if [ -f ${NANO_WORLDDIR}/boot/boot ]; then
601 bsdlabel -w -B -b ${NANO_WORLDDIR}/boot/boot ${MD}s1
608 populate_slice /dev/${MD}s1a ${NANO_WORLDDIR} ${MNT} "s1a"
609 mount /dev/${MD}s1a ${MNT}
610 echo "Generating mtree..."
611 ( cd ${MNT} && mtree -c ) > ${NANO_OBJ}/_.mtree
612 ( cd ${MNT} && du -k ) > ${NANO_OBJ}/_.du
615 if [ $NANO_IMAGES -gt 1 -a $NANO_INIT_IMG2 -gt 0 ] ; then
616 # Duplicate to second image (if present)
617 echo "Duplicating to second image..."
618 dd conv=sparse if=/dev/${MD}s1 of=/dev/${MD}s2 bs=64k
619 mount /dev/${MD}s2a ${MNT}
620 for f in ${MNT}/etc/fstab ${MNT}/conf/base/etc/fstab
622 sed -i "" "s=${NANO_DRIVE}s1=${NANO_DRIVE}s2=g" $f
625 # Override the label from the first partition so we
626 # don't confuse glabel with duplicates.
627 if [ ! -z ${NANO_LABEL} ]; then
628 tunefs -L ${NANO_LABEL}"s2a" /dev/${MD}s2a
632 # Create Config slice
633 populate_cfg_slice /dev/${MD}s3 "${NANO_CFGDIR}" ${MNT} "s3"
635 # Create Data slice, if any.
636 if [ $NANO_DATASIZE -ne 0 ] ; then
637 populate_data_slice /dev/${MD}s4 "${NANO_DATADIR}" ${MNT} "s4"
640 if [ "${NANO_MD_BACKING}" = "swap" ] ; then
641 if [ ${NANO_IMAGE_MBRONLY} ]; then
642 echo "Writing out _.disk.mbr..."
643 dd if=/dev/${MD} of=${NANO_DISKIMGDIR}/_.disk.mbr bs=512 count=1
645 echo "Writing out ${NANO_IMGNAME}..."
646 dd if=/dev/${MD} of=${IMG} bs=64k
649 echo "Writing out ${NANO_IMGNAME}..."
650 dd conv=sparse if=/dev/${MD} of=${IMG} bs=64k
653 if ${do_copyout_partition} ; then
654 echo "Writing out _.disk.image..."
655 dd conv=sparse if=/dev/${MD}s1 of=${NANO_DISKIMGDIR}/_.disk.image bs=64k
660 trap nano_cleanup EXIT
662 ) > ${NANO_OBJ}/_.di 2>&1
666 # Redefine this function with any last orders you may have
667 # after the build completed, for instance to copy the finished
668 # image to a more convenient place:
669 # cp ${NANO_DISKIMGDIR}/_.disk.image /home/ftp/pub/nanobsd.disk
673 #######################################################################
675 # Optional convenience functions.
677 #######################################################################
679 #######################################################################
680 # Common Flash device geometries
684 if [ -d ${NANO_TOOLS} ] ; then
685 . ${NANO_TOOLS}/FlashDevice.sub
687 . ${NANO_SRC}/${NANO_TOOLS}/FlashDevice.sub
689 sub_FlashDevice $1 $2
692 #######################################################################
693 # USB device geometries
696 # UsbDevice Generic 1000 # a generic flash key sold as having 1GB
698 # This function will set NANO_MEDIASIZE, NANO_HEADS and NANO_SECTS for you.
700 # Note that the capacity of a flash key is usually advertised in MB or
701 # GB, *not* MiB/GiB. As such, the precise number of cylinders available
702 # for C/H/S geometry may vary depending on the actual flash geometry.
704 # The following generic device layouts are understood:
705 # generic An alias for generic-hdd.
706 # generic-hdd 255H 63S/T xxxxC with no MBR restrictions.
707 # generic-fdd 64H 32S/T xxxxC with no MBR restrictions.
709 # The generic-hdd device is preferred for flash devices larger than 1GB.
713 a1=`echo $1 | tr '[:upper:]' '[:lower:]'`
718 NANO_MEDIASIZE=$(( $2 * 1000 * 1000 / 512 ))
723 NANO_MEDIASIZE=$(( $2 * 1000 * 1000 / 512 ))
726 echo "Unknown USB flash device"
732 #######################################################################
733 # Setup serial console
736 # Enable getty on console
737 sed -i "" -e /tty[du]0/s/off/on/ ${NANO_WORLDDIR}/etc/ttys
739 # Disable getty on syscons devices
740 sed -i "" -e '/^ttyv[0-8]/s/ on/ off/' ${NANO_WORLDDIR}/etc/ttys
742 # Tell loader to use serial console early.
743 echo "${NANO_BOOT2CFG}" > ${NANO_WORLDDIR}/boot.config
746 #######################################################################
747 # Allow root login via ssh
749 cust_allow_ssh_root () (
750 sed -i "" -e '/PermitRootLogin/s/.*/PermitRootLogin yes/' \
751 ${NANO_WORLDDIR}/etc/ssh/sshd_config
754 #######################################################################
755 # Install the stuff under ./Files
757 cust_install_files () (
758 cd ${NANO_TOOLS}/Files
759 find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)' | cpio -Ldumpv ${NANO_WORLDDIR}
762 #######################################################################
763 # Install packages from ${NANO_PACKAGE_DIR}
767 # If the package directory doesn't exist, we're done.
768 if [ ! -d ${NANO_PACKAGE_DIR} ]; then
769 echo "DONE 0 packages"
773 # Copy packages into chroot
774 mkdir -p ${NANO_WORLDDIR}/Pkg ${NANO_WORLDDIR}/${NANO_PKG_META_BASE}/pkg
776 cd ${NANO_PACKAGE_DIR}
777 find ${NANO_PACKAGE_LIST} -print |
778 cpio -Ldumpv ${NANO_WORLDDIR}/Pkg
781 # Count & report how many we have to install
782 todo=`ls ${NANO_WORLDDIR}/Pkg | wc -l`
783 echo "=== TODO: $todo"
784 ls ${NANO_WORLDDIR}/Pkg
788 # Record how many we have now
789 have=`ls ${NANO_WORLDDIR}/${NANO_PKG_META_BASE}/pkg | wc -l`
791 # Attempt to install more packages
792 # ...but no more than 200 at a time due to pkg_add's internal
794 CR0 'ls Pkg/*tbz | xargs -n 200 env PKG_DBDIR='${NANO_PKG_META_BASE}'/pkg pkg_add -v -F'
796 # See what that got us
797 now=`ls ${NANO_WORLDDIR}/${NANO_PKG_META_BASE}/pkg | wc -l`
799 ls ${NANO_WORLDDIR}/${NANO_PKG_META_BASE}/pkg
803 if [ $now -eq $todo ] ; then
804 echo "DONE $now packages"
806 elif [ $now -eq $have ] ; then
807 echo "FAILED: Nothing happened on this pass"
811 nano_rm -rf ${NANO_WORLDDIR}/Pkg
816 # If the package directory doesn't exist, we're done.
817 if [ ! -d ${NANO_PACKAGE_DIR} ]; then
818 echo "DONE 0 packages"
822 # Find a pkg-* package
823 for x in `find -s ${NANO_PACKAGE_DIR} -iname 'pkg-*'`; do
824 _NANO_PKG_PACKAGE=`basename "$x"`
826 if [ -z "${_NANO_PKG_PACKAGE}" -o ! -f "${NANO_PACKAGE_DIR}/${_NANO_PKG_PACKAGE}" ]; then
827 echo "FAILED: need a pkg/ package for bootstrapping"
831 # Copy packages into chroot
832 mkdir -p ${NANO_WORLDDIR}/Pkg
834 cd ${NANO_PACKAGE_DIR}
835 find ${NANO_PACKAGE_LIST} -print |
836 cpio -Ldumpv ${NANO_WORLDDIR}/Pkg
840 CR env ASSUME_ALWAYS_YES=YES SIGNATURE_TYPE=none /usr/sbin/pkg add /Pkg/${_NANO_PKG_PACKAGE}
841 CR pkg -N >/dev/null 2>&1
842 if [ "$?" -ne "0" ]; then
843 echo "FAILED: pkg bootstrapping faied"
846 nano_rm -f ${NANO_WORLDDIR}/Pkg/pkg-*
848 # Count & report how many we have to install
849 todo=`ls ${NANO_WORLDDIR}/Pkg | /usr/bin/wc -l`
850 todo=$(expr $todo + 1) # add one for pkg since it is installed already
851 echo "=== TODO: $todo"
852 ls ${NANO_WORLDDIR}/Pkg
856 # Record how many we have now
857 have=$(CR env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg info | /usr/bin/wc -l)
859 # Attempt to install more packages
860 CR0 'ls 'Pkg/*txz' | xargs env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg add'
862 # See what that got us
863 now=$(CR env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg info | /usr/bin/wc -l)
865 CR env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg info
867 if [ $now -eq $todo ] ; then
868 echo "DONE $now packages"
870 elif [ $now -eq $have ] ; then
871 echo "FAILED: Nothing happened on this pass"
875 nano_rm -rf ${NANO_WORLDDIR}/Pkg
878 #######################################################################
879 # Convenience function:
880 # Register all args as customize function.
883 NANO_CUSTOMIZE="$NANO_CUSTOMIZE $*"
886 #######################################################################
887 # Convenience function:
888 # Register all args as late customize function to run just before
891 late_customize_cmd () {
892 NANO_LATE_CUSTOMIZE="$NANO_LATE_CUSTOMIZE $*"
895 #######################################################################
897 # All set up to go...
899 #######################################################################
902 # Print $2 at level $1.
904 if [ "$1" -le $PPLEVEL ]; then
905 runtime=$(( `date +%s` - $NANO_STARTTIME ))
906 printf "%s %.${1}s %s\n" "`date -u -r $runtime +%H:%M:%S`" "#####" "$2" 1>&3
912 echo "Usage: $0 [-bfiKknqvw] [-c config_file]"
913 echo " -b suppress builds (both kernel and world)"
914 echo " -c specify config file"
915 echo " -f suppress code slice extraction"
916 echo " -i suppress disk image build"
917 echo " -K suppress installkernel"
918 echo " -k suppress buildkernel"
919 echo " -n add -DNO_CLEAN to buildworld, buildkernel, etc"
920 echo " -q make output more quiet"
921 echo " -v make output more verbose"
922 echo " -w suppress buildworld"
927 #######################################################################
928 # Setup and Export Internal variables
933 # Lookup value of the variable.
935 pprint 3 "Setting variable: $var=\"$val\""
939 # Call this function to set defaults _after_ parsing options.
940 set_defaults_and_export() {
941 test -n "${NANO_OBJ}" || NANO_OBJ=/usr/obj/nanobsd.${NANO_NAME}
942 test -n "${MAKEOBJDIRPREFIX}" || MAKEOBJDIRPREFIX=${NANO_OBJ}
943 test -n "${NANO_DISKIMGDIR}" || NANO_DISKIMGDIR=${NANO_OBJ}
944 NANO_WORLDDIR=${NANO_OBJ}/_.w
945 NANO_MAKE_CONF_BUILD=${MAKEOBJDIRPREFIX}/make.conf.build
946 NANO_MAKE_CONF_INSTALL=${NANO_OBJ}/make.conf.install
948 # Override user's NANO_DRIVE if they specified a NANO_LABEL
949 [ ! -z "${NANO_LABEL}" ] && NANO_DRIVE="ufs/${NANO_LABEL}"
951 # Set a default NANO_TOOLS to NANO_SRC/NANO_TOOLS if it exists.
952 [ ! -d "${NANO_TOOLS}" ] && [ -d "${NANO_SRC}/${NANO_TOOLS}" ] && \
953 NANO_TOOLS="${NANO_SRC}/${NANO_TOOLS}"
955 NANO_STARTTIME=`date +%s`
956 pprint 3 "Exporting NanoBSD variables"
957 export_var MAKEOBJDIRPREFIX
959 export_var NANO_CODESIZE
960 export_var NANO_CONFSIZE
961 export_var NANO_CUSTOMIZE
962 export_var NANO_DATASIZE
963 export_var NANO_DRIVE
964 export_var NANO_HEADS
965 export_var NANO_IMAGES
966 export_var NANO_IMGNAME
968 export_var NANO_MAKE_CONF_BUILD
969 export_var NANO_MAKE_CONF_INSTALL
970 export_var NANO_MEDIASIZE
972 export_var NANO_NEWFS
974 export_var NANO_PMAKE
975 export_var NANO_SECTS
977 export_var NANO_TOOLS
978 export_var NANO_WORLDDIR
979 export_var NANO_BOOT0CFG
980 export_var NANO_BOOTLOADER
981 export_var NANO_LABEL
982 export_var NANO_MODULES