+if [ -f "$BUILD_OUTPUT"/live/${GRML_NAME}.squashfs -a -z "$UPDATE" -a -z "$BUILD_ONLY" -a -z "$BUILD_DIRTY" ] ; then
+ log "Skipping stage 'squashfs' as $BUILD_OUTPUT/live exists already."
+ ewarn "Skipping stage 'squashfs' as $BUILD_OUTPUT/live exists already." ; eend 0
+elif [ -n "$SKIP_MKSQUASHFS" ] ; then
+ log "Skipping stage 'squashfs' as requested via option -q or -N"
+ ewarn "Skipping stage 'squashfs' as requested via option -q or -N" ; eend 0
+else
+ [ -d "$BUILD_OUTPUT"/live ] || mkdir "$BUILD_OUTPUT"/live
+ # make sure we don't leave (even an empty) base.tgz:
+ [ -f "$CHROOT_OUTPUT/base.tgz" ] && rm -f "$CHROOT_OUTPUT/base.tgz"
+
+ # if unconfigured default to squashfs-tools' mksquashfs binary
+ if [ -z "$SQUASHFS_BINARY" ] ; then
+ SQUASHFS_BINARY='mksquashfs'
+ fi
+
+ if which "$SQUASHFS_BINARY" >/dev/null 2>&1 ; then
+ log "Using mksquashfs binary ${SQUASHFS_BINARY}"
+ einfo "Using mksquashfs binary ${SQUASHFS_BINARY}" ; eend 0
+ else
+ log "Error: mksquashfs binary ($SQUASHFS_BINARY) not found. Exiting."
+ eerror "Error: mksquashfs binary ($SQUASHFS_BINARY) not found. Exiting." ; eend 1
+ bailout
+ fi
+
+ # use sane defaults if $SQUASHFS_OPTIONS isn't set
+ if [ -z "$SQUASHFS_OPTIONS" ] ; then
+ # use blocksize 256k as this gives best result with regards to time + compression
+ SQUASHFS_OPTIONS="-b 256k"
+
+ # set lzma/xz compression by default, unless -z option has been specified on command line
+ if [ -z "$SQUASHFS_ZLIB" ] ; then
+ SQUASHFS_OPTIONS="$SQUASHFS_OPTIONS -comp xz"
+ else
+ SQUASHFS_OPTIONS="$SQUASHFS_OPTIONS -comp gzip"
+ fi
+ fi
+
+ # support exclusion of files via exclude-file:
+ if [ -n "$SQUASHFS_EXCLUDES_FILE" -a "$SQUASHFS_EXCLUDES_FILE" ] ; then
+ SQUASHFS_OPTIONS="$SQUASHFS_OPTIONS -ef $SQUASHFS_EXCLUDES_FILE"
+ fi
+
+ # get rid of unnecessary files when building grml-small for final release:
+ if echo "$CLASSES" | grep -q GRML_SMALL ; then
+ SQUASHFS_OPTIONS="$SQUASHFS_OPTIONS -e initrd.img* vmlinuz*"
+ fi
+
+ # log stuff
+ SQUASHFS_STDERR="$(mktemp -t grml-live.XXXXXX)"
+
+ # informational stuff
+ [ -n "$SQUASHFS_OPTIONS" ] && SQUASHFS_INFO_MSG="$SQUASHFS_OPTIONS"
+ [ -n "$SQUASHFS_INFO_MSG" ] && SQUASHFS_INFO_MSG="using options: $SQUASHFS_INFO_MSG"
+ einfo "Squashfs build information: running binary $SQUASHFS_BINARY $SQUASHFS_INFO_MSG"
+
+ log "$SQUASHFS_BINARY $CHROOT_OUTPUT/* $BUILD_OUTPUT/live/${GRML_NAME}.squashfs -noappend $SQUASHFS_OPTIONS"
+
+ if $SQUASHFS_BINARY $CHROOT_OUTPUT/* $BUILD_OUTPUT/live/"${GRML_NAME}".squashfs \
+ -noappend $SQUASHFS_OPTIONS 2>"${SQUASHFS_STDERR}" ; then
+ echo "${GRML_NAME}.squashfs" > $BUILD_OUTPUT/live/filesystem.module
+ log "Finished execution of stage 'squashfs' [$(date)]"
+ einfo "Finished execution of stage 'squashfs'" ; eend 0
+ else
+ log "Error: there was a critical error executing stage 'squashfs' [$(date)]:"
+ log "$(cat $SQUASHFS_STDERR)"
+ eerror "Error: there was a critical error executing stage 'squashfs':"
+ cat "${SQUASHFS_STDERR}"
+ eend 1
+ bailout
+ fi
+
+ FORCE_ISO_REBUILD=true
+fi
+
+# create md5sum file:
+if [ -z "$BOOTSTRAP_ONLY" ] ; then
+ ( cd $BUILD_OUTPUT/GRML &&
+ find .. -type f -not -name md5sums -not -name isolinux.bin -exec md5sum {} \; > md5sums )
+fi
+# }}}
+
+# ISO_OUTPUT - mkisofs {{{
+[ -n "$ISO_OUTPUT" ] || ISO_OUTPUT="$OUTPUT/grml_isos"
+[ -n "$ISO_NAME" ] || ISO_NAME="${GRML_NAME}_${VERSION}.iso"
+
+if [ "$BOOT_METHOD" = "isolinux" ] ; then
+ BOOT_ARGS="-no-emul-boot -boot-load-size 4 -boot-info-table -b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat"
+elif [ "$BOOT_METHOD" = "grub" ] ; then
+ BOOT_ARGS="-no-emul-boot -boot-load-size 4 -boot-info-table -b boot/grub/stage2"
+elif [ "$BOOT_METHOD" = "grub2" ] ; then
+ BOOT_ARGS="-no-emul-boot -boot-load-size 4 -b boot/grub/toriboot.bin"
+fi
+
+# Just until http://bts.grml.org/grml/issue945 has been resolved.
+# HYBRID_METHOD defaults to manifold, so make sure the default works OOTB.
+if [[ $BOOT_METHOD != isolinux && ($HYBRID_METHOD = isohybrid || $HYBRID_METHOD = manifold) ]]; then
+ log "Setting HYBRID_METHOD to grub2 as hybrid mode does not work with isohybrid yet."
+ ewarn "Setting HYBRID_METHOD to grub2 as hybrid mode does not work with isohybrid yet."
+ HYBRID_METHOD='grub2'
+ eend 0
+fi
+
+if [ -f "${ISO_OUTPUT}/${ISO_NAME}" -a -z "$UPDATE" -a -z "$BUILD_ONLY" -a -z "$BUILD_DIRTY" -a "$FORCE_ISO_REBUILD" = "false" ] ; then
+ log "Skipping stage 'iso build' as $ISO_OUTPUT/${ISO_NAME} exists already."
+ ewarn "Skipping stage 'iso build' as $ISO_OUTPUT/${ISO_NAME} exists already." ; eend 0
+elif [ -n "$SKIP_MKISOFS" ] ; then
+ log "Skipping stage 'iso build' as requested via option -n or -N"
+ ewarn "Skipping stage 'iso build' as requested via option -n or -N" ; eend 0
+else
+ 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
+fi
+# }}}
+
+# log build information to database if grml-live-db is installed and enabled {{{
+dpkg_to_db() {
+if [ -d /usr/share/grml-live-db ] ; then
+
+ # safe defaults
+ DPKG_LIST="/var/log/fai/$HOSTNAME/last/dpkg.list" # the dpkg --list output of the chroot:
+ [ -n "$DPKG_DATABASE" ] || DPKG_DATABASE=/var/log/grml-live.db
+ [ -n "$DPKG_DBSCRIPT" ] || DPKG_DBSCRIPT=/usr/share/grml-live-db/scripts/dpkg-to-db
+ [ -n "$DPKG_DBOPTIONS" ] || DPKG_DBOPTIONS="--database $DPKG_DATABASE --logfile $LOGFILE --flavour $GRML_NAME --dpkg $DPKG_LIST"
+
+ if ! [ -x "$DPKG_DBSCRIPT" ] ; then
+ log "Error: $DPKG_DBSCRIPT is not executable, can not log dpkg information."
+ eerror "Error: $DPKG_DBSCRIPT is not executable, can not log dpkg information." ; eend 1
+ bailout 14
+ fi
+
+ # disable by default for now, not sure whether really everyone is using a local db file
+ #if ! touch "$DPKG_DATABASE" ; then
+ # eerror "Error: can not write to ${DPKG_DATABASE}, can not log dpkg information." ; eend 1
+ # bailout 14
+ #fi
+
+ if ! [ -r "$DPKG_LIST" ] ; then
+ log "Warning: can not read $DPKG_LIST - can not provide information to $DPKG_DBSCRIPT (dirty build?)"
+ ewarn "Warning: can not read $DPKG_LIST - can not provide information to $DPKG_DBSCRIPT (dirty build?)" ; eend 0
+ else
+ einfo "Logging $DPKG_LIST to database $DPKG_DATABASE"
+ log "Logging $DPKG_LIST to database $DPKG_DATABASE"
+ log "Executing $DPKG_DBSCRIPT $DPKG_DBOPTIONS"
+ eindent
+
+ if DB_INFO=$("$DPKG_DBSCRIPT" $DPKG_DBOPTIONS 2>&1) ; then
+ einfo "$DB_INFO"
+ eend 0
+ else
+ eerror "$DB_INFO"
+ eend 1
+ fi
+
+ eoutdent
+ fi
+
+fi
+}
+# }}}
+
+# finalize {{{
+[ -n "$start_seconds" ] && SECONDS="$[$(cut -d . -f 1 /proc/uptime)-$start_seconds]" || SECONDS="unknown"
+log "Successfully finished execution of $PN [$(date) - running ${SECONDS} seconds]"
+
+dpkg_to_db # make sure we catch the last log line as well, therefore execute between log + einfo
+
+einfo "Successfully finished execution of $PN [$(date) - running ${SECONDS} seconds]" ; eend 0