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 558e7676caSGleb Smirnoff# Path to mtree file to apply to anything copied by cust_install_files(). 568e7676caSGleb Smirnoff# If you specify this, the mtree file *must* have an entry for every file and 578e7676caSGleb Smirnoff# directory located in Files. 588e7676caSGleb Smirnoff#NANO_CUST_FILES_MTREE="" 598e7676caSGleb Smirnoff 606b8c8deeSWill Andrews# Object tree directory 616b8c8deeSWill Andrews# default is subdir of /usr/obj 626b8c8deeSWill Andrews#NANO_OBJ="" 636b8c8deeSWill Andrews 646b8c8deeSWill Andrews# The directory to put the final images 656b8c8deeSWill Andrews# default is ${NANO_OBJ} 666b8c8deeSWill Andrews#NANO_DISKIMGDIR="" 676b8c8deeSWill Andrews 686b8c8deeSWill Andrews# Make & parallel Make 696b8c8deeSWill AndrewsNANO_MAKE="make" 706b8c8deeSWill AndrewsNANO_PMAKE="make -j 3" 716b8c8deeSWill Andrews 726b8c8deeSWill Andrews# The default name for any image we create. 736b8c8deeSWill AndrewsNANO_IMGNAME="_.disk.full" 74df6c7936SWarner LoshNANO_IMG1NAME="_.disk.image" 756b8c8deeSWill Andrews 766b8c8deeSWill Andrews# Options to put in make.conf during buildworld only 776b8c8deeSWill AndrewsCONF_BUILD=' ' 786b8c8deeSWill Andrews 796b8c8deeSWill Andrews# Options to put in make.conf during installworld only 806b8c8deeSWill AndrewsCONF_INSTALL=' ' 816b8c8deeSWill Andrews 826b8c8deeSWill Andrews# Options to put in make.conf during both build- & installworld. 836b8c8deeSWill AndrewsCONF_WORLD=' ' 846b8c8deeSWill Andrews 856b8c8deeSWill Andrews# Kernel config file to use 866b8c8deeSWill AndrewsNANO_KERNEL=GENERIC 876b8c8deeSWill Andrews 886b8c8deeSWill Andrews# Kernel modules to install. If empty, no modules are installed. 896b8c8deeSWill Andrews# Use "default" to install all built modules. 906b8c8deeSWill AndrewsNANO_MODULES= 916b8c8deeSWill Andrews 925b4ca9d7SGleb Smirnoff# Early customize commands. 935b4ca9d7SGleb SmirnoffNANO_EARLY_CUSTOMIZE="" 945b4ca9d7SGleb Smirnoff 956b8c8deeSWill Andrews# Customize commands. 966b8c8deeSWill AndrewsNANO_CUSTOMIZE="" 976b8c8deeSWill Andrews 986b8c8deeSWill Andrews# Late customize commands. 996b8c8deeSWill AndrewsNANO_LATE_CUSTOMIZE="" 1006b8c8deeSWill Andrews 101bd0ca238SPedro F. Giffuni# Newfs parameters to use 1026b8c8deeSWill AndrewsNANO_NEWFS="-b 4096 -f 512 -i 8192 -U" 1036b8c8deeSWill Andrews 1046b8c8deeSWill Andrews# The drive name of the media at runtime 1054c1ca03bSWarner LoshNANO_DRIVE=ada0 1066b8c8deeSWill Andrews 1076b8c8deeSWill Andrews# Target media size in 512 bytes sectors 1086b8c8deeSWill AndrewsNANO_MEDIASIZE=2000000 1096b8c8deeSWill Andrews 1106b8c8deeSWill Andrews# Number of code images on media (1 or 2) 1116b8c8deeSWill AndrewsNANO_IMAGES=2 1126b8c8deeSWill Andrews 1136b8c8deeSWill Andrews# 0 -> Leave second image all zeroes so it compresses better. 1146b8c8deeSWill Andrews# 1 -> Initialize second image with a copy of the first 1156b8c8deeSWill AndrewsNANO_INIT_IMG2=1 1166b8c8deeSWill Andrews 1176b8c8deeSWill Andrews# Size of code file system in 512 bytes sectors 1186b8c8deeSWill Andrews# If zero, size will be as large as possible. 1196b8c8deeSWill AndrewsNANO_CODESIZE=0 1206b8c8deeSWill Andrews 1216b8c8deeSWill Andrews# Size of configuration file system in 512 bytes sectors 1226b8c8deeSWill Andrews# Cannot be zero. 1236b8c8deeSWill AndrewsNANO_CONFSIZE=2048 1246b8c8deeSWill Andrews 1256b8c8deeSWill Andrews# Size of data file system in 512 bytes sectors 1266b8c8deeSWill Andrews# If zero: no partition configured. 1276b8c8deeSWill Andrews# If negative: max size possible 1286b8c8deeSWill AndrewsNANO_DATASIZE=0 1296b8c8deeSWill Andrews 1306b8c8deeSWill Andrews# Size of the /etc ramdisk in 512 bytes sectors 1316b8c8deeSWill AndrewsNANO_RAM_ETCSIZE=10240 1326b8c8deeSWill Andrews 1336b8c8deeSWill Andrews# Size of the /tmp+/var ramdisk in 512 bytes sectors 1346b8c8deeSWill AndrewsNANO_RAM_TMPVARSIZE=10240 1356b8c8deeSWill Andrews 1366b8c8deeSWill Andrews# boot0 flags/options and configuration 1376b8c8deeSWill AndrewsNANO_BOOT0CFG="-o packet -s 1 -m 3" 1386b8c8deeSWill AndrewsNANO_BOOTLOADER="boot/boot0sio" 1396b8c8deeSWill Andrews 1406b8c8deeSWill Andrews# boot2 flags/options 1416b8c8deeSWill Andrews# default force serial console 142a9598aaeSWarner LoshNANO_BOOT2CFG="-h -S115200" 1436b8c8deeSWill Andrews 1446b8c8deeSWill Andrews# Backing type of md(4) device 1456b8c8deeSWill Andrews# Can be "file" or "swap" 1466b8c8deeSWill AndrewsNANO_MD_BACKING="file" 1476b8c8deeSWill Andrews 1486b8c8deeSWill Andrews# for swap type md(4) backing, write out the mbr only 1496b8c8deeSWill AndrewsNANO_IMAGE_MBRONLY=true 1506b8c8deeSWill Andrews 1516b8c8deeSWill Andrews# Progress Print level 1526b8c8deeSWill AndrewsPPLEVEL=3 1536b8c8deeSWill Andrews 1546b8c8deeSWill Andrews# Set NANO_LABEL to non-blank to form the basis for using /dev/ufs/label 1556b8c8deeSWill Andrews# in preference to /dev/${NANO_DRIVE} 1566b8c8deeSWill Andrews# Root partition will be ${NANO_LABEL}s{1,2} 1576b8c8deeSWill Andrews# /cfg partition will be ${NANO_LABEL}s3 1586b8c8deeSWill Andrews# /data partition will be ${NANO_LABEL}s4 1596b8c8deeSWill AndrewsNANO_LABEL="" 1607b77d3eaSWarner LoshNANO_SLICE_ROOT=s1 1617b77d3eaSWarner LoshNANO_SLICE_ALTROOT=s2 1627b77d3eaSWarner LoshNANO_SLICE_CFG=s3 1637b77d3eaSWarner LoshNANO_SLICE_DATA=s4 1645e4bd293SWarner LoshNANO_ROOT=s1a 1655e4bd293SWarner LoshNANO_ALTROOT=s2a 1667b77d3eaSWarner Losh 16719edffefSWarner Losh# Default ownwership for nopriv build 16819edffefSWarner LoshNANO_DEF_UNAME=root 16919edffefSWarner LoshNANO_DEF_GNAME=wheel 1706b8c8deeSWill Andrews 1716b8c8deeSWill Andrews####################################################################### 1726b8c8deeSWill Andrews# Architecture to build. Corresponds to TARGET_ARCH in a buildworld. 1736b8c8deeSWill Andrews# Unfortunately, there's no way to set TARGET at this time, and it 174d07833f9SWarner Losh# conflates the two, so architectures where TARGET != TARGET_ARCH and 175d07833f9SWarner Losh# TARGET can't be guessed from TARGET_ARCH do not work. This defaults 176d07833f9SWarner Losh# to the arch of the current machine. 1776b8c8deeSWill AndrewsNANO_ARCH=`uname -p` 1786b8c8deeSWill Andrews 179d07833f9SWarner Losh# CPUTYPE defaults to "" which is the default when CPUTYPE isn't 180d07833f9SWarner Losh# defined. 181d07833f9SWarner LoshNANO_CPUTYPE="" 182d07833f9SWarner Losh 1836b8c8deeSWill Andrews# Directory to populate /cfg from 1846b8c8deeSWill AndrewsNANO_CFGDIR="" 1856b8c8deeSWill Andrews 1866b8c8deeSWill Andrews# Directory to populate /data from 1876b8c8deeSWill AndrewsNANO_DATADIR="" 1886b8c8deeSWill Andrews 189a9d9c49fSWarner Losh# We don't need SRCCONF or SRC_ENV_CONF. NanoBSD puts everything we 190a9d9c49fSWarner Losh# need for the build in files included with __MAKE_CONF. Override in your 191a9d9c49fSWarner Losh# config file if you really must. We set them unconditionally here, though 192a9d9c49fSWarner Losh# in case they are stray in the build environment 193a9d9c49fSWarner LoshSRCCONF=/dev/null 194a9d9c49fSWarner LoshSRC_ENV_CONF=/dev/null 1956b8c8deeSWill Andrews 1966b8c8deeSWill Andrews####################################################################### 1976b8c8deeSWill Andrews# 1986b8c8deeSWill Andrews# The functions which do the real work. 1996b8c8deeSWill Andrews# Can be overridden from the config file(s) 2006b8c8deeSWill Andrews# 2016b8c8deeSWill Andrews####################################################################### 2026b8c8deeSWill Andrews 2031934c7aaSWarner Losh# Export values into the shell. Must use { } instead of ( ) like 2041934c7aaSWarner Losh# other functions to avoid a subshell. 2051934c7aaSWarner Losh# We set __MAKE_CONF as a global since it is easier to get quoting 2061934c7aaSWarner Losh# right for paths with spaces in them. 2071934c7aaSWarner Loshmake_export ( ) { 2081934c7aaSWarner Losh # Similar to export_var, except puts the data out to stdout 2091934c7aaSWarner Losh var=$1 2101934c7aaSWarner Losh eval val=\$$var 2111934c7aaSWarner Losh echo "Setting variable: $var=\"$val\"" 2121934c7aaSWarner Losh export $1 2131934c7aaSWarner Losh} 2141934c7aaSWarner Losh 2151934c7aaSWarner Loshnano_make_build_env ( ) { 2161934c7aaSWarner Losh __MAKE_CONF="${NANO_MAKE_CONF_BUILD}" 2171934c7aaSWarner Losh make_export __MAKE_CONF 2181934c7aaSWarner Losh} 2191934c7aaSWarner Losh 2201934c7aaSWarner Loshnano_make_install_env ( ) { 2211934c7aaSWarner Losh __MAKE_CONF="${NANO_MAKE_CONF_INSTALL}" 2221934c7aaSWarner Losh make_export __MAKE_CONF 2231934c7aaSWarner Losh} 2241934c7aaSWarner Losh 2251934c7aaSWarner Losh# Extra environment variables for kernel builds 2261934c7aaSWarner Loshnano_make_kernel_env ( ) { 227a5ae1a98SGleb Smirnoff if [ -f "${NANO_KERNEL}" ] ; then 2281934c7aaSWarner Losh KERNCONFDIR="$(realpath $(dirname ${NANO_KERNEL}))" 2291934c7aaSWarner Losh KERNCONF="$(basename ${NANO_KERNEL})" 2301934c7aaSWarner Losh make_export KERNCONFDIR 2311934c7aaSWarner Losh make_export KERNCONF 2321934c7aaSWarner Losh else 2331934c7aaSWarner Losh export KERNCONF="${NANO_KERNEL}" 2341934c7aaSWarner Losh make_export KERNCONF 2351934c7aaSWarner Losh fi 2361934c7aaSWarner Losh} 2371934c7aaSWarner Losh 2381934c7aaSWarner Loshnano_global_make_env ( ) ( 239849f5467SWarner Losh # global settings for the make.conf file, if set 240849f5467SWarner Losh [ -z "${NANO_ARCH}" ] || echo TARGET_ARCH="${NANO_ARCH}" 241849f5467SWarner Losh [ -z "${NANO_CPUTYPE}" ] || echo TARGET_CPUTYPE="${NANO_CPUTYPE}" 2421934c7aaSWarner Losh) 2431934c7aaSWarner Losh 2446b8c8deeSWill Andrews# rm doesn't know -x prior to FreeBSD 10, so cope with a variety of build 245849f5467SWarner Losh# hosts for now. This will go away when support in the base goes away. 246849f5467SWarner Loshrm ( ) { 247849f5467SWarner Losh echo "NANO RM $*" 2486b8c8deeSWill Andrews case $(uname -r) in 249849f5467SWarner Losh 7*|8*|9*) command rm $* ;; 250849f5467SWarner Losh *) command rm -x $* ;; 2516b8c8deeSWill Andrews esac 2526b8c8deeSWill Andrews} 2536b8c8deeSWill Andrews 25419edffefSWarner Losh# 25519edffefSWarner Losh# Create empty files in the target tree, and record the fact. All paths 25619edffefSWarner Losh# are relative to NANO_WORLDDIR. 25719edffefSWarner Losh# 25819edffefSWarner Loshtgt_touch ( ) ( 25919edffefSWarner Losh cd "${NANO_WORLDDIR}" 26019edffefSWarner Losh for i; do 26119edffefSWarner Losh touch $i 26219edffefSWarner Losh echo "./${i} type=file" >> ${NANO_METALOG} 26319edffefSWarner Losh done 26419edffefSWarner Losh) 26519edffefSWarner Losh 26619edffefSWarner Losh# 26719edffefSWarner Losh# Convert a directory into a symlink. Takes two arguments, the 26819edffefSWarner Losh# current directory and what it should become a symlink to. The 26919edffefSWarner Losh# directory is removed and a symlink is created. If we're doing 27019edffefSWarner Losh# a nopriv build, then append this fact to the metalog 27119edffefSWarner Losh# 27219edffefSWarner Loshtgt_dir2symlink ( ) ( 27319edffefSWarner Losh dir=$1 27419edffefSWarner Losh symlink=$2 27519edffefSWarner Losh 27619edffefSWarner Losh cd "${NANO_WORLDDIR}" 27719edffefSWarner Losh rm -rf "$dir" 27819edffefSWarner Losh ln -s "$symlink" "$dir" 2790a852830SWarner Losh if [ -n "$NANO_METALOG" ]; then 28019edffefSWarner Losh echo "./${dir} type=link mode=0777 link=${symlink}" >> ${NANO_METALOG} 28119edffefSWarner Losh fi 28219edffefSWarner Losh) 28319edffefSWarner Losh 2846b8c8deeSWill Andrews# run in the world chroot, errors fatal 2851934c7aaSWarner LoshCR ( ) { 2861934c7aaSWarner Losh chroot "${NANO_WORLDDIR}" /bin/sh -exc "$*" 2876b8c8deeSWill Andrews} 2886b8c8deeSWill Andrews 2896b8c8deeSWill Andrews# run in the world chroot, errors not fatal 2901934c7aaSWarner LoshCR0 ( ) { 2911934c7aaSWarner Losh chroot "${NANO_WORLDDIR}" /bin/sh -c "$*" || true 2926b8c8deeSWill Andrews} 2936b8c8deeSWill Andrews 2946b8c8deeSWill Andrewsclean_build ( ) ( 2956b8c8deeSWill Andrews pprint 2 "Clean and create object directory (${MAKEOBJDIRPREFIX})" 2966b8c8deeSWill Andrews 297849f5467SWarner Losh if ! rm -rf ${MAKEOBJDIRPREFIX}/ > /dev/null 2>&1 ; then 2986b8c8deeSWill Andrews chflags -R noschg ${MAKEOBJDIRPREFIX}/ 299849f5467SWarner Losh rm -r ${MAKEOBJDIRPREFIX}/ 3006b8c8deeSWill Andrews fi 3016b8c8deeSWill Andrews) 3026b8c8deeSWill Andrews 3036b8c8deeSWill Andrewsmake_conf_build ( ) ( 3046b8c8deeSWill Andrews pprint 2 "Construct build make.conf ($NANO_MAKE_CONF_BUILD)" 3056b8c8deeSWill Andrews 3066b8c8deeSWill Andrews mkdir -p ${MAKEOBJDIRPREFIX} 3076b8c8deeSWill Andrews printenv > ${MAKEOBJDIRPREFIX}/_.env 3086b8c8deeSWill Andrews 3091934c7aaSWarner Losh # Make sure we get all the global settings that NanoBSD wants 3101934c7aaSWarner Losh # in addition to the user's global settings 3111934c7aaSWarner Losh ( 3121934c7aaSWarner Losh nano_global_make_env 3131934c7aaSWarner Losh echo "${CONF_WORLD}" 3141934c7aaSWarner Losh echo "${CONF_BUILD}" 3151934c7aaSWarner Losh ) > ${NANO_MAKE_CONF_BUILD} 3166b8c8deeSWill Andrews) 3176b8c8deeSWill Andrews 3186b8c8deeSWill Andrewsbuild_world ( ) ( 3196b8c8deeSWill Andrews pprint 2 "run buildworld" 3206b8c8deeSWill Andrews pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bw" 3216b8c8deeSWill Andrews 3221934c7aaSWarner Losh ( 3231934c7aaSWarner Losh nano_make_build_env 3241934c7aaSWarner Losh set -o xtrace 3251934c7aaSWarner Losh cd "${NANO_SRC}" 3261934c7aaSWarner Losh ${NANO_PMAKE} buildworld 3271934c7aaSWarner Losh ) > ${MAKEOBJDIRPREFIX}/_.bw 2>&1 3286b8c8deeSWill Andrews) 3296b8c8deeSWill Andrews 3306b8c8deeSWill Andrewsbuild_kernel ( ) ( 3316b8c8deeSWill Andrews pprint 2 "build kernel ($NANO_KERNEL)" 3326b8c8deeSWill Andrews pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bk" 3336b8c8deeSWill Andrews 3346b8c8deeSWill Andrews ( 3351934c7aaSWarner Losh nano_make_build_env 3361934c7aaSWarner Losh nano_make_kernel_env 3376b8c8deeSWill Andrews 3386b8c8deeSWill Andrews # Note: We intentionally build all modules, not only the ones in 3396b8c8deeSWill Andrews # NANO_MODULES so the built world can be reused by multiple images. 340bd0ca238SPedro F. Giffuni # Although MODULES_OVERRIDE can be defined in the kernel config 3411934c7aaSWarner Losh # file to override this behavior. Just set NANO_MODULES=default. 3421934c7aaSWarner Losh set -o xtrace 3431934c7aaSWarner Losh cd "${NANO_SRC}" 3441934c7aaSWarner Losh ${NANO_PMAKE} buildkernel 3456b8c8deeSWill Andrews ) > ${MAKEOBJDIRPREFIX}/_.bk 2>&1 3466b8c8deeSWill Andrews) 3476b8c8deeSWill Andrews 3486b8c8deeSWill Andrewsclean_world ( ) ( 3496b8c8deeSWill Andrews if [ "${NANO_OBJ}" != "${MAKEOBJDIRPREFIX}" ]; then 3506b8c8deeSWill Andrews pprint 2 "Clean and create object directory (${NANO_OBJ})" 351849f5467SWarner Losh if ! rm -rf ${NANO_OBJ}/ > /dev/null 2>&1 ; then 3526b8c8deeSWill Andrews chflags -R noschg ${NANO_OBJ} 353849f5467SWarner Losh rm -r ${NANO_OBJ}/ 3546b8c8deeSWill Andrews fi 3551934c7aaSWarner Losh mkdir -p "${NANO_OBJ}" "${NANO_WORLDDIR}" 356c2c06cfaSWarner Losh printenv > ${NANO_LOG}/_.env 3576b8c8deeSWill Andrews else 3586b8c8deeSWill Andrews pprint 2 "Clean and create world directory (${NANO_WORLDDIR})" 359849f5467SWarner Losh if ! rm -rf "${NANO_WORLDDIR}/" > /dev/null 2>&1 ; then 3601934c7aaSWarner Losh chflags -R noschg "${NANO_WORLDDIR}" 361849f5467SWarner Losh rm -rf "${NANO_WORLDDIR}/" 3626b8c8deeSWill Andrews fi 3631934c7aaSWarner Losh mkdir -p "${NANO_WORLDDIR}" 3646b8c8deeSWill Andrews fi 3656b8c8deeSWill Andrews) 3666b8c8deeSWill Andrews 3676b8c8deeSWill Andrewsmake_conf_install ( ) ( 3686b8c8deeSWill Andrews pprint 2 "Construct install make.conf ($NANO_MAKE_CONF_INSTALL)" 3696b8c8deeSWill Andrews 3701934c7aaSWarner Losh # Make sure we get all the global settings that NanoBSD wants 3711934c7aaSWarner Losh # in addition to the user's global settings 3721934c7aaSWarner Losh ( 3731934c7aaSWarner Losh nano_global_make_env 3741934c7aaSWarner Losh echo "${CONF_WORLD}" 3751934c7aaSWarner Losh echo "${CONF_INSTALL}" 376849f5467SWarner Losh if [ -n "${NANO_NOPRIV_BUILD}" ]; then 377c275d9ecSWarner Losh echo NO_ROOT=t 378c275d9ecSWarner Losh echo METALOG=${NANO_METALOG} 379c275d9ecSWarner Losh fi 3801934c7aaSWarner Losh ) > ${NANO_MAKE_CONF_INSTALL} 3816b8c8deeSWill Andrews) 3826b8c8deeSWill Andrews 3836b8c8deeSWill Andrewsinstall_world ( ) ( 3846b8c8deeSWill Andrews pprint 2 "installworld" 385c2c06cfaSWarner Losh pprint 3 "log: ${NANO_LOG}/_.iw" 3866b8c8deeSWill Andrews 3871934c7aaSWarner Losh ( 3881934c7aaSWarner Losh nano_make_install_env 3891934c7aaSWarner Losh set -o xtrace 3901934c7aaSWarner Losh cd "${NANO_SRC}" 3911934c7aaSWarner Losh ${NANO_MAKE} installworld DESTDIR="${NANO_WORLDDIR}" 3921934c7aaSWarner Losh chflags -R noschg "${NANO_WORLDDIR}" 393c2c06cfaSWarner Losh ) > ${NANO_LOG}/_.iw 2>&1 3946b8c8deeSWill Andrews) 3956b8c8deeSWill Andrews 3966b8c8deeSWill Andrewsinstall_etc ( ) ( 3976b8c8deeSWill Andrews pprint 2 "install /etc" 398c2c06cfaSWarner Losh pprint 3 "log: ${NANO_LOG}/_.etc" 3996b8c8deeSWill Andrews 4001934c7aaSWarner Losh ( 4011934c7aaSWarner Losh nano_make_install_env 4021934c7aaSWarner Losh set -o xtrace 4031934c7aaSWarner Losh cd "${NANO_SRC}" 4041934c7aaSWarner Losh ${NANO_MAKE} distribution DESTDIR="${NANO_WORLDDIR}" 4056b8c8deeSWill Andrews # make.conf doesn't get created by default, but some ports need it 4066b8c8deeSWill Andrews # so they can spam it. 4071934c7aaSWarner Losh cp /dev/null "${NANO_WORLDDIR}"/etc/make.conf 408c2c06cfaSWarner Losh ) > ${NANO_LOG}/_.etc 2>&1 4096b8c8deeSWill Andrews) 4106b8c8deeSWill Andrews 4116b8c8deeSWill Andrewsinstall_kernel ( ) ( 4126b8c8deeSWill Andrews pprint 2 "install kernel ($NANO_KERNEL)" 413c2c06cfaSWarner Losh pprint 3 "log: ${NANO_LOG}/_.ik" 4146b8c8deeSWill Andrews 4156b8c8deeSWill Andrews ( 4166b8c8deeSWill Andrews 4171934c7aaSWarner Losh nano_make_install_env 4181934c7aaSWarner Losh nano_make_kernel_env 4191934c7aaSWarner Losh 4206b8c8deeSWill Andrews if [ "${NANO_MODULES}" != "default" ]; then 4211934c7aaSWarner Losh MODULES_OVERRIDE="${NANO_MODULES}" 4221934c7aaSWarner Losh make_export MODULES_OVERRIDE 4236b8c8deeSWill Andrews fi 4246b8c8deeSWill Andrews 4251934c7aaSWarner Losh set -o xtrace 4261934c7aaSWarner Losh cd "${NANO_SRC}" 4271934c7aaSWarner Losh ${NANO_MAKE} installkernel DESTDIR="${NANO_WORLDDIR}" 4281934c7aaSWarner Losh 429c2c06cfaSWarner Losh ) > ${NANO_LOG}/_.ik 2>&1 4306b8c8deeSWill Andrews) 4316b8c8deeSWill Andrews 4326b8c8deeSWill Andrewsnative_xtools ( ) ( 4336b8c8deeSWill Andrews print 2 "Installing the optimized native build tools for cross env" 434c2c06cfaSWarner Losh pprint 3 "log: ${NANO_LOG}/_.native_xtools" 4356b8c8deeSWill Andrews 4361934c7aaSWarner Losh ( 4371934c7aaSWarner Losh 4381934c7aaSWarner Losh nano_make_install_env 4391934c7aaSWarner Losh set -o xtrace 4401934c7aaSWarner Losh cd "${NANO_SRC}" 4411934c7aaSWarner Losh ${NANO_MAKE} native-xtools DESTDIR="${NANO_WORLDDIR}" 4421934c7aaSWarner Losh 443c2c06cfaSWarner Losh ) > ${NANO_LOG}/_.native_xtools 2>&1 4446b8c8deeSWill Andrews) 4456b8c8deeSWill Andrews 44619edffefSWarner Losh# 4475b4ca9d7SGleb Smirnoff# Run the requested set of early customization scripts, run before 4485b4ca9d7SGleb Smirnoff# buildworld. 4495b4ca9d7SGleb Smirnoff# 4505b4ca9d7SGleb Smirnoffrun_early_customize ( ) { 4515b4ca9d7SGleb Smirnoff pprint 2 "run early customize scripts" 4525b4ca9d7SGleb Smirnoff for c in $NANO_EARLY_CUSTOMIZE 4535b4ca9d7SGleb Smirnoff do 4545b4ca9d7SGleb Smirnoff pprint 2 "early customize \"$c\"" 4555b4ca9d7SGleb Smirnoff pprint 3 "log: ${NANO_LOG}/_.early_cust.$c" 4565b4ca9d7SGleb Smirnoff pprint 4 "`type $c`" 4575b4ca9d7SGleb Smirnoff { set -x ; $c ; set +x ; } >${NANO_LOG}/_.early_cust.$c 2>&1 4585b4ca9d7SGleb Smirnoff done 4595b4ca9d7SGleb Smirnoff} 4605b4ca9d7SGleb Smirnoff 4615b4ca9d7SGleb Smirnoff# 46219edffefSWarner Losh# Run the requested set of customization scripts, run after we've 46319edffefSWarner Losh# done an installworld, installed the etc files, installed the kernel 46419edffefSWarner Losh# and tweaked them in the standard way. 46519edffefSWarner Losh# 4666b8c8deeSWill Andrewsrun_customize ( ) ( 4676b8c8deeSWill Andrews 4686b8c8deeSWill Andrews pprint 2 "run customize scripts" 4696b8c8deeSWill Andrews for c in $NANO_CUSTOMIZE 4706b8c8deeSWill Andrews do 4716b8c8deeSWill Andrews pprint 2 "customize \"$c\"" 472c2c06cfaSWarner Losh pprint 3 "log: ${NANO_LOG}/_.cust.$c" 4736b8c8deeSWill Andrews pprint 4 "`type $c`" 474c2c06cfaSWarner Losh ( set -x ; $c ) > ${NANO_LOG}/_.cust.$c 2>&1 4756b8c8deeSWill Andrews done 4766b8c8deeSWill Andrews) 4776b8c8deeSWill Andrews 47819edffefSWarner Losh# 47919edffefSWarner Losh# Run any last-minute customization commands after we've had a chance to 48019edffefSWarner Losh# setup nanobsd, prune empty dirs from /usr, etc 48119edffefSWarner Losh# 4826b8c8deeSWill Andrewsrun_late_customize ( ) ( 4836b8c8deeSWill Andrews pprint 2 "run late customize scripts" 4846b8c8deeSWill Andrews for c in $NANO_LATE_CUSTOMIZE 4856b8c8deeSWill Andrews do 4866b8c8deeSWill Andrews pprint 2 "late customize \"$c\"" 487c2c06cfaSWarner Losh pprint 3 "log: ${NANO_LOG}/_.late_cust.$c" 4886b8c8deeSWill Andrews pprint 4 "`type $c`" 489c2c06cfaSWarner Losh ( set -x ; $c ) > ${NANO_LOG}/_.late_cust.$c 2>&1 4906b8c8deeSWill Andrews done 4916b8c8deeSWill Andrews) 4926b8c8deeSWill Andrews 49319edffefSWarner Losh# 49419edffefSWarner Losh# Hook called after we run all the late customize commands, but 49519edffefSWarner Losh# before we invoke the disk imager. The nopriv build uses it to 49619edffefSWarner Losh# read in the meta log, apply the changes other parts of nanobsd 49719edffefSWarner Losh# have been recording their actions. It's not anticipated that 49819edffefSWarner Losh# a user's cfg file would override this. 49919edffefSWarner Losh# 50019edffefSWarner Loshfixup_before_diskimage ( ) ( 50119edffefSWarner Losh # Run the deduplication script that takes the matalog journal and 50219edffefSWarner Losh # combines multiple entries for the same file (see source for 50319edffefSWarner Losh # details). We take the extra step of removing the size keywords. This 50419edffefSWarner Losh # script, and many of the user scripts, copies, appeneds and otherwise 50519edffefSWarner Losh # modifies files in the build, changing their sizes. These actions are 50619edffefSWarner Losh # impossible to trap, so go ahead remove the size= keyword. For this 50719edffefSWarner Losh # narrow use, it doesn't buy us any protection and just gets in the way. 50819edffefSWarner Losh # The dedup tool's output must be sorted due to limitations in awk. 5090a852830SWarner Losh if [ -n "${NANO_METALOG}" ]; then 51019edffefSWarner Losh pprint 2 "Fixing metalog" 51119edffefSWarner Losh cp ${NANO_METALOG} ${NANO_METALOG}.pre 51245b2ffd0SWarner Losh echo "/set uname=${NANO_DEF_UNAME} gname=${NANO_DEF_GNAME}" > ${NANO_METALOG} 51345b2ffd0SWarner Losh cat ${NANO_METALOG}.pre | ${NANO_TOOLS}/mtree-dedup.awk | \ 51445b2ffd0SWarner Losh sed -e 's/ size=[0-9][0-9]*//' | sort >> ${NANO_METALOG} 51519edffefSWarner Losh fi 51619edffefSWarner Losh) 51719edffefSWarner Losh 5186b8c8deeSWill Andrewssetup_nanobsd ( ) ( 5196b8c8deeSWill Andrews pprint 2 "configure nanobsd setup" 520c2c06cfaSWarner Losh pprint 3 "log: ${NANO_LOG}/_.dl" 5216b8c8deeSWill Andrews 5226b8c8deeSWill Andrews ( 5231934c7aaSWarner Losh cd "${NANO_WORLDDIR}" 5246b8c8deeSWill Andrews 5256b8c8deeSWill Andrews # Move /usr/local/etc to /etc/local so that the /cfg stuff 5266b8c8deeSWill Andrews # can stomp on it. Otherwise packages like ipsec-tools which 5276b8c8deeSWill Andrews # have hardcoded paths under ${prefix}/etc are not tweakable. 5286b8c8deeSWill Andrews if [ -d usr/local/etc ] ; then 5296b8c8deeSWill Andrews ( 5306b8c8deeSWill Andrews cd usr/local/etc 5316b8c8deeSWill Andrews find . -print | cpio -dumpl ../../../etc/local 5326b8c8deeSWill Andrews cd .. 533849f5467SWarner Losh rm -rf etc 5346b8c8deeSWill Andrews ) 5356b8c8deeSWill Andrews fi 5366b8c8deeSWill Andrews 537*07f2d905SWarner Losh # Always setup the usr/local/etc -> etc/local symlink. 538*07f2d905SWarner Losh # usr/local/etc gets created by packages, but if no packages 539*07f2d905SWarner Losh # are installed by this point, but are later in the process, 540*07f2d905SWarner Losh # the symlink not being here causes problems. It never hurts 541*07f2d905SWarner Losh # to have the symlink in error though. 542*07f2d905SWarner Losh ln -s ../../etc/local usr/local/etc 543*07f2d905SWarner Losh 5446b8c8deeSWill Andrews for d in var etc 5456b8c8deeSWill Andrews do 5466b8c8deeSWill Andrews # link /$d under /conf 5476b8c8deeSWill Andrews # we use hard links so we have them both places. 5486b8c8deeSWill Andrews # the files in /$d will be hidden by the mount. 5496b8c8deeSWill Andrews mkdir -p conf/base/$d conf/default/$d 5506b8c8deeSWill Andrews find $d -print | cpio -dumpl conf/base/ 5516b8c8deeSWill Andrews done 5526b8c8deeSWill Andrews 5536b8c8deeSWill Andrews echo "$NANO_RAM_ETCSIZE" > conf/base/etc/md_size 5546b8c8deeSWill Andrews echo "$NANO_RAM_TMPVARSIZE" > conf/base/var/md_size 5556b8c8deeSWill Andrews 5566b8c8deeSWill Andrews # pick up config files from the special partition 5577b77d3eaSWarner Losh echo "mount -o ro /dev/${NANO_DRIVE}${NANO_SLICE_CFG}" > conf/default/etc/remount 5586b8c8deeSWill Andrews 5596b8c8deeSWill Andrews # Put /tmp on the /var ramdisk (could be symlink already) 56019edffefSWarner Losh tgt_dir2symlink tmp var/tmp 5616b8c8deeSWill Andrews 562c2c06cfaSWarner Losh ) > ${NANO_LOG}/_.dl 2>&1 5636b8c8deeSWill Andrews) 5646b8c8deeSWill Andrews 5656b8c8deeSWill Andrewssetup_nanobsd_etc ( ) ( 5666b8c8deeSWill Andrews pprint 2 "configure nanobsd /etc" 5676b8c8deeSWill Andrews 5686b8c8deeSWill Andrews ( 5691934c7aaSWarner Losh cd "${NANO_WORLDDIR}" 5706b8c8deeSWill Andrews 5716b8c8deeSWill Andrews # create diskless marker file 5726b8c8deeSWill Andrews touch etc/diskless 5736b8c8deeSWill Andrews 574849f5467SWarner Losh [ -n "${NANO_NOPRIV_BUILD}" ] && chmod 666 etc/defaults/rc.conf 5759e144f35SWarner Losh 5769e144f35SWarner Losh # Make root filesystem R/O by default 5776b8c8deeSWill Andrews echo "root_rw_mount=NO" >> etc/defaults/rc.conf 5789e144f35SWarner Losh # Disable entropy file, since / is read-only /var/db/entropy should be enough? 5799e144f35SWarner Losh echo "entropy_file=NO" >> etc/defaults/rc.conf 5809e144f35SWarner Losh 581849f5467SWarner Losh [ -n "${NANO_NOPRIV_BUILD}" ] && chmod 444 etc/defaults/rc.conf 5826b8c8deeSWill Andrews 5836b8c8deeSWill Andrews # save config file for scripts 5846b8c8deeSWill Andrews echo "NANO_DRIVE=${NANO_DRIVE}" > etc/nanobsd.conf 5856b8c8deeSWill Andrews 5865e4bd293SWarner Losh echo "/dev/${NANO_DRIVE}${NANO_ROOT} / ufs ro 1 1" > etc/fstab 5877b77d3eaSWarner Losh echo "/dev/${NANO_DRIVE}${NANO_SLICE_CFG} /cfg ufs rw,noauto 2 2" >> etc/fstab 5886b8c8deeSWill Andrews mkdir -p cfg 589*07f2d905SWarner Losh 590*07f2d905SWarner Losh # Create directory for eventual /usr/local/etc contents 591*07f2d905SWarner Losh mkdir -p etc/local 5926b8c8deeSWill Andrews ) 5936b8c8deeSWill Andrews) 5946b8c8deeSWill Andrews 5956b8c8deeSWill Andrewsprune_usr ( ) ( 5966b8c8deeSWill Andrews # Remove all empty directories in /usr 5971934c7aaSWarner Losh find "${NANO_WORLDDIR}"/usr -type d -depth -print | 5986b8c8deeSWill Andrews while read d 5996b8c8deeSWill Andrews do 6006b8c8deeSWill Andrews rmdir $d > /dev/null 2>&1 || true 6016b8c8deeSWill Andrews done 6026b8c8deeSWill Andrews) 6036b8c8deeSWill Andrews 6046b8c8deeSWill Andrewsnewfs_part ( ) ( 6056b8c8deeSWill Andrews local dev mnt lbl 6066b8c8deeSWill Andrews dev=$1 6076b8c8deeSWill Andrews mnt=$2 6086b8c8deeSWill Andrews lbl=$3 6096b8c8deeSWill Andrews echo newfs ${NANO_NEWFS} ${NANO_LABEL:+-L${NANO_LABEL}${lbl}} ${dev} 6106b8c8deeSWill Andrews newfs ${NANO_NEWFS} ${NANO_LABEL:+-L${NANO_LABEL}${lbl}} ${dev} 6116b8c8deeSWill Andrews mount -o async ${dev} ${mnt} 6126b8c8deeSWill Andrews) 6136b8c8deeSWill Andrews 6146b8c8deeSWill Andrews# Convenient spot to work around any umount issues that your build environment 6156b8c8deeSWill Andrews# hits by overriding this method. 6166b8c8deeSWill Andrewsnano_umount ( ) ( 6176b8c8deeSWill Andrews umount ${1} 6186b8c8deeSWill Andrews) 6196b8c8deeSWill Andrews 6206b8c8deeSWill Andrewspopulate_slice ( ) ( 6216b8c8deeSWill Andrews local dev dir mnt lbl 6226b8c8deeSWill Andrews dev=$1 6236b8c8deeSWill Andrews dir=$2 6246b8c8deeSWill Andrews mnt=$3 6256b8c8deeSWill Andrews lbl=$4 6266b8c8deeSWill Andrews echo "Creating ${dev} (mounting on ${mnt})" 6276b8c8deeSWill Andrews newfs_part ${dev} ${mnt} ${lbl} 6286b8c8deeSWill Andrews if [ -n "${dir}" -a -d "${dir}" ]; then 6296b8c8deeSWill Andrews echo "Populating ${lbl} from ${dir}" 6301934c7aaSWarner Losh cd "${dir}" 6319c3163dcSWarner Losh find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)/' | cpio -dumpv ${mnt} 6326b8c8deeSWill Andrews fi 6336b8c8deeSWill Andrews df -i ${mnt} 6346b8c8deeSWill Andrews nano_umount ${mnt} 6356b8c8deeSWill Andrews) 6366b8c8deeSWill Andrews 6376b8c8deeSWill Andrewspopulate_cfg_slice ( ) ( 6386b8c8deeSWill Andrews populate_slice "$1" "$2" "$3" "$4" 6396b8c8deeSWill Andrews) 6406b8c8deeSWill Andrews 6416b8c8deeSWill Andrewspopulate_data_slice ( ) ( 6426b8c8deeSWill Andrews populate_slice "$1" "$2" "$3" "$4" 6436b8c8deeSWill Andrews) 6446b8c8deeSWill Andrews 6456b8c8deeSWill Andrewslast_orders ( ) ( 6466b8c8deeSWill Andrews # Redefine this function with any last orders you may have 6476b8c8deeSWill Andrews # after the build completed, for instance to copy the finished 6486b8c8deeSWill Andrews # image to a more convenient place: 649df6c7936SWarner Losh # cp ${NANO_DISKIMGDIR}/${NANO_IMG1NAME} /home/ftp/pub/nanobsd.disk 6506b8c8deeSWill Andrews true 6516b8c8deeSWill Andrews) 6526b8c8deeSWill Andrews 6536b8c8deeSWill Andrews####################################################################### 6546b8c8deeSWill Andrews# 6556b8c8deeSWill Andrews# Optional convenience functions. 6566b8c8deeSWill Andrews# 6576b8c8deeSWill Andrews####################################################################### 6586b8c8deeSWill Andrews 6596b8c8deeSWill Andrews####################################################################### 6606b8c8deeSWill Andrews# Common Flash device geometries 6616b8c8deeSWill Andrews# 6626b8c8deeSWill Andrews 6636b8c8deeSWill AndrewsFlashDevice ( ) { 6646b8c8deeSWill Andrews if [ -d ${NANO_TOOLS} ] ; then 6656b8c8deeSWill Andrews . ${NANO_TOOLS}/FlashDevice.sub 6666b8c8deeSWill Andrews else 6676b8c8deeSWill Andrews . ${NANO_SRC}/${NANO_TOOLS}/FlashDevice.sub 6686b8c8deeSWill Andrews fi 6696b8c8deeSWill Andrews sub_FlashDevice $1 $2 6706b8c8deeSWill Andrews} 6716b8c8deeSWill Andrews 6726b8c8deeSWill Andrews####################################################################### 6736b8c8deeSWill Andrews# USB device geometries 6746b8c8deeSWill Andrews# 6756b8c8deeSWill Andrews# Usage: 6766b8c8deeSWill Andrews# UsbDevice Generic 1000 # a generic flash key sold as having 1GB 6776b8c8deeSWill Andrews# 6786b8c8deeSWill Andrews# This function will set NANO_MEDIASIZE, NANO_HEADS and NANO_SECTS for you. 6796b8c8deeSWill Andrews# 6806b8c8deeSWill Andrews# Note that the capacity of a flash key is usually advertised in MB or 6816b8c8deeSWill Andrews# GB, *not* MiB/GiB. As such, the precise number of cylinders available 6826b8c8deeSWill Andrews# for C/H/S geometry may vary depending on the actual flash geometry. 6836b8c8deeSWill Andrews# 6846b8c8deeSWill Andrews# The following generic device layouts are understood: 6856b8c8deeSWill Andrews# generic An alias for generic-hdd. 6866b8c8deeSWill Andrews# generic-hdd 255H 63S/T xxxxC with no MBR restrictions. 6876b8c8deeSWill Andrews# generic-fdd 64H 32S/T xxxxC with no MBR restrictions. 6886b8c8deeSWill Andrews# 6896b8c8deeSWill Andrews# The generic-hdd device is preferred for flash devices larger than 1GB. 6906b8c8deeSWill Andrews# 6916b8c8deeSWill Andrews 6926b8c8deeSWill AndrewsUsbDevice ( ) { 6936b8c8deeSWill Andrews a1=`echo $1 | tr '[:upper:]' '[:lower:]'` 6946b8c8deeSWill Andrews case $a1 in 6956b8c8deeSWill Andrews generic-fdd) 6966b8c8deeSWill Andrews NANO_HEADS=64 6976b8c8deeSWill Andrews NANO_SECTS=32 6986b8c8deeSWill Andrews NANO_MEDIASIZE=$(( $2 * 1000 * 1000 / 512 )) 6996b8c8deeSWill Andrews ;; 7006b8c8deeSWill Andrews generic|generic-hdd) 7016b8c8deeSWill Andrews NANO_HEADS=255 7026b8c8deeSWill Andrews NANO_SECTS=63 7036b8c8deeSWill Andrews NANO_MEDIASIZE=$(( $2 * 1000 * 1000 / 512 )) 7046b8c8deeSWill Andrews ;; 7056b8c8deeSWill Andrews *) 7066b8c8deeSWill Andrews echo "Unknown USB flash device" 7076b8c8deeSWill Andrews exit 2 7086b8c8deeSWill Andrews ;; 7096b8c8deeSWill Andrews esac 7106b8c8deeSWill Andrews} 7116b8c8deeSWill Andrews 7126b8c8deeSWill Andrews####################################################################### 7136b8c8deeSWill Andrews# Setup serial console 7146b8c8deeSWill Andrews 7156b8c8deeSWill Andrewscust_comconsole ( ) ( 7166b8c8deeSWill Andrews # Enable getty on console 7176b8c8deeSWill Andrews sed -i "" -e /tty[du]0/s/off/on/ ${NANO_WORLDDIR}/etc/ttys 7186b8c8deeSWill Andrews 7196b8c8deeSWill Andrews # Disable getty on syscons devices 7206b8c8deeSWill Andrews sed -i "" -e '/^ttyv[0-8]/s/ on/ off/' ${NANO_WORLDDIR}/etc/ttys 7216b8c8deeSWill Andrews 7226b8c8deeSWill Andrews # Tell loader to use serial console early. 7236b8c8deeSWill Andrews echo "${NANO_BOOT2CFG}" > ${NANO_WORLDDIR}/boot.config 7246b8c8deeSWill Andrews) 7256b8c8deeSWill Andrews 7266b8c8deeSWill Andrews####################################################################### 7276b8c8deeSWill Andrews# Allow root login via ssh 7286b8c8deeSWill Andrews 7296b8c8deeSWill Andrewscust_allow_ssh_root ( ) ( 7306b8c8deeSWill Andrews sed -i "" -e '/PermitRootLogin/s/.*/PermitRootLogin yes/' \ 7316b8c8deeSWill Andrews ${NANO_WORLDDIR}/etc/ssh/sshd_config 7326b8c8deeSWill Andrews) 7336b8c8deeSWill Andrews 7346b8c8deeSWill Andrews####################################################################### 7356b8c8deeSWill Andrews# Install the stuff under ./Files 7366b8c8deeSWill Andrews 7376b8c8deeSWill Andrewscust_install_files ( ) ( 7381934c7aaSWarner Losh cd "${NANO_TOOLS}/Files" 7399c3163dcSWarner Losh find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)/' | cpio -Ldumpv ${NANO_WORLDDIR} 7408e7676caSGleb Smirnoff 741b805f83dSPoul-Henning Kamp if [ -n "${NANO_CUST_FILES_MTREE}" -a -f ${NANO_CUST_FILES_MTREE} ]; then 7428e7676caSGleb Smirnoff CR "mtree -eiU -p /" <${NANO_CUST_FILES_MTREE} 7438e7676caSGleb Smirnoff fi 7446b8c8deeSWill Andrews) 7456b8c8deeSWill Andrews 7466b8c8deeSWill Andrews####################################################################### 7476b8c8deeSWill Andrews# Install packages from ${NANO_PACKAGE_DIR} 7486b8c8deeSWill Andrews 7496b8c8deeSWill Andrewscust_pkgng ( ) ( 750b805f83dSPoul-Henning Kamp mkdir -p ${NANO_WORLDDIR}/usr/local/etc 7519af130aeSWarner Losh local PKG_CONF="${NANO_WORLDDIR}/usr/local/etc/pkg.conf" 7529af130aeSWarner Losh local PKGCMD="env ASSUME_ALWAYS_YES=YES PKG_DBDIR=${NANO_PKG_META_BASE}/pkg SIGNATURE_TYPE=none /usr/sbin/pkg" 7539af130aeSWarner Losh 7549af130aeSWarner Losh # Ensure pkg.conf points pkg to where the package meta data lives. 7559af130aeSWarner Losh touch ${PKG_CONF} 7569af130aeSWarner Losh if grep -Eiq '^PKG_DBDIR:.*' ${PKG_CONF}; then 7579af130aeSWarner Losh sed -i -e "\|^PKG_DBDIR:.*|Is||PKG_DBDIR: "\"${NANO_PKG_META_BASE}/pkg\""|" ${PKG_CONF} 7589af130aeSWarner Losh else 7599af130aeSWarner Losh echo "PKG_DBDIR: \"${NANO_PKG_META_BASE}/pkg\"" >> ${PKG_CONF} 7609af130aeSWarner Losh fi 7619af130aeSWarner Losh 7626b8c8deeSWill Andrews # If the package directory doesn't exist, we're done. 7636b8c8deeSWill Andrews if [ ! -d ${NANO_PACKAGE_DIR} ]; then 7646b8c8deeSWill Andrews echo "DONE 0 packages" 7656b8c8deeSWill Andrews return 0 7666b8c8deeSWill Andrews fi 7676b8c8deeSWill Andrews 7686b8c8deeSWill Andrews # Find a pkg-* package 7696b8c8deeSWill Andrews for x in `find -s ${NANO_PACKAGE_DIR} -iname 'pkg-*'`; do 7706b8c8deeSWill Andrews _NANO_PKG_PACKAGE=`basename "$x"` 7716b8c8deeSWill Andrews done 7726b8c8deeSWill Andrews if [ -z "${_NANO_PKG_PACKAGE}" -o ! -f "${NANO_PACKAGE_DIR}/${_NANO_PKG_PACKAGE}" ]; then 7736b8c8deeSWill Andrews echo "FAILED: need a pkg/ package for bootstrapping" 7746b8c8deeSWill Andrews exit 2 7756b8c8deeSWill Andrews fi 7766b8c8deeSWill Andrews 7779af130aeSWarner Losh # Mount packages into chroot 7789af130aeSWarner Losh mkdir -p ${NANO_WORLDDIR}/_.p 7799af130aeSWarner Losh mount -t nullfs -o noatime -o ro ${NANO_PACKAGE_DIR} ${NANO_WORLDDIR}/_.p 7806b8c8deeSWill Andrews 781b805f83dSPoul-Henning Kamp trap "umount ${NANO_WORLDDIR}/_.p ; rm -rf ${NANO_WORLDDIR}/_.p" 1 2 15 EXIT 7826b8c8deeSWill Andrews 783fca41131SWarner Losh # Install pkg-* package 784fca41131SWarner Losh CR "${PKGCMD} add /_.p/${_NANO_PKG_PACKAGE}" 785fca41131SWarner Losh 786fca41131SWarner Losh ( 787fca41131SWarner Losh # Expand any glob characters in pacakge list 788fca41131SWarner Losh cd "${NANO_PACKAGE_DIR}" 789fca41131SWarner Losh _PKGS=`find ${NANO_PACKAGE_LIST} -not -name "${_NANO_PKG_PACKAGE}" -print | sort | uniq` 790fca41131SWarner Losh 791fca41131SWarner Losh # Show todo 792fca41131SWarner Losh todo=`echo "$_PKGS" | wc -l` 7936b8c8deeSWill Andrews echo "=== TODO: $todo" 794fca41131SWarner Losh echo "$_PKGS" 7956b8c8deeSWill Andrews echo "===" 796fca41131SWarner Losh 797fca41131SWarner Losh # Install packages 798fca41131SWarner Losh for _PKG in $_PKGS; do 7999af130aeSWarner Losh CR "${PKGCMD} add /_.p/${_PKG}" 8006b8c8deeSWill Andrews done 801fca41131SWarner Losh ) 8029af130aeSWarner Losh 8039af130aeSWarner Losh CR0 "${PKGCMD} info" 8049af130aeSWarner Losh 8059af130aeSWarner Losh trap - 1 2 15 EXIT 8069af130aeSWarner Losh umount ${NANO_WORLDDIR}/_.p 8079af130aeSWarner Losh rm -rf ${NANO_WORLDDIR}/_.p 8086b8c8deeSWill Andrews) 8096b8c8deeSWill Andrews 8106b8c8deeSWill Andrews####################################################################### 8116b8c8deeSWill Andrews# Convenience function: 8125b4ca9d7SGleb Smirnoff# Register all args as early customize function to run just before 8135b4ca9d7SGleb Smirnoff# build commences. 8145b4ca9d7SGleb Smirnoff 8155b4ca9d7SGleb Smirnoffearly_customize_cmd ( ) { 8165b4ca9d7SGleb Smirnoff NANO_EARLY_CUSTOMIZE="$NANO_EARLY_CUSTOMIZE $*" 8175b4ca9d7SGleb Smirnoff} 8185b4ca9d7SGleb Smirnoff 8195b4ca9d7SGleb Smirnoff####################################################################### 8205b4ca9d7SGleb Smirnoff# Convenience function: 8216b8c8deeSWill Andrews# Register all args as customize function. 8226b8c8deeSWill Andrews 8236b8c8deeSWill Andrewscustomize_cmd ( ) { 8246b8c8deeSWill Andrews NANO_CUSTOMIZE="$NANO_CUSTOMIZE $*" 8256b8c8deeSWill Andrews} 8266b8c8deeSWill Andrews 8276b8c8deeSWill Andrews####################################################################### 8286b8c8deeSWill Andrews# Convenience function: 8296b8c8deeSWill Andrews# Register all args as late customize function to run just before 8306b8c8deeSWill Andrews# image creation. 8316b8c8deeSWill Andrews 8326b8c8deeSWill Andrewslate_customize_cmd ( ) { 8336b8c8deeSWill Andrews NANO_LATE_CUSTOMIZE="$NANO_LATE_CUSTOMIZE $*" 8346b8c8deeSWill Andrews} 8356b8c8deeSWill Andrews 8366b8c8deeSWill Andrews####################################################################### 8376b8c8deeSWill Andrews# 8386b8c8deeSWill Andrews# All set up to go... 8396b8c8deeSWill Andrews# 8406b8c8deeSWill Andrews####################################################################### 8416b8c8deeSWill Andrews 8426b8c8deeSWill Andrews# Progress Print 8436b8c8deeSWill Andrews# Print $2 at level $1. 8446b8c8deeSWill Andrewspprint ( ) ( 8456b8c8deeSWill Andrews if [ "$1" -le $PPLEVEL ]; then 8466b8c8deeSWill Andrews runtime=$(( `date +%s` - $NANO_STARTTIME )) 8476b8c8deeSWill Andrews printf "%s %.${1}s %s\n" "`date -u -r $runtime +%H:%M:%S`" "#####" "$2" 1>&3 8486b8c8deeSWill Andrews fi 8496b8c8deeSWill Andrews) 8506b8c8deeSWill Andrews 8516b8c8deeSWill Andrewsusage ( ) { 8526b8c8deeSWill Andrews ( 85399aa6241SMaxim Konovalov echo "Usage: $0 [-bfhiKknqvwX] [-c config_file]" 8546b8c8deeSWill Andrews echo " -b suppress builds (both kernel and world)" 8556b8c8deeSWill Andrews echo " -c specify config file" 8566b8c8deeSWill Andrews echo " -f suppress code slice extraction" 85799aa6241SMaxim Konovalov echo " -h print this help summary page" 8586b8c8deeSWill Andrews echo " -i suppress disk image build" 8596b8c8deeSWill Andrews echo " -K suppress installkernel" 8606b8c8deeSWill Andrews echo " -k suppress buildkernel" 8616b8c8deeSWill Andrews echo " -n add -DNO_CLEAN to buildworld, buildkernel, etc" 8626b8c8deeSWill Andrews echo " -q make output more quiet" 8636b8c8deeSWill Andrews echo " -v make output more verbose" 8646b8c8deeSWill Andrews echo " -w suppress buildworld" 86599aa6241SMaxim Konovalov echo " -X make native-xtools" 8666b8c8deeSWill Andrews ) 1>&2 8676b8c8deeSWill Andrews exit 2 8686b8c8deeSWill Andrews} 8696b8c8deeSWill Andrews 8706b8c8deeSWill Andrews####################################################################### 8716b8c8deeSWill Andrews# Setup and Export Internal variables 8726b8c8deeSWill Andrews# 8736b8c8deeSWill Andrews 8741934c7aaSWarner Loshexport_var ( ) { # Don't wawnt a subshell 8756b8c8deeSWill Andrews var=$1 8766b8c8deeSWill Andrews # Lookup value of the variable. 8776b8c8deeSWill Andrews eval val=\$$var 8786b8c8deeSWill Andrews pprint 3 "Setting variable: $var=\"$val\"" 8796b8c8deeSWill Andrews export $1 8806b8c8deeSWill Andrews} 8816b8c8deeSWill Andrews 8826b8c8deeSWill Andrews# Call this function to set defaults _after_ parsing options. 8831934c7aaSWarner Losh# dont want a subshell otherwise variable setting is thrown away. 8846b8c8deeSWill Andrewsset_defaults_and_export ( ) { 885849f5467SWarner Losh : ${NANO_OBJ:=/usr/obj/nanobsd.${NANO_NAME}} 886849f5467SWarner Losh : ${MAKEOBJDIRPREFIX:=${NANO_OBJ}} 8873a757adfSWarner Losh : ${NANO_DISKIMGDIR:=${NANO_OBJ}} 888c2c06cfaSWarner Losh : ${NANO_WORLDDIR:=${NANO_OBJ}/_.w} 889c2c06cfaSWarner Losh : ${NANO_LOG:=${NANO_OBJ}} 8906b8c8deeSWill Andrews NANO_MAKE_CONF_BUILD=${MAKEOBJDIRPREFIX}/make.conf.build 8916b8c8deeSWill Andrews NANO_MAKE_CONF_INSTALL=${NANO_OBJ}/make.conf.install 8926b8c8deeSWill Andrews 8936b8c8deeSWill Andrews # Override user's NANO_DRIVE if they specified a NANO_LABEL 894849f5467SWarner Losh [ -n "${NANO_LABEL}" ] && NANO_DRIVE="ufs/${NANO_LABEL}" || true 8956b8c8deeSWill Andrews 8966b8c8deeSWill Andrews # Set a default NANO_TOOLS to NANO_SRC/NANO_TOOLS if it exists. 8976b8c8deeSWill Andrews [ ! -d "${NANO_TOOLS}" ] && [ -d "${NANO_SRC}/${NANO_TOOLS}" ] && \ 898c275d9ecSWarner Losh NANO_TOOLS="${NANO_SRC}/${NANO_TOOLS}" || true 899c275d9ecSWarner Losh 900849f5467SWarner Losh [ -n "${NANO_NOPRIV_BUILD}" ] && [ -z "${NANO_METALOG}" ] && \ 901c275d9ecSWarner Losh NANO_METALOG=${NANO_OBJ}/_.metalog || true 9026b8c8deeSWill Andrews 9036b8c8deeSWill Andrews NANO_STARTTIME=`date +%s` 9046b8c8deeSWill Andrews pprint 3 "Exporting NanoBSD variables" 9056b8c8deeSWill Andrews export_var MAKEOBJDIRPREFIX 9066b8c8deeSWill Andrews export_var NANO_ARCH 9076b8c8deeSWill Andrews export_var NANO_CODESIZE 9086b8c8deeSWill Andrews export_var NANO_CONFSIZE 9096b8c8deeSWill Andrews export_var NANO_CUSTOMIZE 9106b8c8deeSWill Andrews export_var NANO_DATASIZE 9116b8c8deeSWill Andrews export_var NANO_DRIVE 9126b8c8deeSWill Andrews export_var NANO_HEADS 9136b8c8deeSWill Andrews export_var NANO_IMAGES 9146b8c8deeSWill Andrews export_var NANO_IMGNAME 915df6c7936SWarner Losh export_var NANO_IMG1NAME 9166b8c8deeSWill Andrews export_var NANO_MAKE 9176b8c8deeSWill Andrews export_var NANO_MAKE_CONF_BUILD 9186b8c8deeSWill Andrews export_var NANO_MAKE_CONF_INSTALL 9196b8c8deeSWill Andrews export_var NANO_MEDIASIZE 9206b8c8deeSWill Andrews export_var NANO_NAME 9216b8c8deeSWill Andrews export_var NANO_NEWFS 9226b8c8deeSWill Andrews export_var NANO_OBJ 9236b8c8deeSWill Andrews export_var NANO_PMAKE 9246b8c8deeSWill Andrews export_var NANO_SECTS 9256b8c8deeSWill Andrews export_var NANO_SRC 9266b8c8deeSWill Andrews export_var NANO_TOOLS 9276b8c8deeSWill Andrews export_var NANO_WORLDDIR 9286b8c8deeSWill Andrews export_var NANO_BOOT0CFG 9296b8c8deeSWill Andrews export_var NANO_BOOTLOADER 9306b8c8deeSWill Andrews export_var NANO_LABEL 9316b8c8deeSWill Andrews export_var NANO_MODULES 932c275d9ecSWarner Losh export_var NANO_NOPRIV_BUILD 933c275d9ecSWarner Losh export_var NANO_METALOG 934c2c06cfaSWarner Losh export_var NANO_LOG 9351934c7aaSWarner Losh export_var SRCCONF 936a9d9c49fSWarner Losh export_var SRC_ENV_CONF 9376b8c8deeSWill Andrews} 938