+# netboot package {{{
+create_netbootpackage() {
+ local OUTPUT_FILE="${NETBOOT}/grml_netboot_package_${GRML_NAME}_${VERSION}.tar"
+
+ if [ -f "${OUTPUT_FILE}" -a -z "$UPDATE" -a -z "$BUILD_ONLY" -a -z "$BUILD_DIRTY" ] ; then
+ log "Skipping stage 'netboot' as $OUTPUT_FILE exists already."
+ ewarn "Skipping stage 'netboot' as $OUTPUT_FILE exists already." ; eend 0
+ return 0
+ elif [ -n "$SKIP_NETBOOT" ] ; then
+ log "Skipping stage 'netboot' as requested via option -Q"
+ ewarn "Skipping stage 'netboot' as requested via option -Q" ; eend 0
+ return 0
+ fi
+
+ mkdir -p "$NETBOOT"
+
+ # since syslinux v3:6.03~pre1+dfsg-4 the pxelinux.0 has been split into a
+ # separate pxelinux package
+ if [ -d "${CHROOT_OUTPUT}/usr/lib/PXELINUX/" ] ; then
+ local pxelinux_dir=/usr/lib/PXELINUX
+ else
+ local pxelinux_dir=/usr/lib/syslinux
+ fi
+
+ if ! [ -r "${CHROOT_OUTPUT}/${pxelinux_dir}/pxelinux.0" ] ; then
+ ewarn "File ${pxelinux_dir}/pxelinux.0 not found in build chroot." ; eend 0
+ eindent
+ einfo "Install syslinux[-common]/pxelinux package in chroot to get a netboot package."
+ eoutdent
+ return 0
+ fi
+
+ local OUTPUTDIR="${NETBOOT}/build_tmp"
+ local WORKING_DIR="${OUTPUTDIR}/grml_netboot_package_${GRML_NAME}_${VERSION}/tftpboot/"
+
+ mkdir -p "$WORKING_DIR"
+
+ cp "${CHROOT_OUTPUT}"/boot/vmlinuz-* "$WORKING_DIR"/vmlinuz
+ cp "${CHROOT_OUTPUT}"/boot/initrd.img-* "$WORKING_DIR"/initrd.img
+ cp "${CHROOT_OUTPUT}/${pxelinux_dir}/pxelinux.0" "${WORKING_DIR}/pxelinux.0"
+
+ if [ -r "${CHROOT_OUTPUT}"/usr/lib/syslinux/modules/bios/ldlinux.c32 ] ; then
+ cp "${CHROOT_OUTPUT}"/usr/lib/syslinux/modules/bios/ldlinux.c32 "${WORKING_DIR}"/
+ fi
+
+ mkdir -p "${WORKING_DIR}/pxelinux.cfg"
+ if [ -r "${BUILD_OUTPUT}/boot/isolinux/netboot.cfg" ] ; then
+ cp "${BUILD_OUTPUT}/boot/isolinux/netboot.cfg" "${WORKING_DIR}/pxelinux.cfg/default"
+ else
+ log "File ${BUILD_OUTPUT}/boot/isolinux/netboot.cfg not found."
+ ewarn "File ${BUILD_OUTPUT}/boot/isolinux/netboot.cfg not found."
+ eindent
+ log "Hint: Are you using custom templates which do not provide netboot.cfg?"
+ ewarn "Hint: Are you using custom templates which do not provide netboot.cfg?" ; eend 0
+ eoutdent
+ fi
+
+ # don't include shim + grubnetx64 + grub files in i386 netboot packages,
+ # as those don't make much sense there
+ if [ "$ARCH" = amd64 ] ; then
+ if ! [ -r "${BUILD_OUTPUT}/boot/grub/netboot.cfg" ] ; then
+ log "File ${BUILD_OUTPUT}/boot/grub/netboot.cfg not found."
+ ewarn "File ${BUILD_OUTPUT}/boot/grub/netboot.cfg not found."
+ eindent
+ log "Hint: Are you using custom templates which do not provide grub.cfg?"
+ ewarn "Hint: Are you using custom templates which do not provide grub.cfg?" ; eend 0
+ eoutdent
+ else
+ cp "${BUILD_OUTPUT}/boot/grub/netboot.cfg" "${WORKING_DIR}/grub.cfg"
+ adjust_boot_files "${WORKING_DIR}/grub.cfg"
+
+ if [ -r "${CHROOT_OUTPUT}"/usr/lib/shim/shimx64.efi.signed ] ; then
+ log "Installing ${CHROOT_OUTPUT}/usr/lib/shim/shimx64.efi.signed as shim.efi in netboot package"
+ cp "${CHROOT_OUTPUT}"/usr/lib/shim/shimx64.efi.signed "${WORKING_DIR}"/shim.efi
+ elif [ -r "${CHROOT_OUTPUT}"/usr/lib/shim/shimx64.efi ] ; then
+ log "Installing ${CHROOT_OUTPUT}/usr/lib/shim/shimx64.efi as shim.efi in netboot package"
+ cp "${CHROOT_OUTPUT}"/usr/lib/shim/shimx64.efi "${WORKING_DIR}"/shim.efi
+ else
+ log "No shimx64.efi for usage with PXE boot found (shim-signed not present?)"
+ ewarn "No shimx64.efi for usage with PXE boot found (shim-signed not present?)" ; eend 0
+ fi
+
+ if [ -r "${CHROOT_OUTPUT}"/usr/lib/grub/x86_64-efi-signed/grubnetx64.efi.signed ] ; then
+ log "Installing /usr/lib/grub/x86_64-efi-signed/grubnetx64.efi.signed as grubx64.efi in netboot package"
+ cp "${CHROOT_OUTPUT}"/usr/lib/grub/x86_64-efi-signed/grubnetx64.efi.signed "${WORKING_DIR}"/grubx64.efi
+ elif [ -r "${CHROOT_OUTPUT}"/usr/lib/grub/x86_64-efi/monolithic/grubnetx64.efi ] ; then
+ log "Installing /usr/lib/grub/x86_64-efi/monolithic/grubnetx64.efi as grubx64.efi in netboot package"
+ cp "${CHROOT_OUTPUT}"/usr/lib/grub/x86_64-efi/monolithic/grubnetx64.efi "${WORKING_DIR}"/grubx64.efi
+ else
+ log "No grubnetx64.efi for usage with PXE boot found (grub-efi-amd64-signed not present?)"
+ ewarn "No grubnetx64.efi for usage with PXE boot found (grub-efi-amd64-signed not present?)." ; eend 0
+ fi
+
+ if [ -r "${CHROOT_OUTPUT}"/usr/share/grub/unicode.pf2 ] ; then
+ log "Installing ${CHROOT_OUTPUT}/usr/share/grub/unicode.pf2 as grub/fonts/unicode.pf2 in netboot package"
+ mkdir -p "${WORKING_DIR}"/grub/fonts/
+ cp "${CHROOT_OUTPUT}"/usr/share/grub/unicode.pf2 "${WORKING_DIR}"/grub/fonts/
+ else
+ log "No unicode.pf2 for usage with PXE boot found (grub-common not present?)"
+ ewarn "No unicode.pf2 for usage with PXE boot found (grub-common not present?)" ; eend 0
+ fi
+ fi
+ fi
+
+ if tar -C "$OUTPUTDIR" -cf "${OUTPUT_FILE}" "grml_netboot_package_${GRML_NAME}_${VERSION}" ; then
+ (
+ cd $(dirname "${OUTPUT_FILE}")
+ sha256sum $(basename "${OUTPUT_FILE}") > "${OUTPUT_FILE}.sha256"
+ )
+ einfo "Generated netboot package ${OUTPUT_FILE}" ; eend 0
+ rm -rf "${OUTPUTDIR}"
+ else
+ rm -rf "${OUTPUTDIR}"
+ eerror "Could not generate netboot package ${OUTPUT_FILE}" ; eend 1
+ bailout 21
+ fi
+}
+
+create_netbootpackage
+# }}}
+