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
23*8715SJan.Kryl@Sun.COM# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate# Use is subject to license terms.
250Sstevel@tonic-gate#
260Sstevel@tonic-gate
270Sstevel@tonic-gate# utility to pack and unpack a boot/root archive
280Sstevel@tonic-gate# both ufs and hsfs (iso9660) format archives are unpacked
290Sstevel@tonic-gate# only ufs archives are generated
300Sstevel@tonic-gate#
310Sstevel@tonic-gate# usage: pack   <archive> <root>
320Sstevel@tonic-gate#        unpack <archive> <root>
330Sstevel@tonic-gate#        packmedia   <solaris_image> <root>
340Sstevel@tonic-gate#        unpackmedia <solaris_image> <root>
350Sstevel@tonic-gate#
360Sstevel@tonic-gate#   Where <root> is the directory to unpack to and will be cleaned out
370Sstevel@tonic-gate#   if it exists.
380Sstevel@tonic-gate#
390Sstevel@tonic-gate#   In the case of (un)packmedia, the image is packed or unpacked to/from
400Sstevel@tonic-gate#   Solaris media and all the things that don't go into the ramdisk image
410Sstevel@tonic-gate#   are (un)cpio'd as well
420Sstevel@tonic-gate#
430Sstevel@tonic-gate
440Sstevel@tonic-gateusage()
450Sstevel@tonic-gate{
460Sstevel@tonic-gate	printf "usage: root_archive pack <archive> <root>\n"
470Sstevel@tonic-gate	printf "       root_archive unpack <archive> <root>\n"
480Sstevel@tonic-gate	printf "       root_archive packmedia   <solaris_image> <root>\n"
490Sstevel@tonic-gate	printf "       root_archive unpackmedia <solaris_image> <root>\n"
500Sstevel@tonic-gate}
510Sstevel@tonic-gate
522334Ssetjecleanup()
532334Ssetje{
542334Ssetje	if [ -d $MNT ] ; then
552334Ssetje		umount $MNT 2> /dev/null
562334Ssetje		rmdir $MNT
572334Ssetje	fi
582334Ssetje
592851Sjongkis	lofiadm -d "$TMR" 2>/dev/null
605648Ssetje        if [ "$REALTHING" != true ] ; then
615648Ssetje		rm -f "$TMR"
625648Ssetje	fi
635648Ssetje	rm -f "$TMR.gz"
647563SPrasad.Singamsetty@Sun.COM	rm -f /tmp/flist$$
652334Ssetje}
662334Ssetje
675822Sjhdpreload_Gnome()
684889Ssjelinek{
694889Ssjelinek	MEDIA="$1"
704889Ssjelinek	MINIROOT="$2"
714889Ssjelinek
724889Ssjelinek
734889Ssjelinek	(
744889Ssjelinek		# Prepopulate the gconf database. This needs to be done and
754889Ssjelinek		# done first for several reasons. 1) Archiving out the gnome
764889Ssjelinek		# libraries and binaries causes the gconftool-2 to not run
774889Ssjelinek		# appropriately at boot time. 2) The binaries and libraries
784889Ssjelinek		# needed to run this are big and thus we want to archive
794889Ssjelinek		# them separately. 3) Having schemas prepopluated in the
804889Ssjelinek		# miniroot means faster boot times.
814889Ssjelinek		#
824889Ssjelinek
834889Ssjelinek		cd "$MINIROOT"
844889Ssjelinek		HOME="./tmp/root"
854889Ssjelinek		export HOME
864889Ssjelinek		umask 0022
875648Ssetje		mumble=.tmp_proto/root/etc/gconf/gconf.xml.defaults
885648Ssetje		GCONF_CONFIG_SOURCE="xml:merged:$MINIROOT/$mumble"
894889Ssjelinek		export GCONF_CONFIG_SOURCE
904889Ssjelinek		SCHEMADIR="$MINIROOT/.tmp_proto/root/etc/gconf/schemas"
914889Ssjelinek		export SCHEMADIR
925648Ssetje		/usr/bin/gconftool-2 --makefile-install-rule \
935648Ssetje		    $SCHEMADIR/*.schemas >/dev/null 2>&1
945571Ssjelinek		echo '
955571Ssjelinek		xml:readwrite:/tmp/root/.gconf
965571Ssjelinek		xml:readonly:/etc/gconf/gconf.xml.defaults
975571Ssjelinek		' > /"$MINIROOT"/.tmp_proto/root/etc/gconf/2/path
985822Sjhd	)
995822Sjhd}
1005571Ssjelinek
1015822Sjhdarchive_Gnome()
1025822Sjhd{
1035822Sjhd	MEDIA="$1"
1045822Sjhd	MINIROOT="$2"
1055822Sjhd
1065822Sjhd	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
1075822Sjhd	RELEASE=`basename "$RELEASE"`
1085822Sjhd	CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
1095822Sjhd
1105822Sjhd	# Create the gnome archive
1115822Sjhd	#
1125822Sjhd	(
1134889Ssjelinek		# usr/share gnome stuff
1144889Ssjelinek		cd "$MINIROOT"
1154889Ssjelinek		find usr/share/GConf usr/share/application-registry \
1164889Ssjelinek		    usr/share/autostart usr/share/dbus-1 usr/share/dtds \
1174889Ssjelinek		    usr/share/emacs usr/share/gnome usr/share/gnome-2.0 \
1184889Ssjelinek		    usr/share/gnome-background-properties \
1194889Ssjelinek		    usr/share/gtk-engines usr/share/gui-install \
1204889Ssjelinek		    usr/share/icon-naming-utils usr/share/control-center \
1214889Ssjelinek		    usr/share/icons usr/share/locale usr/share/metacity \
1224889Ssjelinek		    usr/share/mime usr/share/mime-info usr/share/pixmaps \
1234889Ssjelinek		    usr/share/scrollkeeper usr/share/sgml usr/share/themes \
1244889Ssjelinek		    usr/share/xml \
1254889Ssjelinek		    -print > /tmp/gnome_share.$$ 2>/dev/null
1264889Ssjelinek
1274889Ssjelinek		if [ ! -f /tmp/gnome_share.$$ ] ; then
1284889Ssjelinek			echo "/tmp/gnome_share.$$ file list not found."
1295648Ssetje			return
1304889Ssjelinek		fi
1314889Ssjelinek
1324889Ssjelinek		# usr/lib gnome stuff
1334889Ssjelinek
1344889Ssjelinek		find usr/lib/libgnome*\.so\.* \
1354889Ssjelinek		    usr/lib/libgst*\.so\.* usr/lib/libgconf*\.so\.* \
1364889Ssjelinek		    usr/lib/libgdk*\.so\.* usr/lib/libgtk*\.so\.* \
1374889Ssjelinek		    usr/lib/libglade*\.so\.* usr/lib/libmetacity*\.so\.* \
1384889Ssjelinek		    usr/lib/libfontconfig*\.so\.* usr/lib/libgmodule*\.so\.* \
1394889Ssjelinek		    usr/lib/libgobject*\.so\.* usr/lib/libgthread*\.so\.* \
1404889Ssjelinek		    usr/lib/libpopt*\.so\.* usr/lib/libstartup*\.so\.* \
1414889Ssjelinek		    usr/lib/libexif*\.so\.* usr/lib/libtiff*\.so\.* \
1424889Ssjelinek		    usr/lib/libdbus*\.so\.* usr/lib/libstartup*\.so\.* \
1434889Ssjelinek		    usr/lib/libexif*\.so\.* usr/lib/libORBit*\.so\.* \
1444889Ssjelinek	 	    usr/lib/libmlib*\.so\.* usr/lib/libxsl*\.so\.* \
1454889Ssjelinek		    usr/lib/libpango*\.so\.* usr/lib/libpng*\.so\.* \
1464889Ssjelinek		    usr/lib/liboil*\.so\.* usr/lib/libbonobo*\.so\.* \
1474889Ssjelinek		    usr/lib/libart*\.so\.* usr/lib/libcairo*\.so\.* \
1484889Ssjelinek		    usr/lib/libjpeg*\.so\.* \
1494889Ssjelinek		    usr/lib/libpolkit*\.so\.* \
1504889Ssjelinek			-print | egrep -v '\.so\.[0]$' > \
1514889Ssjelinek		       /tmp/gnome_lib.$$ 2>/dev/null
1524889Ssjelinek
1534889Ssjelinek		find usr/lib/nautilus usr/lib/pango usr/lib/iconv \
1544889Ssjelinek		    usr/lib/metacity-dialog usr/lib/window-manager-settings \
1554889Ssjelinek		    usr/lib/bonobo-2.0 usr/lib/bononbo usr/lib/gtk-2.0 \
1564889Ssjelinek		    usr/lib/GConf usr/lib/bonobo-activation-server \
1574889Ssjelinek		    usr/lib/python2.4 usr/lib/gstreamer-0.10 \
1584889Ssjelinek		    usr/lib/gconf-sanity-check-2 usr/lib/gconfd \
1594889Ssjelinek		    usr/lib/gnome-vfs-2.0 usr/lib/dbus-daemon \
1604889Ssjelinek		    usr/lib/gnome-vfs-daemon usr/lib/gnome-settings-daemon \
1614889Ssjelinek		    usr/lib/gnome_segv2 usr/lib/orbit-2.0 \
1624889Ssjelinek		    usr/lib/libmlib \
1634889Ssjelinek		    print > /tmp/gnome_libdir.$$ 2>/dev/null
1644889Ssjelinek
1654889Ssjelinek		if [ ! -f /tmp/gnome_lib.$$  -a ! -f gnome_libdir.$$ ] ; then
1664889Ssjelinek			echo "/tmp/gnome_lib.$$ file list not found."
1674889Ssjelinek			return
1684889Ssjelinek		fi
1694889Ssjelinek
1704889Ssjelinek		# /usr/sfw gnome stuff
1714889Ssjelinek		find usr/sfw/bin usr/sfw/include usr/sfw/share usr/sfw/src \
1724889Ssjelinek		    -print > /tmp/gnome_sfw.$$ 2>/dev/null
1734889Ssjelinek
1744889Ssjelinek		if [ ! -f /tmp/gnome_sfw.$$ ] ; then
1754889Ssjelinek			echo "/tmp/gnome_sfw.$$ file list not found."
1764889Ssjelinek			return
1774889Ssjelinek		fi
1784889Ssjelinek
1794889Ssjelinek		# gnome app binaries usr/bin
1804889Ssjelinek		find usr/bin/gnome* usr/bin/gui-install usr/bin/bonobo* \
1814889Ssjelinek		    usr/bin/gtk-* usr/bin/fax* usr/bin/gdk* usr/bin/gif2tiff \
1824889Ssjelinek		    usr/bin/install-lan \
1834889Ssjelinek		    usr/bin/metacity* usr/bin/gst-* usr/bin/gconftool-2 \
1844889Ssjelinek		    usr/bin/pango* usr/bin/desktop* usr/bin/djpeg \
1854889Ssjelinek		    usr/bin/notify-send usr/bin/oil-bugreport \
1864889Ssjelinek		    usr/bin/bmp2tiff usr/bin/thembus-theme-applier \
1874889Ssjelinek		    usr/bin/thumbnail usr/lib/update-* \
1884889Ssjelinek		    usr/bin/ras2tiff usr/bin/raw2tiff usr/bin/rdjpgcom \
1894889Ssjelinek		    usr/bin/thumbnail usr/bin/dbus* \
1904889Ssjelinek		    usr/bin/tiff* usr/bin/rgb2ycbcr \
1914889Ssjelinek		    usr/bin/fc-cache usr/bin/fc-list \
1924889Ssjelinek			-print > /tmp/gnome_bin.$$ 2>/dev/null
1934889Ssjelinek
1944889Ssjelinek		if [ ! -f /tmp/gnome_bin.$$ ] ; then
1954889Ssjelinek			echo "/tmp/gnome_bin.$$ file list not found."
1965648Ssetje			return
1974889Ssjelinek		fi
1984889Ssjelinek
1994889Ssjelinek		# Cat all the files together and create the gnome archive
2004889Ssjelinek		#
2014889Ssjelinek
2024889Ssjelinek		cat /tmp/gnome_libdir.$$ /tmp/gnome_lib.$$ \
2034889Ssjelinek		     /tmp/gnome_share.$$ /tmp/gnome_sfw.$$ /tmp/gnome_bin.$$ \
2044889Ssjelinek		    > /tmp/gnome.$$
2054889Ssjelinek
2064889Ssjelinek		if [ ! -f /tmp/gnome.$$ ] ; then
2074889Ssjelinek			echo "/tmp/gnome.$$ file not found."
2084889Ssjelinek			return
2094889Ssjelinek		fi
2104889Ssjelinek		# Save off this file in the miniroot for use later
2114889Ssjelinek		# when unpacking. Clean up old cruft if there.
2124889Ssjelinek		#
2134889Ssjelinek
2144889Ssjelinek		if [ -f .tmp_proto/gnome_saved ]; then
2154889Ssjelinek			rm -f .tmp_proto/gnome_saved
2164889Ssjelinek		fi
2174889Ssjelinek
2184889Ssjelinek		cp /tmp/gnome.$$ .tmp_proto/gnome_saved
2194889Ssjelinek
2204889Ssjelinek		# Create gnome archive
2214889Ssjelinek		#
2224889Ssjelinek
2234889Ssjelinek		cpio -ocmPuB < /tmp/gnome.$$ 2>/dev/null | bzip2 > \
2244889Ssjelinek		    "$CPIO_DIR/gnome.cpio.bz2"
2254889Ssjelinek
2265648Ssetje		# Remove files from miniroot that are in archive.
2274889Ssjelinek		# Create symlinks for files in archive
2284889Ssjelinek
2294889Ssjelinek		rm -rf `cat /tmp/gnome_share.$$`
2304889Ssjelinek
2314889Ssjelinek		for i in `cat /tmp/gnome_share.$$`
2325648Ssetje		do
2334889Ssjelinek			ln -s /tmp/root/$i $i 2>/dev/null
2344889Ssjelinek		done
2354889Ssjelinek
2364889Ssjelinek		rm -rf `cat /tmp/gnome_lib.$$`
2374889Ssjelinek		for i in `cat /tmp/gnome_lib.$$`
2384889Ssjelinek		do
2394889Ssjelinek			ln -s /tmp/root/$i $i 2>/dev/null
2404889Ssjelinek		done
2414889Ssjelinek
2424889Ssjelinek		rm -rf `cat /tmp/gnome_libdir.$$`
2434889Ssjelinek		for i in `cat /tmp/gnome_libdir.$$`
2445648Ssetje		do
2454889Ssjelinek			ln -s /tmp/root/$i $i 2>/dev/null
2464889Ssjelinek		done
2474889Ssjelinek
2484889Ssjelinek		rm -rf `cat /tmp/gnome_sfw.$$`
2494889Ssjelinek		for i in `cat /tmp/gnome_sfw.$$`
2505648Ssetje		do
2514889Ssjelinek			ln -s /tmp/root/$i $i 2>/dev/null
2524889Ssjelinek		done
2534889Ssjelinek
2544889Ssjelinek		rm -rf `cat /tmp/gnome_bin.$$`
2554889Ssjelinek		for i in `cat /tmp/gnome_bin.$$`
2565648Ssetje		do
2574889Ssjelinek			ln -s /tmp/root/$i $i 2>/dev/null
2584889Ssjelinek		done
2594889Ssjelinek		rm -f /tmp/gnome_share.$$
2604889Ssjelinek		rm -f /tmp/gnome_lib.$$
2614889Ssjelinek		rm -f /tmp/gnome_libdir.$$
2624889Ssjelinek		rm -f /tmp/gnome_bin.$$
2634889Ssjelinek	)
2644889Ssjelinek}
2654889Ssjelinek
2664889Ssjelinekarchive_JavaGUI()
2674889Ssjelinek{
2684889Ssjelinek	MEDIA="$1"
2694889Ssjelinek	MINIROOT="$2"
2704889Ssjelinek
2714889Ssjelinek	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
2724889Ssjelinek	RELEASE=`basename "$RELEASE"`
2734889Ssjelinek
2745648Ssetje	CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
2754889Ssjelinek
2764889Ssjelinek	# Archive the java wizard components that are only used in the
2774889Ssjelinek	# non developer express path.
2784889Ssjelinek	#
2794889Ssjelinek	(
2804889Ssjelinek		# path is usr/lib/install/data
2814889Ssjelinek		cd "$MINIROOT"
2824889Ssjelinek		find usr/lib/install/data/wizards \
2834889Ssjelinek		    -print > /tmp/java_ui.$$ 2>/dev/null
2844889Ssjelinek
2854889Ssjelinek		if [ ! -f /tmp/java_ui.$$ ] ; then
2864889Ssjelinek			echo "/tmp/java_ui.$$ file list not found."
2875648Ssetje			return
2884889Ssjelinek		fi
2894889Ssjelinek
2904889Ssjelinek		cpio -ocmPuB < /tmp/java_ui.$$ 2>/dev/null | bzip2 > \
2914889Ssjelinek		    "$CPIO_DIR/javaui.cpio.bz2"
2924889Ssjelinek
2934889Ssjelinek		rm -rf `cat /tmp/java_ui.$$`
2945648Ssetje		ln -s /tmp/root/usr/lib/install/data/wizards \
2955648Ssetje		    usr/lib/install/data/wizards 2>/dev/null
2964889Ssjelinek
2974889Ssjelinek		rm -f /tmp/java_ui.$$
2984889Ssjelinek
2994889Ssjelinek	)
3004889Ssjelinek}
3014889Ssjelinek
3024889Ssjelinekarchive_Misc()
3034889Ssjelinek{
3044889Ssjelinek	MEDIA="$1"
3054889Ssjelinek	MINIROOT="$2"
3064889Ssjelinek
3074889Ssjelinek	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
3084889Ssjelinek	RELEASE=`basename "$RELEASE"`
3094889Ssjelinek
3105648Ssetje	CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
3114889Ssjelinek
3124889Ssjelinek	# Archive misc stuff that is needed by non devex installer
3134889Ssjelinek	#
3144889Ssjelinek	(
3154889Ssjelinek		# usr/lib stuff
3164889Ssjelinek		cd "$MINIROOT"
3174889Ssjelinek		find usr/lib/lp -print > /tmp/lp.$$ 2>/dev/null
3184889Ssjelinek		if [ ! -f /tmp/lp.$$ ] ; then
3194889Ssjelinek			echo "/tmp/lp.$$ file list not found."
3205648Ssetje			return
3214889Ssjelinek		fi
3224889Ssjelinek
3234889Ssjelinek		cpio -ocmPuB < /tmp/lp.$$ 2>/dev/null | bzip2 > \
3244889Ssjelinek		    "$CPIO_DIR/lpmisc.cpio.bz2"
3254889Ssjelinek
3264889Ssjelinek		rm -rf `cat /tmp/lp.$$`
3274889Ssjelinek		ln -s /tmp/root/usr/lib/lp usr/lib/lp 2>/dev/null
3284889Ssjelinek
3294889Ssjelinek		rm -f /tmp/lp.$$
3304889Ssjelinek	)
3314889Ssjelinek
3324889Ssjelinek}
3334889Ssjelinek
3344889Ssjelinekarchive_Perl()
3354889Ssjelinek{
3364889Ssjelinek	MEDIA="$1"
3374889Ssjelinek	MINIROOT="$2"
3384889Ssjelinek
3394889Ssjelinek	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
3404889Ssjelinek	RELEASE=`basename "$RELEASE"`
3414889Ssjelinek
3425648Ssetje	CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
3434889Ssjelinek
3444889Ssjelinek	# Archive perl, it is only needed by gnome gui.
3454889Ssjelinek	#
3464889Ssjelinek	(
3474889Ssjelinek		# in usr
3484889Ssjelinek		cd "$MINIROOT"
3494889Ssjelinek		find usr/perl5 -print > /tmp/perl.$$ 2>/dev/null
3504889Ssjelinek
3514889Ssjelinek		if [ ! -f /tmp/perl.$$ ] ; then
3524889Ssjelinek			echo "/tmp/perl.$$ file list not found."
3535648Ssetje			return
3544889Ssjelinek		fi
3554889Ssjelinek		cpio -ocmPuB < /tmp/perl.$$ 2>/dev/null | bzip2 > \
3564889Ssjelinek		    "$CPIO_DIR/perl.cpio.bz2"
3574889Ssjelinek
3584889Ssjelinek		rm -rf `cat /tmp/perl.$$` 2>/dev/null
3595571Ssjelinek		ln -s /tmp/root/usr/perl5 usr/perl5 2>/dev/null
3604889Ssjelinek
3614889Ssjelinek		rm -f /tmp/perl.$$
3624889Ssjelinek	)
3634889Ssjelinek}
3641777Ssetjearchive_X()
3650Sstevel@tonic-gate{
3661777Ssetje	MEDIA="$1"
3671777Ssetje	MINIROOT="$2"
3680Sstevel@tonic-gate
3691777Ssetje	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
3701777Ssetje	RELEASE=`basename "$RELEASE"`
3710Sstevel@tonic-gate
3725648Ssetje	CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
3730Sstevel@tonic-gate
3740Sstevel@tonic-gate	# create the graphics and non-graphics X archive
3750Sstevel@tonic-gate	#
3762851Sjongkis	(
3774889Ssjelinek		cd "$MINIROOT"
3784889Ssjelinek		find usr/openwin usr/dt usr/X11 -print 2> /dev/null |\
3792851Sjongkis		    cpio -ocmPuB 2> /dev/null | bzip2 > "$CPIO_DIR/X.cpio.bz2"
3800Sstevel@tonic-gate
3814889Ssjelinek		find usr/openwin/bin/mkfontdir \
3824889Ssjelinek		     usr/openwin/lib/installalias \
3834889Ssjelinek		     usr/openwin/server/lib/libfont.so.1 \
3844889Ssjelinek		     usr/openwin/server/lib/libtypesclr.so.0 \
3852851Sjongkis			 -print | cpio -ocmPuB 2> /dev/null | bzip2 > \
3862851Sjongkis			 "$CPIO_DIR/X_small.cpio.bz2"
3870Sstevel@tonic-gate
3884889Ssjelinek		rm -rf usr/dt usr/openwin usr/X11
3894889Ssjelinek		ln -s /tmp/root/usr/dt usr/dt
3904889Ssjelinek		ln -s /tmp/root/usr/openwin usr/openwin
3914889Ssjelinek		ln -s /tmp/root/usr/X11 usr/X11
3922851Sjongkis	)
3931777Ssetje}
3941777Ssetje
3955648Ssetjearchive_lu()
3965648Ssetje{
3975648Ssetje	MEDIA="$1"
3985648Ssetje	MINIROOT="$2"
3995648Ssetje
4005648Ssetje	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
4015648Ssetje	RELEASE=`basename "$RELEASE"`
4025648Ssetje
4035648Ssetje	CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
4045648Ssetje
4055648Ssetje	(
4065648Ssetje		cd "$MINIROOT"
4077563SPrasad.Singamsetty@Sun.COM		find usr/lib/install usr/snadm usr/sbin \
4087563SPrasad.Singamsetty@Sun.COM		    boot/grub boot/solaris/bootenv.rc \
4097563SPrasad.Singamsetty@Sun.COM		    tmp/root/boot/grub tmp/root/boot/solaris/bootenv.rc \
4107563SPrasad.Singamsetty@Sun.COM		    2> /dev/null | cpio -ocmPuB 2> /dev/null | bzip2 \
4117563SPrasad.Singamsetty@Sun.COM		    > "$CPIO_DIR"/lu.cpio.bz2
4125648Ssetje		ls platform > "$CPIO_DIR/lu.platforms"
4135648Ssetje	)
4145648Ssetje}
4155648Ssetje
4167563SPrasad.Singamsetty@Sun.COMcleanout_pkgdata()
4177563SPrasad.Singamsetty@Sun.COM{
4187563SPrasad.Singamsetty@Sun.COM	rm -Rf tmp/root/var/sadm/install tmp/root/var/sadm/pkg
4197563SPrasad.Singamsetty@Sun.COM}
4207563SPrasad.Singamsetty@Sun.COM
4211777Ssetjepackmedia()
4221777Ssetje{
4231777Ssetje	MEDIA="$1"
4241777Ssetje	MINIROOT="$2"
4251777Ssetje
4261777Ssetje	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
4271777Ssetje	RELEASE=`basename "$RELEASE"`
4285822Sjhd	ARCHIVES="X X_small perl lpmisc javaui gnome"
4291777Ssetje
4301777Ssetje	mkdir -p "$MEDIA/$RELEASE/Tools/Boot"
4315648Ssetje
4325648Ssetje	if [ -d "$MINIROOT/platform/i86pc" ] ; then
4335648Ssetje		mkdir -p "$MEDIA/boot/amd64"
4345648Ssetje		mkdir -p "$MEDIA/boot/platform/i86pc/kernel"
4355648Ssetje		mkdir -p "$MEDIA/boot/platform/i86pc/kernel/amd64"
4365648Ssetje		mkdir -p "$MEDIA/boot/platform/i86xpv/kernel"
4375648Ssetje		mkdir -p "$MEDIA/boot/platform/i86xpv/kernel/amd64"
4385648Ssetje		cp "$MINIROOT/platform/i86pc/multiboot" "$MEDIA/boot"
4395648Ssetje		cp "$MINIROOT/platform/i86pc/kernel/unix" \
4405648Ssetje		    "$MEDIA/boot/platform/i86pc/kernel/unix"
4415648Ssetje		cp "$MINIROOT/platform/i86pc/kernel/amd64/unix" \
4425648Ssetje		    "$MEDIA/boot/platform/i86pc/kernel/amd64/unix"
4435648Ssetje		cp "$MINIROOT/platform/i86xpv/kernel/unix" \
4445648Ssetje		    "$MEDIA/boot/platform/i86xpv/kernel/unix"
4455648Ssetje		cp "$MINIROOT/platform/i86xpv/kernel/amd64/unix" \
4465648Ssetje		    "$MEDIA/boot/platform/i86xpv/kernel/amd64/unix"
4475648Ssetje		(
4485648Ssetje			cd "$MEDIA/$RELEASE/Tools/Boot"
4495648Ssetje			ln -sf ../../../boot/x86.miniroot
4505648Ssetje			ln -sf ../../../boot/multiboot
4515648Ssetje			ln -sf ../../../boot/platform/i86pc/kernel/unix
4525648Ssetje			ln -sf ../../../boot/platform/i86pc/kernel/amd64/unix
4535648Ssetje			ln -sf ../../../boot/platform/i86xpv/kernel/unix
4545648Ssetje			ln -sf ../../../boot/platform/i86xpv/kernel/amd64/unix
4555648Ssetje			ln -sf ../../../boot/grub/pxegrub
4565648Ssetje		)
4575648Ssetje	fi
4585648Ssetje
4595648Ssetje	if [ -d "$MINIROOT/platform/sun4u" ] ; then
4605648Ssetje		mkdir -p "$MEDIA/boot"
4616319Sjg		dd if="$MINIROOT/platform/sun4u/lib/fs/hsfs/bootblk" \
4625648Ssetje		    of="$MEDIA/boot/hsfs.bootblock" \
4635648Ssetje		    bs=1b oseek=1 count=15 conv=sync 2> /dev/null
4645648Ssetje	fi
4655648Ssetje
4665648Ssetje	for arch in sun4u sun4v ; do
4675648Ssetje		if [ -d "$MINIROOT/platform/$arch" ] ; then
4685648Ssetje			archdir="$MEDIA/$RELEASE/Tools/Boot/platform/$arch"
4695648Ssetje			mkdir -p $archdir
4705648Ssetje			ln -sf ../../../../../boot/sparc.miniroot \
4715648Ssetje			    "$archdir/boot_archive"
4725648Ssetje			cp "$MINIROOT/usr/platform/$arch/lib/fs/nfs/inetboot" \
4735648Ssetje			    "$archdir"
4745648Ssetje			cp "$MINIROOT/platform/$arch/wanboot" \
4755648Ssetje			    "$archdir"
4765648Ssetje			mkdir -p "$MEDIA/platform/$arch"
4775648Ssetje			ln -sf ../../boot/sparc.miniroot \
4785648Ssetje			    "$MEDIA/platform/$arch/boot_archive"
4798144SJerry.Gilliam@Sun.COM			ln -sf ../../$RELEASE/Tools/Boot/platform/$arch/wanboot \
4808144SJerry.Gilliam@Sun.COM			    "$MEDIA/platform/$arch/wanboot"
4815648Ssetje		fi
4825648Ssetje	done
4831777Ssetje
4841777Ssetje	# archive package databases to conserve memory
4851777Ssetje	#
4862851Sjongkis	(
4872851Sjongkis		cd "$MINIROOT"
4882851Sjongkis		find tmp/root/var/sadm/install tmp/root/var/sadm/pkg -print | \
4892851Sjongkis		    cpio -ocmPuB 2> /dev/null | bzip2 > \
4902851Sjongkis		    "$MEDIA/$RELEASE/Tools/Boot/pkg_db.cpio.bz2"
4911777Ssetje
4927563SPrasad.Singamsetty@Sun.COM		cleanout_pkgdata
4937563SPrasad.Singamsetty@Sun.COM	)
4947563SPrasad.Singamsetty@Sun.COM
4957563SPrasad.Singamsetty@Sun.COM	archive_lu "$MEDIA" "$MINIROOT"
4965648Ssetje
4972595Ssetje	archive_X "$MEDIA" "$MINIROOT"
4982595Ssetje
4994889Ssjelinek	# Take out the gnome and java parts of the installer from
5004889Ssjelinek	# the miniroot. These are not required to boot the system
5014889Ssjelinek	# and start the installers.
5024889Ssjelinek
5035648Ssetje	if [ -d "$MINIROOT/platform/i86pc" ] ; then
5045822Sjhd		preload_Gnome "$MEDIA" "$MINIROOT"
5055648Ssetje		archive_Gnome "$MEDIA" "$MINIROOT"
5065648Ssetje		archive_JavaGUI "$MEDIA" "$MINIROOT"
5075648Ssetje		archive_Misc "$MEDIA" "$MINIROOT"
5085648Ssetje		archive_Perl "$MEDIA" "$MINIROOT"
5095822Sjhd		MR="$MEDIA/boot/amd64/x86.miniroot"
5105822Sjhd		pack
5115822Sjhd
5125822Sjhd        	# Now that the 64-bit archives & miniroot have been created,
5135822Sjhd        	# restore the files from archives and save the 64-bit
5145822Sjhd        	# archives. Strip the 64-bit objects and create the
5155822Sjhd		# 32-bit archives and miniroot
5165822Sjhd
5175822Sjhd		unpackmedia "$MEDIA" "$MINIROOT"
5187563SPrasad.Singamsetty@Sun.COM		cleanout_pkgdata
5195822Sjhd		mkdir -p "$MEDIA/$RELEASE/Tools/Boot/amd64"
5205822Sjhd		for i in $ARCHIVES; do
5215822Sjhd			mv "$MEDIA/$RELEASE/Tools/Boot/${i}.cpio.bz2" \
5225822Sjhd				"$MEDIA/$RELEASE/Tools/Boot/amd64"
5235822Sjhd		done
5245822Sjhd		if [ -z "$STRIP_AMD64" ]; then
5255822Sjhd			strip_amd64
5265822Sjhd		fi
5275822Sjhd
5285822Sjhd		archive_X "$MEDIA" "$MINIROOT"
5295822Sjhd		archive_Gnome "$MEDIA" "$MINIROOT"
5305822Sjhd		archive_JavaGUI "$MEDIA" "$MINIROOT"
5315822Sjhd		archive_Perl "$MEDIA" "$MINIROOT"
5325822Sjhd		archive_Misc "$MEDIA" "$MINIROOT"
5335822Sjhd		MR="$MEDIA/boot/x86.miniroot"
5345648Ssetje	fi
5350Sstevel@tonic-gate
5361821Ssetje	# copy the install menu to menu.lst so we have a menu
5371821Ssetje	# on the install media
5381821Ssetje	#
5395648Ssetje	if [ -f "$MINIROOT/boot/grub/install_menu" ] ; then
5405648Ssetje		cp $MINIROOT/boot/grub/install_menu \
5415648Ssetje		    $MEDIA/boot/grub/menu.lst
5421821Ssetje	fi
5437204Sjg
5447204Sjg	#
5457204Sjg	# jumpstart utilities in usr/sbin/install.d
5467204Sjg	#
5477204Sjg	if [ -d "$MINIROOT/usr/sbin/install.d" ] ; then
5487204Sjg		(
5497204Sjg		cd ${MINIROOT}
5507204Sjg		find usr/sbin/install.d/chkprobe \
5517204Sjg		    -print | cpio -ocmPuB 2> /dev/null | bzip2 > \
5527204Sjg		    ${MEDIA}/${RELEASE}/Tools/Boot/usr_sbin_install_d.cpio.bz2
5537204Sjg		)
5547204Sjg	fi
5551777Ssetje}
5560Sstevel@tonic-gate
5571777Ssetjeunarchive_X()
5581777Ssetje{
5591777Ssetje	MEDIA="$1"
5601777Ssetje	UNPACKED_ROOT="$2"
5611777Ssetje
5621777Ssetje	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
5631777Ssetje	RELEASE=`basename "$RELEASE"`
5641777Ssetje
5655648Ssetje	CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
5661777Ssetje
5671777Ssetje	# unpack X
5681777Ssetje	#
5692851Sjongkis	(
5704889Ssjelinek		cd "$UNPACKED_ROOT"
5714889Ssjelinek		rm -rf usr/dt usr/openwin usr/X11
5722851Sjongkis		bzcat "$CPIO_DIR/X.cpio.bz2" | cpio -icdmu 2> /dev/null
5732851Sjongkis	)
5740Sstevel@tonic-gate}
5750Sstevel@tonic-gate
5760Sstevel@tonic-gateunpackmedia()
5771777Ssetje{
5781777Ssetje	MEDIA="$1"
5791777Ssetje	UNPACKED_ROOT="$2"
5800Sstevel@tonic-gate
5811777Ssetje	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
5821777Ssetje	RELEASE=`basename "$RELEASE"`
5831777Ssetje
5841777Ssetje	unarchive_X "$MEDIA" "$UNPACKED_ROOT"
5850Sstevel@tonic-gate
5860Sstevel@tonic-gate	# unpack package databases
5870Sstevel@tonic-gate	#
5882851Sjongkis	(
5892851Sjongkis		cd "$UNPACKED_ROOT"
5902851Sjongkis		bzcat "$MEDIA/$RELEASE/Tools/Boot/pkg_db.cpio.bz2" |
5912851Sjongkis		    cpio -icdmu 2> /dev/null
5924889Ssjelinek
593*8715SJan.Kryl@Sun.COM		if [ -d "$MINIROOT/platform/i86pc" ] ; then
594*8715SJan.Kryl@Sun.COM
595*8715SJan.Kryl@Sun.COM			# unpack gnome, perl, java and misc
596*8715SJan.Kryl@Sun.COM			# Remove symlinks left from unpacking x86.miniroot
597*8715SJan.Kryl@Sun.COM			# so that unpacking subsequent archives will populate
598*8715SJan.Kryl@Sun.COM			# appropriately.
599*8715SJan.Kryl@Sun.COM			#
600*8715SJan.Kryl@Sun.COM			rm -rf usr/perl5
601*8715SJan.Kryl@Sun.COM			rm -rf usr/lib/install/data/wizards
602*8715SJan.Kryl@Sun.COM			rm -rf usr/lib/lp
6034889Ssjelinek
604*8715SJan.Kryl@Sun.COM			# Gnome list saved off from packmedia
605*8715SJan.Kryl@Sun.COM			for i in `cat .tmp_proto/gnome_saved`
606*8715SJan.Kryl@Sun.COM			do
607*8715SJan.Kryl@Sun.COM				rm -rf $i
608*8715SJan.Kryl@Sun.COM			done
609*8715SJan.Kryl@Sun.COM
610*8715SJan.Kryl@Sun.COM			bzcat "$MEDIA/$RELEASE/Tools/Boot/gnome.cpio.bz2" |
611*8715SJan.Kryl@Sun.COM			    cpio -icdmu 2>/dev/null
612*8715SJan.Kryl@Sun.COM			bzcat "$MEDIA/$RELEASE/Tools/Boot/javaui.cpio.bz2" |
613*8715SJan.Kryl@Sun.COM			    cpio -icdmu 2>/dev/null
614*8715SJan.Kryl@Sun.COM			bzcat "$MEDIA/$RELEASE/Tools/Boot/lpmisc.cpio.bz2" |
615*8715SJan.Kryl@Sun.COM			    cpio -icdmu 2>/dev/null
616*8715SJan.Kryl@Sun.COM			bzcat "$MEDIA/$RELEASE/Tools/Boot/perl.cpio.bz2" |
617*8715SJan.Kryl@Sun.COM			    cpio -icdmu 2>/dev/null
618*8715SJan.Kryl@Sun.COM		fi
6192851Sjongkis	)
6200Sstevel@tonic-gate}
6210Sstevel@tonic-gate
6220Sstevel@tonic-gatedo_unpack()
6230Sstevel@tonic-gate{
6241777Ssetje	rm -rf "$UNPACKED_ROOT"
6251777Ssetje	mkdir -p "$UNPACKED_ROOT"
6262851Sjongkis	(
6272851Sjongkis		cd $MNT
6282851Sjongkis		find . -print | cpio -pdum "$UNPACKED_ROOT" 2> /dev/null
6292851Sjongkis	)
6300Sstevel@tonic-gate	umount $MNT
6310Sstevel@tonic-gate}
6320Sstevel@tonic-gate
6330Sstevel@tonic-gateunpack()
6340Sstevel@tonic-gate{
6350Sstevel@tonic-gate
6361777Ssetje	if [ ! -f "$MR" ] ; then
6370Sstevel@tonic-gate		usage
6380Sstevel@tonic-gate		exit 1
6390Sstevel@tonic-gate	fi
6400Sstevel@tonic-gate
6417563SPrasad.Singamsetty@Sun.COM	if [ `uname -i` = i86pc ] ; then
6425648Ssetje		gzcat "$MR" > $TMR
6435648Ssetje	else
6445648Ssetje		REALTHING=true ; export REALTHING
6455648Ssetje		TMR="$MR"
6465648Ssetje	fi
6470Sstevel@tonic-gate
6482334Ssetje	LOFIDEV=`/usr/sbin/lofiadm -a $TMR`
6490Sstevel@tonic-gate	if [ $? != 0 ] ; then
6500Sstevel@tonic-gate		echo lofi plumb failed
6510Sstevel@tonic-gate		exit 2
6520Sstevel@tonic-gate	fi
6530Sstevel@tonic-gate
6541777Ssetje	mkdir -p $MNT
6550Sstevel@tonic-gate
6562334Ssetje	FSTYP=`fstyp $LOFIDEV`
6570Sstevel@tonic-gate
6581777Ssetje	if [ "$FSTYP" = ufs ] ; then
6592334Ssetje		/usr/sbin/mount -o ro,nologging $LOFIDEV $MNT
6600Sstevel@tonic-gate		do_unpack
6611777Ssetje	elif [ "$FSTYP" = hsfs ] ; then
6622334Ssetje		/usr/sbin/mount -F hsfs -o ro $LOFIDEV $MNT
6630Sstevel@tonic-gate		do_unpack
6640Sstevel@tonic-gate	else
6650Sstevel@tonic-gate		printf "invalid root archive\n"
6660Sstevel@tonic-gate	fi
6670Sstevel@tonic-gate
6685648Ssetje
6690Sstevel@tonic-gate	rmdir $MNT
6702851Sjongkis	lofiadm -d $TMR ; LOFIDEV=
6715648Ssetje	if [ "$REALTHING" != true ] ; then
6725648Ssetje		rm $TMR
6735648Ssetje	fi
6745648Ssetje}
6755648Ssetje
6765648Ssetjecompress()
6775648Ssetje{
6785648Ssetje	SRC=$1
6795648Ssetje	DST=$2
6805648Ssetje
6815648Ssetje	(
6825648Ssetje		cd $SRC
6835648Ssetje		filelist=`find .`
6845648Ssetje
6855648Ssetje		for file in $filelist ; do
6865648Ssetje
6875648Ssetje			file=`echo $file | sed s#^./##`
6885648Ssetje
6895648Ssetje			# copy all files over to preserve hard links
6905648Ssetje			#
6915648Ssetje			echo $file | cpio -pdum $DST 2> /dev/null
6925648Ssetje
6935648Ssetje			if [ -f $file ] && [ -s $file ] && [ ! -h $file ] ; then
6945648Ssetje				fiocompress -mc $file $DST/$file &
6955648Ssetje			fi
6965648Ssetje
6975648Ssetje		done
6985648Ssetje
6997563SPrasad.Singamsetty@Sun.COM		wait `pgrep fiocompress`
7007563SPrasad.Singamsetty@Sun.COM
7015648Ssetje		# now re-copy a couple of uncompressed files
7025648Ssetje
7037563SPrasad.Singamsetty@Sun.COM		if [ -d "$SRC/platform/i86pc" ] ; then
7047563SPrasad.Singamsetty@Sun.COM			find `cat boot/solaris/filelist.ramdisk` -type file \
7057563SPrasad.Singamsetty@Sun.COM			    -print 2> /dev/null > /tmp/flist$$
7067563SPrasad.Singamsetty@Sun.COM			find usr/kernel -type file -print 2> /dev/null \
7077563SPrasad.Singamsetty@Sun.COM			    >> /tmp/flist$$
7087563SPrasad.Singamsetty@Sun.COM			# some of the files are replaced with links into
7097563SPrasad.Singamsetty@Sun.COM			# tmp/root on the miniroot, so find the backing files
7107563SPrasad.Singamsetty@Sun.COM			# from there as well and add them to the list ti
7117563SPrasad.Singamsetty@Sun.COM			# be copied uncompressed
7127563SPrasad.Singamsetty@Sun.COM			(
7137563SPrasad.Singamsetty@Sun.COM				cd $SRC/tmp/root
7147563SPrasad.Singamsetty@Sun.COM				find `cat ../../boot/solaris/filelist.ramdisk` \
7157563SPrasad.Singamsetty@Sun.COM				    -type file -print 2> /dev/null | \
7167563SPrasad.Singamsetty@Sun.COM				    sed 's#^#tmp/root/#' >> /tmp/flist$$
7177563SPrasad.Singamsetty@Sun.COM			)
7187563SPrasad.Singamsetty@Sun.COM			flist=`cat /tmp/flist$$`
7197563SPrasad.Singamsetty@Sun.COM			(
7207563SPrasad.Singamsetty@Sun.COM				cd $DST
7217563SPrasad.Singamsetty@Sun.COM				rm -f $flist
7227563SPrasad.Singamsetty@Sun.COM			)
7237563SPrasad.Singamsetty@Sun.COM			for file in $flist ; do
7247563SPrasad.Singamsetty@Sun.COM				echo $file | cpio -pdum $DST 2> /dev/null
7257563SPrasad.Singamsetty@Sun.COM			done
7267563SPrasad.Singamsetty@Sun.COM		else
7277563SPrasad.Singamsetty@Sun.COM			find kernel platform -name unix | \
7287563SPrasad.Singamsetty@Sun.COM			    cpio -pdum $DST 2> /dev/null
7297563SPrasad.Singamsetty@Sun.COM			find kernel platform -name genunix | cpio -pdum $DST \
7307563SPrasad.Singamsetty@Sun.COM			    2> /dev/null
7317563SPrasad.Singamsetty@Sun.COM			find kernel platform -name platmod | cpio -pdum $DST \
7327563SPrasad.Singamsetty@Sun.COM			    2> /dev/null
7337563SPrasad.Singamsetty@Sun.COM			find `find kernel platform -name cpu` | \
7347563SPrasad.Singamsetty@Sun.COM			    cpio -pdum $DST 2> /dev/null
7357563SPrasad.Singamsetty@Sun.COM			find `find kernel platform -name kmdb\*` | \
7367563SPrasad.Singamsetty@Sun.COM				cpio -pdum $DST 2> /dev/null
7377563SPrasad.Singamsetty@Sun.COM			find kernel/misc/sparcv9/ctf kernel/fs/sparcv9/dcfs \
7387563SPrasad.Singamsetty@Sun.COM			    kernel/misc/ctf kernel/fs/dcfs \
7397563SPrasad.Singamsetty@Sun.COM			    etc/system etc/name_to_major etc/path_to_inst \
7407563SPrasad.Singamsetty@Sun.COM			    etc/name_to_sysnum | cpio -pdum $DST 2> /dev/null
7417563SPrasad.Singamsetty@Sun.COM		fi
7425648Ssetje	)
7435648Ssetje}
7445648Ssetje
7455648Ssetjeroot_is_ramdisk()
7465648Ssetje{
7475648Ssetje	grep -v "set root_is_ramdisk=" "$UNPACKED_ROOT"/etc/system | \
7485648Ssetje	    grep -v "set ramdisk_size=" > /tmp/system.$$
7495648Ssetje	cat /tmp/system.$$ > "$UNPACKED_ROOT"/etc/system
7505648Ssetje	rm /tmp/system.$$
7515648Ssetje
7525648Ssetje	echo set root_is_ramdisk=1 >> "$UNPACKED_ROOT"/etc/system
7535648Ssetje	echo set ramdisk_size=$1 >> "$UNPACKED_ROOT"/etc/system
7540Sstevel@tonic-gate}
7550Sstevel@tonic-gate
7560Sstevel@tonic-gatepack()
7570Sstevel@tonic-gate{
7581777Ssetje	if [ ! -d "$UNPACKED_ROOT" -o -z "$MR" ] ; then
7590Sstevel@tonic-gate		usage
7600Sstevel@tonic-gate		exit 1
7610Sstevel@tonic-gate	fi
7620Sstevel@tonic-gate
7637563SPrasad.Singamsetty@Sun.COM	# always compress if fiocompress exists
7645648Ssetje	#
7657563SPrasad.Singamsetty@Sun.COM	if [ -x /usr/sbin/fiocompress ] ; then
7665648Ssetje		COMPRESS=true
7675648Ssetje	fi
7685648Ssetje
7692511Sjongkis	# Estimate image size and add %10 overhead for ufs stuff.
7702511Sjongkis	# Note, we can't use du here in case $UNPACKED_ROOT is on a filesystem,
7712511Sjongkis	# e.g. zfs, in which the disk usage is less than the sum of the file
7725648Ssetje	# sizes.  The nawk code
7732511Sjongkis	#
7742511Sjongkis	#	{t += ($7 % 1024) ? (int($7 / 1024) + 1) * 1024 : $7}
7752511Sjongkis	#
7762511Sjongkis	# below rounds up the size of a file/directory, in bytes, to the
7772511Sjongkis	# next multiple of 1024.  This mimics the behavior of ufs especially
7782511Sjongkis	# with directories.  This results in a total size that's slightly
7792511Sjongkis	# bigger than if du was called on a ufs directory.
7805648Ssetje	#
7815648Ssetje	# if the operation in turn is compressing the files the amount
7825648Ssetje	# of typical shrinkage is used to come up with a useful archive
7835648Ssetje	# size
7842511Sjongkis	size=$(find "$UNPACKED_ROOT" -ls | nawk '
7852511Sjongkis	    {t += ($7 % 1024) ? (int($7 / 1024) + 1) * 1024 : $7}
7862511Sjongkis	    END {print int(t * 1.10 / 1024)}')
7875648Ssetje	if [ "$COMPRESS" = true ] ; then
7887563SPrasad.Singamsetty@Sun.COM		size=`echo $size | nawk '{s = $1} END {print int(s * 0.6)}'`
7895648Ssetje	fi
7900Sstevel@tonic-gate
7912334Ssetje	/usr/sbin/mkfile ${size}k "$TMR"
7922334Ssetje
7932334Ssetje	LOFIDEV=`/usr/sbin/lofiadm -a "$TMR"`
7940Sstevel@tonic-gate	if [ $? != 0 ] ; then
7950Sstevel@tonic-gate		echo lofi plumb failed
7960Sstevel@tonic-gate		exit 2
7970Sstevel@tonic-gate	fi
7980Sstevel@tonic-gate
7992334Ssetje	RLOFIDEV=`echo $LOFIDEV | sed s/lofi/rlofi/`
8005648Ssetje	newfs $RLOFIDEV < /dev/null 2> /dev/null
8011777Ssetje	mkdir -p $MNT
8025648Ssetje	mount -o nologging $LOFIDEV $MNT
8031777Ssetje	rmdir $MNT/lost+found
8045648Ssetje
8055648Ssetje	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
8065648Ssetje		root_is_ramdisk $size
8075648Ssetje	fi
8085648Ssetje
8092851Sjongkis	(
8102851Sjongkis		cd "$UNPACKED_ROOT"
8115648Ssetje		if [ "$COMPRESS" = true ] ; then
8125648Ssetje			compress . $MNT
8135648Ssetje		else
8145648Ssetje			find . -print | cpio -pdum $MNT 2> /dev/null
8155648Ssetje		fi
8162851Sjongkis	)
8170Sstevel@tonic-gate	lockfs -f $MNT
8180Sstevel@tonic-gate	umount $MNT
8190Sstevel@tonic-gate	rmdir $MNT
8205648Ssetje
8215648Ssetje	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
8225648Ssetje		"$UNPACKED_ROOT/usr/sbin/installboot" \
8236319Sjg		    "$UNPACKED_ROOT/platform/sun4u/lib/fs/ufs/bootblk" \
8245648Ssetje		    $RLOFIDEV
8255648Ssetje	fi
8265648Ssetje
8272334Ssetje	lofiadm -d $LOFIDEV
8282851Sjongkis	LOFIDEV=
8290Sstevel@tonic-gate
8302334Ssetje	rm -f "$TMR.gz"
8315648Ssetje
8325648Ssetje	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
8335648Ssetje		mv "$TMR" "$MR"
8345648Ssetje	else
8355648Ssetje		gzip -f "$TMR"
8365648Ssetje		mv "$TMR.gz" "$MR"
8375648Ssetje	fi
8385648Ssetje
8391777Ssetje	chmod a+r "$MR"
8400Sstevel@tonic-gate}
8410Sstevel@tonic-gate
8425716Ssetjestrip_amd64()
8435716Ssetje{
8445716Ssetje	find "$UNPACKED_ROOT" -name amd64 -type directory | xargs rm -rf
8455716Ssetje}
8465716Ssetje
8470Sstevel@tonic-gate# main
8480Sstevel@tonic-gate#
8490Sstevel@tonic-gate
8502334SsetjeEXTRA_SPACE=0
8512851SjongkisSTRIP_AMD64=
8525648SsetjeCOMPRESS=
8532334Ssetje
8545648SsetjePATH=/usr/sbin:/usr/bin:/opt/sfw/bin ; export PATH
8555648Ssetje
8565648Ssetjewhile getopts s:6c opt ; do
8572334Ssetje	case $opt in
8582334Ssetje	s)	EXTRA_SPACE="$OPTARG"
8592334Ssetje		;;
8602334Ssetje	6)	STRIP_AMD64=false
8612334Ssetje		;;
8625648Ssetje	c)	COMPRESS=true
8635648Ssetje		;;
8642334Ssetje	*)	usage
8652334Ssetje		exit 1
8662334Ssetje		;;
8672334Ssetje	esac
8682334Ssetjedone
8692334Ssetjeshift `expr $OPTIND - 1`
8702334Ssetje
8710Sstevel@tonic-gateif [ $# != 3 ] ; then
8720Sstevel@tonic-gate	usage
8730Sstevel@tonic-gate	exit 1
8740Sstevel@tonic-gatefi
8750Sstevel@tonic-gate
8761777SsetjeUNPACKED_ROOT="$3"
8771777SsetjeBASE="`pwd`"
8780Sstevel@tonic-gateMNT=/tmp/mnt$$
8792334SsetjeTMR=/tmp/mr$$
8802334SsetjeLOFIDEV=
8811777SsetjeMR="$2"
8820Sstevel@tonic-gate
8830Sstevel@tonic-gateif [ "`dirname $MR`" = . ] ; then
8841777Ssetje	MR="$BASE/$MR"
8850Sstevel@tonic-gatefi
8860Sstevel@tonic-gateif [ "`dirname $UNPACKED_ROOT`" = . ] ; then
8871777Ssetje	UNPACKED_ROOT="$BASE/$UNPACKED_ROOT"
8880Sstevel@tonic-gatefi
8890Sstevel@tonic-gate
8905648Ssetje
8915648SsetjeMEDIA="$MR"
8925648Ssetje
8932334Ssetjetrap cleanup EXIT
8942334Ssetje
8950Sstevel@tonic-gatecase $1 in
8960Sstevel@tonic-gate	packmedia)
8971777Ssetje		if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
8985648Ssetje			ARCHIVE=sparc.miniroot
8995648Ssetje		else
9005822Sjhd			ARCHIVE=x86.miniroot
9015648Ssetje		fi
9025716Ssetje		MR="$MEDIA/boot/$ARCHIVE"
9035716Ssetje
9045648Ssetje		packmedia "$MEDIA" "$UNPACKED_ROOT"
9055648Ssetje		pack
9065716Ssetje
9075648Ssetje		;;
9085648Ssetje	unpackmedia)
9095648Ssetje		if [ -f "$MEDIA/boot/sparc.miniroot" ] ; then
9105648Ssetje			ARCHIVE=sparc.miniroot
9111777Ssetje		else
9125648Ssetje			ARCHIVE=x86.miniroot
9135648Ssetje		fi
9145716Ssetje		MR="$MEDIA/boot/$ARCHIVE"
9155648Ssetje		unpack
9165648Ssetje		unpackmedia "$MEDIA" "$UNPACKED_ROOT"
9175648Ssetje		;;
9185648Ssetje	pack)	pack
9195648Ssetje		;;
9205648Ssetje	unpack)	unpack
9215648Ssetje		;;
9225648Ssetje	*)	usage
9235648Ssetje		;;
9240Sstevel@tonic-gateesac
925