+ mkdir -p "$CHROOT_OUTPUT" || bailout 5 "Problem with creating $CHROOT_OUTPUT for FAI"
+
+ if [ -n "${MIRROR_DIRECTORY}" ] ; then
+ mkdir -p "${CHROOT_OUTPUT}/${MIRROR_DIRECTORY}"
+ mount --bind "${MIRROR_DIRECTORY}" "${CHROOT_OUTPUT}/${MIRROR_DIRECTORY}"
+ fi
+
+ log "Executed FAI command line:"
+ log "BUILD_ONLY=$BUILD_ONLY fai $VERBOSE -C $GRML_FAI_CONFIG -c$CLASSES -u $HOSTNAME $FAI_ACTION $CHROOT_OUTPUT $FAI_ARGS"
+ BUILD_ONLY="$BUILD_ONLY" fai $VERBOSE -C "$GRML_FAI_CONFIG" -c"$CLASSES" -u \
+ "$HOSTNAME" $FAI_ACTION "$CHROOT_OUTPUT" $FAI_ARGS | tee -a $LOGFILE
+ RC="$PIPESTATUS" # notice: bash-only
+
+ if [ "$RC" != 0 ] ; then
+ log "Error while executing fai [exit code ${RC}]. Exiting."
+ eerror "Error while executing fai [exit code ${RC}]. Exiting." ; eend 1
+ bailout 1
+ else
+ log "Setting /etc/grml_version to $GRML_NAME $VERSION Release Codename $RELEASENAME [$ISO_DATE]"
+ echo "$GRML_NAME $VERSION Release Codename $RELEASENAME [$ISO_DATE]" > $CHROOT_OUTPUT/etc/grml_version
+ chmod 644 $CHROOT_OUTPUT/etc/grml_version
+ einfo "Rebuilding initramfs"
+ # make sure new /etc/grml_version reaches the initramfs:
+ chroot $CHROOT_OUTPUT update-initramfs -u -t
+ eend $?
+ fi
+
+ # Remove all FAI logs from chroot if class RELEASE is used:
+ if [ -f "$CHROOT_OUTPUT"/etc/grml_fai_release ] ; then
+ rm -rf "$CHROOT_OUTPUT"/var/log/fai/*
+ fi
+
+ # make sure we don't leave any mounts - FAI doesn't remove them always
+ umount $CHROOT_OUTPUT/proc 2>/dev/null || /bin/true
+ umount $CHROOT_OUTPUT/sys 2>/dev/null || /bin/true
+ umount $CHROOT_OUTPUT/dev/pts 2>/dev/null || /bin/true
+ umount $CHROOT_OUTPUT/dev 2>/dev/null || /bin/true
+
+ [ -n "$MIRROR_DIRECTORY" ] && umount "${CHROOT_OUTPUT}/${MIRROR_DIRECTORY}"
+
+ # notice: 'fai dirinstall' does not seem to exit appropriate, so:
+ ERROR=''
+ CHECKLOG=/var/log/fai/$HOSTNAME/last
+ if [ -r "$CHECKLOG/software.log" ] ; then
+ # 1 errors during executing of commands
+ grep 'dpkg: error processing' $CHECKLOG/software.log >> $LOGFILE && ERROR=1
+ grep 'E: Method http has died unexpectedly!' $CHECKLOG/software.log >> $LOGFILE && ERROR=2
+ grep 'ERROR: chroot' $CHECKLOG/software.log >> $LOGFILE && ERROR=3
+ grep 'E: Failed to fetch' $CHECKLOG/software.log >> $LOGFILE && ERROR=4
+ grep 'Unable to write mmap - msync (28 No space left on device)' $CHECKLOG/software.log >> $LOGFILE && ERROR=5
+ fi
+
+ if [ -r "$CHECKLOG/shell.log" ] ; then
+ grep 'FAILED with exit code' $CHECKLOG/shell.log >> $LOGFILE && ERROR=2
+ fi
+
+ if [ -n "$ERROR" ] ; then
+ log "There was an error [${ERROR}] during execution of stage 'fai dirinstall' [$(date)]"
+ eerror "There was an error during execution of stage 'fai dirinstall'"
+ echo " Check out ${CHECKLOG}/ for details. [exit ${ERROR}]"
+ eend 1
+ bailout 1
+ else
+ log "Finished execution of stage 'fai dirinstall' [$(date)]"
+ einfo "Finished execution of stage 'fai dirinstall'"
+ fi
+