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'
32 echo >&2 "Usage: $0 [OPTIONS] -o target.iso source1.iso [source2.iso ...]"
35 -b Boot Params Additional boot parameters passed to grml2usb
36 -c Directory Copy files from directory to generated iso
37 -f Force overwrite of existing target.iso
38 -r BootParam Remove specified boot params.
39 Could be specfied multiple times.
41 [ -n "$1" ] && exit $1 || exit 1
45 # command line handling {{{
46 [[ $# -gt 2 ]] || usage 1
52 typeset -a REMOVE_OPTS
53 while getopts fb:c:o:r: name; do
55 o) ISOFILE="$OPTARG";;
56 b) ADD_OPTS="--bootoption="$OPTARG"";;
59 r) REMOVE_OPTS+=(--remove-bootoption="$OPTARG");;
64 # make sure -o is specified
65 [ -n "$ISOFILE" ] || usage 1
67 # we don't to override any files by accident
68 if [ -e "$ISOFILE" -a ! -n "$FORCE" ]; then
69 echo "Error: target file $ISOFILE exists already." >&2
73 if [ ! -z "$DIR" -a ! -d "$DIR" ] ; then
74 echo "Error: specified parameter for -c is not a directory" >&2
78 shift $(($OPTIND - 1))
81 # we need root permissions for executing grml2usb {{{
82 if [[ $(id -u) != 0 ]]; then
83 echo >&2 "Error: please run $0 as root."
90 # note: grub-pc_1.96+20090603-1 seems to be b0rken
91 GRUB_VERSION="grub-pc_1.96+20080724-16"
96 *) ISOFILE=$ORIG_DIR/$ISOFILE ;;
100 # create necessary stuff under WRKDIR {{{
101 [ -d "$WRKDIR" ] && WRKDIR_EXISTED='true' || WRKDIR_EXISTED='false'
102 rm -rf "$WRKDIR/cddir" "$WRKDIR/grub_tmp"
103 mkdir -p "$WRKDIR/cddir"
106 # execute grml2usb with all ISOs you'd like to install {{{
107 $GRML2USB "${REMOVE_OPTS[@]}" ${ADD_OPTS:+"$ADD_OPTS"} "$@" "$WRKDIR/cddir"
110 # move syslinux to isolinux {{{
111 mv "$WRKDIR"/cddir/boot/syslinux "$WRKDIR"/cddir/boot/isolinux
114 echo "menu label ^Isolinux prompt" > boot/isolinux/promptname.cfg
115 echo "include hd.cfg" >> boot/isolinux/grmlmain.cfg
118 # copy specified directory to cd {{{
119 if [ -n "$DIR" ] ; then
120 echo >&2 "Copying ${DIR} to generated iso"
126 # generate the CD/DVD ISO {{{
127 mkisofs -V 'grml-multiboot' -l -r -J -no-pad \
128 -no-emul-boot -boot-load-size 4 -boot-info-table \
129 -b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat \
133 # pad the output ISO to multiples of 256 KiB for partition table support {{{
134 siz=$($getfilesize "$ISOFILE")
135 cyls=$(echo "$siz / 512 / 32 / 16 + 1" | bc) # C=$cyls H=16 S=32
136 ofs=$(echo "$cyls * 16 * 32 * 512 - 1" | bc) # padding offset (size - 1)
137 dd if=/dev/zero bs=1 count=1 seek=$ofs of="$ISOFILE" 2>/dev/null
144 rm -rf "$WRKDIR/cddir" "$WRKDIR/grub_tmp"
145 [[ $WRKDIR_EXISTED = 'false' ]] && rmdir "$WRKDIR"
146 echo "Generated $ISOFILE"
149 ## EOF #########################################################################
150 # vim:foldmethod=marker ts=2 ft=sh ai expandtab tw=80 sw=3