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
26246283Shrs	echo Usage: $0 '[-b] image-label image-name base-bits-dir [extra-bits-dir]' > /dev/stderr
27105060Sjake	exit 1
28105060Sjakefi
29105060Sjake
30246283Shrscase $1 in
31246283Shrs-b)	BOPT=$1; shift ;;
32246283Shrsesac
33245177ShrsLABEL=`echo $1 | tr '[:lower:]' '[:upper:]'`; shift
34105060SjakeNAME=$1; shift
35253676SmariusBASEBITSDIR=$1
36105060Sjake
37246283Shrs# Create an ISO image
38246283Shrspublisher="The FreeBSD Project.  http://www.FreeBSD.org/"
39253676Smariusecho "/dev/iso9660/$LABEL / cd9660 ro 0 0" > "${BASEBITSDIR}/etc/fstab"
40253676Smariusmakefs -t cd9660 -o rockridge -o label="$LABEL" -o publisher="$publisher" ${NAME}.tmp $*
41253676Smariusrm "${BASEBITSDIR}/etc/fstab"
42246283Shrs
43246283Shrsif [ "x$BOPT" != "x-b" ]; then
44246283Shrs	mv ${NAME}.tmp ${NAME}
45246283Shrs	exit 0
46246283Shrsfi
47253676Smarius
48246283ShrsTMPIMGDIR=`mktemp -d /tmp/bootfs.XXXXXXXX` || exit 1
49246283ShrsBOOTFSDIR="${TMPIMGDIR}/bootfs"
50246283ShrsBOOTFSIMG="${TMPIMGDIR}/bootfs.img"
51246283Shrs
52246283Shrs# Create a boot filesystem
53246283Shrsmkdir -p "${BOOTFSDIR}/boot"
54253676Smariuscp -p "${BASEBITSDIR}/boot/loader" "${BOOTFSDIR}/boot"
55246283Shrsmakefs -t ffs -B be -M 512k "${BOOTFSIMG}" "${BOOTFSDIR}"
56253676Smariusdd if="${BASEBITSDIR}/boot/boot1" of="${BOOTFSIMG}" bs=512 conv=notrunc,sync
57246283Shrs
58246283Shrs# Create a boot ISO image
59246283Shrs: ${CYLSIZE:=640}
60246283ShrsISOSIZE=$(stat -f %z ${NAME}.tmp)
61246283ShrsISOBLKS=$(((${ISOSIZE} + 511) / 512))
62246283ShrsISOCYLS=$(((${ISOBLKS} + (${CYLSIZE} - 1)) / ${CYLSIZE}))
63246283Shrs
64246283ShrsBOOTFSSIZE=$(stat -f %z "${BOOTFSIMG}")
65246283ShrsBOOTFSBLKS=$(((${BOOTFSSIZE} + 511) / 512))
66246283ShrsBOOTFSCYLS=$(((${BOOTFSBLKS} + (${CYLSIZE} - 1)) / ${CYLSIZE}))
67246283Shrs
68246283ShrsENDCYL=$((${ISOCYLS} + ${BOOTFSCYLS}))
69246283ShrsNSECTS=$((${ENDCYL} * 1 * ${CYLSIZE}))
70246283Shrs
71246283Shrsdd if=${NAME}.tmp of=${NAME} bs=${CYLSIZE}b conv=notrunc,sync
72246283Shrsdd if=${BOOTFSIMG} of=${NAME} bs=${CYLSIZE}b seek=${ISOCYLS} conv=notrunc,sync
73246283Shrs# The number of alternative cylinders is always 2.
74246283Shrsdd if=/dev/zero of=${NAME} bs=${CYLSIZE}b seek=${ENDCYL} count=2 conv=notrunc,sync
75246283Shrsrm -rf ${NAME}.tmp ${TMPIMGDIR}
76246283Shrs
77246283Shrs# Write VTOC8 label to boot ISO image
78246283ShrsMD=`mdconfig -a -t vnode -S 512 -y 1 -x ${CYLSIZE} -f ${NAME}`
79246283Shrsgpart create -s VTOC8 ${MD}
80246283Shrs# !4: usr, for ISO image part
81246283Shrsgpart add -i 1 -s $((${ISOCYLS} * ${CYLSIZE} * 512))b -t \!4 ${MD}
82246283Shrs# !2: root, for bootfs part.
83246283Shrsgpart add -i 6 -s $((${BOOTFSCYLS} * ${CYLSIZE} * 512))b -t \!2 ${MD}
84246283Shrsmdconfig -d -u ${MD#md}
85