]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[build] Merge util/geniso and util/genliso
authorChristian Hesse <mail@eworm.de>
Tue, 13 May 2014 16:38:52 +0000 (18:38 +0200)
committerMichael Brown <mcb30@ipxe.org>
Wed, 14 May 2014 15:00:58 +0000 (16:00 +0100)
Rework geniso and genliso to provide a single merged utility for
generating ISO images.

Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/i386/Makefile.pcbios
src/util/geniso
src/util/genliso [deleted file]

index d3fe8b9e60765c5a9a4f525528f4a47d859835b1..50e93144b5a23df781576dc251ec4a170dd49e03 100644 (file)
@@ -49,13 +49,13 @@ LIST_NAME_mrom := ROMS
 NON_AUTO_MEDIA += iso
 %iso:  %lkrn util/geniso
        $(QM)$(ECHO) "  [GENISO] $@"
-       $(Q)ISOLINUX_BIN=$(ISOLINUX_BIN) bash util/geniso $@ $<
+       $(Q)ISOLINUX_BIN=$(ISOLINUX_BIN) VERSION="$(VERSION)" bash util/geniso -o $@ $<
 
 # rule to make a floppy emulation ISO boot image
 NON_AUTO_MEDIA += liso
-%liso: %lkrn util/genliso
-       $(QM)$(ECHO) "  [GENLISO] $@"
-       $(Q)bash util/genliso $@ $<
+%liso: %lkrn util/geniso
+       $(QM)$(ECHO) "  [GENISO] $@"
+       $(Q)VERSION="$(VERSION)" bash util/geniso -l -o $@ $<
 
 # rule to make a syslinux floppy image (mountable, bootable)
 NON_AUTO_MEDIA += sdsk
index bcf294a66f47886048fc4c024083299acfe61e9c..521c929e1ca3b9d1bb1d5c5b82e0398d7eef10e1 100755 (executable)
 #!/bin/bash
 #
 # Generate a isolinux ISO boot image
-#
-# geniso foo.iso foo.lkrn
-#
-# the ISO image is the first argument so that a list of .lkrn images
-# to include can be specified
-#
-case $# in
-0|1)
-       echo Usage: $0 foo.iso foo.lkrn ...
-       exit 1
-       ;;
-esac
 
-# This should be the default location of the isolinux.bin file
-isolinux_bin=${ISOLINUX_BIN:-util/isolinux.bin}
-if [ ! -r $isolinux_bin ]
-then
-       echo $0: $isolinux_bin not found, please install, or set ISOLINUX_BIN in arch/i386/Makefile correctly
+function help() {
+       echo "usage: ${0} [OPTIONS] foo.lkrn [bar.lkrn,...]"
+       echo
+       echo "where OPTIONS are:"
+       echo " -h       show this help"
+       echo " -l       build legacy image with floppy emulation"
+       echo " -o FILE  save iso image to file"
+}
+
+LEGACY=0
+FIRST=""
+
+while getopts "hlo:" opt; do
+       case ${opt} in
+               h)
+                       help
+                       exit 0
+                       ;;
+               l)
+                       LEGACY=1
+                       ;;
+               o)
+                       OUT="${OPTARG}"
+                       ;;
+       esac
+done
+
+shift $((OPTIND - 1))
+
+if [ -z "${OUT}" ]; then
+       echo "${0}: no output file given" >&2
+       help
        exit 1
 fi
 
 # There should either be mkisofs or the compatible genisoimage program
-mkisofs=`which mkisofs genisoimage 2>/dev/null | head -n1`
-if [ -z $mkisofs ]
-then
-       echo $0: mkisofs or genisoimage not found, please install or set PATH
+for command in genisoimage mkisofs; do
+       if ${command} --version >/dev/null 2>/dev/null; then
+               mkisofs=(${command})
+               break
+       fi
+done
+
+if [ -z "${mkisofs}" ]; then
+       echo "${0}: mkisofs or genisoimage not found, please install or set PATH" >&2
        exit 1
 fi
 
-# isohybrid will be used if available
-isohybrid=`which isohybrid 2>/dev/null`
+dir=$(mktemp -d bin/iso.dir.XXXXXX)
+cfg=${dir}/isolinux.cfg
 
-out=$1
-shift
-dir=`mktemp -d bin/iso.dir.XXXXXX`
-cfg=$dir/isolinux.cfg
-cp $isolinux_bin $dir
+mkisofs+=(-quiet -l -volid "iPXE" -preparer "iPXE build system"
+       -appid "iPXE ${VERSION} - Open Source Network Boot Firmware"
+       -publisher "http://ipxe.org/" -c boot.cat)
 
-# syslinux 6.x needs a file called ldlinux.c32
-ldlinux_c32=$(dirname ${isolinux_bin})/ldlinux.c32
-if [ -s ${ldlinux_c32} ]
-then
-       cp ${ldlinux_c32} ${dir}
-fi
-
-cat > $cfg <<EOF
+# generate the config
+cat > ${cfg} <<EOF
 # These default options can be changed in the geniso script
 SAY iPXE ISO boot image
 TIMEOUT 30
 EOF
-first=
-for f
-do
-       if [ ! -r $f ]
-       then
-               echo $f does not exist, skipping 1>&2
+for f; do
+       if [ ! -r ${f} ]; then
+               echo "${f} does not exist, skipping" >&2
                continue
        fi
-       b=$(basename $f)
+       b=$(basename ${f})
        g=${b%.lkrn}
-       g=${g//[^a-z0-9]}.krn
-       case "$first" in
-       "")
-               echo DEFAULT $b
-               ;;
+       g=${g//[^a-z0-9]}
+       g=${g:0:8}.krn
+       case "${FIRST}" in
+               "")
+                       echo "DEFAULT ${b}"
+                       FIRST=${g}
+                       ;;
        esac
-       first=$g
-       echo LABEL $b
-       echo "" KERNEL $g
-       cp $f $dir/$g
-done >> $cfg
-$mkisofs -quiet -l -o $out -c boot.cat -b isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table $dir
-rm -fr $dir
-if [ -n "$isohybrid" ]
-then
-    $isohybrid $out >/dev/null
-fi
+       echo "LABEL ${b}"
+       echo " KERNEL ${g}"
+       cp ${f} ${dir}/${g}
+done >> ${cfg}
+
+case "${LEGACY}" in
+       1)
+               # check for mtools
+               case "$(mtools -V)" in
+                       Mtools\ version\ 3.9.9*|Mtools\ version\ 3.9.1[0-9]*|[mM]tools\ *\ [4-9].*)
+                               ;;
+                       *)
+                               echo "Mtools version 3.9.9 or later is required" >&2
+                               exit 1
+                               ;;
+               esac
+
+               # generate floppy image
+               img=${dir}/boot.img
+               mformat -f 1440 -C -i ${img} ::
+
+               # copy lkrn file to floppy image
+               for f in ${dir}/*.krn; do
+                       mcopy -m -i ${img} ${f} ::$(basename ${g})
+                       rm -f ${f}
+               done
+
+               # copy config file to floppy image
+               mcopy -i ${img} ${cfg} ::syslinux.cfg
+               rm -f ${cfg}
+
+               # write syslinux bootloader to floppy image
+               if ! syslinux ${img}; then
+                       echo "${0}: failed writing syslinux to floppy image ${img}" >&2
+                       exit 1
+               fi
+
+               # generate the iso image
+               "${mkisofs[@]}" -b boot.img -output ${OUT} ${dir}
+               ;;
+       0)
+               # copy isolinux bootloader
+               cp ${ISOLINUX_BIN} ${dir}
+
+               # syslinux 6.x needs a file called ldlinux.c32
+               LDLINUX_C32=$(dirname ${ISOLINUX_BIN})/ldlinux.c32
+               if [ -s ${LDLINUX_C32} ]; then
+                       cp ${LDLINUX_C32} ${dir}
+               fi
+
+               # generate the iso image
+               "${mkisofs[@]}" -b isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -output ${OUT} ${dir}
+
+               # isohybrid will be used if available
+               if isohybrid --version >/dev/null 2>/dev/null; then
+                       isohybrid ${OUT} >/dev/null
+               fi
+               ;;
+esac
+
+# clean up temporary dir
+rm -fr ${dir}
diff --git a/src/util/genliso b/src/util/genliso
deleted file mode 100755 (executable)
index 7a112a1..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-#!/bin/bash
-#
-# Generate a legacy floppy emulation ISO boot image
-#
-# genliso foo.liso foo.lkrn bar.lkrn ...
-#
-# The .liso image filename is the first argument followed by
-#   a list of .lkrn images  include in .liso image
-
-case $# in
-0|1)
-       echo Usage: $0 foo.liso foo.lkrn ...
-       exit 1
-       ;;
-esac
-
-case "`mtools -V`" in
-Mtools\ version\ 3.9.9*|Mtools\ version\ 3.9.1[0-9]*|[mM]tools\ *\ [4-9].*)
-       ;;
-*)
-       echo Mtools version 3.9.9 or later is required
-       exit 1
-       ;;
-esac
-
-out=$1
-shift
-
-dir=`mktemp -d bin/liso.dir.XXXXXX`
-
-img=$dir/boot.img
-mformat -f 1440 -C -i $img ::
-
-cfg=$dir/syslinux.cfg
-cat > $cfg <<EOF
-# These default options can be changed in the genliso script
-SAY iPXE ISO boot image generated by genliso
-TIMEOUT 30
-EOF
-
-first=
-for f
-do
-       if [ ! -r $f ]
-       then
-               echo $f does not exist, skipping 1>&2
-               continue
-       fi
-       # shorten name for 8.3 filesystem
-       b=$(basename $f)
-       g=${b%.lkrn}
-       g=${g//[^a-z0-9]}
-       g=${g:0:8}.krn
-       case "$first" in
-       "")
-               echo DEFAULT $g
-               ;;
-       esac
-       first=$g
-       echo LABEL $g
-       echo "" KERNEL $g
-       mcopy -m -i $img $f ::$g
-done >> $cfg
-
-mcopy -i $img $cfg ::syslinux.cfg
-
-if ! syslinux $img
-then
-       exit 1
-fi
-
-mkisofs -q -o $out -c boot.cat -b boot.img $dir
-
-rm -fr $dir