+CUSTOM_DIR=
+OUTPUT_BASE=
+DRY_RUN=""
+OUTPUT_NAME=""
+TYPES=""
+KARGS_STR=""
+
+# various globals
+BUILDTMP=""
+FULL_VERSION_STRING=""
+ISOREF=""
+ISOFS=""
+OVERLAY=""
+IS_SERIAL=""
+console_dev=""
+console_baud=""
+console_spec=""
+console_serial_line=""
+kernel_args=""
+
+
+#################### 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"