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# 286b8c8deeSWill Andrews 296b8c8deeSWill Andrewsset -e 306b8c8deeSWill Andrews 316b8c8deeSWill Andrews####################################################################### 326b8c8deeSWill Andrews# 336b8c8deeSWill Andrews# Setup default values for all controlling variables. 346b8c8deeSWill Andrews# These values can be overridden from the config file(s) 356b8c8deeSWill Andrews# 366b8c8deeSWill Andrews####################################################################### 376b8c8deeSWill Andrews 386b8c8deeSWill Andrews# Name of this NanoBSD build. (Used to construct workdir names) 396b8c8deeSWill AndrewsNANO_NAME=full 406b8c8deeSWill Andrews 416b8c8deeSWill Andrews# Source tree directory 426b8c8deeSWill AndrewsNANO_SRC=/usr/src 436b8c8deeSWill Andrews 446b8c8deeSWill Andrews# Where nanobsd additional files live under the source tree 456b8c8deeSWill AndrewsNANO_TOOLS=tools/tools/nanobsd 466b8c8deeSWill Andrews 4718803951SWarner Losh# Where cust_pkgng() finds packages to install 486b8c8deeSWill AndrewsNANO_PACKAGE_DIR=${NANO_SRC}/${NANO_TOOLS}/Pkg 496b8c8deeSWill AndrewsNANO_PACKAGE_LIST="*" 506b8c8deeSWill Andrews 516b8c8deeSWill Andrews# where package metadata gets placed 526b8c8deeSWill AndrewsNANO_PKG_META_BASE=/var/db 536b8c8deeSWill Andrews 548e7676caSGleb Smirnoff# Path to mtree file to apply to anything copied by cust_install_files(). 558e7676caSGleb Smirnoff# If you specify this, the mtree file *must* have an entry for every file and 568e7676caSGleb Smirnoff# directory located in Files. 578e7676caSGleb Smirnoff#NANO_CUST_FILES_MTREE="" 588e7676caSGleb Smirnoff 596b8c8deeSWill Andrews# Object tree directory 606b8c8deeSWill Andrews# default is subdir of /usr/obj 616b8c8deeSWill Andrews#NANO_OBJ="" 626b8c8deeSWill Andrews 636b8c8deeSWill Andrews# The directory to put the final images 646b8c8deeSWill Andrews# default is ${NANO_OBJ} 656b8c8deeSWill Andrews#NANO_DISKIMGDIR="" 666b8c8deeSWill Andrews 676b8c8deeSWill Andrews# Make & parallel Make 686b8c8deeSWill AndrewsNANO_MAKE="make" 697e3a794bSWarner LoshNANO_NCPU=$(sysctl -n hw.ncpu) 706b8c8deeSWill Andrews 716b8c8deeSWill Andrews# The default name for any image we create. 726b8c8deeSWill AndrewsNANO_IMGNAME="_.disk.full" 73df6c7936SWarner LoshNANO_IMG1NAME="_.disk.image" 746b8c8deeSWill Andrews 756b8c8deeSWill Andrews# Options to put in make.conf during buildworld only 766b8c8deeSWill AndrewsCONF_BUILD=' ' 776b8c8deeSWill Andrews 786b8c8deeSWill Andrews# Options to put in make.conf during installworld only 796b8c8deeSWill AndrewsCONF_INSTALL=' ' 806b8c8deeSWill Andrews 816b8c8deeSWill Andrews# Options to put in make.conf during both build- & installworld. 826b8c8deeSWill AndrewsCONF_WORLD=' ' 836b8c8deeSWill Andrews 846b8c8deeSWill Andrews# Kernel config file to use 856b8c8deeSWill AndrewsNANO_KERNEL=GENERIC 866b8c8deeSWill Andrews 876b8c8deeSWill Andrews# Kernel modules to install. If empty, no modules are installed. 886b8c8deeSWill Andrews# Use "default" to install all built modules. 896b8c8deeSWill AndrewsNANO_MODULES= 906b8c8deeSWill Andrews 915b4ca9d7SGleb Smirnoff# Early customize commands. 925b4ca9d7SGleb SmirnoffNANO_EARLY_CUSTOMIZE="" 935b4ca9d7SGleb Smirnoff 946b8c8deeSWill Andrews# Customize commands. 956b8c8deeSWill AndrewsNANO_CUSTOMIZE="" 966b8c8deeSWill Andrews 976b8c8deeSWill Andrews# Late customize commands. 986b8c8deeSWill AndrewsNANO_LATE_CUSTOMIZE="" 996b8c8deeSWill Andrews 100bd0ca238SPedro F. Giffuni# Newfs parameters to use 1016b8c8deeSWill AndrewsNANO_NEWFS="-b 4096 -f 512 -i 8192 -U" 1026b8c8deeSWill Andrews 1036b8c8deeSWill Andrews# The drive name of the media at runtime 1044c1ca03bSWarner LoshNANO_DRIVE=ada0 1056b8c8deeSWill Andrews 1066b8c8deeSWill Andrews# Target media size in 512 bytes sectors 1076b8c8deeSWill AndrewsNANO_MEDIASIZE=2000000 1086b8c8deeSWill Andrews 1096b8c8deeSWill Andrews# Number of code images on media (1 or 2) 1106b8c8deeSWill AndrewsNANO_IMAGES=2 1116b8c8deeSWill Andrews 1126b8c8deeSWill Andrews# 0 -> Leave second image all zeroes so it compresses better. 1136b8c8deeSWill Andrews# 1 -> Initialize second image with a copy of the first 1146b8c8deeSWill AndrewsNANO_INIT_IMG2=1 1156b8c8deeSWill Andrews 1166b8c8deeSWill Andrews# Size of code file system in 512 bytes sectors 1176b8c8deeSWill Andrews# If zero, size will be as large as possible. 1186b8c8deeSWill AndrewsNANO_CODESIZE=0 1196b8c8deeSWill Andrews 1206b8c8deeSWill Andrews# Size of configuration file system in 512 bytes sectors 1216b8c8deeSWill Andrews# Cannot be zero. 1226b8c8deeSWill AndrewsNANO_CONFSIZE=2048 1236b8c8deeSWill Andrews 1246b8c8deeSWill Andrews# Size of data file system in 512 bytes sectors 1256b8c8deeSWill Andrews# If zero: no partition configured. 1266b8c8deeSWill Andrews# If negative: max size possible 1276b8c8deeSWill AndrewsNANO_DATASIZE=0 1286b8c8deeSWill Andrews 1296b8c8deeSWill Andrews# Size of the /etc ramdisk in 512 bytes sectors 1306b8c8deeSWill AndrewsNANO_RAM_ETCSIZE=10240 1316b8c8deeSWill Andrews 1326b8c8deeSWill Andrews# Size of the /tmp+/var ramdisk in 512 bytes sectors 1336b8c8deeSWill AndrewsNANO_RAM_TMPVARSIZE=10240 1346b8c8deeSWill Andrews 1356b8c8deeSWill Andrews# boot0 flags/options and configuration 1366b8c8deeSWill AndrewsNANO_BOOT0CFG="-o packet -s 1 -m 3" 1376b8c8deeSWill AndrewsNANO_BOOTLOADER="boot/boot0sio" 1386b8c8deeSWill Andrews 1396b8c8deeSWill Andrews# boot2 flags/options 1406b8c8deeSWill Andrews# default force serial console 141a9598aaeSWarner LoshNANO_BOOT2CFG="-h -S115200" 1426b8c8deeSWill Andrews 1436b8c8deeSWill Andrews# Backing type of md(4) device 1446b8c8deeSWill Andrews# Can be "file" or "swap" 1456b8c8deeSWill AndrewsNANO_MD_BACKING="file" 1466b8c8deeSWill Andrews 1476b8c8deeSWill Andrews# for swap type md(4) backing, write out the mbr only 1486b8c8deeSWill AndrewsNANO_IMAGE_MBRONLY=true 1496b8c8deeSWill Andrews 1506b8c8deeSWill Andrews# Progress Print level 1516b8c8deeSWill AndrewsPPLEVEL=3 1526b8c8deeSWill Andrews 1536b8c8deeSWill Andrews# Set NANO_LABEL to non-blank to form the basis for using /dev/ufs/label 1546b8c8deeSWill Andrews# in preference to /dev/${NANO_DRIVE} 1556b8c8deeSWill Andrews# Root partition will be ${NANO_LABEL}s{1,2} 1566b8c8deeSWill Andrews# /cfg partition will be ${NANO_LABEL}s3 1576b8c8deeSWill Andrews# /data partition will be ${NANO_LABEL}s4 1586b8c8deeSWill AndrewsNANO_LABEL="" 1597b77d3eaSWarner LoshNANO_SLICE_ROOT=s1 1607b77d3eaSWarner LoshNANO_SLICE_ALTROOT=s2 1617b77d3eaSWarner LoshNANO_SLICE_CFG=s3 1627b77d3eaSWarner LoshNANO_SLICE_DATA=s4 163587c054bSArrigo MarchioriNANO_PARTITION_ROOT=a 164587c054bSArrigo MarchioriNANO_PARTITION_ALTROOT=a 1655e4bd293SWarner LoshNANO_ROOT=s1a 1665e4bd293SWarner LoshNANO_ALTROOT=s2a 1677b77d3eaSWarner Losh 16819edffefSWarner Losh# Default ownwership for nopriv build 16919edffefSWarner LoshNANO_DEF_UNAME=root 17019edffefSWarner LoshNANO_DEF_GNAME=wheel 1716b8c8deeSWill Andrews 1726b8c8deeSWill Andrews####################################################################### 1736b8c8deeSWill Andrews# Architecture to build. Corresponds to TARGET_ARCH in a buildworld. 1746b8c8deeSWill Andrews# Unfortunately, there's no way to set TARGET at this time, and it 175d07833f9SWarner Losh# conflates the two, so architectures where TARGET != TARGET_ARCH and 176d07833f9SWarner Losh# TARGET can't be guessed from TARGET_ARCH do not work. This defaults 177d07833f9SWarner Losh# to the arch of the current machine. 1786b8c8deeSWill AndrewsNANO_ARCH=`uname -p` 1796b8c8deeSWill Andrews 180d07833f9SWarner Losh# CPUTYPE defaults to "" which is the default when CPUTYPE isn't 181d07833f9SWarner Losh# defined. 182d07833f9SWarner LoshNANO_CPUTYPE="" 183d07833f9SWarner Losh 1846b8c8deeSWill Andrews# Directory to populate /cfg from 1856b8c8deeSWill AndrewsNANO_CFGDIR="" 1866b8c8deeSWill Andrews 1876b8c8deeSWill Andrews# Directory to populate /data from 1886b8c8deeSWill AndrewsNANO_DATADIR="" 1896b8c8deeSWill Andrews 190a9d9c49fSWarner Losh# We don't need SRCCONF or SRC_ENV_CONF. NanoBSD puts everything we 191a9d9c49fSWarner Losh# need for the build in files included with __MAKE_CONF. Override in your 192a9d9c49fSWarner Losh# config file if you really must. We set them unconditionally here, though 193a9d9c49fSWarner Losh# in case they are stray in the build environment 194a9d9c49fSWarner LoshSRCCONF=/dev/null 195a9d9c49fSWarner LoshSRC_ENV_CONF=/dev/null 1966b8c8deeSWill Andrews 197183b6feaSPoul-Henning Kamp# Comment this out if /usr/obj is a symlink 198183b6feaSPoul-Henning Kamp# CPIO_SYMLINK=--insecure 199183b6feaSPoul-Henning Kamp 2006b8c8deeSWill Andrews####################################################################### 2016b8c8deeSWill Andrews# 2026b8c8deeSWill Andrews# The functions which do the real work. 2036b8c8deeSWill Andrews# Can be overridden from the config file(s) 2046b8c8deeSWill Andrews# 2056b8c8deeSWill Andrews####################################################################### 2066b8c8deeSWill Andrews 2071934c7aaSWarner Losh# Export values into the shell. Must use { } instead of ( ) like 2081934c7aaSWarner Losh# other functions to avoid a subshell. 2091934c7aaSWarner Losh# We set __MAKE_CONF as a global since it is easier to get quoting 2101934c7aaSWarner Losh# right for paths with spaces in them. 2111934c7aaSWarner Loshmake_export ( ) { 2121934c7aaSWarner Losh # Similar to export_var, except puts the data out to stdout 2131934c7aaSWarner Losh var=$1 2141934c7aaSWarner Losh eval val=\$$var 2151934c7aaSWarner Losh echo "Setting variable: $var=\"$val\"" 2161934c7aaSWarner Losh export $1 2171934c7aaSWarner Losh} 2181934c7aaSWarner Losh 2191934c7aaSWarner Loshnano_make_build_env ( ) { 2201934c7aaSWarner Losh __MAKE_CONF="${NANO_MAKE_CONF_BUILD}" 2211934c7aaSWarner Losh make_export __MAKE_CONF 2221934c7aaSWarner Losh} 2231934c7aaSWarner Losh 2241934c7aaSWarner Loshnano_make_install_env ( ) { 2251934c7aaSWarner Losh __MAKE_CONF="${NANO_MAKE_CONF_INSTALL}" 2261934c7aaSWarner Losh make_export __MAKE_CONF 2271934c7aaSWarner Losh} 2281934c7aaSWarner Losh 2291934c7aaSWarner Losh# Extra environment variables for kernel builds 2301934c7aaSWarner Loshnano_make_kernel_env ( ) { 231a5ae1a98SGleb Smirnoff if [ -f "${NANO_KERNEL}" ] ; then 2321934c7aaSWarner Losh KERNCONFDIR="$(realpath $(dirname ${NANO_KERNEL}))" 2331934c7aaSWarner Losh KERNCONF="$(basename ${NANO_KERNEL})" 2341934c7aaSWarner Losh make_export KERNCONFDIR 2351934c7aaSWarner Losh make_export KERNCONF 2361934c7aaSWarner Losh else 2371934c7aaSWarner Losh export KERNCONF="${NANO_KERNEL}" 2381934c7aaSWarner Losh make_export KERNCONF 2391934c7aaSWarner Losh fi 2401934c7aaSWarner Losh} 2411934c7aaSWarner Losh 2421934c7aaSWarner Loshnano_global_make_env ( ) ( 243849f5467SWarner Losh # global settings for the make.conf file, if set 244849f5467SWarner Losh [ -z "${NANO_ARCH}" ] || echo TARGET_ARCH="${NANO_ARCH}" 245849f5467SWarner Losh [ -z "${NANO_CPUTYPE}" ] || echo TARGET_CPUTYPE="${NANO_CPUTYPE}" 2461934c7aaSWarner Losh) 2471934c7aaSWarner Losh 24819edffefSWarner Losh# 24919edffefSWarner Losh# Create empty files in the target tree, and record the fact. All paths 25019edffefSWarner Losh# are relative to NANO_WORLDDIR. 25119edffefSWarner Losh# 25219edffefSWarner Loshtgt_touch ( ) ( 25319edffefSWarner Losh cd "${NANO_WORLDDIR}" 25419edffefSWarner Losh for i; do 25519edffefSWarner Losh touch $i 25619edffefSWarner Losh echo "./${i} type=file" >> ${NANO_METALOG} 25719edffefSWarner Losh done 25819edffefSWarner Losh) 25919edffefSWarner Losh 26019edffefSWarner Losh# 26119edffefSWarner Losh# Convert a directory into a symlink. Takes two arguments, the 26219edffefSWarner Losh# current directory and what it should become a symlink to. The 26319edffefSWarner Losh# directory is removed and a symlink is created. If we're doing 26419edffefSWarner Losh# a nopriv build, then append this fact to the metalog 26519edffefSWarner Losh# 26619edffefSWarner Loshtgt_dir2symlink ( ) ( 26719edffefSWarner Losh dir=$1 26819edffefSWarner Losh symlink=$2 26919edffefSWarner Losh 27019edffefSWarner Losh cd "${NANO_WORLDDIR}" 271067f74c2SWarner Losh rm -xrf "$dir" 27219edffefSWarner Losh ln -s "$symlink" "$dir" 2730a852830SWarner Losh if [ -n "$NANO_METALOG" ]; then 27419edffefSWarner Losh echo "./${dir} type=link mode=0777 link=${symlink}" >> ${NANO_METALOG} 27519edffefSWarner Losh fi 27619edffefSWarner Losh) 27719edffefSWarner 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 Andrewsclean_build ( ) ( 2896b8c8deeSWill Andrews pprint 2 "Clean and create object directory (${MAKEOBJDIRPREFIX})" 2906b8c8deeSWill Andrews 291067f74c2SWarner Losh if ! rm -xrf ${MAKEOBJDIRPREFIX}/ > /dev/null 2>&1 ; then 2926b8c8deeSWill Andrews chflags -R noschg ${MAKEOBJDIRPREFIX}/ 293067f74c2SWarner Losh rm -xr ${MAKEOBJDIRPREFIX}/ 2946b8c8deeSWill Andrews fi 2956b8c8deeSWill Andrews) 2966b8c8deeSWill Andrews 2976b8c8deeSWill Andrewsmake_conf_build ( ) ( 2986b8c8deeSWill Andrews pprint 2 "Construct build make.conf ($NANO_MAKE_CONF_BUILD)" 2996b8c8deeSWill Andrews 3006b8c8deeSWill Andrews mkdir -p ${MAKEOBJDIRPREFIX} 3016b8c8deeSWill Andrews printenv > ${MAKEOBJDIRPREFIX}/_.env 3026b8c8deeSWill Andrews 3031934c7aaSWarner Losh # Make sure we get all the global settings that NanoBSD wants 3041934c7aaSWarner Losh # in addition to the user's global settings 3051934c7aaSWarner Losh ( 3061934c7aaSWarner Losh nano_global_make_env 3071934c7aaSWarner Losh echo "${CONF_WORLD}" 3081934c7aaSWarner Losh echo "${CONF_BUILD}" 3091934c7aaSWarner Losh ) > ${NANO_MAKE_CONF_BUILD} 3106b8c8deeSWill Andrews) 3116b8c8deeSWill Andrews 3126b8c8deeSWill Andrewsbuild_world ( ) ( 3136b8c8deeSWill Andrews pprint 2 "run buildworld" 3146b8c8deeSWill Andrews pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bw" 3156b8c8deeSWill Andrews 3161934c7aaSWarner Losh ( 3171934c7aaSWarner Losh nano_make_build_env 3181934c7aaSWarner Losh set -o xtrace 3191934c7aaSWarner Losh cd "${NANO_SRC}" 3201934c7aaSWarner Losh ${NANO_PMAKE} buildworld 3211934c7aaSWarner Losh ) > ${MAKEOBJDIRPREFIX}/_.bw 2>&1 3226b8c8deeSWill Andrews) 3236b8c8deeSWill Andrews 3246b8c8deeSWill Andrewsbuild_kernel ( ) ( 3256b8c8deeSWill Andrews pprint 2 "build kernel ($NANO_KERNEL)" 3266b8c8deeSWill Andrews pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bk" 3276b8c8deeSWill Andrews 3286b8c8deeSWill Andrews ( 3291934c7aaSWarner Losh nano_make_build_env 3301934c7aaSWarner Losh nano_make_kernel_env 3316b8c8deeSWill Andrews 3326b8c8deeSWill Andrews # Note: We intentionally build all modules, not only the ones in 3336b8c8deeSWill Andrews # NANO_MODULES so the built world can be reused by multiple images. 334bd0ca238SPedro F. Giffuni # Although MODULES_OVERRIDE can be defined in the kernel config 3351934c7aaSWarner Losh # file to override this behavior. Just set NANO_MODULES=default. 3361934c7aaSWarner Losh set -o xtrace 3371934c7aaSWarner Losh cd "${NANO_SRC}" 3381934c7aaSWarner Losh ${NANO_PMAKE} buildkernel 3396b8c8deeSWill Andrews ) > ${MAKEOBJDIRPREFIX}/_.bk 2>&1 3406b8c8deeSWill Andrews) 3416b8c8deeSWill Andrews 3426b8c8deeSWill Andrewsclean_world ( ) ( 3436b8c8deeSWill Andrews if [ "${NANO_OBJ}" != "${MAKEOBJDIRPREFIX}" ]; then 3446b8c8deeSWill Andrews pprint 2 "Clean and create object directory (${NANO_OBJ})" 345067f74c2SWarner Losh if ! rm -xrf ${NANO_OBJ}/ > /dev/null 2>&1 ; then 3466b8c8deeSWill Andrews chflags -R noschg ${NANO_OBJ} 347067f74c2SWarner Losh rm -xr ${NANO_OBJ}/ 3486b8c8deeSWill Andrews fi 3491934c7aaSWarner Losh mkdir -p "${NANO_OBJ}" "${NANO_WORLDDIR}" 350c2c06cfaSWarner Losh printenv > ${NANO_LOG}/_.env 3516b8c8deeSWill Andrews else 3526b8c8deeSWill Andrews pprint 2 "Clean and create world directory (${NANO_WORLDDIR})" 353067f74c2SWarner Losh if ! rm -xrf "${NANO_WORLDDIR}/" > /dev/null 2>&1 ; then 3541934c7aaSWarner Losh chflags -R noschg "${NANO_WORLDDIR}" 355067f74c2SWarner Losh rm -xrf "${NANO_WORLDDIR}/" 3566b8c8deeSWill Andrews fi 3571934c7aaSWarner Losh mkdir -p "${NANO_WORLDDIR}" 3586b8c8deeSWill Andrews fi 3596b8c8deeSWill Andrews) 3606b8c8deeSWill Andrews 3616b8c8deeSWill Andrewsmake_conf_install ( ) ( 3626b8c8deeSWill Andrews pprint 2 "Construct install make.conf ($NANO_MAKE_CONF_INSTALL)" 3636b8c8deeSWill Andrews 3641934c7aaSWarner Losh # Make sure we get all the global settings that NanoBSD wants 3651934c7aaSWarner Losh # in addition to the user's global settings 3661934c7aaSWarner Losh ( 3671934c7aaSWarner Losh nano_global_make_env 3681934c7aaSWarner Losh echo "${CONF_WORLD}" 3691934c7aaSWarner Losh echo "${CONF_INSTALL}" 370849f5467SWarner Losh if [ -n "${NANO_NOPRIV_BUILD}" ]; then 371c275d9ecSWarner Losh echo NO_ROOT=t 372c275d9ecSWarner Losh echo METALOG=${NANO_METALOG} 373c275d9ecSWarner Losh fi 3741934c7aaSWarner Losh ) > ${NANO_MAKE_CONF_INSTALL} 3756b8c8deeSWill Andrews) 3766b8c8deeSWill Andrews 3776b8c8deeSWill Andrewsinstall_world ( ) ( 3786b8c8deeSWill Andrews pprint 2 "installworld" 379c2c06cfaSWarner Losh pprint 3 "log: ${NANO_LOG}/_.iw" 3806b8c8deeSWill Andrews 3811934c7aaSWarner Losh ( 3821934c7aaSWarner Losh nano_make_install_env 3831934c7aaSWarner Losh set -o xtrace 3841934c7aaSWarner Losh cd "${NANO_SRC}" 3856ba33ab5SWarner Losh ${NANO_MAKE} installworld DESTDIR="${NANO_WORLDDIR}" DB_FROM_SRC=yes 3861934c7aaSWarner Losh chflags -R noschg "${NANO_WORLDDIR}" 387c2c06cfaSWarner Losh ) > ${NANO_LOG}/_.iw 2>&1 3886b8c8deeSWill Andrews) 3896b8c8deeSWill Andrews 3906b8c8deeSWill Andrewsinstall_etc ( ) ( 3916b8c8deeSWill Andrews pprint 2 "install /etc" 392c2c06cfaSWarner Losh pprint 3 "log: ${NANO_LOG}/_.etc" 3936b8c8deeSWill Andrews 3941934c7aaSWarner Losh ( 3951934c7aaSWarner Losh nano_make_install_env 3961934c7aaSWarner Losh set -o xtrace 3971934c7aaSWarner Losh cd "${NANO_SRC}" 3986ba33ab5SWarner Losh ${NANO_MAKE} distribution DESTDIR="${NANO_WORLDDIR}" DB_FROM_SRC=yes 3996b8c8deeSWill Andrews # make.conf doesn't get created by default, but some ports need it 4006b8c8deeSWill Andrews # so they can spam it. 4011934c7aaSWarner Losh cp /dev/null "${NANO_WORLDDIR}"/etc/make.conf 402c2c06cfaSWarner Losh ) > ${NANO_LOG}/_.etc 2>&1 4036b8c8deeSWill Andrews) 4046b8c8deeSWill Andrews 4056b8c8deeSWill Andrewsinstall_kernel ( ) ( 4066b8c8deeSWill Andrews pprint 2 "install kernel ($NANO_KERNEL)" 407c2c06cfaSWarner Losh pprint 3 "log: ${NANO_LOG}/_.ik" 4086b8c8deeSWill Andrews 4096b8c8deeSWill Andrews ( 4106b8c8deeSWill Andrews 4111934c7aaSWarner Losh nano_make_install_env 4121934c7aaSWarner Losh nano_make_kernel_env 4131934c7aaSWarner Losh 4146b8c8deeSWill Andrews if [ "${NANO_MODULES}" != "default" ]; then 4151934c7aaSWarner Losh MODULES_OVERRIDE="${NANO_MODULES}" 4161934c7aaSWarner Losh make_export MODULES_OVERRIDE 4176b8c8deeSWill Andrews fi 4186b8c8deeSWill Andrews 4191934c7aaSWarner Losh set -o xtrace 4201934c7aaSWarner Losh cd "${NANO_SRC}" 4216ba33ab5SWarner Losh ${NANO_MAKE} installkernel DESTDIR="${NANO_WORLDDIR}" DB_FROM_SRC=yes 4221934c7aaSWarner Losh 423c2c06cfaSWarner Losh ) > ${NANO_LOG}/_.ik 2>&1 4246b8c8deeSWill Andrews) 4256b8c8deeSWill Andrews 4266b8c8deeSWill Andrewsnative_xtools ( ) ( 427e6eb94a8SGuido Falsi pprint 2 "Installing the optimized native build tools for cross env" 428c2c06cfaSWarner Losh pprint 3 "log: ${NANO_LOG}/_.native_xtools" 4296b8c8deeSWill Andrews 4301934c7aaSWarner Losh ( 4311934c7aaSWarner Losh 4321934c7aaSWarner Losh nano_make_install_env 4331934c7aaSWarner Losh set -o xtrace 4341934c7aaSWarner Losh cd "${NANO_SRC}" 4359a0c5c4cSBryan Drewery ${NANO_MAKE} native-xtools 4369a0c5c4cSBryan Drewery ${NANO_MAKE} native-xtools-install DESTDIR="${NANO_WORLDDIR}" 4371934c7aaSWarner Losh 438c2c06cfaSWarner Losh ) > ${NANO_LOG}/_.native_xtools 2>&1 4396b8c8deeSWill Andrews) 4406b8c8deeSWill Andrews 44119edffefSWarner Losh# 4425b4ca9d7SGleb Smirnoff# Run the requested set of early customization scripts, run before 4435b4ca9d7SGleb Smirnoff# buildworld. 4445b4ca9d7SGleb Smirnoff# 4455b4ca9d7SGleb Smirnoffrun_early_customize ( ) { 4465b4ca9d7SGleb Smirnoff pprint 2 "run early customize scripts" 4475b4ca9d7SGleb Smirnoff for c in $NANO_EARLY_CUSTOMIZE 4485b4ca9d7SGleb Smirnoff do 4495b4ca9d7SGleb Smirnoff pprint 2 "early customize \"$c\"" 4505b4ca9d7SGleb Smirnoff pprint 3 "log: ${NANO_LOG}/_.early_cust.$c" 4515b4ca9d7SGleb Smirnoff pprint 4 "`type $c`" 452b4d3716bSWarner Losh { t=$(set -o | awk '$1 == "xtrace" && $2 == "off" { print "set +o xtrace"}'); 453b4d3716bSWarner Losh set -o xtrace ; 45404b9e947SWarner Losh $c ; 45504b9e947SWarner Losh eval $t 45604b9e947SWarner Losh } >${NANO_LOG}/_.early_cust.$c 2>&1 4575b4ca9d7SGleb Smirnoff done 4585b4ca9d7SGleb Smirnoff} 4595b4ca9d7SGleb Smirnoff 4605b4ca9d7SGleb Smirnoff# 46119edffefSWarner Losh# Run the requested set of customization scripts, run after we've 46219edffefSWarner Losh# done an installworld, installed the etc files, installed the kernel 46319edffefSWarner Losh# and tweaked them in the standard way. 46419edffefSWarner Losh# 4656b8c8deeSWill Andrewsrun_customize ( ) ( 4666b8c8deeSWill Andrews 4676b8c8deeSWill Andrews pprint 2 "run customize scripts" 4686b8c8deeSWill Andrews for c in $NANO_CUSTOMIZE 4696b8c8deeSWill Andrews do 4706b8c8deeSWill Andrews pprint 2 "customize \"$c\"" 471c2c06cfaSWarner Losh pprint 3 "log: ${NANO_LOG}/_.cust.$c" 4726b8c8deeSWill Andrews pprint 4 "`type $c`" 473b4d3716bSWarner Losh ( set -o xtrace ; $c ) > ${NANO_LOG}/_.cust.$c 2>&1 4746b8c8deeSWill Andrews done 4756b8c8deeSWill Andrews) 4766b8c8deeSWill Andrews 47719edffefSWarner Losh# 47819edffefSWarner Losh# Run any last-minute customization commands after we've had a chance to 47919edffefSWarner Losh# setup nanobsd, prune empty dirs from /usr, etc 48019edffefSWarner Losh# 4816b8c8deeSWill Andrewsrun_late_customize ( ) ( 4826b8c8deeSWill Andrews pprint 2 "run late customize scripts" 4836b8c8deeSWill Andrews for c in $NANO_LATE_CUSTOMIZE 4846b8c8deeSWill Andrews do 4856b8c8deeSWill Andrews pprint 2 "late customize \"$c\"" 486c2c06cfaSWarner Losh pprint 3 "log: ${NANO_LOG}/_.late_cust.$c" 4876b8c8deeSWill Andrews pprint 4 "`type $c`" 488b4d3716bSWarner Losh ( set -o xtrace ; $c ) > ${NANO_LOG}/_.late_cust.$c 2>&1 4896b8c8deeSWill Andrews done 4906b8c8deeSWill Andrews) 4916b8c8deeSWill Andrews 49219edffefSWarner Losh# 49319edffefSWarner Losh# Hook called after we run all the late customize commands, but 49419edffefSWarner Losh# before we invoke the disk imager. The nopriv build uses it to 49519edffefSWarner Losh# read in the meta log, apply the changes other parts of nanobsd 49619edffefSWarner Losh# have been recording their actions. It's not anticipated that 49719edffefSWarner Losh# a user's cfg file would override this. 49819edffefSWarner Losh# 49919edffefSWarner Loshfixup_before_diskimage ( ) ( 500*12cbad92SJose Luis Duran # Run the deduplication script that takes the metalog journal and 50119edffefSWarner Losh # combines multiple entries for the same file (see source for 50219edffefSWarner Losh # details). We take the extra step of removing the size keywords. This 503*12cbad92SJose Luis Duran # script, and many of the user scripts, copies, appends and otherwise 50419edffefSWarner Losh # modifies files in the build, changing their sizes. These actions are 50519edffefSWarner Losh # impossible to trap, so go ahead remove the size= keyword. For this 50619edffefSWarner Losh # narrow use, it doesn't buy us any protection and just gets in the way. 50719edffefSWarner Losh # The dedup tool's output must be sorted due to limitations in awk. 5080a852830SWarner Losh if [ -n "${NANO_METALOG}" ]; then 50919edffefSWarner Losh pprint 2 "Fixing metalog" 51019edffefSWarner Losh cp ${NANO_METALOG} ${NANO_METALOG}.pre 51145b2ffd0SWarner Losh echo "/set uname=${NANO_DEF_UNAME} gname=${NANO_DEF_GNAME}" > ${NANO_METALOG} 51245b2ffd0SWarner Losh cat ${NANO_METALOG}.pre | ${NANO_TOOLS}/mtree-dedup.awk | \ 51345b2ffd0SWarner Losh sed -e 's/ size=[0-9][0-9]*//' | sort >> ${NANO_METALOG} 51419edffefSWarner Losh fi 51519edffefSWarner Losh) 51619edffefSWarner Losh 5176b8c8deeSWill Andrewssetup_nanobsd ( ) ( 5186b8c8deeSWill Andrews pprint 2 "configure nanobsd setup" 519c2c06cfaSWarner Losh pprint 3 "log: ${NANO_LOG}/_.dl" 5206b8c8deeSWill Andrews 5216b8c8deeSWill Andrews ( 5221934c7aaSWarner Losh cd "${NANO_WORLDDIR}" 5236b8c8deeSWill Andrews 5246b8c8deeSWill Andrews # Move /usr/local/etc to /etc/local so that the /cfg stuff 5256b8c8deeSWill Andrews # can stomp on it. Otherwise packages like ipsec-tools which 5266b8c8deeSWill Andrews # have hardcoded paths under ${prefix}/etc are not tweakable. 5276b8c8deeSWill Andrews if [ -d usr/local/etc ] ; then 5286b8c8deeSWill Andrews ( 5296b8c8deeSWill Andrews cd usr/local/etc 530183b6feaSPoul-Henning Kamp find . -print | cpio ${CPIO_SYMLINK} -dumpl ../../../etc/local 5316b8c8deeSWill Andrews cd .. 532067f74c2SWarner Losh rm -xrf etc 5336b8c8deeSWill Andrews ) 5346b8c8deeSWill Andrews fi 5356b8c8deeSWill Andrews 53607f2d905SWarner Losh # Always setup the usr/local/etc -> etc/local symlink. 53707f2d905SWarner Losh # usr/local/etc gets created by packages, but if no packages 53807f2d905SWarner Losh # are installed by this point, but are later in the process, 53907f2d905SWarner Losh # the symlink not being here causes problems. It never hurts 54007f2d905SWarner Losh # to have the symlink in error though. 54107f2d905SWarner Losh ln -s ../../etc/local usr/local/etc 54207f2d905SWarner Losh 5436b8c8deeSWill Andrews for d in var etc 5446b8c8deeSWill Andrews do 5456b8c8deeSWill Andrews # link /$d under /conf 5466b8c8deeSWill Andrews # we use hard links so we have them both places. 5476b8c8deeSWill Andrews # the files in /$d will be hidden by the mount. 5486b8c8deeSWill Andrews mkdir -p conf/base/$d conf/default/$d 549183b6feaSPoul-Henning Kamp find $d -print | cpio ${CPIO_SYMLINK} -dumpl conf/base/ 5506b8c8deeSWill Andrews done 5516b8c8deeSWill Andrews 5526b8c8deeSWill Andrews echo "$NANO_RAM_ETCSIZE" > conf/base/etc/md_size 5536b8c8deeSWill Andrews echo "$NANO_RAM_TMPVARSIZE" > conf/base/var/md_size 5546b8c8deeSWill Andrews 5556b8c8deeSWill Andrews # pick up config files from the special partition 5567b77d3eaSWarner Losh echo "mount -o ro /dev/${NANO_DRIVE}${NANO_SLICE_CFG}" > conf/default/etc/remount 5576b8c8deeSWill Andrews 5586b8c8deeSWill Andrews # Put /tmp on the /var ramdisk (could be symlink already) 55919edffefSWarner Losh tgt_dir2symlink tmp var/tmp 5606b8c8deeSWill Andrews 561c2c06cfaSWarner Losh ) > ${NANO_LOG}/_.dl 2>&1 5626b8c8deeSWill Andrews) 5636b8c8deeSWill Andrews 5646b8c8deeSWill Andrewssetup_nanobsd_etc ( ) ( 5656b8c8deeSWill Andrews pprint 2 "configure nanobsd /etc" 5666b8c8deeSWill Andrews 5676b8c8deeSWill Andrews ( 5681934c7aaSWarner Losh cd "${NANO_WORLDDIR}" 5696b8c8deeSWill Andrews 5706b8c8deeSWill Andrews # create diskless marker file 5716b8c8deeSWill Andrews touch etc/diskless 5726b8c8deeSWill Andrews 573e5579f98SJose Luis Duran [ -n "${NANO_NOPRIV_BUILD}" ] && chmod 666 boot/defaults/loader.conf 574e5579f98SJose Luis Duran { 575e5579f98SJose Luis Duran echo 576e5579f98SJose Luis Duran echo '### NanoBSD configuration ##################################' 577e5579f98SJose Luis Duran echo 'hostuuid_load="NO"' 578e5579f98SJose Luis Duran echo 'entropy_cache_load="NO" # Disable loading cached entropy at boot time.' 579e5579f98SJose Luis Duran echo 'kern.random.initial_seeding.disable_bypass_warnings="1" # Do not log a warning' 580e5579f98SJose Luis Duran echo " # if the 'bypass_before_seeding' knob is enabled" 581e5579f98SJose Luis Duran echo " # and a request is submitted prior to initial" 582e5579f98SJose Luis Duran echo " # seeding." 583e5579f98SJose Luis Duran } >> boot/defaults/loader.conf 584e5579f98SJose Luis Duran [ -n "${NANO_NOPRIV_BUILD}" ] && chmod 444 boot/defaults/loader.conf 585e5579f98SJose Luis Duran 586849f5467SWarner Losh [ -n "${NANO_NOPRIV_BUILD}" ] && chmod 666 etc/defaults/rc.conf 587e5579f98SJose Luis Duran if ! ed -s etc/defaults/rc.conf <<\EOF 588e5579f98SJose Luis Duran/^### Define source_rc_confs, the mechanism used by \/etc\/rc\.\* ##$/i 589e5579f98SJose Luis Duran### NanoBSD options ######################################## 590e5579f98SJose Luis Duran############################################################## 5919e144f35SWarner Losh 592e5579f98SJose Luis Durankldxref_enable="NO" # Disable building linker.hints files with kldxref(8). 593e5579f98SJose Luis Duranroot_rw_mount="NO" # Inhibit remounting root read-write. 594e5579f98SJose Luis Duranentropy_boot_file="NO" # Disable very early (used at early boot time) 595e5579f98SJose Luis Duran # entropy caching through reboots. 596e5579f98SJose Luis Duranentropy_file="NO" # Disable late (used when going multi-user) 597e5579f98SJose Luis Duran # entropy through reboots. 598e5579f98SJose Luis Duranentropy_dir="NO" # Disable caching entropy via cron. 5999e144f35SWarner Losh 600e5579f98SJose Luis Duran############################################################## 601e5579f98SJose Luis Duran. 602e5579f98SJose Luis Duranw 603e5579f98SJose Luis Duranq 604e5579f98SJose Luis DuranEOF 605e5579f98SJose Luis Duran then 606e5579f98SJose Luis Duran echo "Regular expression pattern not found" 607e5579f98SJose Luis Duran exit 2 608e5579f98SJose Luis Duran fi 609849f5467SWarner Losh [ -n "${NANO_NOPRIV_BUILD}" ] && chmod 444 etc/defaults/rc.conf 6106b8c8deeSWill Andrews 6116b8c8deeSWill Andrews # save config file for scripts 6126b8c8deeSWill Andrews echo "NANO_DRIVE=${NANO_DRIVE}" > etc/nanobsd.conf 6136b8c8deeSWill Andrews 6145e4bd293SWarner Losh echo "/dev/${NANO_DRIVE}${NANO_ROOT} / ufs ro 1 1" > etc/fstab 6157b77d3eaSWarner Losh echo "/dev/${NANO_DRIVE}${NANO_SLICE_CFG} /cfg ufs rw,noauto 2 2" >> etc/fstab 6166b8c8deeSWill Andrews mkdir -p cfg 61707f2d905SWarner Losh 61807f2d905SWarner Losh # Create directory for eventual /usr/local/etc contents 61907f2d905SWarner Losh mkdir -p etc/local 6206b8c8deeSWill Andrews ) 6216b8c8deeSWill Andrews) 6226b8c8deeSWill Andrews 6236b8c8deeSWill Andrewsprune_usr ( ) ( 6246b8c8deeSWill Andrews # Remove all empty directories in /usr 6251934c7aaSWarner Losh find "${NANO_WORLDDIR}"/usr -type d -depth -print | 6266b8c8deeSWill Andrews while read d 6276b8c8deeSWill Andrews do 6286b8c8deeSWill Andrews rmdir $d > /dev/null 2>&1 || true 6296b8c8deeSWill Andrews done 6306b8c8deeSWill Andrews) 6316b8c8deeSWill Andrews 6326b8c8deeSWill Andrewsnewfs_part ( ) ( 6336b8c8deeSWill Andrews local dev mnt lbl 6346b8c8deeSWill Andrews dev=$1 6356b8c8deeSWill Andrews mnt=$2 6366b8c8deeSWill Andrews lbl=$3 6376b8c8deeSWill Andrews echo newfs ${NANO_NEWFS} ${NANO_LABEL:+-L${NANO_LABEL}${lbl}} ${dev} 6386b8c8deeSWill Andrews newfs ${NANO_NEWFS} ${NANO_LABEL:+-L${NANO_LABEL}${lbl}} ${dev} 6396b8c8deeSWill Andrews mount -o async ${dev} ${mnt} 6406b8c8deeSWill Andrews) 6416b8c8deeSWill Andrews 6426b8c8deeSWill Andrews# Convenient spot to work around any umount issues that your build environment 6436b8c8deeSWill Andrews# hits by overriding this method. 6446b8c8deeSWill Andrewsnano_umount ( ) ( 6456b8c8deeSWill Andrews umount ${1} 6466b8c8deeSWill Andrews) 6476b8c8deeSWill Andrews 6486b8c8deeSWill Andrewspopulate_slice ( ) ( 6496b8c8deeSWill Andrews local dev dir mnt lbl 6506b8c8deeSWill Andrews dev=$1 6516b8c8deeSWill Andrews dir=$2 6526b8c8deeSWill Andrews mnt=$3 6536b8c8deeSWill Andrews lbl=$4 6546b8c8deeSWill Andrews echo "Creating ${dev} (mounting on ${mnt})" 6556b8c8deeSWill Andrews newfs_part ${dev} ${mnt} ${lbl} 6566b8c8deeSWill Andrews if [ -n "${dir}" -a -d "${dir}" ]; then 6576b8c8deeSWill Andrews echo "Populating ${lbl} from ${dir}" 6581934c7aaSWarner Losh cd "${dir}" 659183b6feaSPoul-Henning Kamp find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)/' | cpio ${CPIO_SYMLINK} -dumpv ${mnt} 6606b8c8deeSWill Andrews fi 6616b8c8deeSWill Andrews df -i ${mnt} 6626b8c8deeSWill Andrews nano_umount ${mnt} 6636b8c8deeSWill Andrews) 6646b8c8deeSWill Andrews 6656b8c8deeSWill Andrewspopulate_cfg_slice ( ) ( 6666b8c8deeSWill Andrews populate_slice "$1" "$2" "$3" "$4" 6676b8c8deeSWill Andrews) 6686b8c8deeSWill Andrews 6696b8c8deeSWill Andrewspopulate_data_slice ( ) ( 6706b8c8deeSWill Andrews populate_slice "$1" "$2" "$3" "$4" 6716b8c8deeSWill Andrews) 6726b8c8deeSWill Andrews 6736b8c8deeSWill Andrewslast_orders ( ) ( 6746b8c8deeSWill Andrews # Redefine this function with any last orders you may have 6756b8c8deeSWill Andrews # after the build completed, for instance to copy the finished 6766b8c8deeSWill Andrews # image to a more convenient place: 677df6c7936SWarner Losh # cp ${NANO_DISKIMGDIR}/${NANO_IMG1NAME} /home/ftp/pub/nanobsd.disk 6786b8c8deeSWill Andrews true 6796b8c8deeSWill Andrews) 6806b8c8deeSWill Andrews 6816b8c8deeSWill Andrews####################################################################### 6826b8c8deeSWill Andrews# 6836b8c8deeSWill Andrews# Optional convenience functions. 6846b8c8deeSWill Andrews# 6856b8c8deeSWill Andrews####################################################################### 6866b8c8deeSWill Andrews 6876b8c8deeSWill Andrews####################################################################### 6886b8c8deeSWill Andrews# Common Flash device geometries 6896b8c8deeSWill Andrews# 6906b8c8deeSWill Andrews 6916b8c8deeSWill AndrewsFlashDevice ( ) { 6926b8c8deeSWill Andrews if [ -d ${NANO_TOOLS} ] ; then 6936b8c8deeSWill Andrews . ${NANO_TOOLS}/FlashDevice.sub 6946b8c8deeSWill Andrews else 6956b8c8deeSWill Andrews . ${NANO_SRC}/${NANO_TOOLS}/FlashDevice.sub 6966b8c8deeSWill Andrews fi 6976b8c8deeSWill Andrews sub_FlashDevice $1 $2 6986b8c8deeSWill Andrews} 6996b8c8deeSWill Andrews 7006b8c8deeSWill Andrews####################################################################### 7016b8c8deeSWill Andrews# USB device geometries 7026b8c8deeSWill Andrews# 7036b8c8deeSWill Andrews# Usage: 7046b8c8deeSWill Andrews# UsbDevice Generic 1000 # a generic flash key sold as having 1GB 7056b8c8deeSWill Andrews# 7066b8c8deeSWill Andrews# This function will set NANO_MEDIASIZE, NANO_HEADS and NANO_SECTS for you. 7076b8c8deeSWill Andrews# 7086b8c8deeSWill Andrews# Note that the capacity of a flash key is usually advertised in MB or 7096b8c8deeSWill Andrews# GB, *not* MiB/GiB. As such, the precise number of cylinders available 7106b8c8deeSWill Andrews# for C/H/S geometry may vary depending on the actual flash geometry. 7116b8c8deeSWill Andrews# 7126b8c8deeSWill Andrews# The following generic device layouts are understood: 7136b8c8deeSWill Andrews# generic An alias for generic-hdd. 7146b8c8deeSWill Andrews# generic-hdd 255H 63S/T xxxxC with no MBR restrictions. 7156b8c8deeSWill Andrews# generic-fdd 64H 32S/T xxxxC with no MBR restrictions. 7166b8c8deeSWill Andrews# 7176b8c8deeSWill Andrews# The generic-hdd device is preferred for flash devices larger than 1GB. 7186b8c8deeSWill Andrews# 7196b8c8deeSWill Andrews 7206b8c8deeSWill AndrewsUsbDevice ( ) { 7216b8c8deeSWill Andrews a1=`echo $1 | tr '[:upper:]' '[:lower:]'` 7226b8c8deeSWill Andrews case $a1 in 7236b8c8deeSWill Andrews generic-fdd) 7246b8c8deeSWill Andrews NANO_HEADS=64 7256b8c8deeSWill Andrews NANO_SECTS=32 7266b8c8deeSWill Andrews NANO_MEDIASIZE=$(( $2 * 1000 * 1000 / 512 )) 7276b8c8deeSWill Andrews ;; 7286b8c8deeSWill Andrews generic|generic-hdd) 7296b8c8deeSWill Andrews NANO_HEADS=255 7306b8c8deeSWill Andrews NANO_SECTS=63 7316b8c8deeSWill Andrews NANO_MEDIASIZE=$(( $2 * 1000 * 1000 / 512 )) 7326b8c8deeSWill Andrews ;; 7336b8c8deeSWill Andrews *) 7346b8c8deeSWill Andrews echo "Unknown USB flash device" 7356b8c8deeSWill Andrews exit 2 7366b8c8deeSWill Andrews ;; 7376b8c8deeSWill Andrews esac 7386b8c8deeSWill Andrews} 7396b8c8deeSWill Andrews 7406b8c8deeSWill Andrews####################################################################### 7416b8c8deeSWill Andrews# Setup serial console 7426b8c8deeSWill Andrews 7436b8c8deeSWill Andrewscust_comconsole ( ) ( 7446b8c8deeSWill Andrews # Enable getty on console 7450f7b0db5SJose Luis Duran sed -i "" -e '/^tty[du]0/s/off/onifconsole/' ${NANO_WORLDDIR}/etc/ttys 7466b8c8deeSWill Andrews 7470f7b0db5SJose Luis Duran # Disable getty on syscons or vt devices 7480f7b0db5SJose Luis Duran sed -i "" -E '/^ttyv[0-8]/s/\ton(ifexists)?/\toff/' ${NANO_WORLDDIR}/etc/ttys 7496b8c8deeSWill Andrews 7506b8c8deeSWill Andrews # Tell loader to use serial console early. 7516b8c8deeSWill Andrews echo "${NANO_BOOT2CFG}" > ${NANO_WORLDDIR}/boot.config 7526b8c8deeSWill Andrews) 7536b8c8deeSWill Andrews 7546b8c8deeSWill Andrews####################################################################### 7556b8c8deeSWill Andrews# Allow root login via ssh 7566b8c8deeSWill Andrews 7576b8c8deeSWill Andrewscust_allow_ssh_root ( ) ( 75873358cd2SJose Luis Duran sed -i "" -E 's/^#?PermitRootLogin.*/PermitRootLogin yes/' \ 7596b8c8deeSWill Andrews ${NANO_WORLDDIR}/etc/ssh/sshd_config 7606b8c8deeSWill Andrews) 7616b8c8deeSWill Andrews 7626b8c8deeSWill Andrews####################################################################### 7636b8c8deeSWill Andrews# Install the stuff under ./Files 7646b8c8deeSWill Andrews 7656b8c8deeSWill Andrewscust_install_files ( ) ( 7661934c7aaSWarner Losh cd "${NANO_TOOLS}/Files" 767183b6feaSPoul-Henning Kamp find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)/' | cpio ${CPIO_SYMLINK} -Ldumpv ${NANO_WORLDDIR} 7688e7676caSGleb Smirnoff 769b805f83dSPoul-Henning Kamp if [ -n "${NANO_CUST_FILES_MTREE}" -a -f ${NANO_CUST_FILES_MTREE} ]; then 7708e7676caSGleb Smirnoff CR "mtree -eiU -p /" <${NANO_CUST_FILES_MTREE} 7718e7676caSGleb Smirnoff fi 7726b8c8deeSWill Andrews) 7736b8c8deeSWill Andrews 7746b8c8deeSWill Andrews####################################################################### 7756b8c8deeSWill Andrews# Install packages from ${NANO_PACKAGE_DIR} 7766b8c8deeSWill Andrews 7776b8c8deeSWill Andrewscust_pkgng ( ) ( 778b805f83dSPoul-Henning Kamp mkdir -p ${NANO_WORLDDIR}/usr/local/etc 7799af130aeSWarner Losh local PKG_CONF="${NANO_WORLDDIR}/usr/local/etc/pkg.conf" 7807d608e53SWarner Losh local PKGCMD="env BATCH=YES ASSUME_ALWAYS_YES=YES PKG_DBDIR=${NANO_PKG_META_BASE}/pkg SIGNATURE_TYPE=none /usr/sbin/pkg" 7819af130aeSWarner Losh 7829af130aeSWarner Losh # Ensure pkg.conf points pkg to where the package meta data lives. 7839af130aeSWarner Losh touch ${PKG_CONF} 7849af130aeSWarner Losh if grep -Eiq '^PKG_DBDIR:.*' ${PKG_CONF}; then 7859af130aeSWarner Losh sed -i -e "\|^PKG_DBDIR:.*|Is||PKG_DBDIR: "\"${NANO_PKG_META_BASE}/pkg\""|" ${PKG_CONF} 7869af130aeSWarner Losh else 7879af130aeSWarner Losh echo "PKG_DBDIR: \"${NANO_PKG_META_BASE}/pkg\"" >> ${PKG_CONF} 7889af130aeSWarner Losh fi 7899af130aeSWarner Losh 7906b8c8deeSWill Andrews # If the package directory doesn't exist, we're done. 7914223c668SJose Luis Duran NANO_PACKAGE_DIR="$(realpath $NANO_PACKAGE_DIR)" 7926b8c8deeSWill Andrews if [ ! -d ${NANO_PACKAGE_DIR} ]; then 7936b8c8deeSWill Andrews echo "DONE 0 packages" 7946b8c8deeSWill Andrews return 0 7956b8c8deeSWill Andrews fi 7966b8c8deeSWill Andrews 7976b8c8deeSWill Andrews # Find a pkg-* package 7986b8c8deeSWill Andrews for x in `find -s ${NANO_PACKAGE_DIR} -iname 'pkg-*'`; do 7996b8c8deeSWill Andrews _NANO_PKG_PACKAGE=`basename "$x"` 8006b8c8deeSWill Andrews done 8016b8c8deeSWill Andrews if [ -z "${_NANO_PKG_PACKAGE}" -o ! -f "${NANO_PACKAGE_DIR}/${_NANO_PKG_PACKAGE}" ]; then 8026b8c8deeSWill Andrews echo "FAILED: need a pkg/ package for bootstrapping" 8036b8c8deeSWill Andrews exit 2 8046b8c8deeSWill Andrews fi 8056b8c8deeSWill Andrews 8069af130aeSWarner Losh # Mount packages into chroot 8079af130aeSWarner Losh mkdir -p ${NANO_WORLDDIR}/_.p 8089af130aeSWarner Losh mount -t nullfs -o noatime -o ro ${NANO_PACKAGE_DIR} ${NANO_WORLDDIR}/_.p 809804b7863SWarner Losh mount -t devfs devfs ${NANO_WORLDDIR}/dev 8106b8c8deeSWill Andrews 811067f74c2SWarner Losh trap "umount ${NANO_WORLDDIR}/dev; umount ${NANO_WORLDDIR}/_.p ; rm -xrf ${NANO_WORLDDIR}/_.p" 1 2 15 EXIT 8126b8c8deeSWill Andrews 813fca41131SWarner Losh # Install pkg-* package 814fca41131SWarner Losh CR "${PKGCMD} add /_.p/${_NANO_PKG_PACKAGE}" 815fca41131SWarner Losh 816fca41131SWarner Losh ( 817*12cbad92SJose Luis Duran # Expand any glob characters in package list 818fca41131SWarner Losh cd "${NANO_PACKAGE_DIR}" 819fca41131SWarner Losh _PKGS=`find ${NANO_PACKAGE_LIST} -not -name "${_NANO_PKG_PACKAGE}" -print | sort | uniq` 820fca41131SWarner Losh 821fca41131SWarner Losh # Show todo 822fca41131SWarner Losh todo=`echo "$_PKGS" | wc -l` 8236b8c8deeSWill Andrews echo "=== TODO: $todo" 824fca41131SWarner Losh echo "$_PKGS" 8256b8c8deeSWill Andrews echo "===" 826fca41131SWarner Losh 827fca41131SWarner Losh # Install packages 828fca41131SWarner Losh for _PKG in $_PKGS; do 8299af130aeSWarner Losh CR "${PKGCMD} add /_.p/${_PKG}" 8306b8c8deeSWill Andrews done 831fca41131SWarner Losh ) 8329af130aeSWarner Losh 8339af130aeSWarner Losh CR0 "${PKGCMD} info" 8349af130aeSWarner Losh 8359af130aeSWarner Losh trap - 1 2 15 EXIT 836804b7863SWarner Losh umount ${NANO_WORLDDIR}/dev 8379af130aeSWarner Losh umount ${NANO_WORLDDIR}/_.p 838067f74c2SWarner Losh rm -xrf ${NANO_WORLDDIR}/_.p 8396b8c8deeSWill Andrews) 8406b8c8deeSWill Andrews 8416b8c8deeSWill Andrews####################################################################### 8426b8c8deeSWill Andrews# Convenience function: 8435b4ca9d7SGleb Smirnoff# Register all args as early customize function to run just before 8445b4ca9d7SGleb Smirnoff# build commences. 8455b4ca9d7SGleb Smirnoff 8465b4ca9d7SGleb Smirnoffearly_customize_cmd ( ) { 8475b4ca9d7SGleb Smirnoff NANO_EARLY_CUSTOMIZE="$NANO_EARLY_CUSTOMIZE $*" 8485b4ca9d7SGleb Smirnoff} 8495b4ca9d7SGleb Smirnoff 8505b4ca9d7SGleb Smirnoff####################################################################### 8515b4ca9d7SGleb Smirnoff# Convenience function: 8526b8c8deeSWill Andrews# Register all args as customize function. 8536b8c8deeSWill Andrews 8546b8c8deeSWill Andrewscustomize_cmd ( ) { 8556b8c8deeSWill Andrews NANO_CUSTOMIZE="$NANO_CUSTOMIZE $*" 8566b8c8deeSWill Andrews} 8576b8c8deeSWill Andrews 8586b8c8deeSWill Andrews####################################################################### 8596b8c8deeSWill Andrews# Convenience function: 8606b8c8deeSWill Andrews# Register all args as late customize function to run just before 8616b8c8deeSWill Andrews# image creation. 8626b8c8deeSWill Andrews 8636b8c8deeSWill Andrewslate_customize_cmd ( ) { 8646b8c8deeSWill Andrews NANO_LATE_CUSTOMIZE="$NANO_LATE_CUSTOMIZE $*" 8656b8c8deeSWill Andrews} 8666b8c8deeSWill Andrews 8676b8c8deeSWill Andrews####################################################################### 8686b8c8deeSWill Andrews# 8696b8c8deeSWill Andrews# All set up to go... 8706b8c8deeSWill Andrews# 8716b8c8deeSWill Andrews####################################################################### 8726b8c8deeSWill Andrews 8736b8c8deeSWill Andrews# Progress Print 8746b8c8deeSWill Andrews# Print $2 at level $1. 8756b8c8deeSWill Andrewspprint ( ) ( 8766b8c8deeSWill Andrews if [ "$1" -le $PPLEVEL ]; then 8776b8c8deeSWill Andrews runtime=$(( `date +%s` - $NANO_STARTTIME )) 8786b8c8deeSWill Andrews printf "%s %.${1}s %s\n" "`date -u -r $runtime +%H:%M:%S`" "#####" "$2" 1>&3 8796b8c8deeSWill Andrews fi 8806b8c8deeSWill Andrews) 8816b8c8deeSWill Andrews 8826b8c8deeSWill Andrewsusage ( ) { 8836b8c8deeSWill Andrews ( 884999f288aSJose Luis Duran echo "Usage: $0 [-BbfhIiKknqvWwX] [-c config_file]" 885999f288aSJose Luis Duran echo " -B suppress installs (both kernel and world)" 8866b8c8deeSWill Andrews echo " -b suppress builds (both kernel and world)" 8876b8c8deeSWill Andrews echo " -c specify config file" 888587c054bSArrigo Marchiori echo " -f suppress code slice extraction (implies -i)" 88999aa6241SMaxim Konovalov echo " -h print this help summary page" 890999f288aSJose Luis Duran echo " -I build disk image from existing build/install" 8916b8c8deeSWill Andrews echo " -i suppress disk image build" 8926b8c8deeSWill Andrews echo " -K suppress installkernel" 8936b8c8deeSWill Andrews echo " -k suppress buildkernel" 8946b8c8deeSWill Andrews echo " -n add -DNO_CLEAN to buildworld, buildkernel, etc" 8956b8c8deeSWill Andrews echo " -q make output more quiet" 8966b8c8deeSWill Andrews echo " -v make output more verbose" 897999f288aSJose Luis Duran echo " -W suppress installworld" 8986b8c8deeSWill Andrews echo " -w suppress buildworld" 89999aa6241SMaxim Konovalov echo " -X make native-xtools" 9006b8c8deeSWill Andrews ) 1>&2 9016b8c8deeSWill Andrews exit 2 9026b8c8deeSWill Andrews} 9036b8c8deeSWill Andrews 9046b8c8deeSWill Andrews####################################################################### 9056b8c8deeSWill Andrews# Setup and Export Internal variables 9066b8c8deeSWill Andrews# 9076b8c8deeSWill Andrews 908*12cbad92SJose Luis Duranexport_var ( ) { # Don't want a subshell 9096b8c8deeSWill Andrews var=$1 9106b8c8deeSWill Andrews # Lookup value of the variable. 9116b8c8deeSWill Andrews eval val=\$$var 9126b8c8deeSWill Andrews pprint 3 "Setting variable: $var=\"$val\"" 9136b8c8deeSWill Andrews export $1 9146b8c8deeSWill Andrews} 9156b8c8deeSWill Andrews 9166b8c8deeSWill Andrews# Call this function to set defaults _after_ parsing options. 917*12cbad92SJose Luis Duran# don't want a subshell otherwise variable setting is thrown away. 9186b8c8deeSWill Andrewsset_defaults_and_export ( ) { 91933008947SGleb Smirnoff : ${NANO_OBJ:=/usr/obj/nanobsd.${NANO_NAME}${NANO_LAYOUT:+.${NANO_LAYOUT}}} 920849f5467SWarner Losh : ${MAKEOBJDIRPREFIX:=${NANO_OBJ}} 9213a757adfSWarner Losh : ${NANO_DISKIMGDIR:=${NANO_OBJ}} 922c2c06cfaSWarner Losh : ${NANO_WORLDDIR:=${NANO_OBJ}/_.w} 923c2c06cfaSWarner Losh : ${NANO_LOG:=${NANO_OBJ}} 9243c5d19a4SJose Luis Duran : ${NANO_PMAKE:="${NANO_MAKE} -j ${NANO_NCPU}"} 9253c5d19a4SJose Luis Duran if ! $do_clean; then 9263c5d19a4SJose Luis Duran NANO_PMAKE="${NANO_PMAKE} -DNO_CLEAN" 9273c5d19a4SJose Luis Duran fi 9286b8c8deeSWill Andrews NANO_MAKE_CONF_BUILD=${MAKEOBJDIRPREFIX}/make.conf.build 9296b8c8deeSWill Andrews NANO_MAKE_CONF_INSTALL=${NANO_OBJ}/make.conf.install 9306b8c8deeSWill Andrews 9316b8c8deeSWill Andrews # Override user's NANO_DRIVE if they specified a NANO_LABEL 932849f5467SWarner Losh [ -n "${NANO_LABEL}" ] && NANO_DRIVE="ufs/${NANO_LABEL}" || true 9336b8c8deeSWill Andrews 9346b8c8deeSWill Andrews # Set a default NANO_TOOLS to NANO_SRC/NANO_TOOLS if it exists. 9356b8c8deeSWill Andrews [ ! -d "${NANO_TOOLS}" ] && [ -d "${NANO_SRC}/${NANO_TOOLS}" ] && \ 936c275d9ecSWarner Losh NANO_TOOLS="${NANO_SRC}/${NANO_TOOLS}" || true 937c275d9ecSWarner Losh 938849f5467SWarner Losh [ -n "${NANO_NOPRIV_BUILD}" ] && [ -z "${NANO_METALOG}" ] && \ 939c275d9ecSWarner Losh NANO_METALOG=${NANO_OBJ}/_.metalog || true 9406b8c8deeSWill Andrews 9416b8c8deeSWill Andrews NANO_STARTTIME=`date +%s` 9426b8c8deeSWill Andrews pprint 3 "Exporting NanoBSD variables" 9436b8c8deeSWill Andrews export_var MAKEOBJDIRPREFIX 9446b8c8deeSWill Andrews export_var NANO_ARCH 9456b8c8deeSWill Andrews export_var NANO_CODESIZE 9466b8c8deeSWill Andrews export_var NANO_CONFSIZE 9476b8c8deeSWill Andrews export_var NANO_CUSTOMIZE 9486b8c8deeSWill Andrews export_var NANO_DATASIZE 9496b8c8deeSWill Andrews export_var NANO_DRIVE 9506b8c8deeSWill Andrews export_var NANO_HEADS 9516b8c8deeSWill Andrews export_var NANO_IMAGES 9526b8c8deeSWill Andrews export_var NANO_IMGNAME 953df6c7936SWarner Losh export_var NANO_IMG1NAME 9546b8c8deeSWill Andrews export_var NANO_MAKE 9556b8c8deeSWill Andrews export_var NANO_MAKE_CONF_BUILD 9566b8c8deeSWill Andrews export_var NANO_MAKE_CONF_INSTALL 9576b8c8deeSWill Andrews export_var NANO_MEDIASIZE 9586b8c8deeSWill Andrews export_var NANO_NAME 9597e3a794bSWarner Losh export_var NANO_NCPU 9606b8c8deeSWill Andrews export_var NANO_NEWFS 9616b8c8deeSWill Andrews export_var NANO_OBJ 9626b8c8deeSWill Andrews export_var NANO_PMAKE 9636b8c8deeSWill Andrews export_var NANO_SECTS 9646b8c8deeSWill Andrews export_var NANO_SRC 9656b8c8deeSWill Andrews export_var NANO_TOOLS 9666b8c8deeSWill Andrews export_var NANO_WORLDDIR 9676b8c8deeSWill Andrews export_var NANO_BOOT0CFG 9686b8c8deeSWill Andrews export_var NANO_BOOTLOADER 9696b8c8deeSWill Andrews export_var NANO_LABEL 9706b8c8deeSWill Andrews export_var NANO_MODULES 971c275d9ecSWarner Losh export_var NANO_NOPRIV_BUILD 972c275d9ecSWarner Losh export_var NANO_METALOG 973c2c06cfaSWarner Losh export_var NANO_LOG 9741934c7aaSWarner Losh export_var SRCCONF 975a9d9c49fSWarner Losh export_var SRC_ENV_CONF 9766b8c8deeSWill Andrews} 977