+#
+# Builds custom BootCD ISO and USB images in the current
+# directory.
+#
+# Aaron Klingaman <alk@absarokasoft.com>
+# Mark Huang <mlhuang@cs.princeton.edu>
+# Copyright (C) 2004-2007 The Trustees of Princeton University
+#
+# Jan 2015 - f21 comes with isolinux 6.03 (was 4.05 in f20)
+# http://www.syslinux.org/wiki/index.php/ISOLINUX
+
+COMMAND=$(basename $0)
+DIRNAME=$(dirname $0)
+PATH=/sbin:/bin:/usr/sbin:/usr/bin
+
+# debugging flags
+# keep KERNEL_DEBUG_ARGS void for production
+KERNEL_DEBUG_ARGS=""
+# add more flags here for debugging
+# KERNEL_DEBUG_ARGS="$KERNEL_DEBUG_ARGS some_other_kernel_arg"
+# see also
+# (*) GetBootMedium that has some provisions for common
+# kargs, like e.g. for removing the hangcheck feature,
+# or for turning on debug messages for systemd
+# these can be turned on with tags on the node
+# (*) tests default config, that uses this feature so
+# the tests can benefit these features, without deploying
+# them by default in production
+
+# defaults
+DEFAULT_TYPES="usb iso"
+# Leave 4 MB of free space
+GRAPHIC_CONSOLE="graphic"
+SERIAL_CONSOLE="ttyS0:115200:n:8"
+CONSOLE_INFO=$GRAPHIC_CONSOLE
+MKISOFS_OPTS="-R -J -r -f -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table"
+# isolinux-debug.bin is supposedly helpful as well if available,
+# when things don't work as expected
+#MKISOFS_OPTS="-R -J -r -f -b isolinux-debug.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table"
+
+FREE_SPACE=4096
+
+# command-line settable args
+NODE_CONFIGURATION_FILE=
+CUSTOM_DIR=
+OUTPUT_BASE=
+DRY_RUN=""
+OUTPUT_NAME=""
+TYPES=""
+KERNEL_ARGS=""
+
+# various globals
+BUILDTMP=""
+FULL_VERSION_STRING=""
+ISOREF=""
+ISOFS=""
+OVERLAY=""
+IS_SERIAL=""
+console_dev=""
+console_baud=""
+console_spec=""
+console_serial_line=""
+
+
+#################### compute all supported types
+# removing support for serial in the type
+# this is because kargs.txt goes in the overlay, that is computed only once
+# so we cannot handle serial and graphic modes within the same invokation of this script
+
+ALL_TYPES=""
+for x in iso usb usb_partition; do for c in "" "_cramfs" ; do
+ t="${x}${c}"
+ case $t in
+ usb_partition_cramfs)
+ # unsupported
+ ;;
+ *)
+ ALL_TYPES="$ALL_TYPES $t" ;;
+ esac
+done; done
+
+#################### cleanup utilities
+declare -a _CLEANUPS=()
+function do_cleanup() {
+ cd / ; for i in "${_CLEANUPS[@]}"; do $i ; done
+}
+function push_cleanup() {
+ _CLEANUPS=( "${_CLEANUPS[@]}" "$*" )
+}
+function pop_cleanup() {
+ unset _CLEANUPS[$((${#_CLEANUPS[@]} - 1))]
+}
+
+#################### initialization
+function init_and_check () {
+
+ # Change to our source directory
+ local srcdir=$(cd $DIRNAME && pwd -P)
+ pushd $srcdir
+
+ # Root of the isofs
+ ISOREF=$PWD/${VARIANT}
+
+ # The reference image is expected to have been built by prep.sh (see .spec)
+ # we disable the initial logic that called prep.sh if that was not the case
+ # this is because prep.sh needs to know pldistro
+ if [ ! -f $ISOREF/isofs/bootcd.img -o ! -f $ISOREF/version.txt ] ; then
+ echo "Could not find isofs and version.txt in $ISOREF"
+ if [ "$VARIANT" == "build" ] ; then
+ echo "You have to run prep.sh prior to calling $COMMAND"
+ else
+ echo "You need to create your variant image, see kvariant.sh"
+ fi
+ echo "Exiting .."
+ exit 1
+ fi
+
+ # build/version.txt written by prep.sh
+ BOOTCD_VERSION=$(cat ${VARIANT}/version.txt)
+
+ if [ -f /etc/planetlab/plc_config ] ; then
+ # Source PLC configuration
+ . /etc/planetlab/plc_config
+ fi
+
+ # use /var/tmp that should be large enough on both chroot- or vserver-based myplc
+ BUILDTMP=/var/tmp
+
+ FULL_VERSION_STRING="${PLC_NAME} BootCD ${BOOTCD_VERSION}"
+
+}
+
+# NOTE
+# the custom-dir feature is designed to let a myplc try/ship a patched bootcd
+# without the need for a full devel environment
+# for example, you would create /root/custom-bootcd/etc/rc.d/init.d/pl_hwinit
+# and run this script with -C /root/custom-bootcd
+# this creates a third .img image of the custom dir, that 'hides' the files from
+# bootcd.img in the resulting unionfs
+# it seems that this feature has not been used nor tested in a long time, use with care
+
+usage() {
+ echo "Usage: $COMMAND [OPTION]..."
+ echo " -f plnode.txt Node to customize CD for (default: none)"
+ echo " -t 'types' Build the specified images (default: $DEFAULT_TYPES)"
+ echo " NOTE: mentioning 'serial' as part of the type is not supported anymore"
+ echo " -a Build all known types as listed below"
+ echo " -s console-info Enable a serial line as console and also bring up getty on that line"
+ echo " console-info: tty:baud-rate:parity:bits"
+ echo " or 'default' shortcut for $SERIAL_CONSOLE"
+ echo " -S equivalent to -s default"
+ echo " -O output-base The prefix of the generated files (default: PLC_NAME-BootCD-VERSION)"
+ echo " useful when multiple types are provided"
+ echo " can be a full path"
+ echo " -o output-name The full name of the generated file"
+ echo " -C custom-dir Custom directory"
+ echo " -V variant Use a variant - see kvariant.sh"
+ echo " -n Dry run - mostly for debug/test purposes"
+ echo " -k Add additional parameters to the kargs.txt file"
+ echo " -h This message"
+ echo "All known types: $ALL_TYPES"
+ exit 1
+}
+
+####################
+function parse_command_line () {
+
+ # init
+ TYPES=""
+ # Get options
+ while getopts "f:t:as:SO:o:C:V:k:nh" opt ; do
+ case $opt in
+ f) NODE_CONFIGURATION_FILE=$OPTARG ;;
+ t) TYPES="$TYPES $OPTARG" ;;
+ a) TYPES="$ALL_TYPES" ;;
+ s) CONSOLE_INFO="$OPTARG" ;;
+ S) CONSOLE_INFO=$SERIAL_CONSOLE ;;
+ O) OUTPUT_BASE="$OPTARG" ;;
+ o) OUTPUT_NAME="$OPTARG" ;;
+ C) CUSTOM_DIR="$OPTARG" ;;
+ V) VARIANT="$OPTARG" ;;
+ k) KERNEL_ARGS="$KERNEL_ARGS $OPTARG" ;;
+ n) DRY_RUN=true ;;
+ h|*) usage ;;
+ esac
+ done