+ mkdir -p "$ISO_OUTPUT" || bailout 6 "Problem with creating $ISO_OUTPUT for stage 'iso build'"
+
+ if $FORCE_ISO_REBUILD && ! [ -f "${ISO_OUTPUT}/${ISO_NAME}" ] ; then
+ log "Forcing rebuild of ISO because files on ISO have been modified."
+ einfo "Forcing rebuild of ISO because files on ISO have been modified."
+ fi
+
+ # support mkisofs as well as genisoimage
+ if which mkisofs >/dev/null 2>&1; then
+ MKISOFS='mkisofs'
+ elif which genisoimage >/dev/null 2>&1; then
+ MKISOFS='genisoimage'
+ else
+ log "Error: neither mkisofs nor genisoimage available - can not create ISO."
+ eerror "Error: neither mkisofs nor genisoimage available - can not create ISO." ; eend 1
+ bailout
+ fi
+
+ CURRENT_DIR=$(pwd)
+ if cd "$BUILD_OUTPUT" ; then
+ if [ "$BOOT_METHOD" = "grub2" ]; then
+ # make a 2048-byte bootsector for El Torito
+ dd if=/dev/zero of=boot/grub/toriboot.bin bs=512 count=4 2>/dev/null
+ # those are in 2048-byte sectors, so 1 16 matches 4 63 below
+ echo 1 16 | mksh /usr/share/grml-live/scripts/bootgrub.mksh -B 11 | \
+ dd of=boot/grub/toriboot.bin conv=notrunc 2>/dev/null
+ fi
+ log "$MKISOFS -V '${GRML_NAME} ${VERSION}' -publisher 'grml-live | grml.org' -l -r -J $BOOT_ARGS -o ${ISO_OUTPUT}/${ISO_NAME} ."
+ "$MKISOFS" -V "${GRML_NAME} ${VERSION}" -publisher 'grml-live | grml.org' \
+ -l -r -J $BOOT_ARGS -no-pad \
+ -o "${ISO_OUTPUT}/${ISO_NAME}" . ; RC=$?
+ # both of these need core.img there, so it’s easier to write it here
+ if [ "$BOOT_METHOD" = "grub2" ] || [ "$HYBRID_METHOD" = "grub2" ]; then
+ # must be <= 30720 bytes
+ dd if=boot/grub/core.img of="${ISO_OUTPUT}/${ISO_NAME}" \
+ conv=notrunc bs=512 seek=4 2>/dev/null
+ fi
+
+ # pad the output ISO to multiples of 256 KiB for partition table support
+ siz=$($getfilesize "${ISO_OUTPUT}/${ISO_NAME}")
+ cyls=$((siz / 512 / 32 / 16 + 1)) # C=$cyls H=16 S=32
+ siz=$((cyls * 16 * 32 * 512)) # size after padding
+ dd if=/dev/zero bs=1 count=1 seek=$((siz - 1)) \
+ of="${ISO_OUTPUT}/${ISO_NAME}" 2>/dev/null
+
+ # support disabling hybrid ISO image
+ if [ "$HYBRID_METHOD" = "disable" ] ; then\
+ log "Skipping creation of hybrid ISO file as requested via HYBRID_METHOD=disable"
+ einfo "Skipping creation of hybrid ISO file as requested via HYBRID_METHOD=disable"
+ eend 0
+ # use isohybrid only on request
+ elif [ "$HYBRID_METHOD" = "isohybrid" ] ; then
+ if ! which isohybrid >/dev/null 2>&1 ; then
+ bailout 12 "isohybrid binary not found - please install syslinux/syslinux-common"
+ else
+ log "Creating hybrid ISO file with isohybrid method"
+ einfo "Creating hybrid ISO file with isohybrid method"
+ # Notes for consideration:
+ # "-entry 4 -type 1c"
+ # * using 4 as the partition number is supposed to help with BIOSes
+ # that only support USB-Zip boot
+ # * using 1c (i.e. hidden FAT32 LBA), instead of the default 0x17
+ # (hidden NTFS, IIRC), as the partition type is sometimes needed
+ # to get the BIOS even look at the partition created by isohybrid
+ isohybrid "${ISO_OUTPUT}/${ISO_NAME}"
+ eend $?
+ fi
+ # by default use our manifold boot method:
+ else
+ # isoinfo is part of both mkisofs and genisoimage so we're good
+ bootoff=$(isoinfo -l -i "${ISO_OUTPUT}/${ISO_NAME}" | \
+ sed -n '/^.*\[ *\([0-9]*\)[] ].* ISOLINUX.BIN;1 *$/s//\1/p')
+ if ! [ -r boot/grub/core.img ] ; then
+ ewarn "boot/grub/core.img not found, not creating manifold boot ISO file"
+ elif [ "${bootoff:-0}" -lt 1 ] ; then
+ ewarn "isolinux.bin not found on the ISO file, disabling manifold boot"
+ else
+ log "Creating hybrid ISO file with manifold method"
+ einfo "Creating hybrid ISO file with manifold method"
+ if [ "$HYBRID_METHOD" = "grub2" ] ; then
+ # 512 bytes: MBR, partition table, load GRUB 2
+ echo 4 63 | mksh /usr/share/grml-live/scripts/bootgrub.mksh -A -M 4:0x96 -g $cyls:16:32
+ else
+ # read only one but 2048-byte sized (scale: << 2) sector
+ echo $bootoff $bootoff | \
+ mksh /usr/share/grml-live/scripts/bootilnx.mksh -A -M 4:0x96 -g $cyls:16:32 -S 2
+ fi | dd of="${ISO_OUTPUT}/${ISO_NAME}" conv=notrunc 2>/dev/null
+ eend $?
+ fi
+ fi
+
+ # generate md5sum and sha1sum of ISO if we are using class 'RELEASE':
+ case $CLASSES in *RELEASE*)
+ [ "$RC" = 0 ] && \
+ (
+ if cd $ISO_OUTPUT ; then
+ md5sum ${ISO_NAME} > ${ISO_NAME}.md5 && \
+ touch -r ${ISO_NAME} ${ISO_NAME}.md5
+ sha1sum ${ISO_NAME} > ${ISO_NAME}.sha1 && \
+ touch -r ${ISO_NAME} ${ISO_NAME}.sha1
+ fi
+ )
+ ;;
+ esac
+
+ cd "$CURRENT_DIR"
+ fi
+
+ if [ "$RC" = 0 ] ; then
+ log "Finished execution of stage 'iso build' [$(date)]"
+ einfo "Finished execution of stage 'iso build'" ; eend 0
+ else
+ log "Error: there was a critical error ($RC) executing stage 'iso build' [$(date)]"
+ eerror "Error: there was a critical error executing stage 'iso build'" ; eend 1
+ bailout $RC
+ fi