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