nanobsd.sh revision 183314
1#!/bin/sh 2# 3# Copyright (c) 2005 Poul-Henning Kamp. 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# 27# $FreeBSD: head/tools/tools/nanobsd/nanobsd.sh 183314 2008-09-23 18:42:35Z simon $ 28# 29 30set -e 31 32####################################################################### 33# 34# Setup default values for all controlling variables. 35# These values can be overridden from the config file(s) 36# 37####################################################################### 38 39# Name of this NanoBSD build. (Used to construct workdir names) 40NANO_NAME=full 41 42# Source tree directory 43NANO_SRC=/usr/src 44 45# Where nanobsd additional files live under the source tree 46NANO_TOOLS=tools/tools/nanobsd 47 48# Where cust_pkg() finds packages to install 49NANO_PACKAGE_DIR=${NANO_SRC}/${NANO_TOOLS}/Pkg 50 51# Object tree directory 52# default is subdir of /usr/obj 53# XXX: MAKEOBJDIRPREFIX handling... ? 54#NANO_OBJ="" 55 56# The directory to put the final images 57# default is ${NANO_OBJ} 58#NANO_DISKIMGDIR="" 59 60# Parallel Make 61NANO_PMAKE="make -j 3" 62 63# The default name for any image we create. 64NANO_IMGNAME="_.disk.full" 65 66# Options to put in make.conf during buildworld only 67CONF_BUILD=' ' 68 69# Options to put in make.conf during installworld only 70CONF_INSTALL=' ' 71 72# Options to put in make.conf during both build- & installworld. 73CONF_WORLD=' ' 74 75# Kernel config file to use 76NANO_KERNEL=GENERIC 77 78# Customize commands. 79NANO_CUSTOMIZE="" 80 81# Late customize commands. 82NANO_LATE_CUSTOMIZE="" 83 84# Newfs paramters to use 85NANO_NEWFS="-b 4096 -f 512 -i 8192 -O1 -U" 86 87# The drive name of the media at runtime 88NANO_DRIVE=ad0 89 90# Target media size in 512 bytes sectors 91NANO_MEDIASIZE=1200000 92 93# Number of code images on media (1 or 2) 94NANO_IMAGES=2 95 96# 0 -> Leave second image all zeroes so it compresses better. 97# 1 -> Initialize second image with a copy of the first 98NANO_INIT_IMG2=1 99 100# Size of code file system in 512 bytes sectors 101# If zero, size will be as large as possible. 102NANO_CODESIZE=0 103 104# Size of configuration file system in 512 bytes sectors 105# Cannot be zero. 106NANO_CONFSIZE=2048 107 108# Size of data file system in 512 bytes sectors 109# If zero: no partition configured. 110# If negative: max size possible 111NANO_DATASIZE=0 112 113# Size of the /etc ramdisk in 512 bytes sectors 114NANO_RAM_ETCSIZE=10240 115 116# Size of the /tmp+/var ramdisk in 512 bytes sectors 117NANO_RAM_TMPVARSIZE=10240 118 119# Media geometry, only relevant if bios doesn't understand LBA. 120NANO_SECTS=63 121NANO_HEADS=16 122 123# boot0 flags/options and configuration 124NANO_BOOT0CFG="-o packet -s 1 -m 3" 125NANO_BOOTLOADER="boot/boot0sio" 126 127# Backing type of md(4) device 128# Can be "file" or "swap" 129NANO_MD_BACKING="file" 130 131# Progress Print level 132PPLEVEL=3 133 134####################################################################### 135# Not a variable at this time 136 137NANO_ARCH=i386 138 139####################################################################### 140# 141# The functions which do the real work. 142# Can be overridden from the config file(s) 143# 144####################################################################### 145 146clean_build ( ) ( 147 pprint 2 "Clean and create object directory (${MAKEOBJDIRPREFIX})" 148 149 if rm -rf ${MAKEOBJDIRPREFIX} > /dev/null 2>&1 ; then 150 true 151 else 152 chflags -R noschg ${MAKEOBJDIRPREFIX} 153 rm -rf ${MAKEOBJDIRPREFIX} 154 fi 155 mkdir -p ${MAKEOBJDIRPREFIX} 156 printenv > ${MAKEOBJDIRPREFIX}/_.env 157) 158 159make_conf_build ( ) ( 160 pprint 2 "Construct build make.conf ($NANO_MAKE_CONF)" 161 162 echo "${CONF_WORLD}" > ${NANO_MAKE_CONF} 163 echo "${CONF_BUILD}" >> ${NANO_MAKE_CONF} 164) 165 166build_world ( ) ( 167 pprint 2 "run buildworld" 168 pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bw" 169 170 cd ${NANO_SRC} 171 env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} \ 172 __MAKE_CONF=${NANO_MAKE_CONF} buildworld \ 173 > ${MAKEOBJDIRPREFIX}/_.bw 2>&1 174) 175 176build_kernel ( ) ( 177 pprint 2 "build kernel ($NANO_KERNEL)" 178 pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bk" 179 180 if [ -f ${NANO_KERNEL} ] ; then 181 cp ${NANO_KERNEL} ${NANO_SRC}/sys/${NANO_ARCH}/conf 182 fi 183 184 (cd ${NANO_SRC}; 185 # unset these just in case to avoid compiler complaints 186 # when cross-building 187 unset TARGET_CPUTYPE 188 unset TARGET_BIG_ENDIAN 189 env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} buildkernel \ 190 __MAKE_CONF=${NANO_MAKE_CONF} KERNCONF=`basename ${NANO_KERNEL}` \ 191 > ${MAKEOBJDIRPREFIX}/_.bk 2>&1 192 ) 193) 194 195clean_world ( ) ( 196 pprint 2 "Clean and create world directory (${NANO_WORLDDIR})" 197 if rm -rf ${NANO_WORLDDIR}/ > /dev/null 2>&1 ; then 198 true 199 else 200 chflags -R noschg ${NANO_WORLDDIR}/ 201 rm -rf ${NANO_WORLDDIR}/ 202 fi 203 mkdir -p ${NANO_WORLDDIR}/ 204) 205 206make_conf_install ( ) ( 207 pprint 2 "Construct install make.conf ($NANO_MAKE_CONF)" 208 209 echo "${CONF_WORLD}" > ${NANO_MAKE_CONF} 210 echo "${CONF_INSTALL}" >> ${NANO_MAKE_CONF} 211) 212 213install_world ( ) ( 214 pprint 2 "installworld" 215 pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.iw" 216 217 cd ${NANO_SRC} 218 env TARGET_ARCH=${NANO_ARCH} \ 219 ${NANO_PMAKE} __MAKE_CONF=${NANO_MAKE_CONF} installworld \ 220 DESTDIR=${NANO_WORLDDIR} \ 221 > ${MAKEOBJDIRPREFIX}/_.iw 2>&1 222 chflags -R noschg ${NANO_WORLDDIR} 223) 224 225install_etc ( ) ( 226 227 pprint 2 "install /etc" 228 pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.etc" 229 230 cd ${NANO_SRC} 231 env TARGET_ARCH=${NANO_ARCH} \ 232 ${NANO_PMAKE} __MAKE_CONF=${NANO_MAKE_CONF} distribution \ 233 DESTDIR=${NANO_WORLDDIR} \ 234 > ${MAKEOBJDIRPREFIX}/_.etc 2>&1 235) 236 237install_kernel ( ) ( 238 pprint 2 "install kernel" 239 pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.ik" 240 241 cd ${NANO_SRC} 242 env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} installkernel \ 243 DESTDIR=${NANO_WORLDDIR} \ 244 __MAKE_CONF=${NANO_MAKE_CONF} KERNCONF=`basename ${NANO_KERNEL}` \ 245 > ${MAKEOBJDIRPREFIX}/_.ik 2>&1 246) 247 248run_customize() ( 249 250 pprint 2 "run customize scripts" 251 for c in $NANO_CUSTOMIZE 252 do 253 pprint 2 "customize \"$c\"" 254 pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.cust.$c" 255 pprint 4 "`type $c`" 256 ( $c ) > ${MAKEOBJDIRPREFIX}/_.cust.$c 2>&1 257 done 258) 259 260run_late_customize() ( 261 262 pprint 2 "run late customize scripts" 263 for c in $NANO_LATE_CUSTOMIZE 264 do 265 pprint 2 "late customize \"$c\"" 266 pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.late_cust.$c" 267 pprint 4 "`type $c`" 268 ( $c ) > ${MAKEOBJDIRPREFIX}/_.late_cust.$c 2>&1 269 done 270) 271 272setup_nanobsd ( ) ( 273 pprint 2 "configure nanobsd setup" 274 pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.dl" 275 276 ( 277 cd ${NANO_WORLDDIR} 278 279 # Move /usr/local/etc to /etc/local so that the /cfg stuff 280 # can stomp on it. Otherwise packages like ipsec-tools which 281 # have hardcoded paths under ${prefix}/etc are not tweakable. 282 if [ -d usr/local/etc ] ; then 283 ( 284 mkdir etc/local 285 cd usr/local/etc 286 find . -print | cpio -dumpl ../../../etc/local 287 cd .. 288 rm -rf etc 289 ln -s ../../etc/local etc 290 ) 291 fi 292 293 for d in var etc 294 do 295 # link /$d under /conf 296 # we use hard links so we have them both places. 297 # the files in /$d will be hidden by the mount. 298 # XXX: configure /$d ramdisk size 299 mkdir -p conf/base/$d conf/default/$d 300 find $d -print | cpio -dumpl conf/base/ 301 done 302 303 echo "$NANO_RAM_ETCSIZE" > conf/base/etc/md_size 304 echo "$NANO_RAM_TMPVARSIZE" > conf/base/var/md_size 305 306 # pick up config files from the special partition 307 echo "mount -o ro /dev/${NANO_DRIVE}s3" > conf/default/etc/remount 308 309 # Put /tmp on the /var ramdisk (could be symlink already) 310 rmdir tmp || true 311 rm tmp || true 312 ln -s var/tmp tmp 313 314 ) > ${MAKEOBJDIRPREFIX}/_.dl 2>&1 315) 316 317setup_nanobsd_etc ( ) ( 318 pprint 2 "configure nanobsd /etc" 319 320 ( 321 cd ${NANO_WORLDDIR} 322 323 # create diskless marker file 324 touch etc/diskless 325 326 # Make root filesystem R/O by default 327 echo "root_rw_mount=NO" >> etc/defaults/rc.conf 328 329 # save config file for scripts 330 echo "NANO_DRIVE=${NANO_DRIVE}" > etc/nanobsd.conf 331 332 echo "/dev/${NANO_DRIVE}s1a / ufs ro 1 1" > etc/fstab 333 echo "/dev/${NANO_DRIVE}s3 /cfg ufs rw,noauto 2 2" >> etc/fstab 334 mkdir -p cfg 335 ) 336) 337 338prune_usr() ( 339 340 # Remove all empty directories in /usr 341 find ${NANO_WORLDDIR}/usr -type d -depth -print | 342 while read d 343 do 344 rmdir $d > /dev/null 2>&1 || true 345 done 346) 347 348create_i386_diskimage ( ) ( 349 pprint 2 "build diskimage" 350 pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.di" 351 352 ( 353 echo $NANO_MEDIASIZE $NANO_IMAGES \ 354 $NANO_SECTS $NANO_HEADS \ 355 $NANO_CODESIZE $NANO_CONFSIZE $NANO_DATASIZE | 356 awk ' 357 { 358 printf "# %s\n", $0 359 360 # size of cylinder in sectors 361 cs = $3 * $4 362 363 # number of full cylinders on media 364 cyl = int ($1 / cs) 365 366 # output fdisk geometry spec, truncate cyls to 1023 367 if (cyl <= 1023) 368 print "g c" cyl " h" $4 " s" $3 369 else 370 print "g c" 1023 " h" $4 " s" $3 371 372 if ($7 > 0) { 373 # size of data partition in full cylinders 374 dsl = int (($7 + cs - 1) / cs) 375 } else { 376 dsl = 0; 377 } 378 379 # size of config partition in full cylinders 380 csl = int (($6 + cs - 1) / cs) 381 382 if ($5 == 0) { 383 # size of image partition(s) in full cylinders 384 isl = int ((cyl - dsl - csl) / $2) 385 } else { 386 isl = int (($5 + cs - 1) / cs) 387 } 388 389 # First image partition start at second track 390 print "p 1 165 " $3, isl * cs - $3 391 c = isl * cs; 392 393 # Second image partition (if any) also starts offset one 394 # track to keep them identical. 395 if ($2 > 1) { 396 print "p 2 165 " $3 + c, isl * cs - $3 397 c += isl * cs; 398 } 399 400 # Config partition starts at cylinder boundary. 401 print "p 3 165 " c, csl * cs 402 c += csl * cs 403 404 # Data partition (if any) starts at cylinder boundary. 405 if ($7 > 0) { 406 print "p 4 165 " c, dsl * cs 407 } else if ($7 < 0 && $1 > c) { 408 print "p 4 165 " c, $1 - c 409 } else if ($1 < c) { 410 print "Disk space overcommitted by", \ 411 c - $1, "sectors" > "/dev/stderr" 412 exit 2 413 } 414 415 # Force slice 1 to be marked active. This is necessary 416 # for booting the image from a USB device to work. 417 print "a 1" 418 } 419 ' > ${MAKEOBJDIRPREFIX}/_.fdisk 420 421 IMG=${NANO_DISKIMGDIR}/${NANO_IMGNAME} 422 MNT=${MAKEOBJDIRPREFIX}/_.mnt 423 mkdir -p ${MNT} 424 425 if [ "${NANO_MD_BACKING}" = "swap" ] ; then 426 MD=`mdconfig -a -t swap -s ${NANO_MEDIASIZE} -x ${NANO_SECTS} \ 427 -y ${NANO_HEADS}` 428 else 429 echo "Creating md backing file..." 430 dd if=/dev/zero of=${IMG} bs=${NANO_SECTS}b \ 431 count=`expr ${NANO_MEDIASIZE} / ${NANO_SECTS}` 432 MD=`mdconfig -a -t vnode -f ${IMG} -x ${NANO_SECTS} \ 433 -y ${NANO_HEADS}` 434 fi 435 436 trap "df -i ${MNT} ; umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT 437 438 fdisk -i -f ${MAKEOBJDIRPREFIX}/_.fdisk ${MD} 439 fdisk ${MD} 440 # XXX: params 441 # XXX: pick up cached boot* files, they may not be in image anymore. 442 boot0cfg -B -b ${NANO_WORLDDIR}/${NANO_BOOTLOADER} ${NANO_BOOT0CFG} ${MD} 443 bsdlabel -w -B -b ${NANO_WORLDDIR}/boot/boot ${MD}s1 444 bsdlabel ${MD}s1 445 446 # Create first image 447 newfs ${NANO_NEWFS} /dev/${MD}s1a 448 mount /dev/${MD}s1a ${MNT} 449 df -i ${MNT} 450 echo "Copying worlddir..." 451 ( cd ${NANO_WORLDDIR} && find . -print | cpio -dump ${MNT} ) 452 df -i ${MNT} 453 echo "Generating mtree..." 454 ( cd ${MNT} && mtree -c ) > ${MAKEOBJDIRPREFIX}/_.mtree 455 ( cd ${MNT} && du -k ) > ${MAKEOBJDIRPREFIX}/_.du 456 umount ${MNT} 457 458 if [ $NANO_IMAGES -gt 1 -a $NANO_INIT_IMG2 -gt 0 ] ; then 459 # Duplicate to second image (if present) 460 echo "Duplicating to second image..." 461 dd if=/dev/${MD}s1 of=/dev/${MD}s2 bs=64k 462 mount /dev/${MD}s2a ${MNT} 463 for f in ${MNT}/etc/fstab ${MNT}/conf/base/etc/fstab 464 do 465 sed -i "" "s/${NANO_DRIVE}s1/${NANO_DRIVE}s2/g" $f 466 done 467 umount ${MNT} 468 469 fi 470 471 # Create Config slice 472 newfs ${NANO_NEWFS} /dev/${MD}s3 473 # XXX: fill from where ? 474 475 # Create Data slice, if any. 476 if [ $NANO_DATASIZE -gt 0 ] ; then 477 newfs ${NANO_NEWFS} /dev/${MD}s4 478 # XXX: fill from where ? 479 fi 480 481 if [ "${NANO_MD_BACKING}" = "swap" ] ; then 482 echo "Writing out _.disk.full..." 483 dd if=/dev/${MD} of=${IMG} bs=64k 484 fi 485 486 echo "Writing out _.disk.image..." 487 dd if=/dev/${MD}s1 of=${NANO_DISKIMGDIR}/_.disk.image bs=64k 488 mdconfig -d -u $MD 489 ) > ${MAKEOBJDIRPREFIX}/_.di 2>&1 490) 491 492last_orders () ( 493 # Redefine this function with any last orders you may have 494 # after the build completed, for instance to copy the finished 495 # image to a more convenient place: 496 # cp ${MAKEOBJDIRPREFIX}/_.disk.image /home/ftp/pub/nanobsd.disk 497) 498 499####################################################################### 500# 501# Optional convenience functions. 502# 503####################################################################### 504 505####################################################################### 506# Common Flash device geometries 507# 508 509FlashDevice () { 510 if [ -d ${NANO_TOOLS} ] ; then 511 . ${NANO_TOOLS}/FlashDevice.sub 512 else 513 . ${NANO_SRC}/${NANO_TOOLS}/FlashDevice.sub 514 fi 515 sub_FlashDevice $1 $2 516} 517 518####################################################################### 519# USB device geometries 520# 521# Usage: 522# UsbDevice Generic 1000 # a generic flash key sold as having 1GB 523# 524# This function will set NANO_MEDIASIZE, NANO_HEADS and NANO_SECTS for you. 525# 526# Note that the capacity of a flash key is usually advertised in MB or 527# GB, *not* MiB/GiB. As such, the precise number of cylinders available 528# for C/H/S geometry may vary depending on the actual flash geometry. 529# 530# The following generic device layouts are understood: 531# generic An alias for generic-hdd. 532# generic-hdd 255H 63S/T xxxxC with no MBR restrictions. 533# generic-fdd 64H 32S/T xxxxC with no MBR restrictions. 534# 535# The generic-hdd device is preferred for flash devices larger than 1GB. 536# 537 538UsbDevice () { 539 a1=`echo $1 | tr '[:upper:]' '[:lower:]'` 540 case $a1 in 541 generic-fdd) 542 NANO_HEADS=64 543 NANO_SECTS=32 544 NANO_MEDIASIZE=$(( $2 * 1000 * 1000 / 512 )) 545 ;; 546 generic|generic-hdd) 547 NANO_HEADS=255 548 NANO_SECTS=63 549 NANO_MEDIASIZE=$(( $2 * 1000 * 1000 / 512 )) 550 ;; 551 *) 552 echo "Unknown USB flash device" 553 exit 2 554 ;; 555 esac 556} 557 558####################################################################### 559# Setup serial console 560 561cust_comconsole () ( 562 # Enable getty on console 563 sed -i "" -e /tty[du]0/s/off/on/ ${NANO_WORLDDIR}/etc/ttys 564 565 # Disable getty on syscons devices 566 sed -i "" -e '/^ttyv[0-8]/s/ on/ off/' ${NANO_WORLDDIR}/etc/ttys 567 568 # Tell loader to use serial console early. 569 echo " -h" > ${NANO_WORLDDIR}/boot.config 570) 571 572####################################################################### 573# Allow root login via ssh 574 575cust_allow_ssh_root () ( 576 sed -i "" -e '/PermitRootLogin/s/.*/PermitRootLogin yes/' \ 577 ${NANO_WORLDDIR}/etc/ssh/sshd_config 578) 579 580####################################################################### 581# Install the stuff under ./Files 582 583cust_install_files () ( 584 cd ${NANO_TOOLS}/Files 585 find . -print | grep -v /CVS | cpio -dumpv ${NANO_WORLDDIR} 586) 587 588####################################################################### 589# Install packages from ${NANO_PACKAGE_DIR} 590 591cust_pkg () ( 592 593 # Copy packages into chroot 594 mkdir -p ${NANO_WORLDDIR}/Pkg 595 cp ${NANO_PACKAGE_DIR}/* ${NANO_WORLDDIR}/Pkg 596 597 # Count & report how many we have to install 598 todo=`ls ${NANO_WORLDDIR}/Pkg | wc -l` 599 echo "=== TODO: $todo" 600 ls ${NANO_WORLDDIR}/Pkg 601 echo "===" 602 while true 603 do 604 # Record how many we have now 605 have=`ls ${NANO_WORLDDIR}/var/db/pkg | wc -l` 606 607 # Attempt to install more packages 608 # ...but no more than 200 at a time due to pkg_add's internal 609 # limitations. 610 chroot ${NANO_WORLDDIR} sh -c \ 611 'ls Pkg/*tbz | xargs -n 200 pkg_add -F' || true 612 613 # See what that got us 614 now=`ls ${NANO_WORLDDIR}/var/db/pkg | wc -l` 615 echo "=== NOW $now" 616 ls ${NANO_WORLDDIR}/var/db/pkg 617 echo "===" 618 619 620 if [ $now -eq $todo ] ; then 621 echo "DONE $now packages" 622 break 623 elif [ $now -eq $have ] ; then 624 echo "FAILED: Nothing happened on this pass" 625 exit 2 626 fi 627 done 628 rm -rf ${NANO_WORLDDIR}/Pkg 629) 630 631####################################################################### 632# Convenience function: 633# Register $1 as customize function. 634 635customize_cmd () { 636 NANO_CUSTOMIZE="$NANO_CUSTOMIZE $1" 637} 638 639####################################################################### 640# Convenience function: 641# Register $1 as late customize function to run just before 642# image creation. 643 644late_customize_cmd () { 645 NANO_LATE_CUSTOMIZE="$NANO_LATE_CUSTOMIZE $1" 646} 647 648####################################################################### 649# 650# All set up to go... 651# 652####################################################################### 653 654# Progress Print 655# Print $2 at level $1. 656pprint() { 657 if [ "$1" -le $PPLEVEL ]; then 658 printf "%.${1}s %s\n" "#####" "$2" 659 fi 660} 661 662usage () { 663 ( 664 echo "Usage: $0 [-bikqvw] [-c config_file]" 665 echo " -b suppress builds (both kernel and world)" 666 echo " -i suppress disk image build" 667 echo " -k suppress buildkernel" 668 echo " -q make output more quite" 669 echo " -v make output more verbose" 670 echo " -w suppress buildworld" 671 echo " -c specify config file" 672 ) 1>&2 673 exit 2 674} 675 676####################################################################### 677# Parse arguments 678 679do_kernel=true 680do_world=true 681do_image=true 682 683set +e 684args=`getopt bc:hikqvw $*` 685if [ $? -ne 0 ] ; then 686 usage 687 exit 2 688fi 689set -e 690 691set -- $args 692for i 693do 694 case "$i" 695 in 696 -b) 697 do_world=false 698 do_kernel=false 699 shift 700 ;; 701 -k) 702 do_kernel=false 703 shift 704 ;; 705 -c) 706 . "$2" 707 shift 708 shift 709 ;; 710 -h) 711 usage 712 ;; 713 -i) 714 do_image=false 715 shift 716 ;; 717 -q) 718 PPLEVEL=$(($PPLEVEL - 1)) 719 shift 720 ;; 721 -v) 722 PPLEVEL=$(($PPLEVEL + 1)) 723 shift 724 ;; 725 -w) 726 do_world=false 727 shift 728 ;; 729 --) 730 shift 731 break 732 esac 733done 734 735if [ $# -gt 0 ] ; then 736 echo "$0: Extraneous arguments supplied" 737 usage 738fi 739 740####################################################################### 741# Setup and Export Internal variables 742# 743if [ "x${NANO_OBJ}" = "x" ] ; then 744 MAKEOBJDIRPREFIX=/usr/obj/nanobsd.${NANO_NAME}/ 745 NANO_OBJ=${MAKEOBJDIRPREFIX} 746else 747 MAKEOBJDIRPREFIX=${NANO_OBJ} 748fi 749 750if [ "x${NANO_DISKIMGDIR}" = "x" ] ; then 751 NANO_DISKIMGDIR=${MAKEOBJDIRPREFIX} 752fi 753 754NANO_WORLDDIR=${MAKEOBJDIRPREFIX}/_.w 755NANO_MAKE_CONF=${MAKEOBJDIRPREFIX}/make.conf 756 757if [ -d ${NANO_TOOLS} ] ; then 758 true 759elif [ -d ${NANO_SRC}/${NANO_TOOLS} ] ; then 760 NANO_TOOLS=${NANO_SRC}/${NANO_TOOLS} 761else 762 echo "NANO_TOOLS directory does not exist" 1>&2 763 exit 1 764fi 765 766export MAKEOBJDIRPREFIX 767 768export NANO_ARCH 769export NANO_CODESIZE 770export NANO_CONFSIZE 771export NANO_CUSTOMIZE 772export NANO_DATASIZE 773export NANO_DRIVE 774export NANO_HEADS 775export NANO_IMAGES 776export NANO_IMGNAME 777export NANO_MAKE_CONF 778export NANO_MEDIASIZE 779export NANO_NAME 780export NANO_NEWFS 781export NANO_OBJ 782export NANO_PMAKE 783export NANO_SECTS 784export NANO_SRC 785export NANO_TOOLS 786export NANO_WORLDDIR 787export NANO_BOOT0CFG 788export NANO_BOOTLOADER 789 790####################################################################### 791# And then it is as simple as that... 792 793pprint 1 "NanoBSD image ${NANO_NAME} build starting" 794 795if $do_world ; then 796 clean_build 797 make_conf_build 798 build_world 799else 800 pprint 2 "Skipping buildworld (as instructed)" 801fi 802 803if $do_kernel ; then 804 build_kernel 805else 806 pprint 2 "Skipping buildkernel (as instructed)" 807fi 808 809clean_world 810make_conf_install 811install_world 812install_etc 813setup_nanobsd_etc 814install_kernel 815 816run_customize 817setup_nanobsd 818prune_usr 819run_late_customize 820if $do_image ; then 821 create_${NANO_ARCH}_diskimage 822 echo "# Created NanoBSD disk image: ${MAKEOBJDIRPREFIX}/${NANO_IMGNAME}" 823else 824 pprint 2 "Skipping image build (as instructed)" 825fi 826last_orders 827 828pprint 1 "NanoBSD image ${NANO_NAME} completed" 829