3 # Purpose: create a multiboot grml ISO using grml2usb
4 # Authors: Michael Prokop <mika@grml.org>,
5 # Thorsten Glaser <tg@mirbsd.org>
6 # Bug-Reports: see http://grml.org/bugs/
7 # License: This file is licensed under the GPL v2 or any later version.
8 ################################################################################
10 # * support setting grml2usb options
11 ################################################################################
13 # define function getfilesize before "set -e" {{{
14 if stat --help >/dev/null 2>&1; then
15 getfilesize='stat -c %s' # GNU stat
17 getfilesize='stat -f %z' # BSD stat
21 # adjust variables if necessary through environment {{{
22 # path to the grml2usb script you'd like to use
23 [ -n "$GRML2USB" ] || GRML2USB='grml2usb'
24 # work directory for creating the filesystem
25 [ -n "$WRKDIR" ] || WRKDIR='/tmp/grml2iso.tmp'
26 # support mkisofs as well as genisoimage
27 if which mkisofs >/dev/null 2>&1; then
29 elif which genisoimage >/dev/null 2>&1; then
32 echo >&2 "Error: neither mkisofs nor genisoimage available - can not create ISO."
41 echo >&2 "Usage: $0 [OPTIONS] -o target.iso source1.iso [source2.iso ...]"
44 -b Boot Params Additional boot parameters passed to grml2usb
45 -c Directory Copy files from directory to generated iso
46 -f Force overwrite of existing target.iso
47 -r BootParam Remove specified boot params.
48 Could be specfied multiple times.
50 [ -n "$1" ] && exit $1 || exit 1
54 # command line handling {{{
55 [[ $# -gt 2 ]] || usage 1
61 typeset -a REMOVE_OPTS
62 while getopts fb:c:o:r: name; do
64 o) ISOFILE="$OPTARG";;
65 b) ADD_OPTS="--bootoption="$OPTARG"";;
68 r) REMOVE_OPTS+=(--remove-bootoption="$OPTARG");;
73 # make sure -o is specified
74 [ -n "$ISOFILE" ] || usage 1
76 # we don't to override any files by accident
77 if [ -e "$ISOFILE" -a ! -n "$FORCE" ]; then
78 echo "Error: target file $ISOFILE exists already." >&2
82 if [ ! -z "$DIR" -a ! -d "$DIR" ] ; then
83 echo "Error: specified parameter for -c is not a directory" >&2
88 # we need root permissions for executing grml2usb {{{
89 if [[ $(id -u) != 0 ]]; then
90 echo >&2 "Error: please run $0 as root."
95 # check for grml2usb {{{
96 if [ ! -x "$(which $GRML2USB)" ] || [ ! -x "$GRML2USB" ] ; then
97 echo >&2 "Error: Could not find grml2usb"
98 if [ -x "./$GRML2USB" ] ; then
99 echo >&2 "If you executed grml2iso from the grml2usb repository use"
100 echo >&2 "GRML2USB=./grml2usb $0 $*"
108 # note: grub-pc_1.96+20090603-1 seems to be b0rken
109 GRUB_VERSION="grub-pc_1.96+20080724-16"
114 *) ISOFILE=$ORIG_DIR/$ISOFILE ;;
118 # create necessary stuff under WRKDIR {{{
119 [ -d "$WRKDIR" ] && WRKDIR_EXISTED='true' || WRKDIR_EXISTED='false'
120 rm -rf "$WRKDIR/cddir" "$WRKDIR/grub_tmp"
121 mkdir -p "$WRKDIR/cddir"
124 # execute grml2usb with all ISOs you'd like to install {{{
125 # remove all parameters
126 shift $(($OPTIND - 1))
128 $GRML2USB "${REMOVE_OPTS[@]}" ${ADD_OPTS:+"$ADD_OPTS"} "$@" "$WRKDIR/cddir"
132 # move syslinux to isolinux {{{
133 mv "$WRKDIR"/cddir/boot/syslinux "$WRKDIR"/cddir/boot/isolinux
136 echo "menu label ^Isolinux prompt" > boot/isolinux/promptname.cfg
137 echo "include hd.cfg" >> boot/isolinux/grmlmain.cfg
140 # copy specified directory to cd {{{
141 if [ -n "$DIR" ] ; then
142 echo >&2 "Copying ${DIR} to generated iso"
148 # generate the CD/DVD ISO {{{
149 $MKISOFS -V 'grml-multiboot' -l -r -J -no-pad \
150 -no-emul-boot -boot-load-size 4 -boot-info-table \
151 -b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat \
155 # pad the output ISO to multiples of 256 KiB for partition table support {{{
156 siz=$($getfilesize "$ISOFILE")
157 cyls=$(echo "$siz / 512 / 32 / 16 + 1" | bc) # C=$cyls H=16 S=32
158 ofs=$(echo "$cyls * 16 * 32 * 512 - 1" | bc) # padding offset (size - 1)
159 dd if=/dev/zero bs=1 count=1 seek=$ofs of="$ISOFILE" 2>/dev/null
166 rm -rf "$WRKDIR/cddir" "$WRKDIR/grub_tmp"
167 [[ $WRKDIR_EXISTED = 'false' ]] && rmdir "$WRKDIR"
168 echo "Generated $ISOFILE"
171 ## EOF #########################################################################
172 # vim:foldmethod=marker ts=2 ft=sh ai expandtab tw=80 sw=3