xref: /freebsd/tools/tools/nanobsd/defaults.sh (revision 9af130ae8c039e10912f13b58b5cb97362d00e72)
16b8c8deeSWill Andrews#!/bin/sh
26b8c8deeSWill Andrews#
36b8c8deeSWill Andrews# Copyright (c) 2005 Poul-Henning Kamp.
46b8c8deeSWill Andrews# All rights reserved.
56b8c8deeSWill Andrews#
66b8c8deeSWill Andrews# Redistribution and use in source and binary forms, with or without
76b8c8deeSWill Andrews# modification, are permitted provided that the following conditions
86b8c8deeSWill Andrews# are met:
96b8c8deeSWill Andrews# 1. Redistributions of source code must retain the above copyright
106b8c8deeSWill Andrews#    notice, this list of conditions and the following disclaimer.
116b8c8deeSWill Andrews# 2. Redistributions in binary form must reproduce the above copyright
126b8c8deeSWill Andrews#    notice, this list of conditions and the following disclaimer in the
136b8c8deeSWill Andrews#    documentation and/or other materials provided with the distribution.
146b8c8deeSWill Andrews#
156b8c8deeSWill Andrews# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
166b8c8deeSWill Andrews# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
176b8c8deeSWill Andrews# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
186b8c8deeSWill Andrews# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
196b8c8deeSWill Andrews# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
206b8c8deeSWill Andrews# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
216b8c8deeSWill Andrews# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
226b8c8deeSWill Andrews# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
236b8c8deeSWill Andrews# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
246b8c8deeSWill Andrews# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
256b8c8deeSWill Andrews# SUCH DAMAGE.
266b8c8deeSWill Andrews#
276b8c8deeSWill Andrews# $FreeBSD$
286b8c8deeSWill Andrews#
296b8c8deeSWill Andrews
306b8c8deeSWill Andrewsset -e
316b8c8deeSWill Andrews
326b8c8deeSWill Andrews#######################################################################
336b8c8deeSWill Andrews#
346b8c8deeSWill Andrews# Setup default values for all controlling variables.
356b8c8deeSWill Andrews# These values can be overridden from the config file(s)
366b8c8deeSWill Andrews#
376b8c8deeSWill Andrews#######################################################################
386b8c8deeSWill Andrews
396b8c8deeSWill Andrews# Name of this NanoBSD build.  (Used to construct workdir names)
406b8c8deeSWill AndrewsNANO_NAME=full
416b8c8deeSWill Andrews
426b8c8deeSWill Andrews# Source tree directory
436b8c8deeSWill AndrewsNANO_SRC=/usr/src
446b8c8deeSWill Andrews
456b8c8deeSWill Andrews# Where nanobsd additional files live under the source tree
466b8c8deeSWill AndrewsNANO_TOOLS=tools/tools/nanobsd
476b8c8deeSWill Andrews
4818803951SWarner Losh# Where cust_pkgng() finds packages to install
496b8c8deeSWill AndrewsNANO_PACKAGE_DIR=${NANO_SRC}/${NANO_TOOLS}/Pkg
506b8c8deeSWill AndrewsNANO_PACKAGE_LIST="*"
516b8c8deeSWill Andrews
526b8c8deeSWill Andrews# where package metadata gets placed
536b8c8deeSWill AndrewsNANO_PKG_META_BASE=/var/db
546b8c8deeSWill Andrews
556b8c8deeSWill Andrews# Object tree directory
566b8c8deeSWill Andrews# default is subdir of /usr/obj
576b8c8deeSWill Andrews#NANO_OBJ=""
586b8c8deeSWill Andrews
596b8c8deeSWill Andrews# The directory to put the final images
606b8c8deeSWill Andrews# default is ${NANO_OBJ}
616b8c8deeSWill Andrews#NANO_DISKIMGDIR=""
626b8c8deeSWill Andrews
636b8c8deeSWill Andrews# Make & parallel Make
646b8c8deeSWill AndrewsNANO_MAKE="make"
656b8c8deeSWill AndrewsNANO_PMAKE="make -j 3"
666b8c8deeSWill Andrews
676b8c8deeSWill Andrews# The default name for any image we create.
686b8c8deeSWill AndrewsNANO_IMGNAME="_.disk.full"
696b8c8deeSWill Andrews
706b8c8deeSWill Andrews# Options to put in make.conf during buildworld only
716b8c8deeSWill AndrewsCONF_BUILD=' '
726b8c8deeSWill Andrews
736b8c8deeSWill Andrews# Options to put in make.conf during installworld only
746b8c8deeSWill AndrewsCONF_INSTALL=' '
756b8c8deeSWill Andrews
766b8c8deeSWill Andrews# Options to put in make.conf during both build- & installworld.
776b8c8deeSWill AndrewsCONF_WORLD=' '
786b8c8deeSWill Andrews
796b8c8deeSWill Andrews# Kernel config file to use
806b8c8deeSWill AndrewsNANO_KERNEL=GENERIC
816b8c8deeSWill Andrews
826b8c8deeSWill Andrews# Kernel modules to install. If empty, no modules are installed.
836b8c8deeSWill Andrews# Use "default" to install all built modules.
846b8c8deeSWill AndrewsNANO_MODULES=
856b8c8deeSWill Andrews
865b4ca9d7SGleb Smirnoff# Early customize commands.
875b4ca9d7SGleb SmirnoffNANO_EARLY_CUSTOMIZE=""
885b4ca9d7SGleb Smirnoff
896b8c8deeSWill Andrews# Customize commands.
906b8c8deeSWill AndrewsNANO_CUSTOMIZE=""
916b8c8deeSWill Andrews
926b8c8deeSWill Andrews# Late customize commands.
936b8c8deeSWill AndrewsNANO_LATE_CUSTOMIZE=""
946b8c8deeSWill Andrews
956b8c8deeSWill Andrews# Newfs paramters to use
966b8c8deeSWill AndrewsNANO_NEWFS="-b 4096 -f 512 -i 8192 -U"
976b8c8deeSWill Andrews
986b8c8deeSWill Andrews# The drive name of the media at runtime
994c1ca03bSWarner LoshNANO_DRIVE=ada0
1006b8c8deeSWill Andrews
1016b8c8deeSWill Andrews# Target media size in 512 bytes sectors
1026b8c8deeSWill AndrewsNANO_MEDIASIZE=2000000
1036b8c8deeSWill Andrews
1046b8c8deeSWill Andrews# Number of code images on media (1 or 2)
1056b8c8deeSWill AndrewsNANO_IMAGES=2
1066b8c8deeSWill Andrews
1076b8c8deeSWill Andrews# 0 -> Leave second image all zeroes so it compresses better.
1086b8c8deeSWill Andrews# 1 -> Initialize second image with a copy of the first
1096b8c8deeSWill AndrewsNANO_INIT_IMG2=1
1106b8c8deeSWill Andrews
1116b8c8deeSWill Andrews# Size of code file system in 512 bytes sectors
1126b8c8deeSWill Andrews# If zero, size will be as large as possible.
1136b8c8deeSWill AndrewsNANO_CODESIZE=0
1146b8c8deeSWill Andrews
1156b8c8deeSWill Andrews# Size of configuration file system in 512 bytes sectors
1166b8c8deeSWill Andrews# Cannot be zero.
1176b8c8deeSWill AndrewsNANO_CONFSIZE=2048
1186b8c8deeSWill Andrews
1196b8c8deeSWill Andrews# Size of data file system in 512 bytes sectors
1206b8c8deeSWill Andrews# If zero: no partition configured.
1216b8c8deeSWill Andrews# If negative: max size possible
1226b8c8deeSWill AndrewsNANO_DATASIZE=0
1236b8c8deeSWill Andrews
1246b8c8deeSWill Andrews# Size of the /etc ramdisk in 512 bytes sectors
1256b8c8deeSWill AndrewsNANO_RAM_ETCSIZE=10240
1266b8c8deeSWill Andrews
1276b8c8deeSWill Andrews# Size of the /tmp+/var ramdisk in 512 bytes sectors
1286b8c8deeSWill AndrewsNANO_RAM_TMPVARSIZE=10240
1296b8c8deeSWill Andrews
1306b8c8deeSWill Andrews# Media geometry, only relevant if bios doesn't understand LBA.
1316b8c8deeSWill AndrewsNANO_SECTS=63
1326b8c8deeSWill AndrewsNANO_HEADS=16
1336b8c8deeSWill Andrews
1346b8c8deeSWill Andrews# boot0 flags/options and configuration
1356b8c8deeSWill AndrewsNANO_BOOT0CFG="-o packet -s 1 -m 3"
1366b8c8deeSWill AndrewsNANO_BOOTLOADER="boot/boot0sio"
1376b8c8deeSWill Andrews
1386b8c8deeSWill Andrews# boot2 flags/options
1396b8c8deeSWill Andrews# default force serial console
140a9598aaeSWarner LoshNANO_BOOT2CFG="-h -S115200"
1416b8c8deeSWill Andrews
1426b8c8deeSWill Andrews# Backing type of md(4) device
1436b8c8deeSWill Andrews# Can be "file" or "swap"
1446b8c8deeSWill AndrewsNANO_MD_BACKING="file"
1456b8c8deeSWill Andrews
1466b8c8deeSWill Andrews# for swap type md(4) backing, write out the mbr only
1476b8c8deeSWill AndrewsNANO_IMAGE_MBRONLY=true
1486b8c8deeSWill Andrews
1496b8c8deeSWill Andrews# Progress Print level
1506b8c8deeSWill AndrewsPPLEVEL=3
1516b8c8deeSWill Andrews
1526b8c8deeSWill Andrews# Set NANO_LABEL to non-blank to form the basis for using /dev/ufs/label
1536b8c8deeSWill Andrews# in preference to /dev/${NANO_DRIVE}
1546b8c8deeSWill Andrews# Root partition will be ${NANO_LABEL}s{1,2}
1556b8c8deeSWill Andrews# /cfg partition will be ${NANO_LABEL}s3
1566b8c8deeSWill Andrews# /data partition will be ${NANO_LABEL}s4
1576b8c8deeSWill AndrewsNANO_LABEL=""
1587b77d3eaSWarner LoshNANO_SLICE_ROOT=s1
1597b77d3eaSWarner LoshNANO_SLICE_ALTROOT=s2
1607b77d3eaSWarner LoshNANO_SLICE_CFG=s3
1617b77d3eaSWarner LoshNANO_SLICE_DATA=s4
1625e4bd293SWarner LoshNANO_ROOT=s1a
1635e4bd293SWarner LoshNANO_ALTROOT=s2a
1647b77d3eaSWarner Losh
16519edffefSWarner Losh# Default ownwership for nopriv build
16619edffefSWarner LoshNANO_DEF_UNAME=root
16719edffefSWarner LoshNANO_DEF_GNAME=wheel
1686b8c8deeSWill Andrews
1696b8c8deeSWill Andrews#######################################################################
1706b8c8deeSWill Andrews# Architecture to build.  Corresponds to TARGET_ARCH in a buildworld.
1716b8c8deeSWill Andrews# Unfortunately, there's no way to set TARGET at this time, and it
172d07833f9SWarner Losh# conflates the two, so architectures where TARGET != TARGET_ARCH and
173d07833f9SWarner Losh# TARGET can't be guessed from TARGET_ARCH do not work.  This defaults
174d07833f9SWarner Losh# to the arch of the current machine.
1756b8c8deeSWill AndrewsNANO_ARCH=`uname -p`
1766b8c8deeSWill Andrews
177d07833f9SWarner Losh# CPUTYPE defaults to "" which is the default when CPUTYPE isn't
178d07833f9SWarner Losh# defined.
179d07833f9SWarner LoshNANO_CPUTYPE=""
180d07833f9SWarner Losh
1816b8c8deeSWill Andrews# Directory to populate /cfg from
1826b8c8deeSWill AndrewsNANO_CFGDIR=""
1836b8c8deeSWill Andrews
1846b8c8deeSWill Andrews# Directory to populate /data from
1856b8c8deeSWill AndrewsNANO_DATADIR=""
1866b8c8deeSWill Andrews
187a9d9c49fSWarner Losh# We don't need SRCCONF or SRC_ENV_CONF. NanoBSD puts everything we
188a9d9c49fSWarner Losh# need for the build in files included with __MAKE_CONF. Override in your
189a9d9c49fSWarner Losh# config file if you really must. We set them unconditionally here, though
190a9d9c49fSWarner Losh# in case they are stray in the build environment
191a9d9c49fSWarner LoshSRCCONF=/dev/null
192a9d9c49fSWarner LoshSRC_ENV_CONF=/dev/null
1936b8c8deeSWill Andrews
1946b8c8deeSWill Andrews#######################################################################
1956b8c8deeSWill Andrews#
1966b8c8deeSWill Andrews# The functions which do the real work.
1976b8c8deeSWill Andrews# Can be overridden from the config file(s)
1986b8c8deeSWill Andrews#
1996b8c8deeSWill Andrews#######################################################################
2006b8c8deeSWill Andrews
2011934c7aaSWarner Losh# Export values into the shell. Must use { } instead of ( ) like
2021934c7aaSWarner Losh# other functions to avoid a subshell.
2031934c7aaSWarner Losh# We set __MAKE_CONF as a global since it is easier to get quoting
2041934c7aaSWarner Losh# right for paths with spaces in them.
2051934c7aaSWarner Loshmake_export ( ) {
2061934c7aaSWarner Losh	# Similar to export_var, except puts the data out to stdout
2071934c7aaSWarner Losh	var=$1
2081934c7aaSWarner Losh	eval val=\$$var
2091934c7aaSWarner Losh	echo "Setting variable: $var=\"$val\""
2101934c7aaSWarner Losh	export $1
2111934c7aaSWarner Losh}
2121934c7aaSWarner Losh
2131934c7aaSWarner Loshnano_make_build_env ( ) {
2141934c7aaSWarner Losh	__MAKE_CONF="${NANO_MAKE_CONF_BUILD}"
2151934c7aaSWarner Losh	make_export __MAKE_CONF
2161934c7aaSWarner Losh}
2171934c7aaSWarner Losh
2181934c7aaSWarner Loshnano_make_install_env ( ) {
2191934c7aaSWarner Losh	__MAKE_CONF="${NANO_MAKE_CONF_INSTALL}"
2201934c7aaSWarner Losh	make_export __MAKE_CONF
2211934c7aaSWarner Losh}
2221934c7aaSWarner Losh
2231934c7aaSWarner Losh# Extra environment variables for kernel builds
2241934c7aaSWarner Loshnano_make_kernel_env ( ) {
2251934c7aaSWarner Losh	if [ -f ${NANO_KERNEL} ] ; then
2261934c7aaSWarner Losh		KERNCONFDIR="$(realpath $(dirname ${NANO_KERNEL}))"
2271934c7aaSWarner Losh		KERNCONF="$(basename ${NANO_KERNEL})"
2281934c7aaSWarner Losh		make_export KERNCONFDIR
2291934c7aaSWarner Losh		make_export KERNCONF
2301934c7aaSWarner Losh	else
2311934c7aaSWarner Losh		export KERNCONF="${NANO_KERNEL}"
2321934c7aaSWarner Losh		make_export KERNCONF
2331934c7aaSWarner Losh	fi
2341934c7aaSWarner Losh}
2351934c7aaSWarner Losh
2361934c7aaSWarner Loshnano_global_make_env ( ) (
237849f5467SWarner Losh	# global settings for the make.conf file, if set
238849f5467SWarner Losh	[ -z "${NANO_ARCH}" ] || echo TARGET_ARCH="${NANO_ARCH}"
239849f5467SWarner Losh	[ -z "${NANO_CPUTYPE}" ] || echo TARGET_CPUTYPE="${NANO_CPUTYPE}"
2401934c7aaSWarner Losh)
2411934c7aaSWarner Losh
2426b8c8deeSWill Andrews# rm doesn't know -x prior to FreeBSD 10, so cope with a variety of build
243849f5467SWarner Losh# hosts for now. This will go away when support in the base goes away.
244849f5467SWarner Loshrm ( ) {
245849f5467SWarner Losh    echo "NANO RM $*"
2466b8c8deeSWill Andrews	case $(uname -r) in
247849f5467SWarner Losh	7*|8*|9*) command rm $* ;;
248849f5467SWarner Losh	*) command rm -x $* ;;
2496b8c8deeSWill Andrews	esac
2506b8c8deeSWill Andrews}
2516b8c8deeSWill Andrews
25219edffefSWarner Losh#
25319edffefSWarner Losh# Create empty files in the target tree, and record the fact.  All paths
25419edffefSWarner Losh# are relative to NANO_WORLDDIR.
25519edffefSWarner Losh#
25619edffefSWarner Loshtgt_touch ( ) (
25719edffefSWarner Losh
25819edffefSWarner Losh	cd "${NANO_WORLDDIR}"
25919edffefSWarner Losh	for i; do
26019edffefSWarner Losh		touch $i
26119edffefSWarner Losh		echo "./${i} type=file" >> ${NANO_METALOG}
26219edffefSWarner Losh	done
26319edffefSWarner Losh)
26419edffefSWarner Losh
26519edffefSWarner Losh#
26619edffefSWarner Losh# Convert a directory into a symlink. Takes two arguments, the
26719edffefSWarner Losh# current directory and what it should become a symlink to. The
26819edffefSWarner Losh# directory is removed and a symlink is created. If we're doing
26919edffefSWarner Losh# a nopriv build, then append this fact to the metalog
27019edffefSWarner Losh#
27119edffefSWarner Loshtgt_dir2symlink () (
27219edffefSWarner Losh	dir=$1
27319edffefSWarner Losh	symlink=$2
27419edffefSWarner Losh
27519edffefSWarner Losh	cd "${NANO_WORLDDIR}"
27619edffefSWarner Losh	rm -rf "$dir"
27719edffefSWarner Losh	ln -s "$symlink" "$dir"
2780a852830SWarner Losh	if [ -n "$NANO_METALOG" ]; then
27919edffefSWarner Losh		echo "./${dir} type=link mode=0777 link=${symlink}" >> ${NANO_METALOG}
28019edffefSWarner Losh	fi
28119edffefSWarner Losh)
28219edffefSWarner Losh
2836b8c8deeSWill Andrews# run in the world chroot, errors fatal
2841934c7aaSWarner LoshCR ( ) {
2851934c7aaSWarner Losh	chroot "${NANO_WORLDDIR}" /bin/sh -exc "$*"
2866b8c8deeSWill Andrews}
2876b8c8deeSWill Andrews
2886b8c8deeSWill Andrews# run in the world chroot, errors not fatal
2891934c7aaSWarner LoshCR0 ( ) {
2901934c7aaSWarner Losh	chroot "${NANO_WORLDDIR}" /bin/sh -c "$*" || true
2916b8c8deeSWill Andrews}
2926b8c8deeSWill Andrews
2936b8c8deeSWill Andrewsnano_cleanup ( ) (
294849f5467SWarner Losh	[ $? -eq 0 ] || echo "Error encountered.  Check for errors in last log file." 1>&2
2956b8c8deeSWill Andrews	exit $?
2966b8c8deeSWill Andrews)
2976b8c8deeSWill Andrews
2986b8c8deeSWill Andrewsclean_build ( ) (
2996b8c8deeSWill Andrews	pprint 2 "Clean and create object directory (${MAKEOBJDIRPREFIX})"
3006b8c8deeSWill Andrews
301849f5467SWarner Losh	if ! rm -rf ${MAKEOBJDIRPREFIX}/ > /dev/null 2>&1 ; then
3026b8c8deeSWill Andrews		chflags -R noschg ${MAKEOBJDIRPREFIX}/
303849f5467SWarner Losh		rm -r ${MAKEOBJDIRPREFIX}/
3046b8c8deeSWill Andrews	fi
3056b8c8deeSWill Andrews)
3066b8c8deeSWill Andrews
3076b8c8deeSWill Andrewsmake_conf_build ( ) (
3086b8c8deeSWill Andrews	pprint 2 "Construct build make.conf ($NANO_MAKE_CONF_BUILD)"
3096b8c8deeSWill Andrews
3106b8c8deeSWill Andrews	mkdir -p ${MAKEOBJDIRPREFIX}
3116b8c8deeSWill Andrews	printenv > ${MAKEOBJDIRPREFIX}/_.env
3126b8c8deeSWill Andrews
3131934c7aaSWarner Losh	# Make sure we get all the global settings that NanoBSD wants
3141934c7aaSWarner Losh	# in addition to the user's global settings
3151934c7aaSWarner Losh	(
3161934c7aaSWarner Losh	nano_global_make_env
3171934c7aaSWarner Losh	echo "${CONF_WORLD}"
3181934c7aaSWarner Losh	echo "${CONF_BUILD}"
3191934c7aaSWarner Losh	) > ${NANO_MAKE_CONF_BUILD}
3206b8c8deeSWill Andrews)
3216b8c8deeSWill Andrews
3226b8c8deeSWill Andrewsbuild_world ( ) (
3236b8c8deeSWill Andrews	pprint 2 "run buildworld"
3246b8c8deeSWill Andrews	pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bw"
3256b8c8deeSWill Andrews
3261934c7aaSWarner Losh	(
3271934c7aaSWarner Losh	nano_make_build_env
3281934c7aaSWarner Losh	set -o xtrace
3291934c7aaSWarner Losh	cd "${NANO_SRC}"
3301934c7aaSWarner Losh	${NANO_PMAKE} buildworld
3311934c7aaSWarner Losh	) > ${MAKEOBJDIRPREFIX}/_.bw 2>&1
3326b8c8deeSWill Andrews)
3336b8c8deeSWill Andrews
3346b8c8deeSWill Andrewsbuild_kernel ( ) (
3356b8c8deeSWill Andrews	local extra
3366b8c8deeSWill Andrews
3376b8c8deeSWill Andrews	pprint 2 "build kernel ($NANO_KERNEL)"
3386b8c8deeSWill Andrews	pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bk"
3396b8c8deeSWill Andrews
3406b8c8deeSWill Andrews	(
3411934c7aaSWarner Losh	nano_make_build_env
3421934c7aaSWarner Losh	nano_make_kernel_env
3436b8c8deeSWill Andrews
3446b8c8deeSWill Andrews	# Note: We intentionally build all modules, not only the ones in
3456b8c8deeSWill Andrews	# NANO_MODULES so the built world can be reused by multiple images.
3461934c7aaSWarner Losh	# Although MODULES_OVERRIDE can be defined in the kenrel config
3471934c7aaSWarner Losh	# file to override this behavior. Just set NANO_MODULES=default.
3481934c7aaSWarner Losh	set -o xtrace
3491934c7aaSWarner Losh	cd "${NANO_SRC}"
3501934c7aaSWarner Losh	${NANO_PMAKE} buildkernel
3516b8c8deeSWill Andrews	) > ${MAKEOBJDIRPREFIX}/_.bk 2>&1
3526b8c8deeSWill Andrews)
3536b8c8deeSWill Andrews
3546b8c8deeSWill Andrewsclean_world ( ) (
3556b8c8deeSWill Andrews	if [ "${NANO_OBJ}" != "${MAKEOBJDIRPREFIX}" ]; then
3566b8c8deeSWill Andrews		pprint 2 "Clean and create object directory (${NANO_OBJ})"
357849f5467SWarner Losh		if ! rm -rf ${NANO_OBJ}/ > /dev/null 2>&1 ; then
3586b8c8deeSWill Andrews			chflags -R noschg ${NANO_OBJ}
359849f5467SWarner Losh			rm -r ${NANO_OBJ}/
3606b8c8deeSWill Andrews		fi
3611934c7aaSWarner Losh		mkdir -p "${NANO_OBJ}" "${NANO_WORLDDIR}"
362c2c06cfaSWarner Losh		printenv > ${NANO_LOG}/_.env
3636b8c8deeSWill Andrews	else
3646b8c8deeSWill Andrews		pprint 2 "Clean and create world directory (${NANO_WORLDDIR})"
365849f5467SWarner Losh		if ! rm -rf "${NANO_WORLDDIR}/" > /dev/null 2>&1 ; then
3661934c7aaSWarner Losh			chflags -R noschg "${NANO_WORLDDIR}"
367849f5467SWarner Losh			rm -rf "${NANO_WORLDDIR}/"
3686b8c8deeSWill Andrews		fi
3691934c7aaSWarner Losh		mkdir -p "${NANO_WORLDDIR}"
3706b8c8deeSWill Andrews	fi
3716b8c8deeSWill Andrews)
3726b8c8deeSWill Andrews
3736b8c8deeSWill Andrewsmake_conf_install ( ) (
3746b8c8deeSWill Andrews	pprint 2 "Construct install make.conf ($NANO_MAKE_CONF_INSTALL)"
3756b8c8deeSWill Andrews
3761934c7aaSWarner Losh	# Make sure we get all the global settings that NanoBSD wants
3771934c7aaSWarner Losh	# in addition to the user's global settings
3781934c7aaSWarner Losh	(
3791934c7aaSWarner Losh	nano_global_make_env
3801934c7aaSWarner Losh	echo "${CONF_WORLD}"
3811934c7aaSWarner Losh	echo "${CONF_INSTALL}"
382849f5467SWarner Losh	if [ -n "${NANO_NOPRIV_BUILD}" ]; then
383c275d9ecSWarner Losh	    echo NO_ROOT=t
384c275d9ecSWarner Losh	    echo METALOG=${NANO_METALOG}
385c275d9ecSWarner Losh	fi
3861934c7aaSWarner Losh	) >  ${NANO_MAKE_CONF_INSTALL}
3876b8c8deeSWill Andrews)
3886b8c8deeSWill Andrews
3896b8c8deeSWill Andrewsinstall_world ( ) (
3906b8c8deeSWill Andrews	pprint 2 "installworld"
391c2c06cfaSWarner Losh	pprint 3 "log: ${NANO_LOG}/_.iw"
3926b8c8deeSWill Andrews
3931934c7aaSWarner Losh	(
3941934c7aaSWarner Losh	nano_make_install_env
3951934c7aaSWarner Losh	set -o xtrace
3961934c7aaSWarner Losh	cd "${NANO_SRC}"
3971934c7aaSWarner Losh	${NANO_MAKE} installworld DESTDIR="${NANO_WORLDDIR}"
3981934c7aaSWarner Losh	chflags -R noschg "${NANO_WORLDDIR}"
399c2c06cfaSWarner Losh	) > ${NANO_LOG}/_.iw 2>&1
4006b8c8deeSWill Andrews)
4016b8c8deeSWill Andrews
4026b8c8deeSWill Andrewsinstall_etc ( ) (
4036b8c8deeSWill Andrews
4046b8c8deeSWill Andrews	pprint 2 "install /etc"
405c2c06cfaSWarner Losh	pprint 3 "log: ${NANO_LOG}/_.etc"
4066b8c8deeSWill Andrews
4071934c7aaSWarner Losh	(
4081934c7aaSWarner Losh	nano_make_install_env
4091934c7aaSWarner Losh	set -o xtrace
4101934c7aaSWarner Losh	cd "${NANO_SRC}"
4111934c7aaSWarner Losh	${NANO_MAKE} distribution DESTDIR="${NANO_WORLDDIR}"
4126b8c8deeSWill Andrews	# make.conf doesn't get created by default, but some ports need it
4136b8c8deeSWill Andrews	# so they can spam it.
4141934c7aaSWarner Losh	cp /dev/null "${NANO_WORLDDIR}"/etc/make.conf
415c2c06cfaSWarner Losh	) > ${NANO_LOG}/_.etc 2>&1
4166b8c8deeSWill Andrews)
4176b8c8deeSWill Andrews
4186b8c8deeSWill Andrewsinstall_kernel ( ) (
4196b8c8deeSWill Andrews	local extra
4206b8c8deeSWill Andrews
4216b8c8deeSWill Andrews	pprint 2 "install kernel ($NANO_KERNEL)"
422c2c06cfaSWarner Losh	pprint 3 "log: ${NANO_LOG}/_.ik"
4236b8c8deeSWill Andrews
4246b8c8deeSWill Andrews	(
4256b8c8deeSWill Andrews
4261934c7aaSWarner Losh	nano_make_install_env
4271934c7aaSWarner Losh	nano_make_kernel_env
4281934c7aaSWarner Losh
4296b8c8deeSWill Andrews	if [ "${NANO_MODULES}" != "default" ]; then
4301934c7aaSWarner Losh		MODULES_OVERRIDE="${NANO_MODULES}"
4311934c7aaSWarner Losh		make_export MODULES_OVERRIDE
4326b8c8deeSWill Andrews	fi
4336b8c8deeSWill Andrews
4341934c7aaSWarner Losh	set -o xtrace
4351934c7aaSWarner Losh	cd "${NANO_SRC}"
4361934c7aaSWarner Losh	${NANO_MAKE} installkernel DESTDIR="${NANO_WORLDDIR}"
4371934c7aaSWarner Losh
438c2c06cfaSWarner Losh	) > ${NANO_LOG}/_.ik 2>&1
4396b8c8deeSWill Andrews)
4406b8c8deeSWill Andrews
4416b8c8deeSWill Andrewsnative_xtools ( ) (
4426b8c8deeSWill Andrews	print 2 "Installing the optimized native build tools for cross env"
443c2c06cfaSWarner Losh	pprint 3 "log: ${NANO_LOG}/_.native_xtools"
4446b8c8deeSWill Andrews
4451934c7aaSWarner Losh	(
4461934c7aaSWarner Losh
4471934c7aaSWarner Losh	nano_make_install_env
4481934c7aaSWarner Losh	set -o xtrace
4491934c7aaSWarner Losh	cd "${NANO_SRC}"
4501934c7aaSWarner Losh	${NANO_MAKE} native-xtools DESTDIR="${NANO_WORLDDIR}"
4511934c7aaSWarner Losh
452c2c06cfaSWarner Losh	) > ${NANO_LOG}/_.native_xtools 2>&1
4536b8c8deeSWill Andrews)
4546b8c8deeSWill Andrews
45519edffefSWarner Losh#
4565b4ca9d7SGleb Smirnoff# Run the requested set of early customization scripts, run before
4575b4ca9d7SGleb Smirnoff# buildworld.
4585b4ca9d7SGleb Smirnoff#
4595b4ca9d7SGleb Smirnoffrun_early_customize() {
4605b4ca9d7SGleb Smirnoff
4615b4ca9d7SGleb Smirnoff	pprint 2 "run early customize scripts"
4625b4ca9d7SGleb Smirnoff	for c in $NANO_EARLY_CUSTOMIZE
4635b4ca9d7SGleb Smirnoff	do
4645b4ca9d7SGleb Smirnoff		pprint 2 "early customize \"$c\""
4655b4ca9d7SGleb Smirnoff		pprint 3 "log: ${NANO_LOG}/_.early_cust.$c"
4665b4ca9d7SGleb Smirnoff		pprint 4 "`type $c`"
4675b4ca9d7SGleb Smirnoff		{ set -x ; $c ; set +x ; } >${NANO_LOG}/_.early_cust.$c 2>&1
4685b4ca9d7SGleb Smirnoff	done
4695b4ca9d7SGleb Smirnoff}
4705b4ca9d7SGleb Smirnoff
4715b4ca9d7SGleb Smirnoff#
47219edffefSWarner Losh# Run the requested set of customization scripts, run after we've
47319edffefSWarner Losh# done an installworld, installed the etc files, installed the kernel
47419edffefSWarner Losh# and tweaked them in the standard way.
47519edffefSWarner Losh#
4766b8c8deeSWill Andrewsrun_customize ( ) (
4776b8c8deeSWill Andrews
4786b8c8deeSWill Andrews	pprint 2 "run customize scripts"
4796b8c8deeSWill Andrews	for c in $NANO_CUSTOMIZE
4806b8c8deeSWill Andrews	do
4816b8c8deeSWill Andrews		pprint 2 "customize \"$c\""
482c2c06cfaSWarner Losh		pprint 3 "log: ${NANO_LOG}/_.cust.$c"
4836b8c8deeSWill Andrews		pprint 4 "`type $c`"
484c2c06cfaSWarner Losh		( set -x ; $c ) > ${NANO_LOG}/_.cust.$c 2>&1
4856b8c8deeSWill Andrews	done
4866b8c8deeSWill Andrews)
4876b8c8deeSWill Andrews
48819edffefSWarner Losh#
48919edffefSWarner Losh# Run any last-minute customization commands after we've had a chance to
49019edffefSWarner Losh# setup nanobsd, prune empty dirs from /usr, etc
49119edffefSWarner Losh#
4926b8c8deeSWill Andrewsrun_late_customize ( ) (
4936b8c8deeSWill Andrews
4946b8c8deeSWill Andrews	pprint 2 "run late customize scripts"
4956b8c8deeSWill Andrews	for c in $NANO_LATE_CUSTOMIZE
4966b8c8deeSWill Andrews	do
4976b8c8deeSWill Andrews		pprint 2 "late customize \"$c\""
498c2c06cfaSWarner Losh		pprint 3 "log: ${NANO_LOG}/_.late_cust.$c"
4996b8c8deeSWill Andrews		pprint 4 "`type $c`"
500c2c06cfaSWarner Losh		( set -x ; $c ) > ${NANO_LOG}/_.late_cust.$c 2>&1
5016b8c8deeSWill Andrews	done
5026b8c8deeSWill Andrews)
5036b8c8deeSWill Andrews
50419edffefSWarner Losh#
50519edffefSWarner Losh# Hook called after we run all the late customize commands, but
50619edffefSWarner Losh# before we invoke the disk imager. The nopriv build uses it to
50719edffefSWarner Losh# read in the meta log, apply the changes other parts of nanobsd
50819edffefSWarner Losh# have been recording their actions. It's not anticipated that
50919edffefSWarner Losh# a user's cfg file would override this.
51019edffefSWarner Losh#
51119edffefSWarner Loshfixup_before_diskimage ( ) (
51219edffefSWarner Losh
51319edffefSWarner Losh	# Run the deduplication script that takes the matalog journal and
51419edffefSWarner Losh	# combines multiple entries for the same file (see source for
51519edffefSWarner Losh	# details). We take the extra step of removing the size keywords. This
51619edffefSWarner Losh	# script, and many of the user scripts, copies, appeneds and otherwise
51719edffefSWarner Losh	# modifies files in the build, changing their sizes.  These actions are
51819edffefSWarner Losh	# impossible to trap, so go ahead remove the size= keyword. For this
51919edffefSWarner Losh	# narrow use, it doesn't buy us any protection and just gets in the way.
52019edffefSWarner Losh	# The dedup tool's output must be sorted due to limitations in awk.
5210a852830SWarner Losh	if [ -n "${NANO_METALOG}" ]; then
52219edffefSWarner Losh		pprint 2 "Fixing metalog"
52319edffefSWarner Losh		cp ${NANO_METALOG} ${NANO_METALOG}.pre
52445b2ffd0SWarner Losh		echo "/set uname=${NANO_DEF_UNAME} gname=${NANO_DEF_GNAME}" > ${NANO_METALOG}
52545b2ffd0SWarner Losh		cat ${NANO_METALOG}.pre | ${NANO_TOOLS}/mtree-dedup.awk | \
52645b2ffd0SWarner Losh		    sed -e 's/ size=[0-9][0-9]*//' | sort >> ${NANO_METALOG}
52719edffefSWarner Losh	fi
52819edffefSWarner Losh)
52919edffefSWarner Losh
5306b8c8deeSWill Andrewssetup_nanobsd ( ) (
5316b8c8deeSWill Andrews	pprint 2 "configure nanobsd setup"
532c2c06cfaSWarner Losh	pprint 3 "log: ${NANO_LOG}/_.dl"
5336b8c8deeSWill Andrews
5346b8c8deeSWill Andrews	(
5351934c7aaSWarner Losh	cd "${NANO_WORLDDIR}"
5366b8c8deeSWill Andrews
5376b8c8deeSWill Andrews	# Move /usr/local/etc to /etc/local so that the /cfg stuff
5386b8c8deeSWill Andrews	# can stomp on it.  Otherwise packages like ipsec-tools which
5396b8c8deeSWill Andrews	# have hardcoded paths under ${prefix}/etc are not tweakable.
5406b8c8deeSWill Andrews	if [ -d usr/local/etc ] ; then
5416b8c8deeSWill Andrews		(
5426b8c8deeSWill Andrews		mkdir -p etc/local
5436b8c8deeSWill Andrews		cd usr/local/etc
5446b8c8deeSWill Andrews		find . -print | cpio -dumpl ../../../etc/local
5456b8c8deeSWill Andrews		cd ..
546849f5467SWarner Losh		rm -rf etc
5476b8c8deeSWill Andrews		ln -s ../../etc/local etc
5486b8c8deeSWill Andrews		)
5496b8c8deeSWill Andrews	fi
5506b8c8deeSWill Andrews
5516b8c8deeSWill Andrews	for d in var etc
5526b8c8deeSWill Andrews	do
5536b8c8deeSWill Andrews		# link /$d under /conf
5546b8c8deeSWill Andrews		# we use hard links so we have them both places.
5556b8c8deeSWill Andrews		# the files in /$d will be hidden by the mount.
5566b8c8deeSWill Andrews		mkdir -p conf/base/$d conf/default/$d
5576b8c8deeSWill Andrews		find $d -print | cpio -dumpl conf/base/
5586b8c8deeSWill Andrews	done
5596b8c8deeSWill Andrews
5606b8c8deeSWill Andrews	echo "$NANO_RAM_ETCSIZE" > conf/base/etc/md_size
5616b8c8deeSWill Andrews	echo "$NANO_RAM_TMPVARSIZE" > conf/base/var/md_size
5626b8c8deeSWill Andrews
5636b8c8deeSWill Andrews	# pick up config files from the special partition
5647b77d3eaSWarner Losh	echo "mount -o ro /dev/${NANO_DRIVE}${NANO_SLICE_CFG}" > conf/default/etc/remount
5656b8c8deeSWill Andrews
5666b8c8deeSWill Andrews	# Put /tmp on the /var ramdisk (could be symlink already)
56719edffefSWarner Losh	tgt_dir2symlink tmp var/tmp
5686b8c8deeSWill Andrews
569c2c06cfaSWarner Losh	) > ${NANO_LOG}/_.dl 2>&1
5706b8c8deeSWill Andrews)
5716b8c8deeSWill Andrews
5726b8c8deeSWill Andrewssetup_nanobsd_etc ( ) (
5736b8c8deeSWill Andrews	pprint 2 "configure nanobsd /etc"
5746b8c8deeSWill Andrews
5756b8c8deeSWill Andrews	(
5761934c7aaSWarner Losh	cd "${NANO_WORLDDIR}"
5776b8c8deeSWill Andrews
5786b8c8deeSWill Andrews	# create diskless marker file
5796b8c8deeSWill Andrews	touch etc/diskless
5806b8c8deeSWill Andrews
581849f5467SWarner Losh	[ -n "${NANO_NOPRIV_BUILD}" ] && chmod 666 etc/defaults/rc.conf
5829e144f35SWarner Losh
5839e144f35SWarner Losh	# Make root filesystem R/O by default
5846b8c8deeSWill Andrews	echo "root_rw_mount=NO" >> etc/defaults/rc.conf
5859e144f35SWarner Losh	# Disable entropy file, since / is read-only /var/db/entropy should be enough?
5869e144f35SWarner Losh	echo "entropy_file=NO" >> etc/defaults/rc.conf
5879e144f35SWarner Losh
588849f5467SWarner Losh	[ -n "${NANO_NOPRIV_BUILD}" ] && chmod 444 etc/defaults/rc.conf
5896b8c8deeSWill Andrews
5906b8c8deeSWill Andrews	# save config file for scripts
5916b8c8deeSWill Andrews	echo "NANO_DRIVE=${NANO_DRIVE}" > etc/nanobsd.conf
5926b8c8deeSWill Andrews
5935e4bd293SWarner Losh	echo "/dev/${NANO_DRIVE}${NANO_ROOT} / ufs ro 1 1" > etc/fstab
5947b77d3eaSWarner Losh	echo "/dev/${NANO_DRIVE}${NANO_SLICE_CFG} /cfg ufs rw,noauto 2 2" >> etc/fstab
5956b8c8deeSWill Andrews	mkdir -p cfg
5966b8c8deeSWill Andrews	)
5976b8c8deeSWill Andrews)
5986b8c8deeSWill Andrews
5996b8c8deeSWill Andrewsprune_usr ( ) (
6006b8c8deeSWill Andrews
6016b8c8deeSWill Andrews	# Remove all empty directories in /usr
6021934c7aaSWarner Losh	find "${NANO_WORLDDIR}"/usr -type d -depth -print |
6036b8c8deeSWill Andrews		while read d
6046b8c8deeSWill Andrews		do
6056b8c8deeSWill Andrews			rmdir $d > /dev/null 2>&1 || true
6066b8c8deeSWill Andrews		done
6076b8c8deeSWill Andrews)
6086b8c8deeSWill Andrews
6096b8c8deeSWill Andrewsnewfs_part ( ) (
6106b8c8deeSWill Andrews	local dev mnt lbl
6116b8c8deeSWill Andrews	dev=$1
6126b8c8deeSWill Andrews	mnt=$2
6136b8c8deeSWill Andrews	lbl=$3
6146b8c8deeSWill Andrews	echo newfs ${NANO_NEWFS} ${NANO_LABEL:+-L${NANO_LABEL}${lbl}} ${dev}
6156b8c8deeSWill Andrews	newfs ${NANO_NEWFS} ${NANO_LABEL:+-L${NANO_LABEL}${lbl}} ${dev}
6166b8c8deeSWill Andrews	mount -o async ${dev} ${mnt}
6176b8c8deeSWill Andrews)
6186b8c8deeSWill Andrews
6196b8c8deeSWill Andrews# Convenient spot to work around any umount issues that your build environment
6206b8c8deeSWill Andrews# hits by overriding this method.
6216b8c8deeSWill Andrewsnano_umount ( ) (
6226b8c8deeSWill Andrews	umount ${1}
6236b8c8deeSWill Andrews)
6246b8c8deeSWill Andrews
6256b8c8deeSWill Andrewspopulate_slice ( ) (
6266b8c8deeSWill Andrews	local dev dir mnt lbl
6276b8c8deeSWill Andrews	dev=$1
6286b8c8deeSWill Andrews	dir=$2
6296b8c8deeSWill Andrews	mnt=$3
6306b8c8deeSWill Andrews	lbl=$4
6316b8c8deeSWill Andrews	echo "Creating ${dev} (mounting on ${mnt})"
6326b8c8deeSWill Andrews	newfs_part ${dev} ${mnt} ${lbl}
6336b8c8deeSWill Andrews	if [ -n "${dir}" -a -d "${dir}" ]; then
6346b8c8deeSWill Andrews		echo "Populating ${lbl} from ${dir}"
6351934c7aaSWarner Losh		cd "${dir}"
6366b8c8deeSWill Andrews		find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)' | cpio -dumpv ${mnt}
6376b8c8deeSWill Andrews	fi
6386b8c8deeSWill Andrews	df -i ${mnt}
6396b8c8deeSWill Andrews	nano_umount ${mnt}
6406b8c8deeSWill Andrews)
6416b8c8deeSWill Andrews
6426b8c8deeSWill Andrewspopulate_cfg_slice ( ) (
6436b8c8deeSWill Andrews	populate_slice "$1" "$2" "$3" "$4"
6446b8c8deeSWill Andrews)
6456b8c8deeSWill Andrews
6466b8c8deeSWill Andrewspopulate_data_slice ( ) (
6476b8c8deeSWill Andrews	populate_slice "$1" "$2" "$3" "$4"
6486b8c8deeSWill Andrews)
6496b8c8deeSWill Andrews
6506b8c8deeSWill Andrewscreate_diskimage ( ) (
6516b8c8deeSWill Andrews	pprint 2 "build diskimage"
652c2c06cfaSWarner Losh	pprint 3 "log: ${NANO_LOG}/_.di"
6536b8c8deeSWill Andrews
6546b8c8deeSWill Andrews	(
6556b8c8deeSWill Andrews	echo $NANO_MEDIASIZE $NANO_IMAGES \
6566b8c8deeSWill Andrews		$NANO_SECTS $NANO_HEADS \
6576b8c8deeSWill Andrews		$NANO_CODESIZE $NANO_CONFSIZE $NANO_DATASIZE |
6586b8c8deeSWill Andrews	awk '
6596b8c8deeSWill Andrews	{
6606b8c8deeSWill Andrews		printf "# %s\n", $0
6616b8c8deeSWill Andrews
6626b8c8deeSWill Andrews		# size of cylinder in sectors
6636b8c8deeSWill Andrews		cs = $3 * $4
6646b8c8deeSWill Andrews
6656b8c8deeSWill Andrews		# number of full cylinders on media
6666b8c8deeSWill Andrews		cyl = int ($1 / cs)
6676b8c8deeSWill Andrews
6686b8c8deeSWill Andrews		# output fdisk geometry spec, truncate cyls to 1023
6696b8c8deeSWill Andrews		if (cyl <= 1023)
6706b8c8deeSWill Andrews			print "g c" cyl " h" $4 " s" $3
6716b8c8deeSWill Andrews		else
6726b8c8deeSWill Andrews			print "g c" 1023 " h" $4 " s" $3
6736b8c8deeSWill Andrews
6746b8c8deeSWill Andrews		if ($7 > 0) {
6756b8c8deeSWill Andrews			# size of data partition in full cylinders
6766b8c8deeSWill Andrews			dsl = int (($7 + cs - 1) / cs)
6776b8c8deeSWill Andrews		} else {
6786b8c8deeSWill Andrews			dsl = 0;
6796b8c8deeSWill Andrews		}
6806b8c8deeSWill Andrews
6816b8c8deeSWill Andrews		# size of config partition in full cylinders
6826b8c8deeSWill Andrews		csl = int (($6 + cs - 1) / cs)
6836b8c8deeSWill Andrews
6846b8c8deeSWill Andrews		if ($5 == 0) {
6856b8c8deeSWill Andrews			# size of image partition(s) in full cylinders
6866b8c8deeSWill Andrews			isl = int ((cyl - dsl - csl) / $2)
6876b8c8deeSWill Andrews		} else {
6886b8c8deeSWill Andrews			isl = int (($5 + cs - 1) / cs)
6896b8c8deeSWill Andrews		}
6906b8c8deeSWill Andrews
6916b8c8deeSWill Andrews		# First image partition start at second track
6926b8c8deeSWill Andrews		print "p 1 165 " $3, isl * cs - $3
6936b8c8deeSWill Andrews		c = isl * cs;
6946b8c8deeSWill Andrews
6956b8c8deeSWill Andrews		# Second image partition (if any) also starts offset one
6966b8c8deeSWill Andrews		# track to keep them identical.
6976b8c8deeSWill Andrews		if ($2 > 1) {
6986b8c8deeSWill Andrews			print "p 2 165 " $3 + c, isl * cs - $3
6996b8c8deeSWill Andrews			c += isl * cs;
7006b8c8deeSWill Andrews		}
7016b8c8deeSWill Andrews
7026b8c8deeSWill Andrews		# Config partition starts at cylinder boundary.
7036b8c8deeSWill Andrews		print "p 3 165 " c, csl * cs
7046b8c8deeSWill Andrews		c += csl * cs
7056b8c8deeSWill Andrews
7066b8c8deeSWill Andrews		# Data partition (if any) starts at cylinder boundary.
7076b8c8deeSWill Andrews		if ($7 > 0) {
7086b8c8deeSWill Andrews			print "p 4 165 " c, dsl * cs
7096b8c8deeSWill Andrews		} else if ($7 < 0 && $1 > c) {
7106b8c8deeSWill Andrews			print "p 4 165 " c, $1 - c
7116b8c8deeSWill Andrews		} else if ($1 < c) {
7126b8c8deeSWill Andrews			print "Disk space overcommitted by", \
7136b8c8deeSWill Andrews			    c - $1, "sectors" > "/dev/stderr"
7146b8c8deeSWill Andrews			exit 2
7156b8c8deeSWill Andrews		}
7166b8c8deeSWill Andrews
7176b8c8deeSWill Andrews		# Force slice 1 to be marked active. This is necessary
7186b8c8deeSWill Andrews		# for booting the image from a USB device to work.
7196b8c8deeSWill Andrews		print "a 1"
7206b8c8deeSWill Andrews	}
721c2c06cfaSWarner Losh	' > ${NANO_LOG}/_.fdisk
7226b8c8deeSWill Andrews
7236b8c8deeSWill Andrews	IMG=${NANO_DISKIMGDIR}/${NANO_IMGNAME}
7246b8c8deeSWill Andrews	MNT=${NANO_OBJ}/_.mnt
7256b8c8deeSWill Andrews	mkdir -p ${MNT}
7266b8c8deeSWill Andrews
7276b8c8deeSWill Andrews	if [ "${NANO_MD_BACKING}" = "swap" ] ; then
7286b8c8deeSWill Andrews		MD=`mdconfig -a -t swap -s ${NANO_MEDIASIZE} -x ${NANO_SECTS} \
7296b8c8deeSWill Andrews			-y ${NANO_HEADS}`
7306b8c8deeSWill Andrews	else
7316b8c8deeSWill Andrews		echo "Creating md backing file..."
732849f5467SWarner Losh		rm -f ${IMG}
7336b8c8deeSWill Andrews		dd if=/dev/zero of=${IMG} seek=${NANO_MEDIASIZE} count=0
7346b8c8deeSWill Andrews		MD=`mdconfig -a -t vnode -f ${IMG} -x ${NANO_SECTS} \
7356b8c8deeSWill Andrews			-y ${NANO_HEADS}`
7366b8c8deeSWill Andrews	fi
7376b8c8deeSWill Andrews
7386b8c8deeSWill Andrews	trap "echo 'Running exit trap code' ; df -i ${MNT} ; nano_umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT
7396b8c8deeSWill Andrews
740c2c06cfaSWarner Losh	fdisk -i -f ${NANO_LOG}/_.fdisk ${MD}
7416b8c8deeSWill Andrews	fdisk ${MD}
7426b8c8deeSWill Andrews	# XXX: params
7436b8c8deeSWill Andrews	# XXX: pick up cached boot* files, they may not be in image anymore.
7446b8c8deeSWill Andrews	if [ -f ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ]; then
7456b8c8deeSWill Andrews		boot0cfg -B -b ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ${NANO_BOOT0CFG} ${MD}
7466b8c8deeSWill Andrews	fi
7476b8c8deeSWill Andrews	if [ -f ${NANO_WORLDDIR}/boot/boot ]; then
7487b77d3eaSWarner Losh		bsdlabel -w -B -b ${NANO_WORLDDIR}/boot/boot ${MD}${NANO_SLICE_ROOT}
7496b8c8deeSWill Andrews	else
7507b77d3eaSWarner Losh		bsdlabel -w ${MD}${NANO_SLICE_ROOT}
7516b8c8deeSWill Andrews	fi
7527b77d3eaSWarner Losh	bsdlabel ${MD}${NANO_SLICE_ROOT}
7536b8c8deeSWill Andrews
7546b8c8deeSWill Andrews	# Create first image
7555e4bd293SWarner Losh	populate_slice /dev/${MD}${NANO_ROOT} ${NANO_WORLDDIR} ${MNT} "${NANO_ROOT}"
7565e4bd293SWarner Losh	mount /dev/${MD}${NANO_ROOT} ${MNT}
7576b8c8deeSWill Andrews	echo "Generating mtree..."
758c2c06cfaSWarner Losh	( cd "${MNT}" && mtree -c ) > ${NANO_LOG}/_.mtree
759c2c06cfaSWarner Losh	( cd "${MNT}" && du -k ) > ${NANO_LOG}/_.du
7601934c7aaSWarner Losh	nano_umount "${MNT}"
7616b8c8deeSWill Andrews
7626b8c8deeSWill Andrews	if [ $NANO_IMAGES -gt 1 -a $NANO_INIT_IMG2 -gt 0 ] ; then
7636b8c8deeSWill Andrews		# Duplicate to second image (if present)
7646b8c8deeSWill Andrews		echo "Duplicating to second image..."
7657b77d3eaSWarner Losh		dd conv=sparse if=/dev/${MD}${NANO_SLICE_ROOT} of=/dev/${MD}${NANO_SLICE_ALTROOT} bs=64k
7665e4bd293SWarner Losh		mount /dev/${MD}${NANO_ALTROOT} ${MNT}
7676b8c8deeSWill Andrews		for f in ${MNT}/etc/fstab ${MNT}/conf/base/etc/fstab
7686b8c8deeSWill Andrews		do
7697b77d3eaSWarner Losh			sed -i "" "s=${NANO_DRIVE}${NANO_SLICE_ROOT}=${NANO_DRIVE}${NANO_SLICE_ALTROOT}=g" $f
7706b8c8deeSWill Andrews		done
7716b8c8deeSWill Andrews		nano_umount ${MNT}
7726b8c8deeSWill Andrews		# Override the label from the first partition so we
7736b8c8deeSWill Andrews		# don't confuse glabel with duplicates.
7740a852830SWarner Losh		if [ -n "${NANO_LABEL}" ]; then
7755e4bd293SWarner Losh			tunefs -L ${NANO_LABEL}"${NANO_ALTROOT}" /dev/${MD}${NANO_ALTROOT}
7766b8c8deeSWill Andrews		fi
7776b8c8deeSWill Andrews	fi
7786b8c8deeSWill Andrews
7796b8c8deeSWill Andrews	# Create Config slice
7807b77d3eaSWarner Losh	populate_cfg_slice /dev/${MD}${NANO_SLICE_CFG} "${NANO_CFGDIR}" ${MNT} "${NANO_SLICE_CFG}"
7816b8c8deeSWill Andrews
7826b8c8deeSWill Andrews	# Create Data slice, if any.
7830a852830SWarner Losh	if [ -n "$NANO_SLICE_DATA" -a "$NANO_SLICE_CFG" = "$NANO_SLICE_DATA" -a \
7840a852830SWarner Losh	   "$NANO_DATASIZE" -ne 0 ]; then
7857b77d3eaSWarner Losh		pprint 2 "NANO_SLICE_DATA is the same as NANO_SLICE_CFG, fix."
7867b77d3eaSWarner Losh		exit 2
7877b77d3eaSWarner Losh	fi
7880a852830SWarner Losh	if [ $NANO_DATASIZE -ne 0 -a -n "$NANO_SLICE_DATA" ] ; then
7897b77d3eaSWarner Losh		populate_data_slice /dev/${MD}${NANO_SLICE_DATA} "${NANO_DATADIR}" ${MNT} "${NANO_SLICE_DATA}"
7906b8c8deeSWill Andrews	fi
7916b8c8deeSWill Andrews
7926b8c8deeSWill Andrews	if [ "${NANO_MD_BACKING}" = "swap" ] ; then
7936b8c8deeSWill Andrews		if [ ${NANO_IMAGE_MBRONLY} ]; then
7946b8c8deeSWill Andrews			echo "Writing out _.disk.mbr..."
7956b8c8deeSWill Andrews			dd if=/dev/${MD} of=${NANO_DISKIMGDIR}/_.disk.mbr bs=512 count=1
7966b8c8deeSWill Andrews		else
7976b8c8deeSWill Andrews			echo "Writing out ${NANO_IMGNAME}..."
7986b8c8deeSWill Andrews			dd if=/dev/${MD} of=${IMG} bs=64k
7996b8c8deeSWill Andrews		fi
8006b8c8deeSWill Andrews
8016b8c8deeSWill Andrews		echo "Writing out ${NANO_IMGNAME}..."
8026b8c8deeSWill Andrews		dd conv=sparse if=/dev/${MD} of=${IMG} bs=64k
8036b8c8deeSWill Andrews	fi
8046b8c8deeSWill Andrews
8056b8c8deeSWill Andrews	if ${do_copyout_partition} ; then
8066b8c8deeSWill Andrews		echo "Writing out _.disk.image..."
8077b77d3eaSWarner Losh		dd conv=sparse if=/dev/${MD}${NANO_SLICE_ROOT} of=${NANO_DISKIMGDIR}/_.disk.image bs=64k
8086b8c8deeSWill Andrews	fi
8096b8c8deeSWill Andrews	mdconfig -d -u $MD
8106b8c8deeSWill Andrews
8116b8c8deeSWill Andrews	trap - 1 2 15
8126b8c8deeSWill Andrews	trap nano_cleanup EXIT
8136b8c8deeSWill Andrews
814c2c06cfaSWarner Losh	) > ${NANO_LOG}/_.di 2>&1
8156b8c8deeSWill Andrews)
8166b8c8deeSWill Andrews
8176b8c8deeSWill Andrewslast_orders ( ) (
8186b8c8deeSWill Andrews	# Redefine this function with any last orders you may have
8196b8c8deeSWill Andrews	# after the build completed, for instance to copy the finished
8206b8c8deeSWill Andrews	# image to a more convenient place:
8216b8c8deeSWill Andrews	# cp ${NANO_DISKIMGDIR}/_.disk.image /home/ftp/pub/nanobsd.disk
8226b8c8deeSWill Andrews	true
8236b8c8deeSWill Andrews)
8246b8c8deeSWill Andrews
8256b8c8deeSWill Andrews#######################################################################
8266b8c8deeSWill Andrews#
8276b8c8deeSWill Andrews# Optional convenience functions.
8286b8c8deeSWill Andrews#
8296b8c8deeSWill Andrews#######################################################################
8306b8c8deeSWill Andrews
8316b8c8deeSWill Andrews#######################################################################
8326b8c8deeSWill Andrews# Common Flash device geometries
8336b8c8deeSWill Andrews#
8346b8c8deeSWill Andrews
8356b8c8deeSWill AndrewsFlashDevice ( ) {
8366b8c8deeSWill Andrews	if [ -d ${NANO_TOOLS} ] ; then
8376b8c8deeSWill Andrews		. ${NANO_TOOLS}/FlashDevice.sub
8386b8c8deeSWill Andrews	else
8396b8c8deeSWill Andrews		. ${NANO_SRC}/${NANO_TOOLS}/FlashDevice.sub
8406b8c8deeSWill Andrews	fi
8416b8c8deeSWill Andrews	sub_FlashDevice $1 $2
8426b8c8deeSWill Andrews}
8436b8c8deeSWill Andrews
8446b8c8deeSWill Andrews#######################################################################
8456b8c8deeSWill Andrews# USB device geometries
8466b8c8deeSWill Andrews#
8476b8c8deeSWill Andrews# Usage:
8486b8c8deeSWill Andrews#	UsbDevice Generic 1000	# a generic flash key sold as having 1GB
8496b8c8deeSWill Andrews#
8506b8c8deeSWill Andrews# This function will set NANO_MEDIASIZE, NANO_HEADS and NANO_SECTS for you.
8516b8c8deeSWill Andrews#
8526b8c8deeSWill Andrews# Note that the capacity of a flash key is usually advertised in MB or
8536b8c8deeSWill Andrews# GB, *not* MiB/GiB. As such, the precise number of cylinders available
8546b8c8deeSWill Andrews# for C/H/S geometry may vary depending on the actual flash geometry.
8556b8c8deeSWill Andrews#
8566b8c8deeSWill Andrews# The following generic device layouts are understood:
8576b8c8deeSWill Andrews#  generic           An alias for generic-hdd.
8586b8c8deeSWill Andrews#  generic-hdd       255H 63S/T xxxxC with no MBR restrictions.
8596b8c8deeSWill Andrews#  generic-fdd       64H 32S/T xxxxC with no MBR restrictions.
8606b8c8deeSWill Andrews#
8616b8c8deeSWill Andrews# The generic-hdd device is preferred for flash devices larger than 1GB.
8626b8c8deeSWill Andrews#
8636b8c8deeSWill Andrews
8646b8c8deeSWill AndrewsUsbDevice ( ) {
8656b8c8deeSWill Andrews	a1=`echo $1 | tr '[:upper:]' '[:lower:]'`
8666b8c8deeSWill Andrews	case $a1 in
8676b8c8deeSWill Andrews	generic-fdd)
8686b8c8deeSWill Andrews		NANO_HEADS=64
8696b8c8deeSWill Andrews		NANO_SECTS=32
8706b8c8deeSWill Andrews		NANO_MEDIASIZE=$(( $2 * 1000 * 1000 / 512 ))
8716b8c8deeSWill Andrews		;;
8726b8c8deeSWill Andrews	generic|generic-hdd)
8736b8c8deeSWill Andrews		NANO_HEADS=255
8746b8c8deeSWill Andrews		NANO_SECTS=63
8756b8c8deeSWill Andrews		NANO_MEDIASIZE=$(( $2 * 1000 * 1000 / 512 ))
8766b8c8deeSWill Andrews		;;
8776b8c8deeSWill Andrews	*)
8786b8c8deeSWill Andrews		echo "Unknown USB flash device"
8796b8c8deeSWill Andrews		exit 2
8806b8c8deeSWill Andrews		;;
8816b8c8deeSWill Andrews	esac
8826b8c8deeSWill Andrews}
8836b8c8deeSWill Andrews
8846b8c8deeSWill Andrews#######################################################################
8856b8c8deeSWill Andrews# Setup serial console
8866b8c8deeSWill Andrews
8876b8c8deeSWill Andrewscust_comconsole ( ) (
8886b8c8deeSWill Andrews	# Enable getty on console
8896b8c8deeSWill Andrews	sed -i "" -e /tty[du]0/s/off/on/ ${NANO_WORLDDIR}/etc/ttys
8906b8c8deeSWill Andrews
8916b8c8deeSWill Andrews	# Disable getty on syscons devices
8926b8c8deeSWill Andrews	sed -i "" -e '/^ttyv[0-8]/s/	on/	off/' ${NANO_WORLDDIR}/etc/ttys
8936b8c8deeSWill Andrews
8946b8c8deeSWill Andrews	# Tell loader to use serial console early.
8956b8c8deeSWill Andrews	echo "${NANO_BOOT2CFG}" > ${NANO_WORLDDIR}/boot.config
8966b8c8deeSWill Andrews)
8976b8c8deeSWill Andrews
8986b8c8deeSWill Andrews#######################################################################
8996b8c8deeSWill Andrews# Allow root login via ssh
9006b8c8deeSWill Andrews
9016b8c8deeSWill Andrewscust_allow_ssh_root ( ) (
9026b8c8deeSWill Andrews	sed -i "" -e '/PermitRootLogin/s/.*/PermitRootLogin yes/' \
9036b8c8deeSWill Andrews	    ${NANO_WORLDDIR}/etc/ssh/sshd_config
9046b8c8deeSWill Andrews)
9056b8c8deeSWill Andrews
9066b8c8deeSWill Andrews#######################################################################
9076b8c8deeSWill Andrews# Install the stuff under ./Files
9086b8c8deeSWill Andrews
9096b8c8deeSWill Andrewscust_install_files ( ) (
9101934c7aaSWarner Losh	cd "${NANO_TOOLS}/Files"
9116b8c8deeSWill Andrews	find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)' | cpio -Ldumpv ${NANO_WORLDDIR}
9126b8c8deeSWill Andrews)
9136b8c8deeSWill Andrews
9146b8c8deeSWill Andrews#######################################################################
9156b8c8deeSWill Andrews# Install packages from ${NANO_PACKAGE_DIR}
9166b8c8deeSWill Andrews
9176b8c8deeSWill Andrewscust_pkgng ( ) (
9186b8c8deeSWill Andrews
919*9af130aeSWarner Losh	local PKG_CONF="${NANO_WORLDDIR}/usr/local/etc/pkg.conf"
920*9af130aeSWarner Losh	local PKGCMD="env ASSUME_ALWAYS_YES=YES PKG_DBDIR=${NANO_PKG_META_BASE}/pkg SIGNATURE_TYPE=none /usr/sbin/pkg"
921*9af130aeSWarner Losh
922*9af130aeSWarner Losh	# Ensure pkg.conf points pkg to where the package meta data lives.
923*9af130aeSWarner Losh	touch ${PKG_CONF}
924*9af130aeSWarner Losh	if grep -Eiq '^PKG_DBDIR:.*' ${PKG_CONF}; then
925*9af130aeSWarner Losh		sed -i -e "\|^PKG_DBDIR:.*|Is||PKG_DBDIR: "\"${NANO_PKG_META_BASE}/pkg\""|" ${PKG_CONF}
926*9af130aeSWarner Losh	else
927*9af130aeSWarner Losh		echo "PKG_DBDIR: \"${NANO_PKG_META_BASE}/pkg\"" >> ${PKG_CONF}
928*9af130aeSWarner Losh	fi
929*9af130aeSWarner Losh
9306b8c8deeSWill Andrews	# If the package directory doesn't exist, we're done.
9316b8c8deeSWill Andrews	if [ ! -d ${NANO_PACKAGE_DIR} ]; then
9326b8c8deeSWill Andrews		echo "DONE 0 packages"
9336b8c8deeSWill Andrews		return 0
9346b8c8deeSWill Andrews	fi
9356b8c8deeSWill Andrews
9366b8c8deeSWill Andrews	# Find a pkg-* package
9376b8c8deeSWill Andrews	for x in `find -s ${NANO_PACKAGE_DIR} -iname 'pkg-*'`; do
9386b8c8deeSWill Andrews		_NANO_PKG_PACKAGE=`basename "$x"`
9396b8c8deeSWill Andrews	done
9406b8c8deeSWill Andrews	if [ -z "${_NANO_PKG_PACKAGE}" -o ! -f "${NANO_PACKAGE_DIR}/${_NANO_PKG_PACKAGE}" ]; then
9416b8c8deeSWill Andrews		echo "FAILED: need a pkg/ package for bootstrapping"
9426b8c8deeSWill Andrews		exit 2
9436b8c8deeSWill Andrews	fi
944*9af130aeSWarner Losh	NANO_PACKAGE_LIST="${_NANO_PKG_PACKAGE} ${NANO_PACKAGE_LIST}"
9456b8c8deeSWill Andrews
946*9af130aeSWarner Losh	# Mount packages into chroot
947*9af130aeSWarner Losh	mkdir -p ${NANO_WORLDDIR}/_.p
948*9af130aeSWarner Losh	mount -t nullfs -o noatime -o ro ${NANO_PACKAGE_DIR} ${NANO_WORLDDIR}/_.p
9496b8c8deeSWill Andrews
950*9af130aeSWarner Losh	trap "umount ${NANO_WORLDDIR}/_.p ; rm -rf ${NANO_WORLDDIR}/_.p" 1 2 15
9516b8c8deeSWill Andrews
952*9af130aeSWarner Losh	# Install packages
953*9af130aeSWarner Losh	todo="$(echo "${NANO_PACKAGE_LIST}" | awk '{ print NF }')"
9546b8c8deeSWill Andrews	echo "=== TODO: $todo"
955*9af130aeSWarner Losh	echo "${NANO_PACKAGE_LIST}"
9566b8c8deeSWill Andrews	echo "==="
957*9af130aeSWarner Losh	for _PKG in ${NANO_PACKAGE_LIST}; do
958*9af130aeSWarner Losh		CR "${PKGCMD} add /_.p/${_PKG}"
9596b8c8deeSWill Andrews	done
960*9af130aeSWarner Losh
961*9af130aeSWarner Losh	CR0 "${PKGCMD} info"
962*9af130aeSWarner Losh
963*9af130aeSWarner Losh	trap - 1 2 15 EXIT
964*9af130aeSWarner Losh	umount ${NANO_WORLDDIR}/_.p
965*9af130aeSWarner Losh	rm -rf ${NANO_WORLDDIR}/_.p
9666b8c8deeSWill Andrews)
9676b8c8deeSWill Andrews
9686b8c8deeSWill Andrews#######################################################################
9696b8c8deeSWill Andrews# Convenience function:
9705b4ca9d7SGleb Smirnoff#	Register all args as early customize function to run just before
9715b4ca9d7SGleb Smirnoff#	build commences.
9725b4ca9d7SGleb Smirnoff
9735b4ca9d7SGleb Smirnoffearly_customize_cmd () {
9745b4ca9d7SGleb Smirnoff	NANO_EARLY_CUSTOMIZE="$NANO_EARLY_CUSTOMIZE $*"
9755b4ca9d7SGleb Smirnoff}
9765b4ca9d7SGleb Smirnoff
9775b4ca9d7SGleb Smirnoff#######################################################################
9785b4ca9d7SGleb Smirnoff# Convenience function:
9796b8c8deeSWill Andrews# 	Register all args as customize function.
9806b8c8deeSWill Andrews
9816b8c8deeSWill Andrewscustomize_cmd ( ) {
9826b8c8deeSWill Andrews	NANO_CUSTOMIZE="$NANO_CUSTOMIZE $*"
9836b8c8deeSWill Andrews}
9846b8c8deeSWill Andrews
9856b8c8deeSWill Andrews#######################################################################
9866b8c8deeSWill Andrews# Convenience function:
9876b8c8deeSWill Andrews# 	Register all args as late customize function to run just before
9886b8c8deeSWill Andrews#	image creation.
9896b8c8deeSWill Andrews
9906b8c8deeSWill Andrewslate_customize_cmd ( ) {
9916b8c8deeSWill Andrews	NANO_LATE_CUSTOMIZE="$NANO_LATE_CUSTOMIZE $*"
9926b8c8deeSWill Andrews}
9936b8c8deeSWill Andrews
9946b8c8deeSWill Andrews#######################################################################
9956b8c8deeSWill Andrews#
9966b8c8deeSWill Andrews# All set up to go...
9976b8c8deeSWill Andrews#
9986b8c8deeSWill Andrews#######################################################################
9996b8c8deeSWill Andrews
10006b8c8deeSWill Andrews# Progress Print
10016b8c8deeSWill Andrews#	Print $2 at level $1.
10026b8c8deeSWill Andrewspprint ( ) (
10036b8c8deeSWill Andrews    if [ "$1" -le $PPLEVEL ]; then
10046b8c8deeSWill Andrews	runtime=$(( `date +%s` - $NANO_STARTTIME ))
10056b8c8deeSWill Andrews	printf "%s %.${1}s %s\n" "`date -u -r $runtime +%H:%M:%S`" "#####" "$2" 1>&3
10066b8c8deeSWill Andrews    fi
10076b8c8deeSWill Andrews)
10086b8c8deeSWill Andrews
10096b8c8deeSWill Andrewsusage ( ) {
10106b8c8deeSWill Andrews	(
10116b8c8deeSWill Andrews	echo "Usage: $0 [-bfiKknqvw] [-c config_file]"
10126b8c8deeSWill Andrews	echo "	-b	suppress builds (both kernel and world)"
10136b8c8deeSWill Andrews	echo "	-c	specify config file"
10146b8c8deeSWill Andrews	echo "	-f	suppress code slice extraction"
10156b8c8deeSWill Andrews	echo "	-i	suppress disk image build"
10166b8c8deeSWill Andrews	echo "	-K	suppress installkernel"
10176b8c8deeSWill Andrews	echo "	-k	suppress buildkernel"
10186b8c8deeSWill Andrews	echo "	-n	add -DNO_CLEAN to buildworld, buildkernel, etc"
10196b8c8deeSWill Andrews	echo "	-q	make output more quiet"
10206b8c8deeSWill Andrews	echo "	-v	make output more verbose"
10216b8c8deeSWill Andrews	echo "	-w	suppress buildworld"
10226b8c8deeSWill Andrews	) 1>&2
10236b8c8deeSWill Andrews	exit 2
10246b8c8deeSWill Andrews}
10256b8c8deeSWill Andrews
10266b8c8deeSWill Andrews#######################################################################
10276b8c8deeSWill Andrews# Setup and Export Internal variables
10286b8c8deeSWill Andrews#
10296b8c8deeSWill Andrews
10301934c7aaSWarner Loshexport_var ( ) {		# Don't wawnt a subshell
10316b8c8deeSWill Andrews	var=$1
10326b8c8deeSWill Andrews	# Lookup value of the variable.
10336b8c8deeSWill Andrews	eval val=\$$var
10346b8c8deeSWill Andrews	pprint 3 "Setting variable: $var=\"$val\""
10356b8c8deeSWill Andrews	export $1
10366b8c8deeSWill Andrews}
10376b8c8deeSWill Andrews
10386b8c8deeSWill Andrews# Call this function to set defaults _after_ parsing options.
10391934c7aaSWarner Losh# dont want a subshell otherwise variable setting is thrown away.
10406b8c8deeSWill Andrewsset_defaults_and_export ( ) {
1041849f5467SWarner Losh	: ${NANO_OBJ:=/usr/obj/nanobsd.${NANO_NAME}}
1042849f5467SWarner Losh	: ${MAKEOBJDIRPREFIX:=${NANO_OBJ}}
10433a757adfSWarner Losh	: ${NANO_DISKIMGDIR:=${NANO_OBJ}}
1044c2c06cfaSWarner Losh	: ${NANO_WORLDDIR:=${NANO_OBJ}/_.w}
1045c2c06cfaSWarner Losh	: ${NANO_LOG:=${NANO_OBJ}}
10466b8c8deeSWill Andrews	NANO_MAKE_CONF_BUILD=${MAKEOBJDIRPREFIX}/make.conf.build
10476b8c8deeSWill Andrews	NANO_MAKE_CONF_INSTALL=${NANO_OBJ}/make.conf.install
10486b8c8deeSWill Andrews
10496b8c8deeSWill Andrews	# Override user's NANO_DRIVE if they specified a NANO_LABEL
1050849f5467SWarner Losh	[ -n "${NANO_LABEL}" ] && NANO_DRIVE="ufs/${NANO_LABEL}" || true
10516b8c8deeSWill Andrews
10526b8c8deeSWill Andrews	# Set a default NANO_TOOLS to NANO_SRC/NANO_TOOLS if it exists.
10536b8c8deeSWill Andrews	[ ! -d "${NANO_TOOLS}" ] && [ -d "${NANO_SRC}/${NANO_TOOLS}" ] && \
1054c275d9ecSWarner Losh		NANO_TOOLS="${NANO_SRC}/${NANO_TOOLS}" || true
1055c275d9ecSWarner Losh
1056849f5467SWarner Losh	[ -n "${NANO_NOPRIV_BUILD}" ] && [ -z "${NANO_METALOG}" ] && \
1057c275d9ecSWarner Losh		NANO_METALOG=${NANO_OBJ}/_.metalog || true
10586b8c8deeSWill Andrews
10596b8c8deeSWill Andrews	NANO_STARTTIME=`date +%s`
10606b8c8deeSWill Andrews	pprint 3 "Exporting NanoBSD variables"
10616b8c8deeSWill Andrews	export_var MAKEOBJDIRPREFIX
10626b8c8deeSWill Andrews	export_var NANO_ARCH
10636b8c8deeSWill Andrews	export_var NANO_CODESIZE
10646b8c8deeSWill Andrews	export_var NANO_CONFSIZE
10656b8c8deeSWill Andrews	export_var NANO_CUSTOMIZE
10666b8c8deeSWill Andrews	export_var NANO_DATASIZE
10676b8c8deeSWill Andrews	export_var NANO_DRIVE
10686b8c8deeSWill Andrews	export_var NANO_HEADS
10696b8c8deeSWill Andrews	export_var NANO_IMAGES
10706b8c8deeSWill Andrews	export_var NANO_IMGNAME
10716b8c8deeSWill Andrews	export_var NANO_MAKE
10726b8c8deeSWill Andrews	export_var NANO_MAKE_CONF_BUILD
10736b8c8deeSWill Andrews	export_var NANO_MAKE_CONF_INSTALL
10746b8c8deeSWill Andrews	export_var NANO_MEDIASIZE
10756b8c8deeSWill Andrews	export_var NANO_NAME
10766b8c8deeSWill Andrews	export_var NANO_NEWFS
10776b8c8deeSWill Andrews	export_var NANO_OBJ
10786b8c8deeSWill Andrews	export_var NANO_PMAKE
10796b8c8deeSWill Andrews	export_var NANO_SECTS
10806b8c8deeSWill Andrews	export_var NANO_SRC
10816b8c8deeSWill Andrews	export_var NANO_TOOLS
10826b8c8deeSWill Andrews	export_var NANO_WORLDDIR
10836b8c8deeSWill Andrews	export_var NANO_BOOT0CFG
10846b8c8deeSWill Andrews	export_var NANO_BOOTLOADER
10856b8c8deeSWill Andrews	export_var NANO_LABEL
10866b8c8deeSWill Andrews	export_var NANO_MODULES
1087c275d9ecSWarner Losh	export_var NANO_NOPRIV_BUILD
1088c275d9ecSWarner Losh	export_var NANO_METALOG
1089c2c06cfaSWarner Losh	export_var NANO_LOG
10901934c7aaSWarner Losh	export_var SRCCONF
1091a9d9c49fSWarner Losh	export_var SRC_ENV_CONF
10926b8c8deeSWill Andrews}
1093