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