+#
+# 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)