xref: /freebsd/tools/tools/nanobsd/defaults.sh (revision 19edffef95dcb9a61d8f7e05cc05728e47f32e2e)
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
866b8c8deeSWill Andrews# Customize commands.
876b8c8deeSWill AndrewsNANO_CUSTOMIZE=""
886b8c8deeSWill Andrews
896b8c8deeSWill Andrews# Late customize commands.
906b8c8deeSWill AndrewsNANO_LATE_CUSTOMIZE=""
916b8c8deeSWill Andrews
926b8c8deeSWill Andrews# Newfs paramters to use
936b8c8deeSWill AndrewsNANO_NEWFS="-b 4096 -f 512 -i 8192 -U"
946b8c8deeSWill Andrews
956b8c8deeSWill Andrews# The drive name of the media at runtime
966b8c8deeSWill AndrewsNANO_DRIVE=ad0
976b8c8deeSWill Andrews
986b8c8deeSWill Andrews# Target media size in 512 bytes sectors
996b8c8deeSWill AndrewsNANO_MEDIASIZE=2000000
1006b8c8deeSWill Andrews
1016b8c8deeSWill Andrews# Number of code images on media (1 or 2)
1026b8c8deeSWill AndrewsNANO_IMAGES=2
1036b8c8deeSWill Andrews
1046b8c8deeSWill Andrews# 0 -> Leave second image all zeroes so it compresses better.
1056b8c8deeSWill Andrews# 1 -> Initialize second image with a copy of the first
1066b8c8deeSWill AndrewsNANO_INIT_IMG2=1
1076b8c8deeSWill Andrews
1086b8c8deeSWill Andrews# Size of code file system in 512 bytes sectors
1096b8c8deeSWill Andrews# If zero, size will be as large as possible.
1106b8c8deeSWill AndrewsNANO_CODESIZE=0
1116b8c8deeSWill Andrews
1126b8c8deeSWill Andrews# Size of configuration file system in 512 bytes sectors
1136b8c8deeSWill Andrews# Cannot be zero.
1146b8c8deeSWill AndrewsNANO_CONFSIZE=2048
1156b8c8deeSWill Andrews
1166b8c8deeSWill Andrews# Size of data file system in 512 bytes sectors
1176b8c8deeSWill Andrews# If zero: no partition configured.
1186b8c8deeSWill Andrews# If negative: max size possible
1196b8c8deeSWill AndrewsNANO_DATASIZE=0
1206b8c8deeSWill Andrews
1216b8c8deeSWill Andrews# Size of the /etc ramdisk in 512 bytes sectors
1226b8c8deeSWill AndrewsNANO_RAM_ETCSIZE=10240
1236b8c8deeSWill Andrews
1246b8c8deeSWill Andrews# Size of the /tmp+/var ramdisk in 512 bytes sectors
1256b8c8deeSWill AndrewsNANO_RAM_TMPVARSIZE=10240
1266b8c8deeSWill Andrews
1276b8c8deeSWill Andrews# Media geometry, only relevant if bios doesn't understand LBA.
1286b8c8deeSWill AndrewsNANO_SECTS=63
1296b8c8deeSWill AndrewsNANO_HEADS=16
1306b8c8deeSWill Andrews
1316b8c8deeSWill Andrews# boot0 flags/options and configuration
1326b8c8deeSWill AndrewsNANO_BOOT0CFG="-o packet -s 1 -m 3"
1336b8c8deeSWill AndrewsNANO_BOOTLOADER="boot/boot0sio"
1346b8c8deeSWill Andrews
1356b8c8deeSWill Andrews# boot2 flags/options
1366b8c8deeSWill Andrews# default force serial console
137a9598aaeSWarner LoshNANO_BOOT2CFG="-h -S115200"
1386b8c8deeSWill Andrews
1396b8c8deeSWill Andrews# Backing type of md(4) device
1406b8c8deeSWill Andrews# Can be "file" or "swap"
1416b8c8deeSWill AndrewsNANO_MD_BACKING="file"
1426b8c8deeSWill Andrews
1436b8c8deeSWill Andrews# for swap type md(4) backing, write out the mbr only
1446b8c8deeSWill AndrewsNANO_IMAGE_MBRONLY=true
1456b8c8deeSWill Andrews
1466b8c8deeSWill Andrews# Progress Print level
1476b8c8deeSWill AndrewsPPLEVEL=3
1486b8c8deeSWill Andrews
1496b8c8deeSWill Andrews# Set NANO_LABEL to non-blank to form the basis for using /dev/ufs/label
1506b8c8deeSWill Andrews# in preference to /dev/${NANO_DRIVE}
1516b8c8deeSWill Andrews# Root partition will be ${NANO_LABEL}s{1,2}
1526b8c8deeSWill Andrews# /cfg partition will be ${NANO_LABEL}s3
1536b8c8deeSWill Andrews# /data partition will be ${NANO_LABEL}s4
1546b8c8deeSWill AndrewsNANO_LABEL=""
1557b77d3eaSWarner LoshNANO_SLICE_ROOT=s1
1567b77d3eaSWarner LoshNANO_SLICE_ALTROOT=s2
1577b77d3eaSWarner LoshNANO_SLICE_CFG=s3
1587b77d3eaSWarner LoshNANO_SLICE_DATA=s4
1597b77d3eaSWarner Losh
160*19edffefSWarner Losh# Default ownwership for nopriv build
161*19edffefSWarner LoshNANO_DEF_UNAME=root
162*19edffefSWarner LoshNANO_DEF_GNAME=wheel
1636b8c8deeSWill Andrews
1646b8c8deeSWill Andrews#######################################################################
1656b8c8deeSWill Andrews# Architecture to build.  Corresponds to TARGET_ARCH in a buildworld.
1666b8c8deeSWill Andrews# Unfortunately, there's no way to set TARGET at this time, and it
167d07833f9SWarner Losh# conflates the two, so architectures where TARGET != TARGET_ARCH and
168d07833f9SWarner Losh# TARGET can't be guessed from TARGET_ARCH do not work.  This defaults
169d07833f9SWarner Losh# to the arch of the current machine.
1706b8c8deeSWill AndrewsNANO_ARCH=`uname -p`
1716b8c8deeSWill Andrews
172d07833f9SWarner Losh# CPUTYPE defaults to "" which is the default when CPUTYPE isn't
173d07833f9SWarner Losh# defined.
174d07833f9SWarner LoshNANO_CPUTYPE=""
175d07833f9SWarner Losh
1766b8c8deeSWill Andrews# Directory to populate /cfg from
1776b8c8deeSWill AndrewsNANO_CFGDIR=""
1786b8c8deeSWill Andrews
1796b8c8deeSWill Andrews# Directory to populate /data from
1806b8c8deeSWill AndrewsNANO_DATADIR=""
1816b8c8deeSWill Andrews
182a9d9c49fSWarner Losh# We don't need SRCCONF or SRC_ENV_CONF. NanoBSD puts everything we
183a9d9c49fSWarner Losh# need for the build in files included with __MAKE_CONF. Override in your
184a9d9c49fSWarner Losh# config file if you really must. We set them unconditionally here, though
185a9d9c49fSWarner Losh# in case they are stray in the build environment
186a9d9c49fSWarner LoshSRCCONF=/dev/null
187a9d9c49fSWarner LoshSRC_ENV_CONF=/dev/null
1886b8c8deeSWill Andrews
1896b8c8deeSWill Andrews#######################################################################
1906b8c8deeSWill Andrews#
1916b8c8deeSWill Andrews# The functions which do the real work.
1926b8c8deeSWill Andrews# Can be overridden from the config file(s)
1936b8c8deeSWill Andrews#
1946b8c8deeSWill Andrews#######################################################################
1956b8c8deeSWill Andrews
1961934c7aaSWarner Losh# Export values into the shell. Must use { } instead of ( ) like
1971934c7aaSWarner Losh# other functions to avoid a subshell.
1981934c7aaSWarner Losh# We set __MAKE_CONF as a global since it is easier to get quoting
1991934c7aaSWarner Losh# right for paths with spaces in them.
2001934c7aaSWarner Loshmake_export ( ) {
2011934c7aaSWarner Losh	# Similar to export_var, except puts the data out to stdout
2021934c7aaSWarner Losh	var=$1
2031934c7aaSWarner Losh	eval val=\$$var
2041934c7aaSWarner Losh	echo "Setting variable: $var=\"$val\""
2051934c7aaSWarner Losh	export $1
2061934c7aaSWarner Losh}
2071934c7aaSWarner Losh
2081934c7aaSWarner Loshnano_make_build_env ( ) {
2091934c7aaSWarner Losh	__MAKE_CONF="${NANO_MAKE_CONF_BUILD}"
2101934c7aaSWarner Losh	make_export __MAKE_CONF
2111934c7aaSWarner Losh}
2121934c7aaSWarner Losh
2131934c7aaSWarner Loshnano_make_install_env ( ) {
2141934c7aaSWarner Losh	__MAKE_CONF="${NANO_MAKE_CONF_INSTALL}"
2151934c7aaSWarner Losh	make_export __MAKE_CONF
2161934c7aaSWarner Losh}
2171934c7aaSWarner Losh
2181934c7aaSWarner Losh# Extra environment variables for kernel builds
2191934c7aaSWarner Loshnano_make_kernel_env ( ) {
2201934c7aaSWarner Losh	if [ -f ${NANO_KERNEL} ] ; then
2211934c7aaSWarner Losh		KERNCONFDIR="$(realpath $(dirname ${NANO_KERNEL}))"
2221934c7aaSWarner Losh		KERNCONF="$(basename ${NANO_KERNEL})"
2231934c7aaSWarner Losh		make_export KERNCONFDIR
2241934c7aaSWarner Losh		make_export KERNCONF
2251934c7aaSWarner Losh	else
2261934c7aaSWarner Losh		export KERNCONF="${NANO_KERNEL}"
2271934c7aaSWarner Losh		make_export KERNCONF
2281934c7aaSWarner Losh	fi
2291934c7aaSWarner Losh}
2301934c7aaSWarner Losh
2311934c7aaSWarner Loshnano_global_make_env ( ) (
232849f5467SWarner Losh	# global settings for the make.conf file, if set
233849f5467SWarner Losh	[ -z "${NANO_ARCH}" ] || echo TARGET_ARCH="${NANO_ARCH}"
234849f5467SWarner Losh	[ -z "${NANO_CPUTYPE}" ] || echo TARGET_CPUTYPE="${NANO_CPUTYPE}"
2351934c7aaSWarner Losh)
2361934c7aaSWarner Losh
2376b8c8deeSWill Andrews# rm doesn't know -x prior to FreeBSD 10, so cope with a variety of build
238849f5467SWarner Losh# hosts for now. This will go away when support in the base goes away.
239849f5467SWarner Loshrm ( ) {
240849f5467SWarner Losh    echo "NANO RM $*"
2416b8c8deeSWill Andrews	case $(uname -r) in
242849f5467SWarner Losh	7*|8*|9*) command rm $* ;;
243849f5467SWarner Losh	*) command rm -x $* ;;
2446b8c8deeSWill Andrews	esac
2456b8c8deeSWill Andrews}
2466b8c8deeSWill Andrews
247*19edffefSWarner Losh#
248*19edffefSWarner Losh# Create empty files in the target tree, and record the fact.  All paths
249*19edffefSWarner Losh# are relative to NANO_WORLDDIR.
250*19edffefSWarner Losh#
251*19edffefSWarner Loshtgt_touch ( ) (
252*19edffefSWarner Losh
253*19edffefSWarner Losh	cd "${NANO_WORLDDIR}"
254*19edffefSWarner Losh	for i; do
255*19edffefSWarner Losh		touch $i
256*19edffefSWarner Losh		echo "./${i} type=file" >> ${NANO_METALOG}
257*19edffefSWarner Losh	done
258*19edffefSWarner Losh)
259*19edffefSWarner Losh
260*19edffefSWarner Losh#
261*19edffefSWarner Losh# Convert a directory into a symlink. Takes two arguments, the
262*19edffefSWarner Losh# current directory and what it should become a symlink to. The
263*19edffefSWarner Losh# directory is removed and a symlink is created. If we're doing
264*19edffefSWarner Losh# a nopriv build, then append this fact to the metalog
265*19edffefSWarner Losh#
266*19edffefSWarner Loshtgt_dir2symlink () (
267*19edffefSWarner Losh	dir=$1
268*19edffefSWarner Losh	symlink=$2
269*19edffefSWarner Losh
270*19edffefSWarner Losh	cd "${NANO_WORLDDIR}"
271*19edffefSWarner Losh	rm -rf "$dir"
272*19edffefSWarner Losh	ln -s "$symlink" "$dir"
273*19edffefSWarner Losh	if [ -n $NANO_METALOG ]; then
274*19edffefSWarner Losh		echo "./${dir} type=link mode=0777 link=${symlink}" >> ${NANO_METALOG}
275*19edffefSWarner Losh	fi
276*19edffefSWarner Losh)
277*19edffefSWarner Losh
2786b8c8deeSWill Andrews# run in the world chroot, errors fatal
2791934c7aaSWarner LoshCR ( ) {
2801934c7aaSWarner Losh	chroot "${NANO_WORLDDIR}" /bin/sh -exc "$*"
2816b8c8deeSWill Andrews}
2826b8c8deeSWill Andrews
2836b8c8deeSWill Andrews# run in the world chroot, errors not fatal
2841934c7aaSWarner LoshCR0 ( ) {
2851934c7aaSWarner Losh	chroot "${NANO_WORLDDIR}" /bin/sh -c "$*" || true
2866b8c8deeSWill Andrews}
2876b8c8deeSWill Andrews
2886b8c8deeSWill Andrewsnano_cleanup ( ) (
289849f5467SWarner Losh	[ $? -eq 0 ] || echo "Error encountered.  Check for errors in last log file." 1>&2
2906b8c8deeSWill Andrews	exit $?
2916b8c8deeSWill Andrews)
2926b8c8deeSWill Andrews
2936b8c8deeSWill Andrewsclean_build ( ) (
2946b8c8deeSWill Andrews	pprint 2 "Clean and create object directory (${MAKEOBJDIRPREFIX})"
2956b8c8deeSWill Andrews
296849f5467SWarner Losh	if ! rm -rf ${MAKEOBJDIRPREFIX}/ > /dev/null 2>&1 ; then
2976b8c8deeSWill Andrews		chflags -R noschg ${MAKEOBJDIRPREFIX}/
298849f5467SWarner Losh		rm -r ${MAKEOBJDIRPREFIX}/
2996b8c8deeSWill Andrews	fi
3006b8c8deeSWill Andrews)
3016b8c8deeSWill Andrews
3026b8c8deeSWill Andrewsmake_conf_build ( ) (
3036b8c8deeSWill Andrews	pprint 2 "Construct build make.conf ($NANO_MAKE_CONF_BUILD)"
3046b8c8deeSWill Andrews
3056b8c8deeSWill Andrews	mkdir -p ${MAKEOBJDIRPREFIX}
3066b8c8deeSWill Andrews	printenv > ${MAKEOBJDIRPREFIX}/_.env
3076b8c8deeSWill Andrews
3081934c7aaSWarner Losh	# Make sure we get all the global settings that NanoBSD wants
3091934c7aaSWarner Losh	# in addition to the user's global settings
3101934c7aaSWarner Losh	(
3111934c7aaSWarner Losh	nano_global_make_env
3121934c7aaSWarner Losh	echo "${CONF_WORLD}"
3131934c7aaSWarner Losh	echo "${CONF_BUILD}"
3141934c7aaSWarner Losh	) > ${NANO_MAKE_CONF_BUILD}
3156b8c8deeSWill Andrews)
3166b8c8deeSWill Andrews
3176b8c8deeSWill Andrewsbuild_world ( ) (
3186b8c8deeSWill Andrews	pprint 2 "run buildworld"
3196b8c8deeSWill Andrews	pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bw"
3206b8c8deeSWill Andrews
3211934c7aaSWarner Losh	(
3221934c7aaSWarner Losh	nano_make_build_env
3231934c7aaSWarner Losh	set -o xtrace
3241934c7aaSWarner Losh	cd "${NANO_SRC}"
3251934c7aaSWarner Losh	${NANO_PMAKE} buildworld
3261934c7aaSWarner Losh	) > ${MAKEOBJDIRPREFIX}/_.bw 2>&1
3276b8c8deeSWill Andrews)
3286b8c8deeSWill Andrews
3296b8c8deeSWill Andrewsbuild_kernel ( ) (
3306b8c8deeSWill Andrews	local extra
3316b8c8deeSWill Andrews
3326b8c8deeSWill Andrews	pprint 2 "build kernel ($NANO_KERNEL)"
3336b8c8deeSWill Andrews	pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bk"
3346b8c8deeSWill Andrews
3356b8c8deeSWill Andrews	(
3361934c7aaSWarner Losh	nano_make_build_env
3371934c7aaSWarner Losh	nano_make_kernel_env
3386b8c8deeSWill Andrews
3396b8c8deeSWill Andrews	# Note: We intentionally build all modules, not only the ones in
3406b8c8deeSWill Andrews	# NANO_MODULES so the built world can be reused by multiple images.
3411934c7aaSWarner Losh	# Although MODULES_OVERRIDE can be defined in the kenrel config
3421934c7aaSWarner Losh	# file to override this behavior. Just set NANO_MODULES=default.
3431934c7aaSWarner Losh	set -o xtrace
3441934c7aaSWarner Losh	cd "${NANO_SRC}"
3451934c7aaSWarner Losh	${NANO_PMAKE} buildkernel
3466b8c8deeSWill Andrews	) > ${MAKEOBJDIRPREFIX}/_.bk 2>&1
3476b8c8deeSWill Andrews)
3486b8c8deeSWill Andrews
3496b8c8deeSWill Andrewsclean_world ( ) (
3506b8c8deeSWill Andrews	if [ "${NANO_OBJ}" != "${MAKEOBJDIRPREFIX}" ]; then
3516b8c8deeSWill Andrews		pprint 2 "Clean and create object directory (${NANO_OBJ})"
352849f5467SWarner Losh		if ! rm -rf ${NANO_OBJ}/ > /dev/null 2>&1 ; then
3536b8c8deeSWill Andrews			chflags -R noschg ${NANO_OBJ}
354849f5467SWarner Losh			rm -r ${NANO_OBJ}/
3556b8c8deeSWill Andrews		fi
3561934c7aaSWarner Losh		mkdir -p "${NANO_OBJ}" "${NANO_WORLDDIR}"
3576b8c8deeSWill Andrews		printenv > ${NANO_OBJ}/_.env
3586b8c8deeSWill Andrews	else
3596b8c8deeSWill Andrews		pprint 2 "Clean and create world directory (${NANO_WORLDDIR})"
360849f5467SWarner Losh		if ! rm -rf "${NANO_WORLDDIR}/" > /dev/null 2>&1 ; then
3611934c7aaSWarner Losh			chflags -R noschg "${NANO_WORLDDIR}"
362849f5467SWarner Losh			rm -rf "${NANO_WORLDDIR}/"
3636b8c8deeSWill Andrews		fi
3641934c7aaSWarner Losh		mkdir -p "${NANO_WORLDDIR}"
3656b8c8deeSWill Andrews	fi
3666b8c8deeSWill Andrews)
3676b8c8deeSWill Andrews
3686b8c8deeSWill Andrewsmake_conf_install ( ) (
3696b8c8deeSWill Andrews	pprint 2 "Construct install make.conf ($NANO_MAKE_CONF_INSTALL)"
3706b8c8deeSWill Andrews
3711934c7aaSWarner Losh	# Make sure we get all the global settings that NanoBSD wants
3721934c7aaSWarner Losh	# in addition to the user's global settings
3731934c7aaSWarner Losh	(
3741934c7aaSWarner Losh	nano_global_make_env
3751934c7aaSWarner Losh	echo "${CONF_WORLD}"
3761934c7aaSWarner Losh	echo "${CONF_INSTALL}"
377849f5467SWarner Losh	if [ -n "${NANO_NOPRIV_BUILD}" ]; then
378c275d9ecSWarner Losh	    echo NO_ROOT=t
379c275d9ecSWarner Losh	    echo METALOG=${NANO_METALOG}
380c275d9ecSWarner Losh	fi
3811934c7aaSWarner Losh	) >  ${NANO_MAKE_CONF_INSTALL}
3826b8c8deeSWill Andrews)
3836b8c8deeSWill Andrews
3846b8c8deeSWill Andrewsinstall_world ( ) (
3856b8c8deeSWill Andrews	pprint 2 "installworld"
3866b8c8deeSWill Andrews	pprint 3 "log: ${NANO_OBJ}/_.iw"
3876b8c8deeSWill Andrews
3881934c7aaSWarner Losh	(
3891934c7aaSWarner Losh	nano_make_install_env
3901934c7aaSWarner Losh	set -o xtrace
3911934c7aaSWarner Losh	cd "${NANO_SRC}"
3921934c7aaSWarner Losh	${NANO_MAKE} installworld DESTDIR="${NANO_WORLDDIR}"
3931934c7aaSWarner Losh	chflags -R noschg "${NANO_WORLDDIR}"
3941934c7aaSWarner Losh	) > ${NANO_OBJ}/_.iw 2>&1
3956b8c8deeSWill Andrews)
3966b8c8deeSWill Andrews
3976b8c8deeSWill Andrewsinstall_etc ( ) (
3986b8c8deeSWill Andrews
3996b8c8deeSWill Andrews	pprint 2 "install /etc"
4006b8c8deeSWill Andrews	pprint 3 "log: ${NANO_OBJ}/_.etc"
4016b8c8deeSWill Andrews
4021934c7aaSWarner Losh	(
4031934c7aaSWarner Losh	nano_make_install_env
4041934c7aaSWarner Losh	set -o xtrace
4051934c7aaSWarner Losh	cd "${NANO_SRC}"
4061934c7aaSWarner Losh	${NANO_MAKE} distribution DESTDIR="${NANO_WORLDDIR}"
4076b8c8deeSWill Andrews	# make.conf doesn't get created by default, but some ports need it
4086b8c8deeSWill Andrews	# so they can spam it.
4091934c7aaSWarner Losh	cp /dev/null "${NANO_WORLDDIR}"/etc/make.conf
4101934c7aaSWarner Losh	) > ${NANO_OBJ}/_.etc 2>&1
4116b8c8deeSWill Andrews)
4126b8c8deeSWill Andrews
4136b8c8deeSWill Andrewsinstall_kernel ( ) (
4146b8c8deeSWill Andrews	local extra
4156b8c8deeSWill Andrews
4166b8c8deeSWill Andrews	pprint 2 "install kernel ($NANO_KERNEL)"
4176b8c8deeSWill Andrews	pprint 3 "log: ${NANO_OBJ}/_.ik"
4186b8c8deeSWill Andrews
4196b8c8deeSWill Andrews	(
4206b8c8deeSWill Andrews
4211934c7aaSWarner Losh	nano_make_install_env
4221934c7aaSWarner Losh	nano_make_kernel_env
4231934c7aaSWarner Losh
4246b8c8deeSWill Andrews	if [ "${NANO_MODULES}" != "default" ]; then
4251934c7aaSWarner Losh		MODULES_OVERRIDE="${NANO_MODULES}"
4261934c7aaSWarner Losh		make_export MODULES_OVERRIDE
4276b8c8deeSWill Andrews	fi
4286b8c8deeSWill Andrews
4291934c7aaSWarner Losh	set -o xtrace
4301934c7aaSWarner Losh	cd "${NANO_SRC}"
4311934c7aaSWarner Losh	${NANO_MAKE} installkernel DESTDIR="${NANO_WORLDDIR}"
4321934c7aaSWarner Losh
4336b8c8deeSWill Andrews	) > ${NANO_OBJ}/_.ik 2>&1
4346b8c8deeSWill Andrews)
4356b8c8deeSWill Andrews
4366b8c8deeSWill Andrewsnative_xtools ( ) (
4376b8c8deeSWill Andrews	print 2 "Installing the optimized native build tools for cross env"
4386b8c8deeSWill Andrews	pprint 3 "log: ${NANO_OBJ}/_.native_xtools"
4396b8c8deeSWill Andrews
4401934c7aaSWarner Losh	(
4411934c7aaSWarner Losh
4421934c7aaSWarner Losh	nano_make_install_env
4431934c7aaSWarner Losh	set -o xtrace
4441934c7aaSWarner Losh	cd "${NANO_SRC}"
4451934c7aaSWarner Losh	${NANO_MAKE} native-xtools DESTDIR="${NANO_WORLDDIR}"
4461934c7aaSWarner Losh
4471934c7aaSWarner Losh	) > ${NANO_OBJ}/_.native_xtools 2>&1
4486b8c8deeSWill Andrews)
4496b8c8deeSWill Andrews
450*19edffefSWarner Losh#
451*19edffefSWarner Losh# Run the requested set of customization scripts, run after we've
452*19edffefSWarner Losh# done an installworld, installed the etc files, installed the kernel
453*19edffefSWarner Losh# and tweaked them in the standard way.
454*19edffefSWarner Losh#
4556b8c8deeSWill Andrewsrun_customize ( ) (
4566b8c8deeSWill Andrews
4576b8c8deeSWill Andrews	pprint 2 "run customize scripts"
4586b8c8deeSWill Andrews	for c in $NANO_CUSTOMIZE
4596b8c8deeSWill Andrews	do
4606b8c8deeSWill Andrews		pprint 2 "customize \"$c\""
4616b8c8deeSWill Andrews		pprint 3 "log: ${NANO_OBJ}/_.cust.$c"
4626b8c8deeSWill Andrews		pprint 4 "`type $c`"
4636b8c8deeSWill Andrews		( set -x ; $c ) > ${NANO_OBJ}/_.cust.$c 2>&1
4646b8c8deeSWill Andrews	done
4656b8c8deeSWill Andrews)
4666b8c8deeSWill Andrews
467*19edffefSWarner Losh#
468*19edffefSWarner Losh# Run any last-minute customization commands after we've had a chance to
469*19edffefSWarner Losh# setup nanobsd, prune empty dirs from /usr, etc
470*19edffefSWarner Losh#
4716b8c8deeSWill Andrewsrun_late_customize ( ) (
4726b8c8deeSWill Andrews
4736b8c8deeSWill Andrews	pprint 2 "run late customize scripts"
4746b8c8deeSWill Andrews	for c in $NANO_LATE_CUSTOMIZE
4756b8c8deeSWill Andrews	do
4766b8c8deeSWill Andrews		pprint 2 "late customize \"$c\""
4776b8c8deeSWill Andrews		pprint 3 "log: ${NANO_OBJ}/_.late_cust.$c"
4786b8c8deeSWill Andrews		pprint 4 "`type $c`"
4796b8c8deeSWill Andrews		( set -x ; $c ) > ${NANO_OBJ}/_.late_cust.$c 2>&1
4806b8c8deeSWill Andrews	done
4816b8c8deeSWill Andrews)
4826b8c8deeSWill Andrews
483*19edffefSWarner Losh#
484*19edffefSWarner Losh# Hook called after we run all the late customize commands, but
485*19edffefSWarner Losh# before we invoke the disk imager. The nopriv build uses it to
486*19edffefSWarner Losh# read in the meta log, apply the changes other parts of nanobsd
487*19edffefSWarner Losh# have been recording their actions. It's not anticipated that
488*19edffefSWarner Losh# a user's cfg file would override this.
489*19edffefSWarner Losh#
490*19edffefSWarner Loshfixup_before_diskimage ( ) (
491*19edffefSWarner Losh
492*19edffefSWarner Losh	# Run the deduplication script that takes the matalog journal and
493*19edffefSWarner Losh	# combines multiple entries for the same file (see source for
494*19edffefSWarner Losh	# details). We take the extra step of removing the size keywords. This
495*19edffefSWarner Losh	# script, and many of the user scripts, copies, appeneds and otherwise
496*19edffefSWarner Losh	# modifies files in the build, changing their sizes.  These actions are
497*19edffefSWarner Losh	# impossible to trap, so go ahead remove the size= keyword. For this
498*19edffefSWarner Losh	# narrow use, it doesn't buy us any protection and just gets in the way.
499*19edffefSWarner Losh	# The dedup tool's output must be sorted due to limitations in awk.
500*19edffefSWarner Losh	if [ -n ${NANO_METALOG} ]; then
501*19edffefSWarner Losh		pprint 2 "Fixing metalog"
502*19edffefSWarner Losh		cp ${NANO_METALOG} ${NANO_METALOG}.pre
503*19edffefSWarner Losh		(echo "/set uname=${NANO_DEF_UNAME} gname=${NANO_DEF_GNAME}" &&
504*19edffefSWarner Losh			cat ${NANO_METALOG}.pre) | \
505*19edffefSWarner Losh		    ${NANO_TOOLS}/mtree-dedup.awk | \
506*19edffefSWarner Losh		    sed -e 's/ size=[0-9][0-9]*//' | sort > ${NANO_METALOG}
507*19edffefSWarner Losh	fi
508*19edffefSWarner Losh)
509*19edffefSWarner Losh
5106b8c8deeSWill Andrewssetup_nanobsd ( ) (
5116b8c8deeSWill Andrews	pprint 2 "configure nanobsd setup"
5126b8c8deeSWill Andrews	pprint 3 "log: ${NANO_OBJ}/_.dl"
5136b8c8deeSWill Andrews
5146b8c8deeSWill Andrews	(
5151934c7aaSWarner Losh	cd "${NANO_WORLDDIR}"
5166b8c8deeSWill Andrews
5176b8c8deeSWill Andrews	# Move /usr/local/etc to /etc/local so that the /cfg stuff
5186b8c8deeSWill Andrews	# can stomp on it.  Otherwise packages like ipsec-tools which
5196b8c8deeSWill Andrews	# have hardcoded paths under ${prefix}/etc are not tweakable.
5206b8c8deeSWill Andrews	if [ -d usr/local/etc ] ; then
5216b8c8deeSWill Andrews		(
5226b8c8deeSWill Andrews		mkdir -p etc/local
5236b8c8deeSWill Andrews		cd usr/local/etc
5246b8c8deeSWill Andrews		find . -print | cpio -dumpl ../../../etc/local
5256b8c8deeSWill Andrews		cd ..
526849f5467SWarner Losh		rm -rf etc
5276b8c8deeSWill Andrews		ln -s ../../etc/local etc
5286b8c8deeSWill Andrews		)
5296b8c8deeSWill Andrews	fi
5306b8c8deeSWill Andrews
5316b8c8deeSWill Andrews	for d in var etc
5326b8c8deeSWill Andrews	do
5336b8c8deeSWill Andrews		# link /$d under /conf
5346b8c8deeSWill Andrews		# we use hard links so we have them both places.
5356b8c8deeSWill Andrews		# the files in /$d will be hidden by the mount.
5366b8c8deeSWill Andrews		mkdir -p conf/base/$d conf/default/$d
5376b8c8deeSWill Andrews		find $d -print | cpio -dumpl conf/base/
5386b8c8deeSWill Andrews	done
5396b8c8deeSWill Andrews
5406b8c8deeSWill Andrews	echo "$NANO_RAM_ETCSIZE" > conf/base/etc/md_size
5416b8c8deeSWill Andrews	echo "$NANO_RAM_TMPVARSIZE" > conf/base/var/md_size
5426b8c8deeSWill Andrews
5436b8c8deeSWill Andrews	# pick up config files from the special partition
5447b77d3eaSWarner Losh	echo "mount -o ro /dev/${NANO_DRIVE}${NANO_SLICE_CFG}" > conf/default/etc/remount
5456b8c8deeSWill Andrews
5466b8c8deeSWill Andrews	# Put /tmp on the /var ramdisk (could be symlink already)
547*19edffefSWarner Losh	tgt_dir2symlink tmp var/tmp
5486b8c8deeSWill Andrews
5496b8c8deeSWill Andrews	) > ${NANO_OBJ}/_.dl 2>&1
5506b8c8deeSWill Andrews)
5516b8c8deeSWill Andrews
5526b8c8deeSWill Andrewssetup_nanobsd_etc ( ) (
5536b8c8deeSWill Andrews	pprint 2 "configure nanobsd /etc"
5546b8c8deeSWill Andrews
5556b8c8deeSWill Andrews	(
5561934c7aaSWarner Losh	cd "${NANO_WORLDDIR}"
5576b8c8deeSWill Andrews
5586b8c8deeSWill Andrews	# create diskless marker file
5596b8c8deeSWill Andrews	touch etc/diskless
5606b8c8deeSWill Andrews
561849f5467SWarner Losh	[ -n "${NANO_NOPRIV_BUILD}" ] && chmod 666 etc/defaults/rc.conf
5629e144f35SWarner Losh
5639e144f35SWarner Losh	# Make root filesystem R/O by default
5646b8c8deeSWill Andrews	echo "root_rw_mount=NO" >> etc/defaults/rc.conf
5659e144f35SWarner Losh	# Disable entropy file, since / is read-only /var/db/entropy should be enough?
5669e144f35SWarner Losh	echo "entropy_file=NO" >> etc/defaults/rc.conf
5679e144f35SWarner Losh
568849f5467SWarner Losh	[ -n "${NANO_NOPRIV_BUILD}" ] && chmod 444 etc/defaults/rc.conf
5696b8c8deeSWill Andrews
5706b8c8deeSWill Andrews	# save config file for scripts
5716b8c8deeSWill Andrews	echo "NANO_DRIVE=${NANO_DRIVE}" > etc/nanobsd.conf
5726b8c8deeSWill Andrews
5737b77d3eaSWarner Losh	echo "/dev/${NANO_DRIVE}${NANO_SLICE_ROOT}a / ufs ro 1 1" > etc/fstab
5747b77d3eaSWarner Losh	echo "/dev/${NANO_DRIVE}${NANO_SLICE_CFG} /cfg ufs rw,noauto 2 2" >> etc/fstab
5756b8c8deeSWill Andrews	mkdir -p cfg
5766b8c8deeSWill Andrews	)
5776b8c8deeSWill Andrews)
5786b8c8deeSWill Andrews
5796b8c8deeSWill Andrewsprune_usr ( ) (
5806b8c8deeSWill Andrews
5816b8c8deeSWill Andrews	# Remove all empty directories in /usr
5821934c7aaSWarner Losh	find "${NANO_WORLDDIR}"/usr -type d -depth -print |
5836b8c8deeSWill Andrews		while read d
5846b8c8deeSWill Andrews		do
5856b8c8deeSWill Andrews			rmdir $d > /dev/null 2>&1 || true
5866b8c8deeSWill Andrews		done
5876b8c8deeSWill Andrews)
5886b8c8deeSWill Andrews
5896b8c8deeSWill Andrewsnewfs_part ( ) (
5906b8c8deeSWill Andrews	local dev mnt lbl
5916b8c8deeSWill Andrews	dev=$1
5926b8c8deeSWill Andrews	mnt=$2
5936b8c8deeSWill Andrews	lbl=$3
5946b8c8deeSWill Andrews	echo newfs ${NANO_NEWFS} ${NANO_LABEL:+-L${NANO_LABEL}${lbl}} ${dev}
5956b8c8deeSWill Andrews	newfs ${NANO_NEWFS} ${NANO_LABEL:+-L${NANO_LABEL}${lbl}} ${dev}
5966b8c8deeSWill Andrews	mount -o async ${dev} ${mnt}
5976b8c8deeSWill Andrews)
5986b8c8deeSWill Andrews
5996b8c8deeSWill Andrews# Convenient spot to work around any umount issues that your build environment
6006b8c8deeSWill Andrews# hits by overriding this method.
6016b8c8deeSWill Andrewsnano_umount ( ) (
6026b8c8deeSWill Andrews	umount ${1}
6036b8c8deeSWill Andrews)
6046b8c8deeSWill Andrews
6056b8c8deeSWill Andrewspopulate_slice ( ) (
6066b8c8deeSWill Andrews	local dev dir mnt lbl
6076b8c8deeSWill Andrews	dev=$1
6086b8c8deeSWill Andrews	dir=$2
6096b8c8deeSWill Andrews	mnt=$3
6106b8c8deeSWill Andrews	lbl=$4
6116b8c8deeSWill Andrews	echo "Creating ${dev} (mounting on ${mnt})"
6126b8c8deeSWill Andrews	newfs_part ${dev} ${mnt} ${lbl}
6136b8c8deeSWill Andrews	if [ -n "${dir}" -a -d "${dir}" ]; then
6146b8c8deeSWill Andrews		echo "Populating ${lbl} from ${dir}"
6151934c7aaSWarner Losh		cd "${dir}"
6166b8c8deeSWill Andrews		find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)' | cpio -dumpv ${mnt}
6176b8c8deeSWill Andrews	fi
6186b8c8deeSWill Andrews	df -i ${mnt}
6196b8c8deeSWill Andrews	nano_umount ${mnt}
6206b8c8deeSWill Andrews)
6216b8c8deeSWill Andrews
6226b8c8deeSWill Andrewspopulate_cfg_slice ( ) (
6236b8c8deeSWill Andrews	populate_slice "$1" "$2" "$3" "$4"
6246b8c8deeSWill Andrews)
6256b8c8deeSWill Andrews
6266b8c8deeSWill Andrewspopulate_data_slice ( ) (
6276b8c8deeSWill Andrews	populate_slice "$1" "$2" "$3" "$4"
6286b8c8deeSWill Andrews)
6296b8c8deeSWill Andrews
6306b8c8deeSWill Andrewscreate_diskimage ( ) (
6316b8c8deeSWill Andrews	pprint 2 "build diskimage"
6326b8c8deeSWill Andrews	pprint 3 "log: ${NANO_OBJ}/_.di"
6336b8c8deeSWill Andrews
6346b8c8deeSWill Andrews	(
6356b8c8deeSWill Andrews	echo $NANO_MEDIASIZE $NANO_IMAGES \
6366b8c8deeSWill Andrews		$NANO_SECTS $NANO_HEADS \
6376b8c8deeSWill Andrews		$NANO_CODESIZE $NANO_CONFSIZE $NANO_DATASIZE |
6386b8c8deeSWill Andrews	awk '
6396b8c8deeSWill Andrews	{
6406b8c8deeSWill Andrews		printf "# %s\n", $0
6416b8c8deeSWill Andrews
6426b8c8deeSWill Andrews		# size of cylinder in sectors
6436b8c8deeSWill Andrews		cs = $3 * $4
6446b8c8deeSWill Andrews
6456b8c8deeSWill Andrews		# number of full cylinders on media
6466b8c8deeSWill Andrews		cyl = int ($1 / cs)
6476b8c8deeSWill Andrews
6486b8c8deeSWill Andrews		# output fdisk geometry spec, truncate cyls to 1023
6496b8c8deeSWill Andrews		if (cyl <= 1023)
6506b8c8deeSWill Andrews			print "g c" cyl " h" $4 " s" $3
6516b8c8deeSWill Andrews		else
6526b8c8deeSWill Andrews			print "g c" 1023 " h" $4 " s" $3
6536b8c8deeSWill Andrews
6546b8c8deeSWill Andrews		if ($7 > 0) {
6556b8c8deeSWill Andrews			# size of data partition in full cylinders
6566b8c8deeSWill Andrews			dsl = int (($7 + cs - 1) / cs)
6576b8c8deeSWill Andrews		} else {
6586b8c8deeSWill Andrews			dsl = 0;
6596b8c8deeSWill Andrews		}
6606b8c8deeSWill Andrews
6616b8c8deeSWill Andrews		# size of config partition in full cylinders
6626b8c8deeSWill Andrews		csl = int (($6 + cs - 1) / cs)
6636b8c8deeSWill Andrews
6646b8c8deeSWill Andrews		if ($5 == 0) {
6656b8c8deeSWill Andrews			# size of image partition(s) in full cylinders
6666b8c8deeSWill Andrews			isl = int ((cyl - dsl - csl) / $2)
6676b8c8deeSWill Andrews		} else {
6686b8c8deeSWill Andrews			isl = int (($5 + cs - 1) / cs)
6696b8c8deeSWill Andrews		}
6706b8c8deeSWill Andrews
6716b8c8deeSWill Andrews		# First image partition start at second track
6726b8c8deeSWill Andrews		print "p 1 165 " $3, isl * cs - $3
6736b8c8deeSWill Andrews		c = isl * cs;
6746b8c8deeSWill Andrews
6756b8c8deeSWill Andrews		# Second image partition (if any) also starts offset one
6766b8c8deeSWill Andrews		# track to keep them identical.
6776b8c8deeSWill Andrews		if ($2 > 1) {
6786b8c8deeSWill Andrews			print "p 2 165 " $3 + c, isl * cs - $3
6796b8c8deeSWill Andrews			c += isl * cs;
6806b8c8deeSWill Andrews		}
6816b8c8deeSWill Andrews
6826b8c8deeSWill Andrews		# Config partition starts at cylinder boundary.
6836b8c8deeSWill Andrews		print "p 3 165 " c, csl * cs
6846b8c8deeSWill Andrews		c += csl * cs
6856b8c8deeSWill Andrews
6866b8c8deeSWill Andrews		# Data partition (if any) starts at cylinder boundary.
6876b8c8deeSWill Andrews		if ($7 > 0) {
6886b8c8deeSWill Andrews			print "p 4 165 " c, dsl * cs
6896b8c8deeSWill Andrews		} else if ($7 < 0 && $1 > c) {
6906b8c8deeSWill Andrews			print "p 4 165 " c, $1 - c
6916b8c8deeSWill Andrews		} else if ($1 < c) {
6926b8c8deeSWill Andrews			print "Disk space overcommitted by", \
6936b8c8deeSWill Andrews			    c - $1, "sectors" > "/dev/stderr"
6946b8c8deeSWill Andrews			exit 2
6956b8c8deeSWill Andrews		}
6966b8c8deeSWill Andrews
6976b8c8deeSWill Andrews		# Force slice 1 to be marked active. This is necessary
6986b8c8deeSWill Andrews		# for booting the image from a USB device to work.
6996b8c8deeSWill Andrews		print "a 1"
7006b8c8deeSWill Andrews	}
7016b8c8deeSWill Andrews	' > ${NANO_OBJ}/_.fdisk
7026b8c8deeSWill Andrews
7036b8c8deeSWill Andrews	IMG=${NANO_DISKIMGDIR}/${NANO_IMGNAME}
7046b8c8deeSWill Andrews	MNT=${NANO_OBJ}/_.mnt
7056b8c8deeSWill Andrews	mkdir -p ${MNT}
7066b8c8deeSWill Andrews
7076b8c8deeSWill Andrews	if [ "${NANO_MD_BACKING}" = "swap" ] ; then
7086b8c8deeSWill Andrews		MD=`mdconfig -a -t swap -s ${NANO_MEDIASIZE} -x ${NANO_SECTS} \
7096b8c8deeSWill Andrews			-y ${NANO_HEADS}`
7106b8c8deeSWill Andrews	else
7116b8c8deeSWill Andrews		echo "Creating md backing file..."
712849f5467SWarner Losh		rm -f ${IMG}
7136b8c8deeSWill Andrews		dd if=/dev/zero of=${IMG} seek=${NANO_MEDIASIZE} count=0
7146b8c8deeSWill Andrews		MD=`mdconfig -a -t vnode -f ${IMG} -x ${NANO_SECTS} \
7156b8c8deeSWill Andrews			-y ${NANO_HEADS}`
7166b8c8deeSWill Andrews	fi
7176b8c8deeSWill Andrews
7186b8c8deeSWill Andrews	trap "echo 'Running exit trap code' ; df -i ${MNT} ; nano_umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT
7196b8c8deeSWill Andrews
7206b8c8deeSWill Andrews	fdisk -i -f ${NANO_OBJ}/_.fdisk ${MD}
7216b8c8deeSWill Andrews	fdisk ${MD}
7226b8c8deeSWill Andrews	# XXX: params
7236b8c8deeSWill Andrews	# XXX: pick up cached boot* files, they may not be in image anymore.
7246b8c8deeSWill Andrews	if [ -f ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ]; then
7256b8c8deeSWill Andrews		boot0cfg -B -b ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ${NANO_BOOT0CFG} ${MD}
7266b8c8deeSWill Andrews	fi
7276b8c8deeSWill Andrews	if [ -f ${NANO_WORLDDIR}/boot/boot ]; then
7287b77d3eaSWarner Losh		bsdlabel -w -B -b ${NANO_WORLDDIR}/boot/boot ${MD}${NANO_SLICE_ROOT}
7296b8c8deeSWill Andrews	else
7307b77d3eaSWarner Losh		bsdlabel -w ${MD}${NANO_SLICE_ROOT}
7316b8c8deeSWill Andrews	fi
7327b77d3eaSWarner Losh	bsdlabel ${MD}${NANO_SLICE_ROOT}
7336b8c8deeSWill Andrews
7346b8c8deeSWill Andrews	# Create first image
7357b77d3eaSWarner Losh	populate_slice /dev/${MD}${NANO_SLICE_ROOT}a ${NANO_WORLDDIR} ${MNT} "${NANO_SLICE_ROOT}a"
7367b77d3eaSWarner Losh	mount /dev/${MD}${NANO_SLICE_ROOT}a ${MNT}
7376b8c8deeSWill Andrews	echo "Generating mtree..."
7381934c7aaSWarner Losh	( cd "${MNT}" && mtree -c ) > ${NANO_OBJ}/_.mtree
7391934c7aaSWarner Losh	( cd "${MNT}" && du -k ) > ${NANO_OBJ}/_.du
7401934c7aaSWarner Losh	nano_umount "${MNT}"
7416b8c8deeSWill Andrews
7426b8c8deeSWill Andrews	if [ $NANO_IMAGES -gt 1 -a $NANO_INIT_IMG2 -gt 0 ] ; then
7436b8c8deeSWill Andrews		# Duplicate to second image (if present)
7446b8c8deeSWill Andrews		echo "Duplicating to second image..."
7457b77d3eaSWarner Losh		dd conv=sparse if=/dev/${MD}${NANO_SLICE_ROOT} of=/dev/${MD}${NANO_SLICE_ALTROOT} bs=64k
7467b77d3eaSWarner Losh		mount /dev/${MD}${NANO_SLICE_ALTROOT}a ${MNT}
7476b8c8deeSWill Andrews		for f in ${MNT}/etc/fstab ${MNT}/conf/base/etc/fstab
7486b8c8deeSWill Andrews		do
7497b77d3eaSWarner Losh			sed -i "" "s=${NANO_DRIVE}${NANO_SLICE_ROOT}=${NANO_DRIVE}${NANO_SLICE_ALTROOT}=g" $f
7506b8c8deeSWill Andrews		done
7516b8c8deeSWill Andrews		nano_umount ${MNT}
7526b8c8deeSWill Andrews		# Override the label from the first partition so we
7536b8c8deeSWill Andrews		# don't confuse glabel with duplicates.
754849f5467SWarner Losh		if [ -n ${NANO_LABEL} ]; then
7557b77d3eaSWarner Losh			tunefs -L ${NANO_LABEL}"${NANO_SLICE_ALTROOT}a" /dev/${MD}${NANO_SLICE_ALTROOT}a
7566b8c8deeSWill Andrews		fi
7576b8c8deeSWill Andrews	fi
7586b8c8deeSWill Andrews
7596b8c8deeSWill Andrews	# Create Config slice
7607b77d3eaSWarner Losh	populate_cfg_slice /dev/${MD}${NANO_SLICE_CFG} "${NANO_CFGDIR}" ${MNT} "${NANO_SLICE_CFG}"
7616b8c8deeSWill Andrews
7626b8c8deeSWill Andrews	# Create Data slice, if any.
763849f5467SWarner Losh	if [ -n $NANO_SLICE_DATA -a $NANO_SLICE_CFG = $NANO_SLICE_DATA -a \
7647b77d3eaSWarner Losh	   $NANO_DATASIZE -ne 0 ]; then
7657b77d3eaSWarner Losh		pprint 2 "NANO_SLICE_DATA is the same as NANO_SLICE_CFG, fix."
7667b77d3eaSWarner Losh		exit 2
7677b77d3eaSWarner Losh	fi
768849f5467SWarner Losh	if [ $NANO_DATASIZE -ne 0 -a -n $NANO_SLICE_DATA ] ; then
7697b77d3eaSWarner Losh		populate_data_slice /dev/${MD}${NANO_SLICE_DATA} "${NANO_DATADIR}" ${MNT} "${NANO_SLICE_DATA}"
7706b8c8deeSWill Andrews	fi
7716b8c8deeSWill Andrews
7726b8c8deeSWill Andrews	if [ "${NANO_MD_BACKING}" = "swap" ] ; then
7736b8c8deeSWill Andrews		if [ ${NANO_IMAGE_MBRONLY} ]; then
7746b8c8deeSWill Andrews			echo "Writing out _.disk.mbr..."
7756b8c8deeSWill Andrews			dd if=/dev/${MD} of=${NANO_DISKIMGDIR}/_.disk.mbr bs=512 count=1
7766b8c8deeSWill Andrews		else
7776b8c8deeSWill Andrews			echo "Writing out ${NANO_IMGNAME}..."
7786b8c8deeSWill Andrews			dd if=/dev/${MD} of=${IMG} bs=64k
7796b8c8deeSWill Andrews		fi
7806b8c8deeSWill Andrews
7816b8c8deeSWill Andrews		echo "Writing out ${NANO_IMGNAME}..."
7826b8c8deeSWill Andrews		dd conv=sparse if=/dev/${MD} of=${IMG} bs=64k
7836b8c8deeSWill Andrews	fi
7846b8c8deeSWill Andrews
7856b8c8deeSWill Andrews	if ${do_copyout_partition} ; then
7866b8c8deeSWill Andrews		echo "Writing out _.disk.image..."
7877b77d3eaSWarner Losh		dd conv=sparse if=/dev/${MD}${NANO_SLICE_ROOT} of=${NANO_DISKIMGDIR}/_.disk.image bs=64k
7886b8c8deeSWill Andrews	fi
7896b8c8deeSWill Andrews	mdconfig -d -u $MD
7906b8c8deeSWill Andrews
7916b8c8deeSWill Andrews	trap - 1 2 15
7926b8c8deeSWill Andrews	trap nano_cleanup EXIT
7936b8c8deeSWill Andrews
7946b8c8deeSWill Andrews	) > ${NANO_OBJ}/_.di 2>&1
7956b8c8deeSWill Andrews)
7966b8c8deeSWill Andrews
7976b8c8deeSWill Andrewslast_orders ( ) (
7986b8c8deeSWill Andrews	# Redefine this function with any last orders you may have
7996b8c8deeSWill Andrews	# after the build completed, for instance to copy the finished
8006b8c8deeSWill Andrews	# image to a more convenient place:
8016b8c8deeSWill Andrews	# cp ${NANO_DISKIMGDIR}/_.disk.image /home/ftp/pub/nanobsd.disk
8026b8c8deeSWill Andrews	true
8036b8c8deeSWill Andrews)
8046b8c8deeSWill Andrews
8056b8c8deeSWill Andrews#######################################################################
8066b8c8deeSWill Andrews#
8076b8c8deeSWill Andrews# Optional convenience functions.
8086b8c8deeSWill Andrews#
8096b8c8deeSWill Andrews#######################################################################
8106b8c8deeSWill Andrews
8116b8c8deeSWill Andrews#######################################################################
8126b8c8deeSWill Andrews# Common Flash device geometries
8136b8c8deeSWill Andrews#
8146b8c8deeSWill Andrews
8156b8c8deeSWill AndrewsFlashDevice ( ) {
8166b8c8deeSWill Andrews	if [ -d ${NANO_TOOLS} ] ; then
8176b8c8deeSWill Andrews		. ${NANO_TOOLS}/FlashDevice.sub
8186b8c8deeSWill Andrews	else
8196b8c8deeSWill Andrews		. ${NANO_SRC}/${NANO_TOOLS}/FlashDevice.sub
8206b8c8deeSWill Andrews	fi
8216b8c8deeSWill Andrews	sub_FlashDevice $1 $2
8226b8c8deeSWill Andrews}
8236b8c8deeSWill Andrews
8246b8c8deeSWill Andrews#######################################################################
8256b8c8deeSWill Andrews# USB device geometries
8266b8c8deeSWill Andrews#
8276b8c8deeSWill Andrews# Usage:
8286b8c8deeSWill Andrews#	UsbDevice Generic 1000	# a generic flash key sold as having 1GB
8296b8c8deeSWill Andrews#
8306b8c8deeSWill Andrews# This function will set NANO_MEDIASIZE, NANO_HEADS and NANO_SECTS for you.
8316b8c8deeSWill Andrews#
8326b8c8deeSWill Andrews# Note that the capacity of a flash key is usually advertised in MB or
8336b8c8deeSWill Andrews# GB, *not* MiB/GiB. As such, the precise number of cylinders available
8346b8c8deeSWill Andrews# for C/H/S geometry may vary depending on the actual flash geometry.
8356b8c8deeSWill Andrews#
8366b8c8deeSWill Andrews# The following generic device layouts are understood:
8376b8c8deeSWill Andrews#  generic           An alias for generic-hdd.
8386b8c8deeSWill Andrews#  generic-hdd       255H 63S/T xxxxC with no MBR restrictions.
8396b8c8deeSWill Andrews#  generic-fdd       64H 32S/T xxxxC with no MBR restrictions.
8406b8c8deeSWill Andrews#
8416b8c8deeSWill Andrews# The generic-hdd device is preferred for flash devices larger than 1GB.
8426b8c8deeSWill Andrews#
8436b8c8deeSWill Andrews
8446b8c8deeSWill AndrewsUsbDevice ( ) {
8456b8c8deeSWill Andrews	a1=`echo $1 | tr '[:upper:]' '[:lower:]'`
8466b8c8deeSWill Andrews	case $a1 in
8476b8c8deeSWill Andrews	generic-fdd)
8486b8c8deeSWill Andrews		NANO_HEADS=64
8496b8c8deeSWill Andrews		NANO_SECTS=32
8506b8c8deeSWill Andrews		NANO_MEDIASIZE=$(( $2 * 1000 * 1000 / 512 ))
8516b8c8deeSWill Andrews		;;
8526b8c8deeSWill Andrews	generic|generic-hdd)
8536b8c8deeSWill Andrews		NANO_HEADS=255
8546b8c8deeSWill Andrews		NANO_SECTS=63
8556b8c8deeSWill Andrews		NANO_MEDIASIZE=$(( $2 * 1000 * 1000 / 512 ))
8566b8c8deeSWill Andrews		;;
8576b8c8deeSWill Andrews	*)
8586b8c8deeSWill Andrews		echo "Unknown USB flash device"
8596b8c8deeSWill Andrews		exit 2
8606b8c8deeSWill Andrews		;;
8616b8c8deeSWill Andrews	esac
8626b8c8deeSWill Andrews}
8636b8c8deeSWill Andrews
8646b8c8deeSWill Andrews#######################################################################
8656b8c8deeSWill Andrews# Setup serial console
8666b8c8deeSWill Andrews
8676b8c8deeSWill Andrewscust_comconsole ( ) (
8686b8c8deeSWill Andrews	# Enable getty on console
8696b8c8deeSWill Andrews	sed -i "" -e /tty[du]0/s/off/on/ ${NANO_WORLDDIR}/etc/ttys
8706b8c8deeSWill Andrews
8716b8c8deeSWill Andrews	# Disable getty on syscons devices
8726b8c8deeSWill Andrews	sed -i "" -e '/^ttyv[0-8]/s/	on/	off/' ${NANO_WORLDDIR}/etc/ttys
8736b8c8deeSWill Andrews
8746b8c8deeSWill Andrews	# Tell loader to use serial console early.
8756b8c8deeSWill Andrews	echo "${NANO_BOOT2CFG}" > ${NANO_WORLDDIR}/boot.config
8766b8c8deeSWill Andrews)
8776b8c8deeSWill Andrews
8786b8c8deeSWill Andrews#######################################################################
8796b8c8deeSWill Andrews# Allow root login via ssh
8806b8c8deeSWill Andrews
8816b8c8deeSWill Andrewscust_allow_ssh_root ( ) (
8826b8c8deeSWill Andrews	sed -i "" -e '/PermitRootLogin/s/.*/PermitRootLogin yes/' \
8836b8c8deeSWill Andrews	    ${NANO_WORLDDIR}/etc/ssh/sshd_config
8846b8c8deeSWill Andrews)
8856b8c8deeSWill Andrews
8866b8c8deeSWill Andrews#######################################################################
8876b8c8deeSWill Andrews# Install the stuff under ./Files
8886b8c8deeSWill Andrews
8896b8c8deeSWill Andrewscust_install_files ( ) (
8901934c7aaSWarner Losh	cd "${NANO_TOOLS}/Files"
8916b8c8deeSWill Andrews	find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)' | cpio -Ldumpv ${NANO_WORLDDIR}
8926b8c8deeSWill Andrews)
8936b8c8deeSWill Andrews
8946b8c8deeSWill Andrews#######################################################################
8956b8c8deeSWill Andrews# Install packages from ${NANO_PACKAGE_DIR}
8966b8c8deeSWill Andrews
8976b8c8deeSWill Andrewscust_pkgng ( ) (
8986b8c8deeSWill Andrews
8996b8c8deeSWill Andrews	# If the package directory doesn't exist, we're done.
9006b8c8deeSWill Andrews	if [ ! -d ${NANO_PACKAGE_DIR} ]; then
9016b8c8deeSWill Andrews		echo "DONE 0 packages"
9026b8c8deeSWill Andrews		return 0
9036b8c8deeSWill Andrews	fi
9046b8c8deeSWill Andrews
9056b8c8deeSWill Andrews	# Find a pkg-* package
9066b8c8deeSWill Andrews	for x in `find -s ${NANO_PACKAGE_DIR} -iname 'pkg-*'`; do
9076b8c8deeSWill Andrews		_NANO_PKG_PACKAGE=`basename "$x"`
9086b8c8deeSWill Andrews	done
9096b8c8deeSWill Andrews	if [ -z "${_NANO_PKG_PACKAGE}" -o ! -f "${NANO_PACKAGE_DIR}/${_NANO_PKG_PACKAGE}" ]; then
9106b8c8deeSWill Andrews		echo "FAILED: need a pkg/ package for bootstrapping"
9116b8c8deeSWill Andrews		exit 2
9126b8c8deeSWill Andrews	fi
9136b8c8deeSWill Andrews
9146b8c8deeSWill Andrews	# Copy packages into chroot
9156b8c8deeSWill Andrews	mkdir -p ${NANO_WORLDDIR}/Pkg
9166b8c8deeSWill Andrews	(
9171934c7aaSWarner Losh		cd "${NANO_PACKAGE_DIR}"
9181934c7aaSWarner Losh		find "${NANO_PACKAGE_LIST}" -print |
9196b8c8deeSWill Andrews		cpio -Ldumpv ${NANO_WORLDDIR}/Pkg
9206b8c8deeSWill Andrews	)
9216b8c8deeSWill Andrews
9226b8c8deeSWill Andrews	#Bootstrap pkg
9236b8c8deeSWill Andrews	CR env ASSUME_ALWAYS_YES=YES SIGNATURE_TYPE=none /usr/sbin/pkg add /Pkg/${_NANO_PKG_PACKAGE}
9246b8c8deeSWill Andrews	CR pkg -N >/dev/null 2>&1
9256b8c8deeSWill Andrews	if [ "$?" -ne "0" ]; then
9266b8c8deeSWill Andrews		echo "FAILED: pkg bootstrapping faied"
9276b8c8deeSWill Andrews		exit 2
9286b8c8deeSWill Andrews	fi
929849f5467SWarner Losh	rm -f ${NANO_WORLDDIR}/Pkg/pkg-*
9306b8c8deeSWill Andrews
9316b8c8deeSWill Andrews	# Count & report how many we have to install
9326b8c8deeSWill Andrews	todo=`ls ${NANO_WORLDDIR}/Pkg | /usr/bin/wc -l`
9336b8c8deeSWill Andrews	todo=$(expr $todo + 1) # add one for pkg since it is installed already
9346b8c8deeSWill Andrews	echo "=== TODO: $todo"
9356b8c8deeSWill Andrews	ls ${NANO_WORLDDIR}/Pkg
9366b8c8deeSWill Andrews	echo "==="
9376b8c8deeSWill Andrews	while true
9386b8c8deeSWill Andrews	do
9396b8c8deeSWill Andrews		# Record how many we have now
9406b8c8deeSWill Andrews 		have=$(CR env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg info | /usr/bin/wc -l)
9416b8c8deeSWill Andrews
9426b8c8deeSWill Andrews		# Attempt to install more packages
9436b8c8deeSWill Andrews		CR0 'ls 'Pkg/*txz' | xargs env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg add'
9446b8c8deeSWill Andrews
9456b8c8deeSWill Andrews		# See what that got us
9466b8c8deeSWill Andrews 		now=$(CR env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg info | /usr/bin/wc -l)
9476b8c8deeSWill Andrews		echo "=== NOW $now"
9486b8c8deeSWill Andrews		CR env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg info
9496b8c8deeSWill Andrews		echo "==="
9506b8c8deeSWill Andrews		if [ $now -eq $todo ] ; then
9516b8c8deeSWill Andrews			echo "DONE $now packages"
9526b8c8deeSWill Andrews			break
9536b8c8deeSWill Andrews		elif [ $now -eq $have ] ; then
9546b8c8deeSWill Andrews			echo "FAILED: Nothing happened on this pass"
9556b8c8deeSWill Andrews			exit 2
9566b8c8deeSWill Andrews		fi
9576b8c8deeSWill Andrews	done
958849f5467SWarner Losh	rm -rf ${NANO_WORLDDIR}/Pkg
9596b8c8deeSWill Andrews)
9606b8c8deeSWill Andrews
9616b8c8deeSWill Andrews#######################################################################
9626b8c8deeSWill Andrews# Convenience function:
9636b8c8deeSWill Andrews# 	Register all args as customize function.
9646b8c8deeSWill Andrews
9656b8c8deeSWill Andrewscustomize_cmd ( ) {
9666b8c8deeSWill Andrews	NANO_CUSTOMIZE="$NANO_CUSTOMIZE $*"
9676b8c8deeSWill Andrews}
9686b8c8deeSWill Andrews
9696b8c8deeSWill Andrews#######################################################################
9706b8c8deeSWill Andrews# Convenience function:
9716b8c8deeSWill Andrews# 	Register all args as late customize function to run just before
9726b8c8deeSWill Andrews#	image creation.
9736b8c8deeSWill Andrews
9746b8c8deeSWill Andrewslate_customize_cmd ( ) {
9756b8c8deeSWill Andrews	NANO_LATE_CUSTOMIZE="$NANO_LATE_CUSTOMIZE $*"
9766b8c8deeSWill Andrews}
9776b8c8deeSWill Andrews
9786b8c8deeSWill Andrews#######################################################################
9796b8c8deeSWill Andrews#
9806b8c8deeSWill Andrews# All set up to go...
9816b8c8deeSWill Andrews#
9826b8c8deeSWill Andrews#######################################################################
9836b8c8deeSWill Andrews
9846b8c8deeSWill Andrews# Progress Print
9856b8c8deeSWill Andrews#	Print $2 at level $1.
9866b8c8deeSWill Andrewspprint ( ) (
9876b8c8deeSWill Andrews    if [ "$1" -le $PPLEVEL ]; then
9886b8c8deeSWill Andrews	runtime=$(( `date +%s` - $NANO_STARTTIME ))
9896b8c8deeSWill Andrews	printf "%s %.${1}s %s\n" "`date -u -r $runtime +%H:%M:%S`" "#####" "$2" 1>&3
9906b8c8deeSWill Andrews    fi
9916b8c8deeSWill Andrews)
9926b8c8deeSWill Andrews
9936b8c8deeSWill Andrewsusage ( ) {
9946b8c8deeSWill Andrews	(
9956b8c8deeSWill Andrews	echo "Usage: $0 [-bfiKknqvw] [-c config_file]"
9966b8c8deeSWill Andrews	echo "	-b	suppress builds (both kernel and world)"
9976b8c8deeSWill Andrews	echo "	-c	specify config file"
9986b8c8deeSWill Andrews	echo "	-f	suppress code slice extraction"
9996b8c8deeSWill Andrews	echo "	-i	suppress disk image build"
10006b8c8deeSWill Andrews	echo "	-K	suppress installkernel"
10016b8c8deeSWill Andrews	echo "	-k	suppress buildkernel"
10026b8c8deeSWill Andrews	echo "	-n	add -DNO_CLEAN to buildworld, buildkernel, etc"
10036b8c8deeSWill Andrews	echo "	-q	make output more quiet"
10046b8c8deeSWill Andrews	echo "	-v	make output more verbose"
10056b8c8deeSWill Andrews	echo "	-w	suppress buildworld"
10066b8c8deeSWill Andrews	) 1>&2
10076b8c8deeSWill Andrews	exit 2
10086b8c8deeSWill Andrews}
10096b8c8deeSWill Andrews
10106b8c8deeSWill Andrews#######################################################################
10116b8c8deeSWill Andrews# Setup and Export Internal variables
10126b8c8deeSWill Andrews#
10136b8c8deeSWill Andrews
10141934c7aaSWarner Loshexport_var ( ) {		# Don't wawnt a subshell
10156b8c8deeSWill Andrews	var=$1
10166b8c8deeSWill Andrews	# Lookup value of the variable.
10176b8c8deeSWill Andrews	eval val=\$$var
10186b8c8deeSWill Andrews	pprint 3 "Setting variable: $var=\"$val\""
10196b8c8deeSWill Andrews	export $1
10206b8c8deeSWill Andrews}
10216b8c8deeSWill Andrews
10226b8c8deeSWill Andrews# Call this function to set defaults _after_ parsing options.
10231934c7aaSWarner Losh# dont want a subshell otherwise variable setting is thrown away.
10246b8c8deeSWill Andrewsset_defaults_and_export ( ) {
1025849f5467SWarner Losh	: ${NANO_OBJ:=/usr/obj/nanobsd.${NANO_NAME}}
1026849f5467SWarner Losh	: ${MAKEOBJDIRPREFIX:=${NANO_OBJ}}
1027849f5467SWarner Losh	: ${NANO_DISKIMGDIR=:${NANO_OBJ}}
10286b8c8deeSWill Andrews	NANO_WORLDDIR=${NANO_OBJ}/_.w
10296b8c8deeSWill Andrews	NANO_MAKE_CONF_BUILD=${MAKEOBJDIRPREFIX}/make.conf.build
10306b8c8deeSWill Andrews	NANO_MAKE_CONF_INSTALL=${NANO_OBJ}/make.conf.install
10316b8c8deeSWill Andrews
10326b8c8deeSWill Andrews	# Override user's NANO_DRIVE if they specified a NANO_LABEL
1033849f5467SWarner Losh	[ -n "${NANO_LABEL}" ] && NANO_DRIVE="ufs/${NANO_LABEL}" || true
10346b8c8deeSWill Andrews
10356b8c8deeSWill Andrews	# Set a default NANO_TOOLS to NANO_SRC/NANO_TOOLS if it exists.
10366b8c8deeSWill Andrews	[ ! -d "${NANO_TOOLS}" ] && [ -d "${NANO_SRC}/${NANO_TOOLS}" ] && \
1037c275d9ecSWarner Losh		NANO_TOOLS="${NANO_SRC}/${NANO_TOOLS}" || true
1038c275d9ecSWarner Losh
1039849f5467SWarner Losh	[ -n "${NANO_NOPRIV_BUILD}" ] && [ -z "${NANO_METALOG}" ] && \
1040c275d9ecSWarner Losh		NANO_METALOG=${NANO_OBJ}/_.metalog || true
10416b8c8deeSWill Andrews
10426b8c8deeSWill Andrews	NANO_STARTTIME=`date +%s`
10436b8c8deeSWill Andrews	pprint 3 "Exporting NanoBSD variables"
10446b8c8deeSWill Andrews	export_var MAKEOBJDIRPREFIX
10456b8c8deeSWill Andrews	export_var NANO_ARCH
10466b8c8deeSWill Andrews	export_var NANO_CODESIZE
10476b8c8deeSWill Andrews	export_var NANO_CONFSIZE
10486b8c8deeSWill Andrews	export_var NANO_CUSTOMIZE
10496b8c8deeSWill Andrews	export_var NANO_DATASIZE
10506b8c8deeSWill Andrews	export_var NANO_DRIVE
10516b8c8deeSWill Andrews	export_var NANO_HEADS
10526b8c8deeSWill Andrews	export_var NANO_IMAGES
10536b8c8deeSWill Andrews	export_var NANO_IMGNAME
10546b8c8deeSWill Andrews	export_var NANO_MAKE
10556b8c8deeSWill Andrews	export_var NANO_MAKE_CONF_BUILD
10566b8c8deeSWill Andrews	export_var NANO_MAKE_CONF_INSTALL
10576b8c8deeSWill Andrews	export_var NANO_MEDIASIZE
10586b8c8deeSWill Andrews	export_var NANO_NAME
10596b8c8deeSWill Andrews	export_var NANO_NEWFS
10606b8c8deeSWill Andrews	export_var NANO_OBJ
10616b8c8deeSWill Andrews	export_var NANO_PMAKE
10626b8c8deeSWill Andrews	export_var NANO_SECTS
10636b8c8deeSWill Andrews	export_var NANO_SRC
10646b8c8deeSWill Andrews	export_var NANO_TOOLS
10656b8c8deeSWill Andrews	export_var NANO_WORLDDIR
10666b8c8deeSWill Andrews	export_var NANO_BOOT0CFG
10676b8c8deeSWill Andrews	export_var NANO_BOOTLOADER
10686b8c8deeSWill Andrews	export_var NANO_LABEL
10696b8c8deeSWill Andrews	export_var NANO_MODULES
1070c275d9ecSWarner Losh	export_var NANO_NOPRIV_BUILD
1071c275d9ecSWarner Losh	export_var NANO_METALOG
10721934c7aaSWarner Losh	export_var SRCCONF
1073a9d9c49fSWarner Losh	export_var SRC_ENV_CONF
10746b8c8deeSWill Andrews}
1075