mkisoimages.sh revision 130016
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 130016 2004-06-02 22:21:15Z marius $
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
28# The hackery function is to help with the development of the release
29# process. It's not intended to be an integral part of it. JFYI...
30hackery() {
31    echo "Sorry, no hackery today and you're out of milk too"
32    exit 2
33}
34
35MKISOFS_PORT=/usr/ports/sysutils/cdrtools
36
37if [ "x$1" = "x-b" ]; then
38    bootable=yes
39    shift
40else
41    bootable=no
42fi
43
44if [ $# -lt 3 ]; then
45    echo usage: $0 '[-b] label iso-name base-dir [extra-dir]'
46    exit 1
47fi
48
49BOOTOPTS=""
50LABEL=$1; shift
51NAME=$1; shift
52BASE=$1; shift
53
54if ! which mkisofs; then
55    echo 'mkisofs(8) does not exist. Fetching the package...'
56    if ! pkg_add -r cdrtools; then
57	if [ -f /usr/ports/sysutils/cdrtools/Makefile ]; then
58	    echo "Don't worry; building the port..."
59	    if ! (cd $MKISOFS_PORT && make install && make clean); then
60		echo "Worry; reverting to hackery..."
61		hackery
62	    fi
63	else
64	    echo "Ports not present. Reverting to hackery..."
65	    hackery
66	fi
67    fi
68fi
69
70EFIPART=efipart.sys
71
72# To create a bootable CD under EFI, the boot image should be an EFI
73# system partition.
74if [ $bootable = yes ]; then
75    EFISZ=32768
76    MNT=/mnt
77    dd if=/dev/zero of=$BASE/$EFIPART count=$EFISZ
78    md=`mdconfig -a -t vnode -f $BASE/$EFIPART`
79    newfs_msdos -F 12 -S 512 -h 4 -o 0 -s $EFISZ -u 16 $md
80    mount -t msdosfs /dev/$md $MNT
81    mkdir -p $MNT/efi/boot $MNT/boot $MNT/boot/kernel
82    cp -R $BASE/boot/defaults $MNT/boot
83    cp $BASE/boot/kernel/kernel $MNT/boot/kernel
84    cp $BASE/boot/device.hints $MNT/boot
85    cp $BASE/boot/loader.* $MNT/boot
86    cp $BASE/boot/mfsroot.gz $MNT/boot
87    cp $BASE/boot/support.4th $MNT/boot
88    mv $MNT/boot/loader.efi $MNT/efi/boot/bootia64.efi
89    umount $MNT
90    mdconfig -d -u $md
91    BOOTOPTS="-b $EFIPART -no-emul-boot"
92fi
93
94mkisofs $BOOTOPTS -r -J -V $LABEL -o $NAME $BASE $*
95rm -f $BASE/$EFIPART
96exit 0
97