Parcourir la source

[build] Merge util/geniso and util/genliso

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>
tags/v1.20.1
Christian Hesse il y a 10 ans
Parent
révision
a8f037a275
3 fichiers modifiés avec 125 ajouts et 137 suppressions
  1. 4
    4
      src/arch/i386/Makefile.pcbios
  2. 121
    59
      src/util/geniso
  3. 0
    74
      src/util/genliso

+ 4
- 4
src/arch/i386/Makefile.pcbios Voir le fichier

@@ -49,13 +49,13 @@ LIST_NAME_mrom := ROMS
49 49
 NON_AUTO_MEDIA	+= iso
50 50
 %iso:	%lkrn util/geniso
51 51
 	$(QM)$(ECHO) "  [GENISO] $@"
52
-	$(Q)ISOLINUX_BIN=$(ISOLINUX_BIN) bash util/geniso $@ $<
52
+	$(Q)ISOLINUX_BIN=$(ISOLINUX_BIN) VERSION="$(VERSION)" bash util/geniso -o $@ $<
53 53
 
54 54
 # rule to make a floppy emulation ISO boot image
55 55
 NON_AUTO_MEDIA	+= liso
56
-%liso:	%lkrn util/genliso
57
-	$(QM)$(ECHO) "  [GENLISO] $@"
58
-	$(Q)bash util/genliso $@ $<
56
+%liso:	%lkrn util/geniso
57
+	$(QM)$(ECHO) "  [GENISO] $@"
58
+	$(Q)VERSION="$(VERSION)" bash util/geniso -l -o $@ $<
59 59
 
60 60
 # rule to make a syslinux floppy image (mountable, bootable)
61 61
 NON_AUTO_MEDIA	+= sdsk

+ 121
- 59
src/util/geniso Voir le fichier

@@ -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}

+ 0
- 74
src/util/genliso Voir le fichier

@@ -1,74 +0,0 @@
1
-#!/bin/bash
2
-#
3
-# Generate a legacy floppy emulation ISO boot image
4
-#
5
-# genliso foo.liso foo.lkrn bar.lkrn ...
6
-#
7
-# The .liso image filename is the first argument followed by
8
-#   a list of .lkrn images  include in .liso image
9
-
10
-case $# in
11
-0|1)
12
-	echo Usage: $0 foo.liso foo.lkrn ...
13
-	exit 1
14
-	;;
15
-esac
16
-
17
-case "`mtools -V`" in
18
-Mtools\ version\ 3.9.9*|Mtools\ version\ 3.9.1[0-9]*|[mM]tools\ *\ [4-9].*)
19
-	;;
20
-*)
21
-	echo Mtools version 3.9.9 or later is required
22
-	exit 1
23
-	;;
24
-esac
25
-
26
-out=$1
27
-shift
28
-
29
-dir=`mktemp -d bin/liso.dir.XXXXXX`
30
-
31
-img=$dir/boot.img
32
-mformat -f 1440 -C -i $img ::
33
-
34
-cfg=$dir/syslinux.cfg
35
-cat > $cfg <<EOF
36
-# These default options can be changed in the genliso script
37
-SAY iPXE ISO boot image generated by genliso
38
-TIMEOUT 30
39
-EOF
40
-
41
-first=
42
-for f
43
-do
44
-	if [ ! -r $f ]
45
-	then
46
-		echo $f does not exist, skipping 1>&2
47
-		continue
48
-	fi
49
-	# shorten name for 8.3 filesystem
50
-	b=$(basename $f)
51
-	g=${b%.lkrn}
52
-	g=${g//[^a-z0-9]}
53
-	g=${g:0:8}.krn
54
-	case "$first" in
55
-	"")
56
-		echo DEFAULT $g
57
-		;;
58
-	esac
59
-	first=$g
60
-	echo LABEL $g
61
-	echo "" KERNEL $g
62
-	mcopy -m -i $img $f ::$g
63
-done >> $cfg
64
-
65
-mcopy -i $img $cfg ::syslinux.cfg
66
-
67
-if ! syslinux $img
68
-then
69
-	exit 1
70
-fi
71
-
72
-mkisofs -q -o $out -c boot.cat -b boot.img $dir
73
-
74
-rm -fr $dir

Chargement…
Annuler
Enregistrer