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) 707e3a794bSWarner LoshNANO_PMAKE="make -j $NANO_NCPU" 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 164587c054bSArrigo MarchioriNANO_PARTITION_ROOT=a 165587c054bSArrigo MarchioriNANO_PARTITION_ALTROOT=a 1665e4bd293SWarner LoshNANO_ROOT=s1a 1675e4bd293SWarner LoshNANO_ALTROOT=s2a 1687b77d3eaSWarner Losh 16919edffefSWarner Losh# Default ownwership for nopriv build 17019edffefSWarner LoshNANO_DEF_UNAME=root 17119edffefSWarner LoshNANO_DEF_GNAME=wheel 1726b8c8deeSWill Andrews 1736b8c8deeSWill Andrews####################################################################### 1746b8c8deeSWill Andrews# Architecture to build. Corresponds to TARGET_ARCH in a buildworld. 1756b8c8deeSWill Andrews# Unfortunately, there's no way to set TARGET at this time, and it 176d07833f9SWarner Losh# conflates the two, so architectures where TARGET != TARGET_ARCH and 177d07833f9SWarner Losh# TARGET can't be guessed from TARGET_ARCH do not work. This defaults 178d07833f9SWarner Losh# to the arch of the current machine. 1796b8c8deeSWill AndrewsNANO_ARCH=`uname -p` 1806b8c8deeSWill Andrews 181d07833f9SWarner Losh# CPUTYPE defaults to "" which is the default when CPUTYPE isn't 182d07833f9SWarner Losh# defined. 183d07833f9SWarner LoshNANO_CPUTYPE="" 184d07833f9SWarner Losh 1856b8c8deeSWill Andrews# Directory to populate /cfg from 1866b8c8deeSWill AndrewsNANO_CFGDIR="" 1876b8c8deeSWill Andrews 1886b8c8deeSWill Andrews# Directory to populate /data from 1896b8c8deeSWill AndrewsNANO_DATADIR="" 1906b8c8deeSWill Andrews 191a9d9c49fSWarner Losh# We don't need SRCCONF or SRC_ENV_CONF. NanoBSD puts everything we 192a9d9c49fSWarner Losh# need for the build in files included with __MAKE_CONF. Override in your 193a9d9c49fSWarner Losh# config file if you really must. We set them unconditionally here, though 194a9d9c49fSWarner Losh# in case they are stray in the build environment 195a9d9c49fSWarner LoshSRCCONF=/dev/null 196a9d9c49fSWarner LoshSRC_ENV_CONF=/dev/null 1976b8c8deeSWill Andrews 198183b6feaSPoul-Henning Kamp# Comment this out if /usr/obj is a symlink 199183b6feaSPoul-Henning Kamp# CPIO_SYMLINK=--insecure 200183b6feaSPoul-Henning Kamp 2016b8c8deeSWill Andrews####################################################################### 2026b8c8deeSWill Andrews# 2036b8c8deeSWill Andrews# The functions which do the real work. 2046b8c8deeSWill Andrews# Can be overridden from the config file(s) 2056b8c8deeSWill Andrews# 2066b8c8deeSWill Andrews####################################################################### 2076b8c8deeSWill Andrews 2081934c7aaSWarner Losh# Export values into the shell. Must use { } instead of ( ) like 2091934c7aaSWarner Losh# other functions to avoid a subshell. 2101934c7aaSWarner Losh# We set __MAKE_CONF as a global since it is easier to get quoting 2111934c7aaSWarner Losh# right for paths with spaces in them. 2121934c7aaSWarner Loshmake_export ( ) { 2131934c7aaSWarner Losh # Similar to export_var, except puts the data out to stdout 2141934c7aaSWarner Losh var=$1 2151934c7aaSWarner Losh eval val=\$$var 2161934c7aaSWarner Losh echo "Setting variable: $var=\"$val\"" 2171934c7aaSWarner Losh export $1 2181934c7aaSWarner Losh} 2191934c7aaSWarner Losh 2201934c7aaSWarner Loshnano_make_build_env ( ) { 2211934c7aaSWarner Losh __MAKE_CONF="${NANO_MAKE_CONF_BUILD}" 2221934c7aaSWarner Losh make_export __MAKE_CONF 2231934c7aaSWarner Losh} 2241934c7aaSWarner Losh 2251934c7aaSWarner Loshnano_make_install_env ( ) { 2261934c7aaSWarner Losh __MAKE_CONF="${NANO_MAKE_CONF_INSTALL}" 2271934c7aaSWarner Losh make_export __MAKE_CONF 2281934c7aaSWarner Losh} 2291934c7aaSWarner Losh 2301934c7aaSWarner Losh# Extra environment variables for kernel builds 2311934c7aaSWarner Loshnano_make_kernel_env ( ) { 232a5ae1a98SGleb Smirnoff if [ -f "${NANO_KERNEL}" ] ; then 2331934c7aaSWarner Losh KERNCONFDIR="$(realpath $(dirname ${NANO_KERNEL}))" 2341934c7aaSWarner Losh KERNCONF="$(basename ${NANO_KERNEL})" 2351934c7aaSWarner Losh make_export KERNCONFDIR 2361934c7aaSWarner Losh make_export KERNCONF 2371934c7aaSWarner Losh else 2381934c7aaSWarner Losh export KERNCONF="${NANO_KERNEL}" 2391934c7aaSWarner Losh make_export KERNCONF 2401934c7aaSWarner Losh fi 2411934c7aaSWarner Losh} 2421934c7aaSWarner Losh 2431934c7aaSWarner Loshnano_global_make_env ( ) ( 244849f5467SWarner Losh # global settings for the make.conf file, if set 245849f5467SWarner Losh [ -z "${NANO_ARCH}" ] || echo TARGET_ARCH="${NANO_ARCH}" 246849f5467SWarner Losh [ -z "${NANO_CPUTYPE}" ] || echo TARGET_CPUTYPE="${NANO_CPUTYPE}" 2471934c7aaSWarner Losh) 2481934c7aaSWarner Losh 24919edffefSWarner Losh# 25019edffefSWarner Losh# Create empty files in the target tree, and record the fact. All paths 25119edffefSWarner Losh# are relative to NANO_WORLDDIR. 25219edffefSWarner Losh# 25319edffefSWarner Loshtgt_touch ( ) ( 25419edffefSWarner Losh cd "${NANO_WORLDDIR}" 25519edffefSWarner Losh for i; do 25619edffefSWarner Losh touch $i 25719edffefSWarner Losh echo "./${i} type=file" >> ${NANO_METALOG} 25819edffefSWarner Losh done 25919edffefSWarner Losh) 26019edffefSWarner Losh 26119edffefSWarner Losh# 26219edffefSWarner Losh# Convert a directory into a symlink. Takes two arguments, the 26319edffefSWarner Losh# current directory and what it should become a symlink to. The 26419edffefSWarner Losh# directory is removed and a symlink is created. If we're doing 26519edffefSWarner Losh# a nopriv build, then append this fact to the metalog 26619edffefSWarner Losh# 26719edffefSWarner Loshtgt_dir2symlink ( ) ( 26819edffefSWarner Losh dir=$1 26919edffefSWarner Losh symlink=$2 27019edffefSWarner Losh 27119edffefSWarner Losh cd "${NANO_WORLDDIR}" 272067f74c2SWarner Losh rm -xrf "$dir" 27319edffefSWarner Losh ln -s "$symlink" "$dir" 2740a852830SWarner Losh if [ -n "$NANO_METALOG" ]; then 27519edffefSWarner Losh echo "./${dir} type=link mode=0777 link=${symlink}" >> ${NANO_METALOG} 27619edffefSWarner Losh fi 27719edffefSWarner Losh) 27819edffefSWarner Losh 2796b8c8deeSWill Andrews# run in the world chroot, errors fatal 2801934c7aaSWarner LoshCR ( ) { 2811934c7aaSWarner Losh chroot "${NANO_WORLDDIR}" /bin/sh -exc "$*" 2826b8c8deeSWill Andrews} 2836b8c8deeSWill Andrews 2846b8c8deeSWill Andrews# run in the world chroot, errors not fatal 2851934c7aaSWarner LoshCR0 ( ) { 2861934c7aaSWarner Losh chroot "${NANO_WORLDDIR}" /bin/sh -c "$*" || true 2876b8c8deeSWill Andrews} 2886b8c8deeSWill Andrews 2896b8c8deeSWill Andrewsclean_build ( ) ( 2906b8c8deeSWill Andrews pprint 2 "Clean and create object directory (${MAKEOBJDIRPREFIX})" 2916b8c8deeSWill Andrews 292067f74c2SWarner Losh if ! rm -xrf ${MAKEOBJDIRPREFIX}/ > /dev/null 2>&1 ; then 2936b8c8deeSWill Andrews chflags -R noschg ${MAKEOBJDIRPREFIX}/ 294067f74c2SWarner Losh rm -xr ${MAKEOBJDIRPREFIX}/ 2956b8c8deeSWill Andrews fi 2966b8c8deeSWill Andrews) 2976b8c8deeSWill Andrews 2986b8c8deeSWill Andrewsmake_conf_build ( ) ( 2996b8c8deeSWill Andrews pprint 2 "Construct build make.conf ($NANO_MAKE_CONF_BUILD)" 3006b8c8deeSWill Andrews 3016b8c8deeSWill Andrews mkdir -p ${MAKEOBJDIRPREFIX} 3026b8c8deeSWill Andrews printenv > ${MAKEOBJDIRPREFIX}/_.env 3036b8c8deeSWill Andrews 3041934c7aaSWarner Losh # Make sure we get all the global settings that NanoBSD wants 3051934c7aaSWarner Losh # in addition to the user's global settings 3061934c7aaSWarner Losh ( 3071934c7aaSWarner Losh nano_global_make_env 3081934c7aaSWarner Losh echo "${CONF_WORLD}" 3091934c7aaSWarner Losh echo "${CONF_BUILD}" 3101934c7aaSWarner Losh ) > ${NANO_MAKE_CONF_BUILD} 3116b8c8deeSWill Andrews) 3126b8c8deeSWill Andrews 3136b8c8deeSWill Andrewsbuild_world ( ) ( 3146b8c8deeSWill Andrews pprint 2 "run buildworld" 3156b8c8deeSWill Andrews pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bw" 3166b8c8deeSWill Andrews 3171934c7aaSWarner Losh ( 3181934c7aaSWarner Losh nano_make_build_env 3191934c7aaSWarner Losh set -o xtrace 3201934c7aaSWarner Losh cd "${NANO_SRC}" 3211934c7aaSWarner Losh ${NANO_PMAKE} buildworld 3221934c7aaSWarner Losh ) > ${MAKEOBJDIRPREFIX}/_.bw 2>&1 3236b8c8deeSWill Andrews) 3246b8c8deeSWill Andrews 3256b8c8deeSWill Andrewsbuild_kernel ( ) ( 3266b8c8deeSWill Andrews pprint 2 "build kernel ($NANO_KERNEL)" 3276b8c8deeSWill Andrews pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bk" 3286b8c8deeSWill Andrews 3296b8c8deeSWill Andrews ( 3301934c7aaSWarner Losh nano_make_build_env 3311934c7aaSWarner Losh nano_make_kernel_env 3326b8c8deeSWill Andrews 3336b8c8deeSWill Andrews # Note: We intentionally build all modules, not only the ones in 3346b8c8deeSWill Andrews # NANO_MODULES so the built world can be reused by multiple images. 335bd0ca238SPedro F. Giffuni # Although MODULES_OVERRIDE can be defined in the kernel config 3361934c7aaSWarner Losh # file to override this behavior. Just set NANO_MODULES=default. 3371934c7aaSWarner Losh set -o xtrace 3381934c7aaSWarner Losh cd "${NANO_SRC}" 3391934c7aaSWarner Losh ${NANO_PMAKE} buildkernel 3406b8c8deeSWill Andrews ) > ${MAKEOBJDIRPREFIX}/_.bk 2>&1 3416b8c8deeSWill Andrews) 3426b8c8deeSWill Andrews 3436b8c8deeSWill Andrewsclean_world ( ) ( 3446b8c8deeSWill Andrews if [ "${NANO_OBJ}" != "${MAKEOBJDIRPREFIX}" ]; then 3456b8c8deeSWill Andrews pprint 2 "Clean and create object directory (${NANO_OBJ})" 346067f74c2SWarner Losh if ! rm -xrf ${NANO_OBJ}/ > /dev/null 2>&1 ; then 3476b8c8deeSWill Andrews chflags -R noschg ${NANO_OBJ} 348067f74c2SWarner Losh rm -xr ${NANO_OBJ}/ 3496b8c8deeSWill Andrews fi 3501934c7aaSWarner Losh mkdir -p "${NANO_OBJ}" "${NANO_WORLDDIR}" 351c2c06cfaSWarner Losh printenv > ${NANO_LOG}/_.env 3526b8c8deeSWill Andrews else 3536b8c8deeSWill Andrews pprint 2 "Clean and create world directory (${NANO_WORLDDIR})" 354067f74c2SWarner Losh if ! rm -xrf "${NANO_WORLDDIR}/" > /dev/null 2>&1 ; then 3551934c7aaSWarner Losh chflags -R noschg "${NANO_WORLDDIR}" 356067f74c2SWarner Losh rm -xrf "${NANO_WORLDDIR}/" 3576b8c8deeSWill Andrews fi 3581934c7aaSWarner Losh mkdir -p "${NANO_WORLDDIR}" 3596b8c8deeSWill Andrews fi 3606b8c8deeSWill Andrews) 3616b8c8deeSWill Andrews 3626b8c8deeSWill Andrewsmake_conf_install ( ) ( 3636b8c8deeSWill Andrews pprint 2 "Construct install make.conf ($NANO_MAKE_CONF_INSTALL)" 3646b8c8deeSWill Andrews 3651934c7aaSWarner Losh # Make sure we get all the global settings that NanoBSD wants 3661934c7aaSWarner Losh # in addition to the user's global settings 3671934c7aaSWarner Losh ( 3681934c7aaSWarner Losh nano_global_make_env 3691934c7aaSWarner Losh echo "${CONF_WORLD}" 3701934c7aaSWarner Losh echo "${CONF_INSTALL}" 371849f5467SWarner Losh if [ -n "${NANO_NOPRIV_BUILD}" ]; then 372c275d9ecSWarner Losh echo NO_ROOT=t 373c275d9ecSWarner Losh echo METALOG=${NANO_METALOG} 374c275d9ecSWarner Losh fi 3751934c7aaSWarner Losh ) > ${NANO_MAKE_CONF_INSTALL} 3766b8c8deeSWill Andrews) 3776b8c8deeSWill Andrews 3786b8c8deeSWill Andrewsinstall_world ( ) ( 3796b8c8deeSWill Andrews pprint 2 "installworld" 380c2c06cfaSWarner Losh pprint 3 "log: ${NANO_LOG}/_.iw" 3816b8c8deeSWill Andrews 3821934c7aaSWarner Losh ( 3831934c7aaSWarner Losh nano_make_install_env 3841934c7aaSWarner Losh set -o xtrace 3851934c7aaSWarner Losh cd "${NANO_SRC}" 3866ba33ab5SWarner Losh ${NANO_MAKE} installworld DESTDIR="${NANO_WORLDDIR}" DB_FROM_SRC=yes 3871934c7aaSWarner Losh chflags -R noschg "${NANO_WORLDDIR}" 388c2c06cfaSWarner Losh ) > ${NANO_LOG}/_.iw 2>&1 3896b8c8deeSWill Andrews) 3906b8c8deeSWill Andrews 3916b8c8deeSWill Andrewsinstall_etc ( ) ( 3926b8c8deeSWill Andrews pprint 2 "install /etc" 393c2c06cfaSWarner Losh pprint 3 "log: ${NANO_LOG}/_.etc" 3946b8c8deeSWill Andrews 3951934c7aaSWarner Losh ( 3961934c7aaSWarner Losh nano_make_install_env 3971934c7aaSWarner Losh set -o xtrace 3981934c7aaSWarner Losh cd "${NANO_SRC}" 3996ba33ab5SWarner Losh ${NANO_MAKE} distribution DESTDIR="${NANO_WORLDDIR}" DB_FROM_SRC=yes 4006b8c8deeSWill Andrews # make.conf doesn't get created by default, but some ports need it 4016b8c8deeSWill Andrews # so they can spam it. 4021934c7aaSWarner Losh cp /dev/null "${NANO_WORLDDIR}"/etc/make.conf 403c2c06cfaSWarner Losh ) > ${NANO_LOG}/_.etc 2>&1 4046b8c8deeSWill Andrews) 4056b8c8deeSWill Andrews 4066b8c8deeSWill Andrewsinstall_kernel ( ) ( 4076b8c8deeSWill Andrews pprint 2 "install kernel ($NANO_KERNEL)" 408c2c06cfaSWarner Losh pprint 3 "log: ${NANO_LOG}/_.ik" 4096b8c8deeSWill Andrews 4106b8c8deeSWill Andrews ( 4116b8c8deeSWill Andrews 4121934c7aaSWarner Losh nano_make_install_env 4131934c7aaSWarner Losh nano_make_kernel_env 4141934c7aaSWarner Losh 4156b8c8deeSWill Andrews if [ "${NANO_MODULES}" != "default" ]; then 4161934c7aaSWarner Losh MODULES_OVERRIDE="${NANO_MODULES}" 4171934c7aaSWarner Losh make_export MODULES_OVERRIDE 4186b8c8deeSWill Andrews fi 4196b8c8deeSWill Andrews 4201934c7aaSWarner Losh set -o xtrace 4211934c7aaSWarner Losh cd "${NANO_SRC}" 4226ba33ab5SWarner Losh ${NANO_MAKE} installkernel DESTDIR="${NANO_WORLDDIR}" DB_FROM_SRC=yes 4231934c7aaSWarner Losh 424c2c06cfaSWarner Losh ) > ${NANO_LOG}/_.ik 2>&1 4256b8c8deeSWill Andrews) 4266b8c8deeSWill Andrews 4276b8c8deeSWill Andrewsnative_xtools ( ) ( 428e6eb94a8SGuido Falsi pprint 2 "Installing the optimized native build tools for cross env" 429c2c06cfaSWarner Losh pprint 3 "log: ${NANO_LOG}/_.native_xtools" 4306b8c8deeSWill Andrews 4311934c7aaSWarner Losh ( 4321934c7aaSWarner Losh 4331934c7aaSWarner Losh nano_make_install_env 4341934c7aaSWarner Losh set -o xtrace 4351934c7aaSWarner Losh cd "${NANO_SRC}" 4369a0c5c4cSBryan Drewery ${NANO_MAKE} native-xtools 4379a0c5c4cSBryan Drewery ${NANO_MAKE} native-xtools-install DESTDIR="${NANO_WORLDDIR}" 4381934c7aaSWarner Losh 439c2c06cfaSWarner Losh ) > ${NANO_LOG}/_.native_xtools 2>&1 4406b8c8deeSWill Andrews) 4416b8c8deeSWill Andrews 44219edffefSWarner Losh# 4435b4ca9d7SGleb Smirnoff# Run the requested set of early customization scripts, run before 4445b4ca9d7SGleb Smirnoff# buildworld. 4455b4ca9d7SGleb Smirnoff# 4465b4ca9d7SGleb Smirnoffrun_early_customize ( ) { 4475b4ca9d7SGleb Smirnoff pprint 2 "run early customize scripts" 4485b4ca9d7SGleb Smirnoff for c in $NANO_EARLY_CUSTOMIZE 4495b4ca9d7SGleb Smirnoff do 4505b4ca9d7SGleb Smirnoff pprint 2 "early customize \"$c\"" 4515b4ca9d7SGleb Smirnoff pprint 3 "log: ${NANO_LOG}/_.early_cust.$c" 4525b4ca9d7SGleb Smirnoff pprint 4 "`type $c`" 453b4d3716bSWarner Losh { t=$(set -o | awk '$1 == "xtrace" && $2 == "off" { print "set +o xtrace"}'); 454b4d3716bSWarner Losh set -o xtrace ; 45504b9e947SWarner Losh $c ; 45604b9e947SWarner Losh eval $t 45704b9e947SWarner Losh } >${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`" 474b4d3716bSWarner Losh ( set -o xtrace ; $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`" 489b4d3716bSWarner Losh ( set -o xtrace ; $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 531183b6feaSPoul-Henning Kamp find . -print | cpio ${CPIO_SYMLINK} -dumpl ../../../etc/local 5326b8c8deeSWill Andrews cd .. 533067f74c2SWarner Losh rm -xrf etc 5346b8c8deeSWill Andrews ) 5356b8c8deeSWill Andrews fi 5366b8c8deeSWill Andrews 53707f2d905SWarner Losh # Always setup the usr/local/etc -> etc/local symlink. 53807f2d905SWarner Losh # usr/local/etc gets created by packages, but if no packages 53907f2d905SWarner Losh # are installed by this point, but are later in the process, 54007f2d905SWarner Losh # the symlink not being here causes problems. It never hurts 54107f2d905SWarner Losh # to have the symlink in error though. 54207f2d905SWarner Losh ln -s ../../etc/local usr/local/etc 54307f2d905SWarner 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 550183b6feaSPoul-Henning Kamp find $d -print | cpio ${CPIO_SYMLINK} -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 58907f2d905SWarner Losh 59007f2d905SWarner Losh # Create directory for eventual /usr/local/etc contents 59107f2d905SWarner 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}" 631183b6feaSPoul-Henning Kamp find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)/' | cpio ${CPIO_SYMLINK} -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 ( ) ( 73073358cd2SJose Luis Duran sed -i "" -E 's/^#?PermitRootLogin.*/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" 739183b6feaSPoul-Henning Kamp find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)/' | cpio ${CPIO_SYMLINK} -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" 7527d608e53SWarner Losh local PKGCMD="env BATCH=YES 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 780804b7863SWarner Losh mount -t devfs devfs ${NANO_WORLDDIR}/dev 7816b8c8deeSWill Andrews 782067f74c2SWarner Losh trap "umount ${NANO_WORLDDIR}/dev; umount ${NANO_WORLDDIR}/_.p ; rm -xrf ${NANO_WORLDDIR}/_.p" 1 2 15 EXIT 7836b8c8deeSWill Andrews 784fca41131SWarner Losh # Install pkg-* package 785fca41131SWarner Losh CR "${PKGCMD} add /_.p/${_NANO_PKG_PACKAGE}" 786fca41131SWarner Losh 787fca41131SWarner Losh ( 788fca41131SWarner Losh # Expand any glob characters in pacakge list 789fca41131SWarner Losh cd "${NANO_PACKAGE_DIR}" 790fca41131SWarner Losh _PKGS=`find ${NANO_PACKAGE_LIST} -not -name "${_NANO_PKG_PACKAGE}" -print | sort | uniq` 791fca41131SWarner Losh 792fca41131SWarner Losh # Show todo 793fca41131SWarner Losh todo=`echo "$_PKGS" | wc -l` 7946b8c8deeSWill Andrews echo "=== TODO: $todo" 795fca41131SWarner Losh echo "$_PKGS" 7966b8c8deeSWill Andrews echo "===" 797fca41131SWarner Losh 798fca41131SWarner Losh # Install packages 799fca41131SWarner Losh for _PKG in $_PKGS; do 8009af130aeSWarner Losh CR "${PKGCMD} add /_.p/${_PKG}" 8016b8c8deeSWill Andrews done 802fca41131SWarner Losh ) 8039af130aeSWarner Losh 8049af130aeSWarner Losh CR0 "${PKGCMD} info" 8059af130aeSWarner Losh 8069af130aeSWarner Losh trap - 1 2 15 EXIT 807804b7863SWarner Losh umount ${NANO_WORLDDIR}/dev 8089af130aeSWarner Losh umount ${NANO_WORLDDIR}/_.p 809067f74c2SWarner Losh rm -xrf ${NANO_WORLDDIR}/_.p 8106b8c8deeSWill Andrews) 8116b8c8deeSWill Andrews 8126b8c8deeSWill Andrews####################################################################### 8136b8c8deeSWill Andrews# Convenience function: 8145b4ca9d7SGleb Smirnoff# Register all args as early customize function to run just before 8155b4ca9d7SGleb Smirnoff# build commences. 8165b4ca9d7SGleb Smirnoff 8175b4ca9d7SGleb Smirnoffearly_customize_cmd ( ) { 8185b4ca9d7SGleb Smirnoff NANO_EARLY_CUSTOMIZE="$NANO_EARLY_CUSTOMIZE $*" 8195b4ca9d7SGleb Smirnoff} 8205b4ca9d7SGleb Smirnoff 8215b4ca9d7SGleb Smirnoff####################################################################### 8225b4ca9d7SGleb Smirnoff# Convenience function: 8236b8c8deeSWill Andrews# Register all args as customize function. 8246b8c8deeSWill Andrews 8256b8c8deeSWill Andrewscustomize_cmd ( ) { 8266b8c8deeSWill Andrews NANO_CUSTOMIZE="$NANO_CUSTOMIZE $*" 8276b8c8deeSWill Andrews} 8286b8c8deeSWill Andrews 8296b8c8deeSWill Andrews####################################################################### 8306b8c8deeSWill Andrews# Convenience function: 8316b8c8deeSWill Andrews# Register all args as late customize function to run just before 8326b8c8deeSWill Andrews# image creation. 8336b8c8deeSWill Andrews 8346b8c8deeSWill Andrewslate_customize_cmd ( ) { 8356b8c8deeSWill Andrews NANO_LATE_CUSTOMIZE="$NANO_LATE_CUSTOMIZE $*" 8366b8c8deeSWill Andrews} 8376b8c8deeSWill Andrews 8386b8c8deeSWill Andrews####################################################################### 8396b8c8deeSWill Andrews# 8406b8c8deeSWill Andrews# All set up to go... 8416b8c8deeSWill Andrews# 8426b8c8deeSWill Andrews####################################################################### 8436b8c8deeSWill Andrews 8446b8c8deeSWill Andrews# Progress Print 8456b8c8deeSWill Andrews# Print $2 at level $1. 8466b8c8deeSWill Andrewspprint ( ) ( 8476b8c8deeSWill Andrews if [ "$1" -le $PPLEVEL ]; then 8486b8c8deeSWill Andrews runtime=$(( `date +%s` - $NANO_STARTTIME )) 8496b8c8deeSWill Andrews printf "%s %.${1}s %s\n" "`date -u -r $runtime +%H:%M:%S`" "#####" "$2" 1>&3 8506b8c8deeSWill Andrews fi 8516b8c8deeSWill Andrews) 8526b8c8deeSWill Andrews 8536b8c8deeSWill Andrewsusage ( ) { 8546b8c8deeSWill Andrews ( 85599aa6241SMaxim Konovalov echo "Usage: $0 [-bfhiKknqvwX] [-c config_file]" 8566b8c8deeSWill Andrews echo " -b suppress builds (both kernel and world)" 8576b8c8deeSWill Andrews echo " -c specify config file" 858587c054bSArrigo Marchiori echo " -f suppress code slice extraction (implies -i)" 85999aa6241SMaxim Konovalov echo " -h print this help summary page" 8606b8c8deeSWill Andrews echo " -i suppress disk image build" 8616b8c8deeSWill Andrews echo " -K suppress installkernel" 8626b8c8deeSWill Andrews echo " -k suppress buildkernel" 8636b8c8deeSWill Andrews echo " -n add -DNO_CLEAN to buildworld, buildkernel, etc" 8646b8c8deeSWill Andrews echo " -q make output more quiet" 8656b8c8deeSWill Andrews echo " -v make output more verbose" 8666b8c8deeSWill Andrews echo " -w suppress buildworld" 86799aa6241SMaxim Konovalov echo " -X make native-xtools" 8686b8c8deeSWill Andrews ) 1>&2 8696b8c8deeSWill Andrews exit 2 8706b8c8deeSWill Andrews} 8716b8c8deeSWill Andrews 8726b8c8deeSWill Andrews####################################################################### 8736b8c8deeSWill Andrews# Setup and Export Internal variables 8746b8c8deeSWill Andrews# 8756b8c8deeSWill Andrews 8761934c7aaSWarner Loshexport_var ( ) { # Don't wawnt a subshell 8776b8c8deeSWill Andrews var=$1 8786b8c8deeSWill Andrews # Lookup value of the variable. 8796b8c8deeSWill Andrews eval val=\$$var 8806b8c8deeSWill Andrews pprint 3 "Setting variable: $var=\"$val\"" 8816b8c8deeSWill Andrews export $1 8826b8c8deeSWill Andrews} 8836b8c8deeSWill Andrews 8846b8c8deeSWill Andrews# Call this function to set defaults _after_ parsing options. 8851934c7aaSWarner Losh# dont want a subshell otherwise variable setting is thrown away. 8866b8c8deeSWill Andrewsset_defaults_and_export ( ) { 88733008947SGleb Smirnoff : ${NANO_OBJ:=/usr/obj/nanobsd.${NANO_NAME}${NANO_LAYOUT:+.${NANO_LAYOUT}}} 888849f5467SWarner Losh : ${MAKEOBJDIRPREFIX:=${NANO_OBJ}} 8893a757adfSWarner Losh : ${NANO_DISKIMGDIR:=${NANO_OBJ}} 890c2c06cfaSWarner Losh : ${NANO_WORLDDIR:=${NANO_OBJ}/_.w} 891c2c06cfaSWarner Losh : ${NANO_LOG:=${NANO_OBJ}} 8926b8c8deeSWill Andrews NANO_MAKE_CONF_BUILD=${MAKEOBJDIRPREFIX}/make.conf.build 8936b8c8deeSWill Andrews NANO_MAKE_CONF_INSTALL=${NANO_OBJ}/make.conf.install 8946b8c8deeSWill Andrews 8956b8c8deeSWill Andrews # Override user's NANO_DRIVE if they specified a NANO_LABEL 896849f5467SWarner Losh [ -n "${NANO_LABEL}" ] && NANO_DRIVE="ufs/${NANO_LABEL}" || true 8976b8c8deeSWill Andrews 8986b8c8deeSWill Andrews # Set a default NANO_TOOLS to NANO_SRC/NANO_TOOLS if it exists. 8996b8c8deeSWill Andrews [ ! -d "${NANO_TOOLS}" ] && [ -d "${NANO_SRC}/${NANO_TOOLS}" ] && \ 900c275d9ecSWarner Losh NANO_TOOLS="${NANO_SRC}/${NANO_TOOLS}" || true 901c275d9ecSWarner Losh 902849f5467SWarner Losh [ -n "${NANO_NOPRIV_BUILD}" ] && [ -z "${NANO_METALOG}" ] && \ 903c275d9ecSWarner Losh NANO_METALOG=${NANO_OBJ}/_.metalog || true 9046b8c8deeSWill Andrews 9056b8c8deeSWill Andrews NANO_STARTTIME=`date +%s` 9066b8c8deeSWill Andrews pprint 3 "Exporting NanoBSD variables" 9076b8c8deeSWill Andrews export_var MAKEOBJDIRPREFIX 9086b8c8deeSWill Andrews export_var NANO_ARCH 9096b8c8deeSWill Andrews export_var NANO_CODESIZE 9106b8c8deeSWill Andrews export_var NANO_CONFSIZE 9116b8c8deeSWill Andrews export_var NANO_CUSTOMIZE 9126b8c8deeSWill Andrews export_var NANO_DATASIZE 9136b8c8deeSWill Andrews export_var NANO_DRIVE 9146b8c8deeSWill Andrews export_var NANO_HEADS 9156b8c8deeSWill Andrews export_var NANO_IMAGES 9166b8c8deeSWill Andrews export_var NANO_IMGNAME 917df6c7936SWarner Losh export_var NANO_IMG1NAME 9186b8c8deeSWill Andrews export_var NANO_MAKE 9196b8c8deeSWill Andrews export_var NANO_MAKE_CONF_BUILD 9206b8c8deeSWill Andrews export_var NANO_MAKE_CONF_INSTALL 9216b8c8deeSWill Andrews export_var NANO_MEDIASIZE 9226b8c8deeSWill Andrews export_var NANO_NAME 9237e3a794bSWarner Losh export_var NANO_NCPU 9246b8c8deeSWill Andrews export_var NANO_NEWFS 9256b8c8deeSWill Andrews export_var NANO_OBJ 9266b8c8deeSWill Andrews export_var NANO_PMAKE 9276b8c8deeSWill Andrews export_var NANO_SECTS 9286b8c8deeSWill Andrews export_var NANO_SRC 9296b8c8deeSWill Andrews export_var NANO_TOOLS 9306b8c8deeSWill Andrews export_var NANO_WORLDDIR 9316b8c8deeSWill Andrews export_var NANO_BOOT0CFG 9326b8c8deeSWill Andrews export_var NANO_BOOTLOADER 9336b8c8deeSWill Andrews export_var NANO_LABEL 9346b8c8deeSWill Andrews export_var NANO_MODULES 935c275d9ecSWarner Losh export_var NANO_NOPRIV_BUILD 936c275d9ecSWarner Losh export_var NANO_METALOG 937c2c06cfaSWarner Losh export_var NANO_LOG 9381934c7aaSWarner Losh export_var SRCCONF 939a9d9c49fSWarner Losh export_var SRC_ENV_CONF 9406b8c8deeSWill Andrews} 941