Home | History | Annotate | Line # | Download | only in common
sunbootcd.sh revision 1.4
      1  1.1  lukem #! /bin/sh
      2  1.1  lukem #
      3  1.4    snj # $NetBSD: sunbootcd.sh,v 1.4 2004/09/22 21:24:07 snj Exp $
      4  1.1  lukem #
      5  1.1  lukem # Copyright (c) 2003 The NetBSD Foundation, Inc.
      6  1.1  lukem # All rights reserved.
      7  1.1  lukem #
      8  1.1  lukem # This code is derived from software contributed to The NetBSD Foundation
      9  1.1  lukem # by Luke Mewburn.
     10  1.1  lukem #
     11  1.1  lukem # Redistribution and use in source and binary forms, with or without
     12  1.1  lukem # modification, are permitted provided that the following conditions
     13  1.1  lukem # are met:
     14  1.1  lukem # 1. Redistributions of source code must retain the above copyright
     15  1.1  lukem #    notice, this list of conditions and the following disclaimer.
     16  1.1  lukem # 2. Redistributions in binary form must reproduce the above copyright
     17  1.1  lukem #    notice, this list of conditions and the following disclaimer in the
     18  1.1  lukem #    documentation and/or other materials provided with the distribution.
     19  1.1  lukem # 3. All advertising materials mentioning features or use of this software
     20  1.1  lukem #    must display the following acknowledgement:
     21  1.1  lukem #        This product includes software developed by the NetBSD
     22  1.1  lukem #        Foundation, Inc. and its contributors.
     23  1.1  lukem # 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.1  lukem #    contributors may be used to endorse or promote products derived
     25  1.1  lukem #    from this software without specific prior written permission.
     26  1.1  lukem #
     27  1.1  lukem # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.1  lukem # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.1  lukem # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.1  lukem # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.1  lukem # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.1  lukem # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.1  lukem # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.1  lukem # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.1  lukem # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.1  lukem # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.1  lukem # POSSIBILITY OF SUCH DAMAGE.
     38  1.1  lukem #
     39  1.1  lukem 
     40  1.3  lukem : ${SUNLABEL:=sunlabel}		# sunlabel(8)
     41  1.1  lukem : ${CYLSIZE:=640}		# Cylinder size, in 512byte blocks
     42  1.1  lukem 
     43  1.1  lukem PROGNAME=${0##*/}
     44  1.1  lukem FORMAT="%-8s offset %4d, size %4d, file %s\n"
     45  1.1  lukem 
     46  1.1  lukem 
     47  1.1  lukem usage()
     48  1.1  lukem {
     49  1.1  lukem 	cat 1>&2 << _USAGE_
     50  1.1  lukem Usage: ${PROGNAME} fsimage sun4 [sun4c [sun4m [sun3|sun4d [sun3x|sun4u]]]]
     51  1.1  lukem 	Combine file system partitions for Sun Microsystems, Inc. computers
     52  1.4    snj 	into a CD-ROM file system image suitable for booting on the
     53  1.1  lukem 	following platforms:
     54  1.1  lukem 		NetBSD/sun3:	sun3, sun3x
     55  1.1  lukem 		NetBSD/sparc:	sun4, sun4c, sun4d, sun4m
     56  1.1  lukem 		NetBSD/sparc64:	sun4u
     57  1.1  lukem 	The architecture arguments must be bootable file system image
     58  1.1  lukem 	for that architecture, or \`-' if no entry is desired.
     59  1.1  lukem 	\`fsimage' is typically an iso9660 file system image, although
     60  1.1  lukem 	any time of file system can be used as long as the first 512
     61  1.1  lukem 	bytes of the image are not used.  \`fsimage' is modified, and
     62  1.1  lukem 	the additional partitions are added in order.  If the same
     63  1.1  lukem 	filename is used more than once for different architectures,
     64  1.1  lukem 	it will only be copied once.
     65  1.1  lukem _USAGE_
     66  1.1  lukem 	exit 1
     67  1.1  lukem }
     68  1.1  lukem 
     69  1.1  lukem if [ $# -lt 2 -o $# -gt 6 ]; then
     70  1.1  lukem 	usage
     71  1.1  lukem fi
     72  1.1  lukem 
     73  1.1  lukem for curfile in $*; do
     74  1.1  lukem 	[ "$curfile" = "-" ] && continue
     75  1.1  lukem 	if [ ! -f "$curfile" ]; then
     76  1.1  lukem 		echo 1>&2 "${PROGNAME}: ${curfile}: No such file."
     77  1.1  lukem 		exit 1
     78  1.1  lukem 	fi
     79  1.1  lukem done
     80  1.1  lukem 
     81  1.1  lukem ISOIMAGE="$1";	shift
     82  1.1  lukem 
     83  1.1  lukem ISOSIZE=$( ls -l "${ISOIMAGE}" | awk '{print $5}' )
     84  1.1  lukem ISOBLKS=$(( (${ISOSIZE} + 511) / 512 ))
     85  1.1  lukem ISOCYLS=$(( (${ISOBLKS} + (${CYLSIZE} - 1)) / ${CYLSIZE} ))
     86  1.1  lukem 
     87  1.1  lukem printf "${FORMAT}" "fsimage:" 0 ${ISOCYLS} "${ISOIMAGE}"
     88  1.1  lukem 
     89  1.1  lukem ENDCYL=${ISOCYLS}
     90  1.1  lukem curpart=0
     91  1.1  lukem for curfile in $*; do
     92  1.1  lukem 	curpart=$(( ${curpart} + 1 ))
     93  1.1  lukem 	[ "$curfile" = "-" ] && continue
     94  1.1  lukem 
     95  1.1  lukem 	tpart=1
     96  1.1  lukem 	curoff=${ENDCYL}
     97  1.1  lukem 	while [ ${tpart} -lt ${curpart} ]; do
     98  1.1  lukem 		tfile=$(eval echo \$PART${tpart}FILE)
     99  1.1  lukem 		if [ "${curfile}" = "${tfile}" ]; then
    100  1.1  lukem 			curoff=$(eval echo \$PART${tpart}OFF)
    101  1.1  lukem 			break
    102  1.1  lukem 		fi
    103  1.1  lukem 		tpart=$(( ${tpart} + 1 ))
    104  1.1  lukem 	done
    105  1.1  lukem 
    106  1.1  lukem 	cursize=$( ls -l "${curfile}" | awk '{print $5}' )
    107  1.1  lukem 	curblks=$(( (${cursize} + 511) / 512 ))
    108  1.1  lukem 	curcyls=$(( (${curblks} + (${CYLSIZE} - 1)) / ${CYLSIZE} ))
    109  1.1  lukem 	printf "${FORMAT}" "Image ${curpart}:" ${curoff} ${curcyls} "${curfile}"
    110  1.1  lukem 
    111  1.1  lukem 	eval	PART${curpart}SIZE=${cursize} \
    112  1.1  lukem 		PART${curpart}BLKS=${curblks} \
    113  1.1  lukem 		PART${curpart}CYLS=${curcyls} \
    114  1.1  lukem 		PART${curpart}OFF=${curoff} \
    115  1.1  lukem 		PART${curpart}FILE="${curfile}"
    116  1.1  lukem 
    117  1.1  lukem 	if [ $curoff -eq $ENDCYL ]; then		# append ${curfile}
    118  1.1  lukem 		echo "    (appending ${curfile} to ${ISOIMAGE})"
    119  1.1  lukem 		dd if="${curfile}" of="${ISOIMAGE}" bs=${CYLSIZE}b \
    120  1.1  lukem 		    seek=${ENDCYL} conv=notrunc,sync 2>/dev/null
    121  1.1  lukem 		ENDCYL=$(( $ENDCYL + $curcyls ))
    122  1.1  lukem 	fi
    123  1.1  lukem 
    124  1.1  lukem done
    125  1.1  lukem 
    126  1.1  lukem printf "${FORMAT}" "Final:" 0 ${ENDCYL} "${ISOIMAGE}"
    127  1.1  lukem 
    128  1.1  lukem ${SUNLABEL} -nq "${ISOIMAGE}" << _partinfo_
    129  1.1  lukem V nsect ${CYLSIZE}
    130  1.1  lukem V nhead 1
    131  1.1  lukem V rpm 300
    132  1.1  lukem V pcyl ${ENDCYL}
    133  1.1  lukem V ncyl ${ENDCYL}
    134  1.1  lukem a 0 $(( ${ISOCYLS} * ${CYLSIZE} ))
    135  1.1  lukem b ${PART1OFF:-0} $(( ${PART1CYLS:-0} * ${CYLSIZE} ))
    136  1.1  lukem c ${PART2OFF:-0} $(( ${PART2CYLS:-0} * ${CYLSIZE} ))
    137  1.1  lukem d ${PART3OFF:-0} $(( ${PART3CYLS:-0} * ${CYLSIZE} ))
    138  1.1  lukem e ${PART4OFF:-0} $(( ${PART4CYLS:-0} * ${CYLSIZE} ))
    139  1.1  lukem f ${PART5OFF:-0} $(( ${PART5CYLS:-0} * ${CYLSIZE} ))
    140  1.1  lukem W
    141  1.1  lukem _partinfo_
    142