12851Sjongkis#!/bin/ksh -p
20Sstevel@tonic-gate#
30Sstevel@tonic-gate# CDDL HEADER START
40Sstevel@tonic-gate#
50Sstevel@tonic-gate# The contents of this file are subject to the terms of the
61777Ssetje# Common Development and Distribution License (the "License").
71777Ssetje# You may not use this file except in compliance with the License.
80Sstevel@tonic-gate#
90Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate# See the License for the specific language governing permissions
120Sstevel@tonic-gate# and limitations under the License.
130Sstevel@tonic-gate#
140Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate#
200Sstevel@tonic-gate# CDDL HEADER END
210Sstevel@tonic-gate#
220Sstevel@tonic-gate
235822Sjhd# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate# Use is subject to license terms.
250Sstevel@tonic-gate#
261777Ssetje# ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate
280Sstevel@tonic-gate# utility to pack and unpack a boot/root archive
290Sstevel@tonic-gate# both ufs and hsfs (iso9660) format archives are unpacked
300Sstevel@tonic-gate# only ufs archives are generated
310Sstevel@tonic-gate#
320Sstevel@tonic-gate# usage: pack   <archive> <root>
330Sstevel@tonic-gate#        unpack <archive> <root>
340Sstevel@tonic-gate#        packmedia   <solaris_image> <root>
350Sstevel@tonic-gate#        unpackmedia <solaris_image> <root>
360Sstevel@tonic-gate#
370Sstevel@tonic-gate#   Where <root> is the directory to unpack to and will be cleaned out
380Sstevel@tonic-gate#   if it exists.
390Sstevel@tonic-gate#
400Sstevel@tonic-gate#   In the case of (un)packmedia, the image is packed or unpacked to/from
410Sstevel@tonic-gate#   Solaris media and all the things that don't go into the ramdisk image
420Sstevel@tonic-gate#   are (un)cpio'd as well
430Sstevel@tonic-gate#
445648Ssetje# This utility is also used to pack parts (in essence the window system,
455648Ssetje# usr/dt and usr/openwin) of the non ramdisk SPARC
465648Ssetje# miniroot. (un)packmedia will recognize that they are being run a SPARC
475648Ssetje# miniroot and do the appropriate work.
481777Ssetje#
490Sstevel@tonic-gate
500Sstevel@tonic-gateusage()
510Sstevel@tonic-gate{
520Sstevel@tonic-gate	printf "usage: root_archive pack <archive> <root>\n"
530Sstevel@tonic-gate	printf "       root_archive unpack <archive> <root>\n"
540Sstevel@tonic-gate	printf "       root_archive packmedia   <solaris_image> <root>\n"
550Sstevel@tonic-gate	printf "       root_archive unpackmedia <solaris_image> <root>\n"
560Sstevel@tonic-gate}
570Sstevel@tonic-gate
582334Ssetjecleanup()
592334Ssetje{
602334Ssetje	if [ -d $MNT ] ; then
612334Ssetje		umount $MNT 2> /dev/null
622334Ssetje		rmdir $MNT
632334Ssetje	fi
642334Ssetje
652851Sjongkis	lofiadm -d "$TMR" 2>/dev/null
665648Ssetje        if [ "$REALTHING" != true ] ; then
675648Ssetje		rm -f "$TMR"
685648Ssetje	fi
695648Ssetje	rm -f "$TMR.gz"
702334Ssetje}
712334Ssetje
725822Sjhdpreload_Gnome()
734889Ssjelinek{
744889Ssjelinek	MEDIA="$1"
754889Ssjelinek	MINIROOT="$2"
764889Ssjelinek
774889Ssjelinek
784889Ssjelinek	(
794889Ssjelinek		# Prepopulate the gconf database. This needs to be done and
804889Ssjelinek		# done first for several reasons. 1) Archiving out the gnome
814889Ssjelinek		# libraries and binaries causes the gconftool-2 to not run
824889Ssjelinek		# appropriately at boot time. 2) The binaries and libraries
834889Ssjelinek		# needed to run this are big and thus we want to archive
844889Ssjelinek		# them separately. 3) Having schemas prepopluated in the
854889Ssjelinek		# miniroot means faster boot times.
864889Ssjelinek		#
874889Ssjelinek
884889Ssjelinek		cd "$MINIROOT"
894889Ssjelinek		HOME="./tmp/root"
904889Ssjelinek		export HOME
914889Ssjelinek		umask 0022
925648Ssetje		mumble=.tmp_proto/root/etc/gconf/gconf.xml.defaults
935648Ssetje		GCONF_CONFIG_SOURCE="xml:merged:$MINIROOT/$mumble"
944889Ssjelinek		export GCONF_CONFIG_SOURCE
954889Ssjelinek		SCHEMADIR="$MINIROOT/.tmp_proto/root/etc/gconf/schemas"
964889Ssjelinek		export SCHEMADIR
975648Ssetje		/usr/bin/gconftool-2 --makefile-install-rule \
985648Ssetje		    $SCHEMADIR/*.schemas >/dev/null 2>&1
995571Ssjelinek		echo '
1005571Ssjelinek		xml:readwrite:/tmp/root/.gconf
1015571Ssjelinek		xml:readonly:/etc/gconf/gconf.xml.defaults
1025571Ssjelinek		' > /"$MINIROOT"/.tmp_proto/root/etc/gconf/2/path
1035822Sjhd	)
1045822Sjhd}
1055571Ssjelinek
1065822Sjhdarchive_Gnome()
1075822Sjhd{
1085822Sjhd	MEDIA="$1"
1095822Sjhd	MINIROOT="$2"
1105822Sjhd
1115822Sjhd	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
1125822Sjhd	RELEASE=`basename "$RELEASE"`
1135822Sjhd	CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
1145822Sjhd
1155822Sjhd	# Create the gnome archive
1165822Sjhd	#
1175822Sjhd	(
1184889Ssjelinek		# usr/share gnome stuff
1194889Ssjelinek		cd "$MINIROOT"
1204889Ssjelinek		find usr/share/GConf usr/share/application-registry \
1214889Ssjelinek		    usr/share/autostart usr/share/dbus-1 usr/share/dtds \
1224889Ssjelinek		    usr/share/emacs usr/share/gnome usr/share/gnome-2.0 \
1234889Ssjelinek		    usr/share/gnome-background-properties \
1244889Ssjelinek		    usr/share/gtk-engines usr/share/gui-install \
1254889Ssjelinek		    usr/share/icon-naming-utils usr/share/control-center \
1264889Ssjelinek		    usr/share/icons usr/share/locale usr/share/metacity \
1274889Ssjelinek		    usr/share/mime usr/share/mime-info usr/share/pixmaps \
1284889Ssjelinek		    usr/share/scrollkeeper usr/share/sgml usr/share/themes \
1294889Ssjelinek		    usr/share/xml \
1304889Ssjelinek		    -print > /tmp/gnome_share.$$ 2>/dev/null
1314889Ssjelinek
1324889Ssjelinek		if [ ! -f /tmp/gnome_share.$$ ] ; then
1334889Ssjelinek			echo "/tmp/gnome_share.$$ file list not found."
1345648Ssetje			return
1354889Ssjelinek		fi
1364889Ssjelinek
1374889Ssjelinek		# usr/lib gnome stuff
1384889Ssjelinek
1394889Ssjelinek		find usr/lib/libgnome*\.so\.* \
1404889Ssjelinek		    usr/lib/libgst*\.so\.* usr/lib/libgconf*\.so\.* \
1414889Ssjelinek		    usr/lib/libgdk*\.so\.* usr/lib/libgtk*\.so\.* \
1424889Ssjelinek		    usr/lib/libglade*\.so\.* usr/lib/libmetacity*\.so\.* \
1434889Ssjelinek		    usr/lib/libfontconfig*\.so\.* usr/lib/libgmodule*\.so\.* \
1444889Ssjelinek		    usr/lib/libgobject*\.so\.* usr/lib/libgthread*\.so\.* \
1454889Ssjelinek		    usr/lib/libpopt*\.so\.* usr/lib/libstartup*\.so\.* \
1464889Ssjelinek		    usr/lib/libexif*\.so\.* usr/lib/libtiff*\.so\.* \
1474889Ssjelinek		    usr/lib/libdbus*\.so\.* usr/lib/libstartup*\.so\.* \
1484889Ssjelinek		    usr/lib/libexif*\.so\.* usr/lib/libORBit*\.so\.* \
1494889Ssjelinek	 	    usr/lib/libmlib*\.so\.* usr/lib/libxsl*\.so\.* \
1504889Ssjelinek		    usr/lib/libpango*\.so\.* usr/lib/libpng*\.so\.* \
1514889Ssjelinek		    usr/lib/liboil*\.so\.* usr/lib/libbonobo*\.so\.* \
1524889Ssjelinek		    usr/lib/libart*\.so\.* usr/lib/libcairo*\.so\.* \
1534889Ssjelinek		    usr/lib/libjpeg*\.so\.* \
1544889Ssjelinek		    usr/lib/libpolkit*\.so\.* \
1554889Ssjelinek			-print | egrep -v '\.so\.[0]$' > \
1564889Ssjelinek		       /tmp/gnome_lib.$$ 2>/dev/null
1574889Ssjelinek
1584889Ssjelinek		find usr/lib/nautilus usr/lib/pango usr/lib/iconv \
1594889Ssjelinek		    usr/lib/metacity-dialog usr/lib/window-manager-settings \
1604889Ssjelinek		    usr/lib/bonobo-2.0 usr/lib/bononbo usr/lib/gtk-2.0 \
1614889Ssjelinek		    usr/lib/GConf usr/lib/bonobo-activation-server \
1624889Ssjelinek		    usr/lib/python2.4 usr/lib/gstreamer-0.10 \
1634889Ssjelinek		    usr/lib/gconf-sanity-check-2 usr/lib/gconfd \
1644889Ssjelinek		    usr/lib/gnome-vfs-2.0 usr/lib/dbus-daemon \
1654889Ssjelinek		    usr/lib/gnome-vfs-daemon usr/lib/gnome-settings-daemon \
1664889Ssjelinek		    usr/lib/gnome_segv2 usr/lib/orbit-2.0 \
1674889Ssjelinek		    usr/lib/libmlib \
1684889Ssjelinek		    print > /tmp/gnome_libdir.$$ 2>/dev/null
1694889Ssjelinek
1704889Ssjelinek		if [ ! -f /tmp/gnome_lib.$$  -a ! -f gnome_libdir.$$ ] ; then
1714889Ssjelinek			echo "/tmp/gnome_lib.$$ file list not found."
1724889Ssjelinek			return
1734889Ssjelinek		fi
1744889Ssjelinek
1754889Ssjelinek		# /usr/sfw gnome stuff
1764889Ssjelinek		find usr/sfw/bin usr/sfw/include usr/sfw/share usr/sfw/src \
1774889Ssjelinek		    -print > /tmp/gnome_sfw.$$ 2>/dev/null
1784889Ssjelinek
1794889Ssjelinek		if [ ! -f /tmp/gnome_sfw.$$ ] ; then
1804889Ssjelinek			echo "/tmp/gnome_sfw.$$ file list not found."
1814889Ssjelinek			return
1824889Ssjelinek		fi
1834889Ssjelinek
1844889Ssjelinek		# gnome app binaries usr/bin
1854889Ssjelinek		find usr/bin/gnome* usr/bin/gui-install usr/bin/bonobo* \
1864889Ssjelinek		    usr/bin/gtk-* usr/bin/fax* usr/bin/gdk* usr/bin/gif2tiff \
1874889Ssjelinek		    usr/bin/install-lan \
1884889Ssjelinek		    usr/bin/metacity* usr/bin/gst-* usr/bin/gconftool-2 \
1894889Ssjelinek		    usr/bin/pango* usr/bin/desktop* usr/bin/djpeg \
1904889Ssjelinek		    usr/bin/notify-send usr/bin/oil-bugreport \
1914889Ssjelinek		    usr/bin/bmp2tiff usr/bin/thembus-theme-applier \
1924889Ssjelinek		    usr/bin/thumbnail usr/lib/update-* \
1934889Ssjelinek		    usr/bin/ras2tiff usr/bin/raw2tiff usr/bin/rdjpgcom \
1944889Ssjelinek		    usr/bin/thumbnail usr/bin/dbus* \
1954889Ssjelinek		    usr/bin/tiff* usr/bin/rgb2ycbcr \
1964889Ssjelinek		    usr/bin/fc-cache usr/bin/fc-list \
1974889Ssjelinek			-print > /tmp/gnome_bin.$$ 2>/dev/null
1984889Ssjelinek
1994889Ssjelinek		if [ ! -f /tmp/gnome_bin.$$ ] ; then
2004889Ssjelinek			echo "/tmp/gnome_bin.$$ file list not found."
2015648Ssetje			return
2024889Ssjelinek		fi
2034889Ssjelinek
2044889Ssjelinek		# Cat all the files together and create the gnome archive
2054889Ssjelinek		#
2064889Ssjelinek
2074889Ssjelinek		cat /tmp/gnome_libdir.$$ /tmp/gnome_lib.$$ \
2084889Ssjelinek		     /tmp/gnome_share.$$ /tmp/gnome_sfw.$$ /tmp/gnome_bin.$$ \
2094889Ssjelinek		    > /tmp/gnome.$$
2104889Ssjelinek
2114889Ssjelinek		if [ ! -f /tmp/gnome.$$ ] ; then
2124889Ssjelinek			echo "/tmp/gnome.$$ file not found."
2134889Ssjelinek			return
2144889Ssjelinek		fi
2154889Ssjelinek		# Save off this file in the miniroot for use later
2164889Ssjelinek		# when unpacking. Clean up old cruft if there.
2174889Ssjelinek		#
2184889Ssjelinek
2194889Ssjelinek		if [ -f .tmp_proto/gnome_saved ]; then
2204889Ssjelinek			rm -f .tmp_proto/gnome_saved
2214889Ssjelinek		fi
2224889Ssjelinek
2234889Ssjelinek		cp /tmp/gnome.$$ .tmp_proto/gnome_saved
2244889Ssjelinek
2254889Ssjelinek		# Create gnome archive
2264889Ssjelinek		#
2274889Ssjelinek
2284889Ssjelinek		cpio -ocmPuB < /tmp/gnome.$$ 2>/dev/null | bzip2 > \
2294889Ssjelinek		    "$CPIO_DIR/gnome.cpio.bz2"
2304889Ssjelinek
2315648Ssetje		# Remove files from miniroot that are in archive.
2324889Ssjelinek		# Create symlinks for files in archive
2334889Ssjelinek
2344889Ssjelinek		rm -rf `cat /tmp/gnome_share.$$`
2354889Ssjelinek
2364889Ssjelinek		for i in `cat /tmp/gnome_share.$$`
2375648Ssetje		do
2384889Ssjelinek			ln -s /tmp/root/$i $i 2>/dev/null
2394889Ssjelinek		done
2404889Ssjelinek
2414889Ssjelinek		rm -rf `cat /tmp/gnome_lib.$$`
2424889Ssjelinek		for i in `cat /tmp/gnome_lib.$$`
2434889Ssjelinek		do
2444889Ssjelinek			ln -s /tmp/root/$i $i 2>/dev/null
2454889Ssjelinek		done
2464889Ssjelinek
2474889Ssjelinek		rm -rf `cat /tmp/gnome_libdir.$$`
2484889Ssjelinek		for i in `cat /tmp/gnome_libdir.$$`
2495648Ssetje		do
2504889Ssjelinek			ln -s /tmp/root/$i $i 2>/dev/null
2514889Ssjelinek		done
2524889Ssjelinek
2534889Ssjelinek		rm -rf `cat /tmp/gnome_sfw.$$`
2544889Ssjelinek		for i in `cat /tmp/gnome_sfw.$$`
2555648Ssetje		do
2564889Ssjelinek			ln -s /tmp/root/$i $i 2>/dev/null
2574889Ssjelinek		done
2584889Ssjelinek
2594889Ssjelinek		rm -rf `cat /tmp/gnome_bin.$$`
2604889Ssjelinek		for i in `cat /tmp/gnome_bin.$$`
2615648Ssetje		do
2624889Ssjelinek			ln -s /tmp/root/$i $i 2>/dev/null
2634889Ssjelinek		done
2644889Ssjelinek		rm -f /tmp/gnome_share.$$
2654889Ssjelinek		rm -f /tmp/gnome_lib.$$
2664889Ssjelinek		rm -f /tmp/gnome_libdir.$$
2674889Ssjelinek		rm -f /tmp/gnome_bin.$$
2684889Ssjelinek	)
2694889Ssjelinek}
2704889Ssjelinek
2714889Ssjelinekarchive_JavaGUI()
2724889Ssjelinek{
2734889Ssjelinek	MEDIA="$1"
2744889Ssjelinek	MINIROOT="$2"
2754889Ssjelinek
2764889Ssjelinek	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
2774889Ssjelinek	RELEASE=`basename "$RELEASE"`
2784889Ssjelinek
2795648Ssetje	CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
2804889Ssjelinek
2814889Ssjelinek	# Archive the java wizard components that are only used in the
2824889Ssjelinek	# non developer express path.
2834889Ssjelinek	#
2844889Ssjelinek	(
2854889Ssjelinek		# path is usr/lib/install/data
2864889Ssjelinek		cd "$MINIROOT"
2874889Ssjelinek		find usr/lib/install/data/wizards \
2884889Ssjelinek		    -print > /tmp/java_ui.$$ 2>/dev/null
2894889Ssjelinek
2904889Ssjelinek		if [ ! -f /tmp/java_ui.$$ ] ; then
2914889Ssjelinek			echo "/tmp/java_ui.$$ file list not found."
2925648Ssetje			return
2934889Ssjelinek		fi
2944889Ssjelinek
2954889Ssjelinek		cpio -ocmPuB < /tmp/java_ui.$$ 2>/dev/null | bzip2 > \
2964889Ssjelinek		    "$CPIO_DIR/javaui.cpio.bz2"
2974889Ssjelinek
2984889Ssjelinek		rm -rf `cat /tmp/java_ui.$$`
2995648Ssetje		ln -s /tmp/root/usr/lib/install/data/wizards \
3005648Ssetje		    usr/lib/install/data/wizards 2>/dev/null
3014889Ssjelinek
3024889Ssjelinek		rm -f /tmp/java_ui.$$
3034889Ssjelinek
3044889Ssjelinek	)
3054889Ssjelinek}
3064889Ssjelinek
3074889Ssjelinekarchive_Misc()
3084889Ssjelinek{
3094889Ssjelinek	MEDIA="$1"
3104889Ssjelinek	MINIROOT="$2"
3114889Ssjelinek
3124889Ssjelinek	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
3134889Ssjelinek	RELEASE=`basename "$RELEASE"`
3144889Ssjelinek
3155648Ssetje	CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
3164889Ssjelinek
3174889Ssjelinek	# Archive misc stuff that is needed by non devex installer
3184889Ssjelinek	#
3194889Ssjelinek	(
3204889Ssjelinek		# usr/lib stuff
3214889Ssjelinek		cd "$MINIROOT"
3224889Ssjelinek		find usr/lib/lp -print > /tmp/lp.$$ 2>/dev/null
3234889Ssjelinek		if [ ! -f /tmp/lp.$$ ] ; then
3244889Ssjelinek			echo "/tmp/lp.$$ file list not found."
3255648Ssetje			return
3264889Ssjelinek		fi
3274889Ssjelinek
3284889Ssjelinek		cpio -ocmPuB < /tmp/lp.$$ 2>/dev/null | bzip2 > \
3294889Ssjelinek		    "$CPIO_DIR/lpmisc.cpio.bz2"
3304889Ssjelinek
3314889Ssjelinek		rm -rf `cat /tmp/lp.$$`
3324889Ssjelinek		ln -s /tmp/root/usr/lib/lp usr/lib/lp 2>/dev/null
3334889Ssjelinek
3344889Ssjelinek		rm -f /tmp/lp.$$
3354889Ssjelinek	)
3364889Ssjelinek
3374889Ssjelinek}
3384889Ssjelinek
3394889Ssjelinekarchive_Perl()
3404889Ssjelinek{
3414889Ssjelinek	MEDIA="$1"
3424889Ssjelinek	MINIROOT="$2"
3434889Ssjelinek
3444889Ssjelinek	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
3454889Ssjelinek	RELEASE=`basename "$RELEASE"`
3464889Ssjelinek
3475648Ssetje	CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
3484889Ssjelinek
3494889Ssjelinek	# Archive perl, it is only needed by gnome gui.
3504889Ssjelinek	#
3514889Ssjelinek	(
3524889Ssjelinek		# in usr
3534889Ssjelinek		cd "$MINIROOT"
3544889Ssjelinek		find usr/perl5 -print > /tmp/perl.$$ 2>/dev/null
3554889Ssjelinek
3564889Ssjelinek		if [ ! -f /tmp/perl.$$ ] ; then
3574889Ssjelinek			echo "/tmp/perl.$$ file list not found."
3585648Ssetje			return
3594889Ssjelinek		fi
3604889Ssjelinek		cpio -ocmPuB < /tmp/perl.$$ 2>/dev/null | bzip2 > \
3614889Ssjelinek		    "$CPIO_DIR/perl.cpio.bz2"
3624889Ssjelinek
3634889Ssjelinek		rm -rf `cat /tmp/perl.$$` 2>/dev/null
3645571Ssjelinek		ln -s /tmp/root/usr/perl5 usr/perl5 2>/dev/null
3654889Ssjelinek
3664889Ssjelinek		rm -f /tmp/perl.$$
3674889Ssjelinek	)
3684889Ssjelinek}
3691777Ssetjearchive_X()
3700Sstevel@tonic-gate{
3711777Ssetje	MEDIA="$1"
3721777Ssetje	MINIROOT="$2"
3730Sstevel@tonic-gate
3741777Ssetje	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
3751777Ssetje	RELEASE=`basename "$RELEASE"`
3760Sstevel@tonic-gate
3775648Ssetje	CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
3780Sstevel@tonic-gate
3790Sstevel@tonic-gate	# create the graphics and non-graphics X archive
3800Sstevel@tonic-gate	#
3812851Sjongkis	(
3824889Ssjelinek		cd "$MINIROOT"
3834889Ssjelinek		find usr/openwin usr/dt usr/X11 -print 2> /dev/null |\
3842851Sjongkis		    cpio -ocmPuB 2> /dev/null | bzip2 > "$CPIO_DIR/X.cpio.bz2"
3850Sstevel@tonic-gate
3864889Ssjelinek		find usr/openwin/bin/mkfontdir \
3874889Ssjelinek		     usr/openwin/lib/installalias \
3884889Ssjelinek		     usr/openwin/server/lib/libfont.so.1 \
3894889Ssjelinek		     usr/openwin/server/lib/libtypesclr.so.0 \
3902851Sjongkis			 -print | cpio -ocmPuB 2> /dev/null | bzip2 > \
3912851Sjongkis			 "$CPIO_DIR/X_small.cpio.bz2"
3920Sstevel@tonic-gate
3934889Ssjelinek		rm -rf usr/dt usr/openwin usr/X11
3944889Ssjelinek		ln -s /tmp/root/usr/dt usr/dt
3954889Ssjelinek		ln -s /tmp/root/usr/openwin usr/openwin
3964889Ssjelinek		ln -s /tmp/root/usr/X11 usr/X11
3972851Sjongkis	)
3981777Ssetje}
3991777Ssetje
4005648Ssetjearchive_lu()
4015648Ssetje{
4025648Ssetje	MEDIA="$1"
4035648Ssetje	MINIROOT="$2"
4045648Ssetje
4055648Ssetje	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
4065648Ssetje	RELEASE=`basename "$RELEASE"`
4075648Ssetje
4085648Ssetje	CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
4095648Ssetje
4105648Ssetje	(
4115648Ssetje		cd "$MINIROOT"
4125648Ssetje		find usr/lib/install usr/snadm usr/sbin | \
4135648Ssetje		    cpio -ocmPuB 2> /dev/null | bzip2 > "$CPIO_DIR"/lu.cpio.bz2
4145648Ssetje		ls platform > "$CPIO_DIR/lu.platforms"
4155648Ssetje	)
4165648Ssetje}
4175648Ssetje
4181777Ssetjepackmedia()
4191777Ssetje{
4201777Ssetje	MEDIA="$1"
4211777Ssetje	MINIROOT="$2"
4221777Ssetje
4231777Ssetje	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
4241777Ssetje	RELEASE=`basename "$RELEASE"`
4255822Sjhd	ARCHIVES="X X_small perl lpmisc javaui gnome"
4261777Ssetje
4271777Ssetje	mkdir -p "$MEDIA/$RELEASE/Tools/Boot"
4285648Ssetje
4295648Ssetje	if [ -d "$MINIROOT/platform/i86pc" ] ; then
4305648Ssetje		mkdir -p "$MEDIA/boot/amd64"
4315648Ssetje		mkdir -p "$MEDIA/boot/platform/i86pc/kernel"
4325648Ssetje		mkdir -p "$MEDIA/boot/platform/i86pc/kernel/amd64"
4335648Ssetje		mkdir -p "$MEDIA/boot/platform/i86xpv/kernel"
4345648Ssetje		mkdir -p "$MEDIA/boot/platform/i86xpv/kernel/amd64"
4355648Ssetje		cp "$MINIROOT/platform/i86pc/multiboot" "$MEDIA/boot"
4365648Ssetje		cp "$MINIROOT/platform/i86pc/kernel/unix" \
4375648Ssetje		    "$MEDIA/boot/platform/i86pc/kernel/unix"
4385648Ssetje		cp "$MINIROOT/platform/i86pc/kernel/amd64/unix" \
4395648Ssetje		    "$MEDIA/boot/platform/i86pc/kernel/amd64/unix"
4405648Ssetje		cp "$MINIROOT/platform/i86xpv/kernel/unix" \
4415648Ssetje		    "$MEDIA/boot/platform/i86xpv/kernel/unix"
4425648Ssetje		cp "$MINIROOT/platform/i86xpv/kernel/amd64/unix" \
4435648Ssetje		    "$MEDIA/boot/platform/i86xpv/kernel/amd64/unix"
4445648Ssetje		(
4455648Ssetje			cd "$MEDIA/$RELEASE/Tools/Boot"
4465648Ssetje			ln -sf ../../../boot/x86.miniroot
4475648Ssetje			ln -sf ../../../boot/multiboot
4485648Ssetje			ln -sf ../../../boot/platform/i86pc/kernel/unix
4495648Ssetje			ln -sf ../../../boot/platform/i86pc/kernel/amd64/unix
4505648Ssetje			ln -sf ../../../boot/platform/i86xpv/kernel/unix
4515648Ssetje			ln -sf ../../../boot/platform/i86xpv/kernel/amd64/unix
4525648Ssetje			ln -sf ../../../boot/grub/pxegrub
4535648Ssetje		)
4545648Ssetje	fi
4555648Ssetje
4565648Ssetje	if [ -d "$MINIROOT/platform/sun4u" ] ; then
4575648Ssetje		mkdir -p "$MEDIA/boot"
458*6319Sjg		dd if="$MINIROOT/platform/sun4u/lib/fs/hsfs/bootblk" \
4595648Ssetje		    of="$MEDIA/boot/hsfs.bootblock" \
4605648Ssetje		    bs=1b oseek=1 count=15 conv=sync 2> /dev/null
4615648Ssetje	fi
4625648Ssetje
4635648Ssetje	for arch in sun4u sun4v ; do
4645648Ssetje		if [ -d "$MINIROOT/platform/$arch" ] ; then
4655648Ssetje			archdir="$MEDIA/$RELEASE/Tools/Boot/platform/$arch"
4665648Ssetje			mkdir -p $archdir
4675648Ssetje			ln -sf ../../../../../boot/sparc.miniroot \
4685648Ssetje			    "$archdir/boot_archive"
4695648Ssetje			cp "$MINIROOT/usr/platform/$arch/lib/fs/nfs/inetboot" \
4705648Ssetje			    "$archdir"
4715648Ssetje			cp "$MINIROOT/platform/$arch/wanboot" \
4725648Ssetje			    "$archdir"
4735648Ssetje			mkdir -p "$MEDIA/platform/$arch"
4745648Ssetje			ln -sf ../../boot/sparc.miniroot \
4755648Ssetje			    "$MEDIA/platform/$arch/boot_archive"
4765648Ssetje		fi
4775648Ssetje	done
4781777Ssetje
4791777Ssetje	# archive package databases to conserve memory
4801777Ssetje	#
4812851Sjongkis	(
4822851Sjongkis		cd "$MINIROOT"
4832851Sjongkis		find tmp/root/var/sadm/install tmp/root/var/sadm/pkg -print | \
4842851Sjongkis		    cpio -ocmPuB 2> /dev/null | bzip2 > \
4852851Sjongkis		    "$MEDIA/$RELEASE/Tools/Boot/pkg_db.cpio.bz2"
4862851Sjongkis	)
4871777Ssetje	rm -rf "$MINIROOT/tmp/root/var/sadm/install"
4881777Ssetje	rm -rf "$MINIROOT/tmp/root/var/sadm/pkg"
4891777Ssetje
4905648Ssetje	if [ -d "$MINIROOT/kernel/drv/sparcv9" ] ; then
4915648Ssetje		archive_lu "$MEDIA" "$MINIROOT"
4925648Ssetje	fi
4935648Ssetje
4942595Ssetje	archive_X "$MEDIA" "$MINIROOT"
4952595Ssetje
4964889Ssjelinek	# Take out the gnome and java parts of the installer from
4974889Ssjelinek	# the miniroot. These are not required to boot the system
4984889Ssjelinek	# and start the installers.
4994889Ssjelinek
5005648Ssetje	if [ -d "$MINIROOT/platform/i86pc" ] ; then
5015822Sjhd		preload_Gnome "$MEDIA" "$MINIROOT"
5025648Ssetje		archive_Gnome "$MEDIA" "$MINIROOT"
5035648Ssetje		archive_JavaGUI "$MEDIA" "$MINIROOT"
5045648Ssetje		archive_Misc "$MEDIA" "$MINIROOT"
5055648Ssetje		archive_Perl "$MEDIA" "$MINIROOT"
5065822Sjhd		MR="$MEDIA/boot/amd64/x86.miniroot"
5075822Sjhd		pack
5085822Sjhd
5095822Sjhd        	# Now that the 64-bit archives & miniroot have been created,
5105822Sjhd        	# restore the files from archives and save the 64-bit
5115822Sjhd        	# archives. Strip the 64-bit objects and create the
5125822Sjhd		# 32-bit archives and miniroot
5135822Sjhd
5145822Sjhd		unpackmedia "$MEDIA" "$MINIROOT"
5155822Sjhd		mkdir -p "$MEDIA/$RELEASE/Tools/Boot/amd64"
5165822Sjhd		for i in $ARCHIVES; do
5175822Sjhd			mv "$MEDIA/$RELEASE/Tools/Boot/${i}.cpio.bz2" \
5185822Sjhd				"$MEDIA/$RELEASE/Tools/Boot/amd64"
5195822Sjhd		done
5205822Sjhd		if [ -z "$STRIP_AMD64" ]; then
5215822Sjhd			strip_amd64
5225822Sjhd		fi
5235822Sjhd
5245822Sjhd		archive_X "$MEDIA" "$MINIROOT"
5255822Sjhd		archive_Gnome "$MEDIA" "$MINIROOT"
5265822Sjhd		archive_JavaGUI "$MEDIA" "$MINIROOT"
5275822Sjhd		archive_Perl "$MEDIA" "$MINIROOT"
5285822Sjhd		archive_Misc "$MEDIA" "$MINIROOT"
5295822Sjhd		MR="$MEDIA/boot/x86.miniroot"
5305648Ssetje	fi
5310Sstevel@tonic-gate
5321821Ssetje	# copy the install menu to menu.lst so we have a menu
5331821Ssetje	# on the install media
5341821Ssetje	#
5355648Ssetje	if [ -f "$MINIROOT/boot/grub/install_menu" ] ; then
5365648Ssetje		cp $MINIROOT/boot/grub/install_menu \
5375648Ssetje		    $MEDIA/boot/grub/menu.lst
5381821Ssetje	fi
5391777Ssetje}
5400Sstevel@tonic-gate
5411777Ssetjeunarchive_X()
5421777Ssetje{
5431777Ssetje	MEDIA="$1"
5441777Ssetje	UNPACKED_ROOT="$2"
5451777Ssetje
5461777Ssetje	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
5471777Ssetje	RELEASE=`basename "$RELEASE"`
5481777Ssetje
5495648Ssetje	CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
5501777Ssetje
5511777Ssetje	# unpack X
5521777Ssetje	#
5532851Sjongkis	(
5544889Ssjelinek		cd "$UNPACKED_ROOT"
5554889Ssjelinek		rm -rf usr/dt usr/openwin usr/X11
5562851Sjongkis		bzcat "$CPIO_DIR/X.cpio.bz2" | cpio -icdmu 2> /dev/null
5572851Sjongkis	)
5580Sstevel@tonic-gate}
5590Sstevel@tonic-gate
5600Sstevel@tonic-gateunpackmedia()
5611777Ssetje{
5621777Ssetje	MEDIA="$1"
5631777Ssetje	UNPACKED_ROOT="$2"
5640Sstevel@tonic-gate
5651777Ssetje	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
5661777Ssetje	RELEASE=`basename "$RELEASE"`
5671777Ssetje
5681777Ssetje	unarchive_X "$MEDIA" "$UNPACKED_ROOT"
5690Sstevel@tonic-gate
5700Sstevel@tonic-gate	# unpack package databases
5710Sstevel@tonic-gate	#
5722851Sjongkis	(
5732851Sjongkis		cd "$UNPACKED_ROOT"
5742851Sjongkis		bzcat "$MEDIA/$RELEASE/Tools/Boot/pkg_db.cpio.bz2" |
5752851Sjongkis		    cpio -icdmu 2> /dev/null
5764889Ssjelinek
5774889Ssjelinek		# unpack gnome, perl, java and misc
5784889Ssjelinek		# Remove symlinks left from unpacking x86.miniroot so that
5794889Ssjelinek		# unpacking subsequent archives will populate appropriately.
5804889Ssjelinek		#
5814889Ssjelinek		rm -rf usr/perl5
5824889Ssjelinek		rm -rf usr/lib/install/data/wizards
5834889Ssjelinek		rm -rf usr/lib/lp
5844889Ssjelinek
5854889Ssjelinek		# Gnome list saved off from packmedia
5864889Ssjelinek		for i in `cat .tmp_proto/gnome_saved`
5875648Ssetje		do
5884889Ssjelinek			rm -rf $i
5894889Ssjelinek		done
5904889Ssjelinek
5914889Ssjelinek		bzcat "$MEDIA/$RELEASE/Tools/Boot/gnome.cpio.bz2" |
5924889Ssjelinek		    cpio -icdmu 2>/dev/null
5934889Ssjelinek		bzcat "$MEDIA/$RELEASE/Tools/Boot/javaui.cpio.bz2" |
5944889Ssjelinek		    cpio -icdmu 2>/dev/null
5954889Ssjelinek		bzcat "$MEDIA/$RELEASE/Tools/Boot/lpmisc.cpio.bz2" |
5964889Ssjelinek		    cpio -icdmu 2>/dev/null
5974889Ssjelinek		bzcat "$MEDIA/$RELEASE/Tools/Boot/perl.cpio.bz2" |
5984889Ssjelinek		    cpio -icdmu 2>/dev/null
5992851Sjongkis	)
6000Sstevel@tonic-gate}
6010Sstevel@tonic-gate
6020Sstevel@tonic-gatedo_unpack()
6030Sstevel@tonic-gate{
6041777Ssetje	rm -rf "$UNPACKED_ROOT"
6051777Ssetje	mkdir -p "$UNPACKED_ROOT"
6062851Sjongkis	(
6072851Sjongkis		cd $MNT
6082851Sjongkis		find . -print | cpio -pdum "$UNPACKED_ROOT" 2> /dev/null
6092851Sjongkis	)
6100Sstevel@tonic-gate	umount $MNT
6110Sstevel@tonic-gate}
6120Sstevel@tonic-gate
6130Sstevel@tonic-gateunpack()
6140Sstevel@tonic-gate{
6150Sstevel@tonic-gate
6161777Ssetje	if [ ! -f "$MR" ] ; then
6170Sstevel@tonic-gate		usage
6180Sstevel@tonic-gate		exit 1
6190Sstevel@tonic-gate	fi
6200Sstevel@tonic-gate
6215648Ssetje	if [ `basename $MR` = x86.miniroot ] ; then
6225648Ssetje		gzcat "$MR" > $TMR
6235648Ssetje	else
6245648Ssetje		REALTHING=true ; export REALTHING
6255648Ssetje		TMR="$MR"
6265648Ssetje	fi
6270Sstevel@tonic-gate
6282334Ssetje	LOFIDEV=`/usr/sbin/lofiadm -a $TMR`
6290Sstevel@tonic-gate	if [ $? != 0 ] ; then
6300Sstevel@tonic-gate		echo lofi plumb failed
6310Sstevel@tonic-gate		exit 2
6320Sstevel@tonic-gate	fi
6330Sstevel@tonic-gate
6341777Ssetje	mkdir -p $MNT
6350Sstevel@tonic-gate
6362334Ssetje	FSTYP=`fstyp $LOFIDEV`
6370Sstevel@tonic-gate
6381777Ssetje	if [ "$FSTYP" = ufs ] ; then
6392334Ssetje		/usr/sbin/mount -o ro,nologging $LOFIDEV $MNT
6400Sstevel@tonic-gate		do_unpack
6411777Ssetje	elif [ "$FSTYP" = hsfs ] ; then
6422334Ssetje		/usr/sbin/mount -F hsfs -o ro $LOFIDEV $MNT
6430Sstevel@tonic-gate		do_unpack
6440Sstevel@tonic-gate	else
6450Sstevel@tonic-gate		printf "invalid root archive\n"
6460Sstevel@tonic-gate	fi
6470Sstevel@tonic-gate
6485648Ssetje
6490Sstevel@tonic-gate	rmdir $MNT
6502851Sjongkis	lofiadm -d $TMR ; LOFIDEV=
6515648Ssetje	if [ "$REALTHING" != true ] ; then
6525648Ssetje		rm $TMR
6535648Ssetje	fi
6545648Ssetje}
6555648Ssetje
6565648Ssetjecompress()
6575648Ssetje{
6585648Ssetje	SRC=$1
6595648Ssetje	DST=$2
6605648Ssetje
6615648Ssetje	(
6625648Ssetje		cd $SRC
6635648Ssetje		filelist=`find .`
6645648Ssetje
6655648Ssetje		for file in $filelist ; do
6665648Ssetje
6675648Ssetje			file=`echo $file | sed s#^./##`
6685648Ssetje
6695648Ssetje			# copy all files over to preserve hard links
6705648Ssetje			#
6715648Ssetje			echo $file | cpio -pdum $DST 2> /dev/null
6725648Ssetje
6735648Ssetje			if [ -f $file ] && [ -s $file ] && [ ! -h $file ] ; then
6745648Ssetje				fiocompress -mc $file $DST/$file &
6755648Ssetje			fi
6765648Ssetje
6775648Ssetje		done
6785648Ssetje
6795648Ssetje		# now re-copy a couple of uncompressed files
6805648Ssetje		#
6815648Ssetje
6825648Ssetje		find kernel platform -name unix | cpio -pdum $DST 2> /dev/null
6835648Ssetje		find kernel platform -name genunix | cpio -pdum $DST \
6845648Ssetje		    2> /dev/null
6855648Ssetje		find kernel platform -name platmod | cpio -pdum $DST \
6865648Ssetje		    2> /dev/null
6875648Ssetje		find `find kernel platform -name cpu` | cpio -pdum $DST \
6885648Ssetje		    2> /dev/null
6895648Ssetje		find `find kernel platform -name kmdb\*` | cpio -pdum $DST \
6905648Ssetje		    2> /dev/null
6915648Ssetje		find kernel/misc/sparcv9/ctf kernel/fs/sparcv9/dcfs \
6925648Ssetje		    etc/system etc/name_to_major etc/path_to_inst \
6935648Ssetje		    etc/name_to_sysnum | cpio -pdum $DST 2> /dev/null
6945648Ssetje	)
6955648Ssetje}
6965648Ssetje
6975648Ssetjeroot_is_ramdisk()
6985648Ssetje{
6995648Ssetje	grep -v "set root_is_ramdisk=" "$UNPACKED_ROOT"/etc/system | \
7005648Ssetje	    grep -v "set ramdisk_size=" > /tmp/system.$$
7015648Ssetje	cat /tmp/system.$$ > "$UNPACKED_ROOT"/etc/system
7025648Ssetje	rm /tmp/system.$$
7035648Ssetje
7045648Ssetje	echo set root_is_ramdisk=1 >> "$UNPACKED_ROOT"/etc/system
7055648Ssetje	echo set ramdisk_size=$1 >> "$UNPACKED_ROOT"/etc/system
7060Sstevel@tonic-gate}
7070Sstevel@tonic-gate
7080Sstevel@tonic-gatepack()
7090Sstevel@tonic-gate{
7101777Ssetje	if [ ! -d "$UNPACKED_ROOT" -o -z "$MR" ] ; then
7110Sstevel@tonic-gate		usage
7120Sstevel@tonic-gate		exit 1
7130Sstevel@tonic-gate	fi
7140Sstevel@tonic-gate
7155648Ssetje	# always compress on sparc if fiocompress exists
7165648Ssetje	#
7175648Ssetje	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] && \
7185648Ssetje	    [ -x /usr/sbin/fiocompress ] ; then
7195648Ssetje		COMPRESS=true
7205648Ssetje	fi
7215648Ssetje
7222511Sjongkis	# Estimate image size and add %10 overhead for ufs stuff.
7232511Sjongkis	# Note, we can't use du here in case $UNPACKED_ROOT is on a filesystem,
7242511Sjongkis	# e.g. zfs, in which the disk usage is less than the sum of the file
7255648Ssetje	# sizes.  The nawk code
7262511Sjongkis	#
7272511Sjongkis	#	{t += ($7 % 1024) ? (int($7 / 1024) + 1) * 1024 : $7}
7282511Sjongkis	#
7292511Sjongkis	# below rounds up the size of a file/directory, in bytes, to the
7302511Sjongkis	# next multiple of 1024.  This mimics the behavior of ufs especially
7312511Sjongkis	# with directories.  This results in a total size that's slightly
7322511Sjongkis	# bigger than if du was called on a ufs directory.
7335648Ssetje	#
7345648Ssetje	# if the operation in turn is compressing the files the amount
7355648Ssetje	# of typical shrinkage is used to come up with a useful archive
7365648Ssetje	# size
7372511Sjongkis	size=$(find "$UNPACKED_ROOT" -ls | nawk '
7382511Sjongkis	    {t += ($7 % 1024) ? (int($7 / 1024) + 1) * 1024 : $7}
7392511Sjongkis	    END {print int(t * 1.10 / 1024)}')
7405648Ssetje	if [ "$COMPRESS" = true ] ; then
7415648Ssetje		size=`echo $size | nawk '{s = $1} END {print int(s * .53)}'`
7425648Ssetje	fi
7430Sstevel@tonic-gate
7442334Ssetje	/usr/sbin/mkfile ${size}k "$TMR"
7452334Ssetje
7462334Ssetje	LOFIDEV=`/usr/sbin/lofiadm -a "$TMR"`
7470Sstevel@tonic-gate	if [ $? != 0 ] ; then
7480Sstevel@tonic-gate		echo lofi plumb failed
7490Sstevel@tonic-gate		exit 2
7500Sstevel@tonic-gate	fi
7510Sstevel@tonic-gate
7522334Ssetje	RLOFIDEV=`echo $LOFIDEV | sed s/lofi/rlofi/`
7535648Ssetje	newfs $RLOFIDEV < /dev/null 2> /dev/null
7541777Ssetje	mkdir -p $MNT
7555648Ssetje	mount -o nologging $LOFIDEV $MNT
7561777Ssetje	rmdir $MNT/lost+found
7575648Ssetje
7585648Ssetje	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
7595648Ssetje		root_is_ramdisk $size
7605648Ssetje	fi
7615648Ssetje
7622851Sjongkis	(
7632851Sjongkis		cd "$UNPACKED_ROOT"
7645648Ssetje		if [ "$COMPRESS" = true ] ; then
7655648Ssetje			compress . $MNT
7665648Ssetje		else
7675648Ssetje			find . -print | cpio -pdum $MNT 2> /dev/null
7685648Ssetje		fi
7692851Sjongkis	)
7700Sstevel@tonic-gate	lockfs -f $MNT
7710Sstevel@tonic-gate	umount $MNT
7720Sstevel@tonic-gate	rmdir $MNT
7735648Ssetje
7745648Ssetje	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
7755648Ssetje		"$UNPACKED_ROOT/usr/sbin/installboot" \
776*6319Sjg		    "$UNPACKED_ROOT/platform/sun4u/lib/fs/ufs/bootblk" \
7775648Ssetje		    $RLOFIDEV
7785648Ssetje	fi
7795648Ssetje
7802334Ssetje	lofiadm -d $LOFIDEV
7812851Sjongkis	LOFIDEV=
7820Sstevel@tonic-gate
7832334Ssetje	rm -f "$TMR.gz"
7845648Ssetje
7855648Ssetje	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
7865648Ssetje		mv "$TMR" "$MR"
7875648Ssetje	else
7885648Ssetje		gzip -f "$TMR"
7895648Ssetje		mv "$TMR.gz" "$MR"
7905648Ssetje	fi
7915648Ssetje
7921777Ssetje	chmod a+r "$MR"
7930Sstevel@tonic-gate}
7940Sstevel@tonic-gate
7955716Ssetjestrip_amd64()
7965716Ssetje{
7975716Ssetje	find "$UNPACKED_ROOT" -name amd64 -type directory | xargs rm -rf
7985716Ssetje}
7995716Ssetje
8000Sstevel@tonic-gate# main
8010Sstevel@tonic-gate#
8020Sstevel@tonic-gate
8032334SsetjeEXTRA_SPACE=0
8042851SjongkisSTRIP_AMD64=
8055648SsetjeCOMPRESS=
8062334Ssetje
8075648SsetjePATH=/usr/sbin:/usr/bin:/opt/sfw/bin ; export PATH
8085648Ssetje
8095648Ssetjewhile getopts s:6c opt ; do
8102334Ssetje	case $opt in
8112334Ssetje	s)	EXTRA_SPACE="$OPTARG"
8122334Ssetje		;;
8132334Ssetje	6)	STRIP_AMD64=false
8142334Ssetje		;;
8155648Ssetje	c)	COMPRESS=true
8165648Ssetje		;;
8172334Ssetje	*)	usage
8182334Ssetje		exit 1
8192334Ssetje		;;
8202334Ssetje	esac
8212334Ssetjedone
8222334Ssetjeshift `expr $OPTIND - 1`
8232334Ssetje
8240Sstevel@tonic-gateif [ $# != 3 ] ; then
8250Sstevel@tonic-gate	usage
8260Sstevel@tonic-gate	exit 1
8270Sstevel@tonic-gatefi
8280Sstevel@tonic-gate
8291777SsetjeUNPACKED_ROOT="$3"
8301777SsetjeBASE="`pwd`"
8310Sstevel@tonic-gateMNT=/tmp/mnt$$
8322334SsetjeTMR=/tmp/mr$$
8332334SsetjeLOFIDEV=
8341777SsetjeMR="$2"
8350Sstevel@tonic-gate
8360Sstevel@tonic-gateif [ "`dirname $MR`" = . ] ; then
8371777Ssetje	MR="$BASE/$MR"
8380Sstevel@tonic-gatefi
8390Sstevel@tonic-gateif [ "`dirname $UNPACKED_ROOT`" = . ] ; then
8401777Ssetje	UNPACKED_ROOT="$BASE/$UNPACKED_ROOT"
8410Sstevel@tonic-gatefi
8420Sstevel@tonic-gate
8435648Ssetje
8445648SsetjeMEDIA="$MR"
8455648Ssetje
8462334Ssetjetrap cleanup EXIT
8472334Ssetje
8480Sstevel@tonic-gatecase $1 in
8490Sstevel@tonic-gate	packmedia)
8501777Ssetje		if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
8515648Ssetje			ARCHIVE=sparc.miniroot
8525648Ssetje		else
8535822Sjhd			ARCHIVE=x86.miniroot
8545648Ssetje		fi
8555716Ssetje		MR="$MEDIA/boot/$ARCHIVE"
8565716Ssetje
8575648Ssetje		packmedia "$MEDIA" "$UNPACKED_ROOT"
8585648Ssetje		pack
8595716Ssetje
8605648Ssetje		;;
8615648Ssetje	unpackmedia)
8625648Ssetje		if [ -f "$MEDIA/boot/sparc.miniroot" ] ; then
8635648Ssetje			ARCHIVE=sparc.miniroot
8641777Ssetje		else
8655648Ssetje			ARCHIVE=x86.miniroot
8665648Ssetje		fi
8675716Ssetje		MR="$MEDIA/boot/$ARCHIVE"
8685648Ssetje		unpack
8695648Ssetje		unpackmedia "$MEDIA" "$UNPACKED_ROOT"
8705648Ssetje		;;
8715648Ssetje	pack)	pack
8725648Ssetje		;;
8735648Ssetje	unpack)	unpack
8745648Ssetje		;;
8755648Ssetje	*)	usage
8765648Ssetje		;;
8770Sstevel@tonic-gateesac
878