mkisoimages.sh revision 141066
1#!/bin/sh
2#
3# Module: mkisoimages.sh
4# Author: Jordan K Hubbard
5# Date:   22 June 2001
6#
7# $FreeBSD: head/release/ia64/mkisoimages.sh 141066 2005-01-30 21:10:52Z kensmith $
8#
9# This script is used by release/Makefile to build the (optional) ISO images
10# for a FreeBSD release.  It is considered architecture dependent since each
11# platform has a slightly unique way of making bootable CDs.  This script
12# is also allowed to generate any number of images since that is more of
13# publishing decision than anything else.
14#
15# Usage:
16#
17# mkisoimages.sh [-b] image-label image-name base-bits-dir [extra-bits-dir]
18#
19# Where -b is passed if the ISO image should be made "bootable" by
20# whatever standards this architecture supports (may be unsupported),
21# image-label is the ISO image label, image-name is the filename of the
22# resulting ISO image, base-bits-dir contains the image contents and
23# extra-bits-dir, if provided, contains additional files to be merged
24# into base-bits-dir as part of making the image.
25
26set -e
27
28if [ "x$1" = "x-b" ]; then
29    bootable=yes
30    shift
31else
32    bootable=no
33fi
34
35if [ $# -lt 3 ]; then
36    echo usage: $0 '[-b] label iso-name base-dir [extra-dir]'
37    exit 1
38fi
39
40LABEL=$1; shift
41NAME=$1; shift
42BASE=$1; shift
43
44MKISOFS=mkisofs
45MKISOFS_PKG=cdrtools
46MKISOFS_PORT=/usr/ports/sysutils/${MKISOFS_PKG}
47
48if ! which ${MKISOFS} > /dev/null; then
49    echo -n "${MKISOFS}(8) does not exist: "
50    if [ -f ${MKISOFS_PORT}/Makefile ]; then
51	echo building the port...
52	if ! (cd ${MKISOFS_PORT} && make install BATCH=yes && make clean); then
53	    echo "error: cannot build ${MKISOFS}(8). Bailing out..."
54	    exit 2
55	fi
56    else
57	echo fetching the package...
58	if ! pkg_add -r ${MKISOFS_PKG}; then
59	    echo "error: cannot fetch ${MKISOFS}(8). Bailing out..."
60	    exit 2
61	fi
62    fi
63fi
64
65EFIPART=efipart.sys
66
67# To create a bootable CD under EFI, the boot image should be an EFI
68# system partition.
69if [ $bootable = yes ]; then
70    EFISZ=32768
71    MNT=/mnt
72    dd if=/dev/zero of=$BASE/$EFIPART count=$EFISZ
73    md=`mdconfig -a -t vnode -f $BASE/$EFIPART`
74    newfs_msdos -F 12 -S 512 -h 4 -o 0 -s $EFISZ -u 16 $md
75    mount -t msdosfs /dev/$md $MNT
76    mkdir -p $MNT/efi/boot $MNT/boot $MNT/boot/kernel
77    cp -R $BASE/boot/defaults $MNT/boot
78    cp $BASE/boot/kernel/kernel $MNT/boot/kernel
79    cp $BASE/boot/kernel/ispfw.ko $MNT/boot/kernel
80    cp $BASE/boot/device.hints $MNT/boot
81    cp $BASE/boot/loader.* $MNT/boot
82    cp $BASE/boot/mfsroot.gz $MNT/boot
83    cp $BASE/boot/support.4th $MNT/boot
84    mv $MNT/boot/loader.efi $MNT/efi/boot/bootia64.efi
85    umount $MNT
86    mdconfig -d -u $md
87    BOOTOPTS="-b $EFIPART -no-emul-boot"
88else
89    BOOTOPTS=""
90fi
91
92publisher="The FreeBSD Project.  http://www.freebsd.org/"
93
94$MKISOFS $BOOTOPTS -r -J -V $LABEL -publisher "$publisher" -o $NAME $BASE $*
95rm -f $BASE/$EFIPART
96exit 0
97