1105060Sjake#!/bin/sh
2105060Sjake#
3105060Sjake# Module: mkisoimages.sh
4105060Sjake# Author: Jordan K Hubbard
5105060Sjake# Date:   22 June 2001
6105060Sjake#
7105060Sjake# $FreeBSD$
8105060Sjake#
9105060Sjake# This script is used by release/Makefile to build the (optional) ISO images
10105060Sjake# for a FreeBSD release.  It is considered architecture dependent since each
11105060Sjake# platform has a slightly unique way of making bootable CDs.  This script
12105060Sjake# is also allowed to generate any number of images since that is more of
13105060Sjake# publishing decision than anything else.
14105060Sjake#
15105060Sjake# Usage:
16105060Sjake#
17105060Sjake# mkisoimages.sh [-b] image-label image-name base-bits-dir [extra-bits-dir]
18105060Sjake#
19105060Sjake# Where -b is passed if the ISO image should be made "bootable" by
20105060Sjake# whatever standards this architecture supports (may be unsupported),
21105060Sjake# image-label is the ISO image label, image-name is the filename of the
22105060Sjake# resulting ISO image, base-bits-dir contains the image contents and
23105060Sjake# extra-bits-dir, if provided, contains additional files to be merged
24105060Sjake# into base-bits-dir as part of making the image.
25105060Sjakeif [ $# -lt 3 ]; then
26287635Sdteske	echo "Usage: $0 [-b] image-label image-name base-bits-dir [extra-bits-dir]" > /dev/stderr
27105060Sjake	exit 1
28105060Sjakefi
29105060Sjake
30287635Sdteskecase "$1" in
31287635Sdteske-b)	BOPT="$1"; shift ;;
32246283Shrsesac
33287635SdteskeLABEL=`echo "$1" | tr '[:lower:]' '[:upper:]'`; shift
34287635SdteskeNAME="$1"; shift
35287635SdteskeBASEBITSDIR="$1"
36105060Sjake
37246283Shrs# Create an ISO image
38246283Shrspublisher="The FreeBSD Project.  http://www.FreeBSD.org/"
39287635Sdteskeecho "/dev/iso9660/$LABEL / cd9660 ro 0 0" > "$BASEBITSDIR/etc/fstab"
40287635Sdteskemakefs -t cd9660 -o rockridge -o label="$LABEL" -o publisher="$publisher" "$NAME.tmp" "$@"
41293223Sgjbrm -f "$BASEBITSDIR/etc/fstab"
42246283Shrs
43246283Shrsif [ "x$BOPT" != "x-b" ]; then
44287635Sdteske	mv "$NAME.tmp" "$NAME"
45246283Shrs	exit 0
46246283Shrsfi
47253676Smarius
48246283ShrsTMPIMGDIR=`mktemp -d /tmp/bootfs.XXXXXXXX` || exit 1
49287635SdteskeBOOTFSDIR="$TMPIMGDIR/bootfs"
50287635SdteskeBOOTFSIMG="$TMPIMGDIR/bootfs.img"
51246283Shrs
52246283Shrs# Create a boot filesystem
53287635Sdteskemkdir -p "$BOOTFSDIR/boot"
54287635Sdteskecp -p "$BASEBITSDIR/boot/loader" "$BOOTFSDIR/boot"
55287635Sdteskemakefs -t ffs -B be -M 512k "$BOOTFSIMG" "$BOOTFSDIR"
56287635Sdteskedd if="$BASEBITSDIR/boot/boot1" of="$BOOTFSIMG" bs=512 conv=notrunc,sync
57246283Shrs
58246283Shrs# Create a boot ISO image
59246283Shrs: ${CYLSIZE:=640}
60287635SdteskeISOSIZE=$(stat -f %z "$NAME.tmp")
61287635SdteskeISOBLKS=$((($ISOSIZE + 511) / 512))
62287635SdteskeISOCYLS=$((($ISOBLKS + ($CYLSIZE - 1)) / $CYLSIZE))
63246283Shrs
64287635SdteskeBOOTFSSIZE=$(stat -f %z "$BOOTFSIMG")
65287635SdteskeBOOTFSBLKS=$((($BOOTFSSIZE + 511) / 512))
66287635SdteskeBOOTFSCYLS=$((($BOOTFSBLKS + ($CYLSIZE - 1)) / $CYLSIZE))
67246283Shrs
68287635SdteskeENDCYL=$(($ISOCYLS + $BOOTFSCYLS))
69287635SdteskeNSECTS=$(($ENDCYL * 1 * $CYLSIZE))
70246283Shrs
71287635Sdteskedd if="$NAME.tmp" of="$NAME" bs="${CYLSIZE}b" conv=notrunc,sync
72287635Sdteskedd if="$BOOTFSIMG" of="$NAME" bs="${CYLSIZE}b" seek=$ISOCYLS conv=notrunc,sync
73246283Shrs# The number of alternative cylinders is always 2.
74287635Sdteskedd if=/dev/zero of="$NAME" bs="${CYLSIZE}b" seek=$ENDCYL count=2 conv=notrunc,sync
75287635Sdteskerm -rf "$NAME.tmp" "$TMPIMGDIR"
76246283Shrs
77246283Shrs# Write VTOC8 label to boot ISO image
78287635SdteskeMD=`mdconfig -a -t vnode -S 512 -y 1 -x "$CYLSIZE" -f "$NAME"`
79287635Sdteskegpart create -s VTOC8 $MD
80246283Shrs# !4: usr, for ISO image part
81287635Sdteskegpart add -i 1 -s "$(($ISOCYLS * $CYLSIZE * 512))b" -t \!4 $MD
82246283Shrs# !2: root, for bootfs part.
83287635Sdteskegpart add -i 6 -s "$(($BOOTFSCYLS * $CYLSIZE * 512))b" -t \!2 $MD
84246283Shrsmdconfig -d -u ${MD#md}
85