|  | @@ -1,80 +1,142 @@
 | 
		
	
		
			
			| 1 | 1 |  #!/bin/bash
 | 
		
	
		
			
			| 2 | 2 |  #
 | 
		
	
		
			
			| 3 | 3 |  # Generate a isolinux ISO boot image
 | 
		
	
		
			
			| 4 |  | -#
 | 
		
	
		
			
			| 5 |  | -# geniso foo.iso foo.lkrn
 | 
		
	
		
			
			| 6 |  | -#
 | 
		
	
		
			
			| 7 |  | -# the ISO image is the first argument so that a list of .lkrn images
 | 
		
	
		
			
			| 8 |  | -# to include can be specified
 | 
		
	
		
			
			| 9 |  | -#
 | 
		
	
		
			
			| 10 |  | -case $# in
 | 
		
	
		
			
			| 11 |  | -0|1)
 | 
		
	
		
			
			| 12 |  | -	echo Usage: $0 foo.iso foo.lkrn ...
 | 
		
	
		
			
			| 13 |  | -	exit 1
 | 
		
	
		
			
			| 14 |  | -	;;
 | 
		
	
		
			
			| 15 |  | -esac
 | 
		
	
		
			
			| 16 | 4 |  
 | 
		
	
		
			
			| 17 |  | -# This should be the default location of the isolinux.bin file
 | 
		
	
		
			
			| 18 |  | -isolinux_bin=${ISOLINUX_BIN:-util/isolinux.bin}
 | 
		
	
		
			
			| 19 |  | -if [ ! -r $isolinux_bin ]
 | 
		
	
		
			
			| 20 |  | -then
 | 
		
	
		
			
			| 21 |  | -	echo $0: $isolinux_bin not found, please install, or set ISOLINUX_BIN in arch/i386/Makefile correctly
 | 
		
	
		
			
			|  | 5 | +function help() {
 | 
		
	
		
			
			|  | 6 | +	echo "usage: ${0} [OPTIONS] foo.lkrn [bar.lkrn,...]"
 | 
		
	
		
			
			|  | 7 | +	echo
 | 
		
	
		
			
			|  | 8 | +	echo "where OPTIONS are:"
 | 
		
	
		
			
			|  | 9 | +	echo " -h       show this help"
 | 
		
	
		
			
			|  | 10 | +	echo " -l       build legacy image with floppy emulation"
 | 
		
	
		
			
			|  | 11 | +	echo " -o FILE  save iso image to file"
 | 
		
	
		
			
			|  | 12 | +}
 | 
		
	
		
			
			|  | 13 | +
 | 
		
	
		
			
			|  | 14 | +LEGACY=0
 | 
		
	
		
			
			|  | 15 | +FIRST=""
 | 
		
	
		
			
			|  | 16 | +
 | 
		
	
		
			
			|  | 17 | +while getopts "hlo:" opt; do
 | 
		
	
		
			
			|  | 18 | +	case ${opt} in
 | 
		
	
		
			
			|  | 19 | +		h)
 | 
		
	
		
			
			|  | 20 | +			help
 | 
		
	
		
			
			|  | 21 | +			exit 0
 | 
		
	
		
			
			|  | 22 | +			;;
 | 
		
	
		
			
			|  | 23 | +		l)
 | 
		
	
		
			
			|  | 24 | +			LEGACY=1
 | 
		
	
		
			
			|  | 25 | +			;;
 | 
		
	
		
			
			|  | 26 | +		o)
 | 
		
	
		
			
			|  | 27 | +			OUT="${OPTARG}"
 | 
		
	
		
			
			|  | 28 | +			;;
 | 
		
	
		
			
			|  | 29 | +	esac
 | 
		
	
		
			
			|  | 30 | +done
 | 
		
	
		
			
			|  | 31 | +
 | 
		
	
		
			
			|  | 32 | +shift $((OPTIND - 1))
 | 
		
	
		
			
			|  | 33 | +
 | 
		
	
		
			
			|  | 34 | +if [ -z "${OUT}" ]; then
 | 
		
	
		
			
			|  | 35 | +	echo "${0}: no output file given" >&2
 | 
		
	
		
			
			|  | 36 | +	help
 | 
		
	
		
			
			| 22 | 37 |  	exit 1
 | 
		
	
		
			
			| 23 | 38 |  fi
 | 
		
	
		
			
			| 24 | 39 |  
 | 
		
	
		
			
			| 25 | 40 |  # There should either be mkisofs or the compatible genisoimage program
 | 
		
	
		
			
			| 26 |  | -mkisofs=`which mkisofs genisoimage 2>/dev/null | head -n1`
 | 
		
	
		
			
			| 27 |  | -if [ -z $mkisofs ]
 | 
		
	
		
			
			| 28 |  | -then
 | 
		
	
		
			
			| 29 |  | -	echo $0: mkisofs or genisoimage not found, please install or set PATH
 | 
		
	
		
			
			|  | 41 | +for command in genisoimage mkisofs; do
 | 
		
	
		
			
			|  | 42 | +	if ${command} --version >/dev/null 2>/dev/null; then
 | 
		
	
		
			
			|  | 43 | +		mkisofs=(${command})
 | 
		
	
		
			
			|  | 44 | +		break
 | 
		
	
		
			
			|  | 45 | +	fi
 | 
		
	
		
			
			|  | 46 | +done
 | 
		
	
		
			
			|  | 47 | +
 | 
		
	
		
			
			|  | 48 | +if [ -z "${mkisofs}" ]; then
 | 
		
	
		
			
			|  | 49 | +	echo "${0}: mkisofs or genisoimage not found, please install or set PATH" >&2
 | 
		
	
		
			
			| 30 | 50 |  	exit 1
 | 
		
	
		
			
			| 31 | 51 |  fi
 | 
		
	
		
			
			| 32 | 52 |  
 | 
		
	
		
			
			| 33 |  | -# isohybrid will be used if available
 | 
		
	
		
			
			| 34 |  | -isohybrid=`which isohybrid 2>/dev/null`
 | 
		
	
		
			
			|  | 53 | +dir=$(mktemp -d bin/iso.dir.XXXXXX)
 | 
		
	
		
			
			|  | 54 | +cfg=${dir}/isolinux.cfg
 | 
		
	
		
			
			| 35 | 55 |  
 | 
		
	
		
			
			| 36 |  | -out=$1
 | 
		
	
		
			
			| 37 |  | -shift
 | 
		
	
		
			
			| 38 |  | -dir=`mktemp -d bin/iso.dir.XXXXXX`
 | 
		
	
		
			
			| 39 |  | -cfg=$dir/isolinux.cfg
 | 
		
	
		
			
			| 40 |  | -cp $isolinux_bin $dir
 | 
		
	
		
			
			|  | 56 | +mkisofs+=(-quiet -l -volid "iPXE" -preparer "iPXE build system"
 | 
		
	
		
			
			|  | 57 | +	-appid "iPXE ${VERSION} - Open Source Network Boot Firmware"
 | 
		
	
		
			
			|  | 58 | +	-publisher "http://ipxe.org/" -c boot.cat)
 | 
		
	
		
			
			| 41 | 59 |  
 | 
		
	
		
			
			| 42 |  | -# syslinux 6.x needs a file called ldlinux.c32
 | 
		
	
		
			
			| 43 |  | -ldlinux_c32=$(dirname ${isolinux_bin})/ldlinux.c32
 | 
		
	
		
			
			| 44 |  | -if [ -s ${ldlinux_c32} ]
 | 
		
	
		
			
			| 45 |  | -then
 | 
		
	
		
			
			| 46 |  | -	cp ${ldlinux_c32} ${dir}
 | 
		
	
		
			
			| 47 |  | -fi
 | 
		
	
		
			
			| 48 |  | -
 | 
		
	
		
			
			| 49 |  | -cat > $cfg <<EOF
 | 
		
	
		
			
			|  | 60 | +# generate the config
 | 
		
	
		
			
			|  | 61 | +cat > ${cfg} <<EOF
 | 
		
	
		
			
			| 50 | 62 |  # These default options can be changed in the geniso script
 | 
		
	
		
			
			| 51 | 63 |  SAY iPXE ISO boot image
 | 
		
	
		
			
			| 52 | 64 |  TIMEOUT 30
 | 
		
	
		
			
			| 53 | 65 |  EOF
 | 
		
	
		
			
			| 54 |  | -first=
 | 
		
	
		
			
			| 55 |  | -for f
 | 
		
	
		
			
			| 56 |  | -do
 | 
		
	
		
			
			| 57 |  | -	if [ ! -r $f ]
 | 
		
	
		
			
			| 58 |  | -	then
 | 
		
	
		
			
			| 59 |  | -		echo $f does not exist, skipping 1>&2
 | 
		
	
		
			
			|  | 66 | +for f; do
 | 
		
	
		
			
			|  | 67 | +	if [ ! -r ${f} ]; then
 | 
		
	
		
			
			|  | 68 | +		echo "${f} does not exist, skipping" >&2
 | 
		
	
		
			
			| 60 | 69 |  		continue
 | 
		
	
		
			
			| 61 | 70 |  	fi
 | 
		
	
		
			
			| 62 |  | -	b=$(basename $f)
 | 
		
	
		
			
			|  | 71 | +	b=$(basename ${f})
 | 
		
	
		
			
			| 63 | 72 |  	g=${b%.lkrn}
 | 
		
	
		
			
			| 64 |  | -	g=${g//[^a-z0-9]}.krn
 | 
		
	
		
			
			| 65 |  | -	case "$first" in
 | 
		
	
		
			
			| 66 |  | -	"")
 | 
		
	
		
			
			| 67 |  | -		echo DEFAULT $b
 | 
		
	
		
			
			| 68 |  | -		;;
 | 
		
	
		
			
			|  | 73 | +	g=${g//[^a-z0-9]}
 | 
		
	
		
			
			|  | 74 | +	g=${g:0:8}.krn
 | 
		
	
		
			
			|  | 75 | +	case "${FIRST}" in
 | 
		
	
		
			
			|  | 76 | +		"")
 | 
		
	
		
			
			|  | 77 | +			echo "DEFAULT ${b}"
 | 
		
	
		
			
			|  | 78 | +			FIRST=${g}
 | 
		
	
		
			
			|  | 79 | +			;;
 | 
		
	
		
			
			| 69 | 80 |  	esac
 | 
		
	
		
			
			| 70 |  | -	first=$g
 | 
		
	
		
			
			| 71 |  | -	echo LABEL $b
 | 
		
	
		
			
			| 72 |  | -	echo "" KERNEL $g
 | 
		
	
		
			
			| 73 |  | -	cp $f $dir/$g
 | 
		
	
		
			
			| 74 |  | -done >> $cfg
 | 
		
	
		
			
			| 75 |  | -$mkisofs -quiet -l -o $out -c boot.cat -b isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table $dir
 | 
		
	
		
			
			| 76 |  | -rm -fr $dir
 | 
		
	
		
			
			| 77 |  | -if [ -n "$isohybrid" ]
 | 
		
	
		
			
			| 78 |  | -then
 | 
		
	
		
			
			| 79 |  | -    $isohybrid $out >/dev/null
 | 
		
	
		
			
			| 80 |  | -fi
 | 
		
	
		
			
			|  | 81 | +	echo "LABEL ${b}"
 | 
		
	
		
			
			|  | 82 | +	echo " KERNEL ${g}"
 | 
		
	
		
			
			|  | 83 | +	cp ${f} ${dir}/${g}
 | 
		
	
		
			
			|  | 84 | +done >> ${cfg}
 | 
		
	
		
			
			|  | 85 | +
 | 
		
	
		
			
			|  | 86 | +case "${LEGACY}" in
 | 
		
	
		
			
			|  | 87 | +	1)
 | 
		
	
		
			
			|  | 88 | +		# check for mtools
 | 
		
	
		
			
			|  | 89 | +		case "$(mtools -V)" in
 | 
		
	
		
			
			|  | 90 | +			Mtools\ version\ 3.9.9*|Mtools\ version\ 3.9.1[0-9]*|[mM]tools\ *\ [4-9].*)
 | 
		
	
		
			
			|  | 91 | +				;;
 | 
		
	
		
			
			|  | 92 | +			*)
 | 
		
	
		
			
			|  | 93 | +				echo "Mtools version 3.9.9 or later is required" >&2
 | 
		
	
		
			
			|  | 94 | +				exit 1
 | 
		
	
		
			
			|  | 95 | +				;;
 | 
		
	
		
			
			|  | 96 | +		esac
 | 
		
	
		
			
			|  | 97 | +
 | 
		
	
		
			
			|  | 98 | +		# generate floppy image
 | 
		
	
		
			
			|  | 99 | +		img=${dir}/boot.img
 | 
		
	
		
			
			|  | 100 | +		mformat -f 1440 -C -i ${img} ::
 | 
		
	
		
			
			|  | 101 | +
 | 
		
	
		
			
			|  | 102 | +		# copy lkrn file to floppy image
 | 
		
	
		
			
			|  | 103 | +		for f in ${dir}/*.krn; do
 | 
		
	
		
			
			|  | 104 | +			mcopy -m -i ${img} ${f} ::$(basename ${g})
 | 
		
	
		
			
			|  | 105 | +			rm -f ${f}
 | 
		
	
		
			
			|  | 106 | +		done
 | 
		
	
		
			
			|  | 107 | +
 | 
		
	
		
			
			|  | 108 | +		# copy config file to floppy image
 | 
		
	
		
			
			|  | 109 | +		mcopy -i ${img} ${cfg} ::syslinux.cfg
 | 
		
	
		
			
			|  | 110 | +		rm -f ${cfg}
 | 
		
	
		
			
			|  | 111 | +
 | 
		
	
		
			
			|  | 112 | +		# write syslinux bootloader to floppy image
 | 
		
	
		
			
			|  | 113 | +		if ! syslinux ${img}; then
 | 
		
	
		
			
			|  | 114 | +			echo "${0}: failed writing syslinux to floppy image ${img}" >&2
 | 
		
	
		
			
			|  | 115 | +			exit 1
 | 
		
	
		
			
			|  | 116 | +		fi
 | 
		
	
		
			
			|  | 117 | +
 | 
		
	
		
			
			|  | 118 | +		# generate the iso image
 | 
		
	
		
			
			|  | 119 | +		"${mkisofs[@]}" -b boot.img -output ${OUT} ${dir}
 | 
		
	
		
			
			|  | 120 | +		;;
 | 
		
	
		
			
			|  | 121 | +	0)
 | 
		
	
		
			
			|  | 122 | +		# copy isolinux bootloader
 | 
		
	
		
			
			|  | 123 | +		cp ${ISOLINUX_BIN} ${dir}
 | 
		
	
		
			
			|  | 124 | +
 | 
		
	
		
			
			|  | 125 | +		# syslinux 6.x needs a file called ldlinux.c32
 | 
		
	
		
			
			|  | 126 | +		LDLINUX_C32=$(dirname ${ISOLINUX_BIN})/ldlinux.c32
 | 
		
	
		
			
			|  | 127 | +		if [ -s ${LDLINUX_C32} ]; then
 | 
		
	
		
			
			|  | 128 | +			cp ${LDLINUX_C32} ${dir}
 | 
		
	
		
			
			|  | 129 | +		fi
 | 
		
	
		
			
			|  | 130 | +
 | 
		
	
		
			
			|  | 131 | +		# generate the iso image
 | 
		
	
		
			
			|  | 132 | +		"${mkisofs[@]}" -b isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -output ${OUT} ${dir}
 | 
		
	
		
			
			|  | 133 | +
 | 
		
	
		
			
			|  | 134 | +		# isohybrid will be used if available
 | 
		
	
		
			
			|  | 135 | +		if isohybrid --version >/dev/null 2>/dev/null; then
 | 
		
	
		
			
			|  | 136 | +			isohybrid ${OUT} >/dev/null
 | 
		
	
		
			
			|  | 137 | +		fi
 | 
		
	
		
			
			|  | 138 | +		;;
 | 
		
	
		
			
			|  | 139 | +esac
 | 
		
	
		
			
			|  | 140 | +
 | 
		
	
		
			
			|  | 141 | +# clean up temporary dir
 | 
		
	
		
			
			|  | 142 | +rm -fr ${dir}
 |