-fi
-
-# build/passwd copied out by prep.sh
-sed -e "s@^root:[^:]*:\(.*\)@root:$ROOT_PASSWORD:\1@" build/passwd \
- >$overlay/etc/passwd
-
-# Install node configuration file (e.g., if node has no floppy disk or USB slot)
-if [ -f "$NODE_CONFIGURATION_FILE" ] ; then
- echo "* Installing node configuration file"
- install -D -m 644 $NODE_CONFIGURATION_FILE $overlay/usr/boot/plnode.txt
-fi
-
-# Pack overlay files into a compressed archive
-echo "* Compressing overlay image"
-(cd $overlay && find . | cpio --quiet -c -o) | gzip -9 >$isofs/overlay.img
-
-rm -rf $overlay
-trap - ERR
-
-# Calculate ramdisk size (total uncompressed size of both archives)
-ramdisk_size=$(gzip -l $isofs/bootcd.img $isofs/overlay.img | tail -1 | awk '{ print $2; }') # bytes
-ramdisk_size=$(($ramdisk_size / 1024)) # kilobytes
-
-# Write isolinux configuration
-echo "$FULL_VERSION_STRING" >$isofs/pl_version
-cat >$isofs/isolinux.cfg <<EOF
-DEFAULT kernel
-APPEND ramdisk_size=$ramdisk_size initrd=bootcd.img,overlay.img root=/dev/ram0 rw
-DISPLAY pl_version
+ fi
+
+ # build/passwd copied out by prep.sh
+ sed -e "s@^root:[^:]*:\(.*\)@root:$ROOT_PASSWORD:\1@" ${VARIANT}/passwd >$OVERLAY/etc/passwd
+
+ # Install node configuration file (e.g., if node has no floppy disk or USB slot)
+ if [ -f "$NODE_CONFIGURATION_FILE" ] ; then
+ echo "* Installing node configuration file $NODE_CONFIGURATION_FILE -> /usr/boot/plnode.txt of the bootcd image"
+ install -D -m 644 $NODE_CONFIGURATION_FILE $OVERLAY/usr/boot/plnode.txt
+ NODE_ID=$(source $NODE_CONFIGURATION_FILE; echo $NODE_ID)
+ echo "* Building network configuration for $NODE_ID"
+ plnet -- --root $OVERLAY --files-only --program BootCD $NODE_ID
+ fi
+
+ [ -n "$IS_SERIAL" ] && KERNEL_ARGS="$KERNEL_ARGS ${console_spec}"
+
+ # tmp: should be restricted to f15 nodes and above
+ # making sure the network interfaces are still numbered eth0 and above
+ KERNEL_ARGS="$KERNEL_ARGS biosdevname=0"
+ # making sure selinux is turned off - somehow this is needed with lxc/f14
+ KERNEL_ARGS="$KERNEL_ARGS selinux=0"
+ # output systemd-related messages on the serial line so it gets with log.txt
+ KERNEL_ARGS="$KERNEL_ARGS systemd.log_target=console console=ttyS0,115200"
+ # add any debug flag if any (defined in the header of this script)
+ KERNEL_ARGS="$KERNEL_ARGS $KERNEL_DEBUG_ARGS"
+ # propagate kernel args for later boot stages
+ [ -n "$KERNEL_ARGS" ] && echo "$KERNEL_ARGS" > $OVERLAY/kargs.txt
+
+ # Pack overlay files into a compressed archive
+ echo "* Compressing overlay image"
+ (cd $OVERLAY && find . | cpio --quiet -c -o) | gzip -9 >$ISOFS/overlay.img
+
+ rm -rf $OVERLAY
+ pop_cleanup
+
+ if [ -n "$CUSTOM_DIR" ]; then
+ echo "* Compressing custom image"
+ (cd "$CUSTOM_DIR" && find . | cpio --quiet -c -o) | gzip -9 >$ISOFS/custom.img
+ fi
+
+ # Calculate ramdisk size (total uncompressed size of both archives)
+ ramdisk_size=$(gzip -l $ISOFS/bootcd.img $ISOFS/overlay.img ${CUSTOM_DIR:+$ISOFS/custom.img} | tail -1 | awk '{ print $2; }') # bytes
+ ramdisk_size=$((($ramdisk_size + 1023) / 1024)) # kilobytes
+
+ echo "$FULL_VERSION_STRING" >$ISOFS/pl_version
+
+ popd
+}
+
+#################### plain ISO
+function build_iso() {
+ local iso="$1" ; shift
+ local custom="$1"
+
+ # Write isolinux configuration
+ cat >$ISOFS/isolinux.cfg <<EOF
+${console_serial_line}
+PROMPT 0
+DEFAULT planetlab-bootcd
+
+LABEL planetlab-bootcd
+ DISPLAY pl_version
+ LINUX kernel
+ APPEND ramdisk_size=$ramdisk_size initrd=bootcd.img,overlay.img${custom:+,custom.img} root=/dev/ram0 rw ${KERNEL_ARGS}
+EOF
+
+ # Create ISO image
+ echo "* Creating ISO image in $(pwd)"
+ mkisofs -o "$iso" $MKISOFS_OPTS $ISOFS
+}
+
+#################### USB with partitions
+function build_usb_partition() {
+ echo -n "* Creating USB image with partitions..."
+ local usb="$1" ; shift
+ local custom="$1"
+
+ local size=$(($(du -Lsk $ISOFS | awk '{ print $1; }') + $FREE_SPACE))
+ size=$(( $size / 1024 ))
+
+ local heads=64
+ local sectors=32
+ local cylinders=$(( ($size*1024*2)/($heads*$sectors) ))
+ local offset=$(( $sectors*512 ))
+
+ if [ -f /usr/lib/syslinux/mkdiskimage ] ; then
+ /usr/lib/syslinux/mkdiskimage -M -4 "$usb" $size $heads $sectors
+ else
+ mkdiskimage -M -4 "$usb" $size $heads $sectors
+ fi
+
+ cat >${BUILDTMP}/mtools.conf<<EOF
+drive z:
+file="${usb}"
+cylinders=$cylinders
+heads=$heads
+sectors=$sectors
+offset=$offset
+mformat_only
+mtools_skip_check=1
+EOF
+ # environment variable for mtools
+ export MTOOLSRC="${BUILDTMP}/mtools.conf"
+
+ ### COPIED FROM build_usb() below!!!!
+ echo -n " populating USB image... "
+ mcopy -bsQ -i "$usb" "$ISOFS"/* z:/
+
+ # Use syslinux instead of isolinux to make the image bootable
+ tmp="${BUILDTMP}/syslinux.cfg"
+ cat >$tmp <<EOF
+${console_serial_line}
+PROMPT 0
+DEFAULT planetlab-bootcd
+
+LABEL planetlab-bootcd
+ DISPLAY pl_version
+ LINUX kernel
+ APPEND ramdisk_size=$ramdisk_size initrd=bootcd.img,overlay.img${custom:+,custom.img} root=/dev/ram0 rw ${KERNEL_ARGS}
+EOF
+ mdel -i "$usb" z:/isolinux.cfg 2>/dev/null || :
+ mcopy -i "$usb" "$tmp" z:/syslinux.cfg
+ rm -f "$tmp"
+ rm -f "${MTOOLSRC}"
+ unset MTOOLSRC
+
+ echo "making USB image bootable."
+ syslinux -o $offset "$usb"
+
+}
+
+#################### plain USB
+function build_usb() {
+ echo -n "* Creating USB image... "
+ local usb="$1" ; shift
+ local custom="$1"
+
+ rm -f "$usb"
+ mkfs.vfat -C "$usb" $(($(du -Lsk $ISOFS | awk '{ print $1; }') + $FREE_SPACE))
+
+ cat >${BUILDTMP}/mtools.conf<<EOF
+mtools_skip_check=1
+EOF
+ # environment variable for mtools
+ export MTOOLSRC="${BUILDTMP}/mtools.conf"
+
+ # Populate it
+ echo -n " populating USB image... "
+ mcopy -bsQ -i "$usb" "$ISOFS"/* ::/
+
+ # Use syslinux instead of isolinux to make the image bootable
+ tmp="${BUILDTMP}/syslinux.cfg"
+ cat >$tmp <<EOF
+${console_serial_line}