-trap "do_cleanup" ERR INT EXIT
-
-BUILDTMP=$(mktemp -d ${BUILDTMP}/bootcd.XXXXXX)
-push_cleanup rm -fr "${BUILDTMP}"
-mkdir "${BUILDTMP}/isofs"
-for i in "$isofs"/{bootcd.img,kernel}; do
- ln -s "$i" "${BUILDTMP}/isofs"
-done
-cp "$isofs/isolinux.bin" "${BUILDTMP}/isofs"
-isofs="${BUILDTMP}/isofs"
-
-# Root of the ISO and USB images
-echo "* Populating root filesystem..."
-overlay="${BUILDTMP}/overlay"
-install -d -m 755 $overlay
-push_cleanup rm -fr $overlay
-
-# Create version files
-echo "* Creating version files"
-
-# Boot Manager compares pl_version in both places to make sure that
-# the right CD is mounted. We used to boot from an initrd and mount
-# the CD on /usr. Now we just run everything out of the initrd.
-for file in $overlay/pl_version $overlay/usr/isolinux/pl_version ; do
- mkdir -p $(dirname $file)
- echo "$FULL_VERSION_STRING" >$file
-done
-
-# Install boot server configuration files
-echo "* Installing boot server configuration files"
-
-# We always intended to bring up and support backup boot servers,
-# but never got around to it. Just install the same parameters for
-# both for now.
-for dir in $overlay/usr/boot $overlay/usr/boot/backup ; do
- install -D -m 644 $PLC_BOOT_CA_SSL_CRT $dir/cacert.pem
- install -D -m 644 $PLC_ROOT_GPG_KEY_PUB $dir/pubring.gpg
- echo "$PLC_BOOT_HOST" >$dir/boot_server
- echo "$PLC_BOOT_SSL_PORT" >$dir/boot_server_port
- echo "/boot/" >$dir/boot_server_path
-done
-
-# (Deprecated) Install old-style boot server configuration files
-install -D -m 644 $PLC_BOOT_CA_SSL_CRT $overlay/usr/bootme/cacert/$PLC_BOOT_HOST/cacert.pem
-echo "$FULL_VERSION_STRING" >$overlay/usr/bootme/ID
-echo "$PLC_BOOT_HOST" >$overlay/usr/bootme/BOOTSERVER
-echo "$PLC_BOOT_HOST" >$overlay/usr/bootme/BOOTSERVER_IP
-echo "$PLC_BOOT_SSL_PORT" >$overlay/usr/bootme/BOOTPORT
-
-# Generate /etc/issue
-echo "* Generating /etc/issue"
-
-if [ "$PLC_WWW_PORT" = "443" ] ; then
- PLC_WWW_URL="https://$PLC_WWW_HOST/"
-elif [ "$PLC_WWW_PORT" != "80" ] ; then
- PLC_WWW_URL="http://$PLC_WWW_HOST:$PLC_WWW_PORT/"
-else
- PLC_WWW_URL="http://$PLC_WWW_HOST/"
-fi
-
-mkdir -p $overlay/etc
-cat >$overlay/etc/issue <<EOF
+#################### run once : build the overlay image
+function build_overlay () {
+
+ BUILDTMP=$(mktemp -d ${BUILDTMP}/bootcd.XXXXXX)
+ push_cleanup rm -fr "${BUILDTMP}"
+
+ # initialize ISOFS
+ ISOFS="${BUILDTMP}/isofs"
+ mkdir -p "$ISOFS"
+ for i in "$ISOREF"/isofs/{bootcd.img,kernel}; do
+ ln -s "$i" "$ISOFS"
+ done
+ # use new location as of fedora 12
+ # used to be in /usr/lib/syslinux/isolinux.bin
+ # removed backward compat in jan. 2015
+ # as of syslinux 6.05 (fedora 21) ldlinux.c32 is required by isolinux.bin
+ # the debug version can come in handy at times, and is 40k as well
+ isolinuxdir="/usr/share/syslinux"
+ # ship only what is mandatory, and forget about
+ # (*) isolinux-debug.bin as its name confuses mkisofs
+ # (*) memdisk that is not useful
+ isolinuxfiles="isolinux.bin ldlinux.c32"
+ for isolinuxfile in $isolinuxfiles; do
+ [ -f $isolinuxdir/$isolinuxfile ] && cp $isolinuxdir/$isolinuxfile "${BUILDTMP}/isofs"
+ done
+
+ # Root of the ISO and USB images
+ echo "* Populating root filesystem..."
+ OVERLAY="${BUILDTMP}/overlay"
+ install -d -m 755 $OVERLAY
+ push_cleanup rm -fr $OVERLAY
+
+ # Create version files
+ echo "* Creating version files"
+
+ # Boot Manager compares pl_version in both places to make sure that
+ # the right CD is mounted. We used to boot from an initrd and mount
+ # the CD on /usr. Now we just run everything out of the initrd.
+ for file in $OVERLAY/pl_version $OVERLAY/usr/isolinux/pl_version ; do
+ mkdir -p $(dirname $file)
+ echo "$FULL_VERSION_STRING" >$file
+ done
+
+ # Install boot server configuration files
+ echo "* Installing boot server configuration files"
+
+ # We always intended to bring up and support backup boot servers,
+ # but never got around to it. Just install the same parameters for
+ # both for now.
+ for dir in $OVERLAY/usr/boot $OVERLAY/usr/boot/backup ; do
+ install -D -m 644 $PLC_BOOT_CA_SSL_CRT $dir/cacert.pem
+ install -D -m 644 $PLC_ROOT_GPG_KEY_PUB $dir/pubring.gpg
+ echo "$PLC_BOOT_HOST" >$dir/boot_server
+ echo "$PLC_BOOT_SSL_PORT" >$dir/boot_server_port
+ echo "/boot/" >$dir/boot_server_path
+ done
+
+ # Install old-style boot server configuration files
+ # as opposed to what a former comment suggested,
+ # this is still required, somewhere in the bootmanager apparently
+ install -D -m 644 $PLC_BOOT_CA_SSL_CRT $OVERLAY/usr/bootme/cacert/$PLC_BOOT_HOST/cacert.pem
+ echo "$FULL_VERSION_STRING" >$OVERLAY/usr/bootme/ID
+ echo "$PLC_BOOT_HOST" >$OVERLAY/usr/bootme/BOOTSERVER
+ echo "$PLC_BOOT_HOST" >$OVERLAY/usr/bootme/BOOTSERVER_IP
+ echo "$PLC_BOOT_SSL_PORT" >$OVERLAY/usr/bootme/BOOTPORT
+
+ # Generate /etc/issue
+ echo "* Generating /etc/issue"
+
+ if [ "$PLC_WWW_PORT" = "443" ] ; then
+ PLC_WWW_URL="https://$PLC_WWW_HOST/"
+ elif [ "$PLC_WWW_PORT" != "80" ] ; then
+ PLC_WWW_URL="http://$PLC_WWW_HOST:$PLC_WWW_PORT/"
+ else
+ PLC_WWW_URL="http://$PLC_WWW_HOST/"
+ fi
+
+ mkdir -p $OVERLAY/etc
+ cat >$OVERLAY/etc/issue <<EOF