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
238715SJan.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"
50*10159SJerry.Gilliam@Sun.COM	exit 1
510Sstevel@tonic-gate}
520Sstevel@tonic-gate
532334Ssetjecleanup()
542334Ssetje{
552334Ssetje	if [ -d $MNT ] ; then
562334Ssetje		umount $MNT 2> /dev/null
572334Ssetje		rmdir $MNT
582334Ssetje	fi
592334Ssetje
602851Sjongkis	lofiadm -d "$TMR" 2>/dev/null
615648Ssetje        if [ "$REALTHING" != true ] ; then
625648Ssetje		rm -f "$TMR"
635648Ssetje	fi
645648Ssetje	rm -f "$TMR.gz"
657563SPrasad.Singamsetty@Sun.COM	rm -f /tmp/flist$$
662334Ssetje}
672334Ssetje
685822Sjhdpreload_Gnome()
694889Ssjelinek{
704889Ssjelinek	MEDIA="$1"
714889Ssjelinek	MINIROOT="$2"
724889Ssjelinek
734889Ssjelinek
744889Ssjelinek	(
754889Ssjelinek		# Prepopulate the gconf database. This needs to be done and
764889Ssjelinek		# done first for several reasons. 1) Archiving out the gnome
774889Ssjelinek		# libraries and binaries causes the gconftool-2 to not run
784889Ssjelinek		# appropriately at boot time. 2) The binaries and libraries
794889Ssjelinek		# needed to run this are big and thus we want to archive
804889Ssjelinek		# them separately. 3) Having schemas prepopluated in the
814889Ssjelinek		# miniroot means faster boot times.
824889Ssjelinek		#
834889Ssjelinek
844889Ssjelinek		cd "$MINIROOT"
854889Ssjelinek		HOME="./tmp/root"
864889Ssjelinek		export HOME
874889Ssjelinek		umask 0022
885648Ssetje		mumble=.tmp_proto/root/etc/gconf/gconf.xml.defaults
895648Ssetje		GCONF_CONFIG_SOURCE="xml:merged:$MINIROOT/$mumble"
904889Ssjelinek		export GCONF_CONFIG_SOURCE
914889Ssjelinek		SCHEMADIR="$MINIROOT/.tmp_proto/root/etc/gconf/schemas"
924889Ssjelinek		export SCHEMADIR
935648Ssetje		/usr/bin/gconftool-2 --makefile-install-rule \
945648Ssetje		    $SCHEMADIR/*.schemas >/dev/null 2>&1
955571Ssjelinek		echo '
965571Ssjelinek		xml:readwrite:/tmp/root/.gconf
975571Ssjelinek		xml:readonly:/etc/gconf/gconf.xml.defaults
985571Ssjelinek		' > /"$MINIROOT"/.tmp_proto/root/etc/gconf/2/path
995822Sjhd	)
1005822Sjhd}
1015571Ssjelinek
1025822Sjhdarchive_Gnome()
1035822Sjhd{
1045822Sjhd	MEDIA="$1"
1055822Sjhd	MINIROOT="$2"
1065822Sjhd
1075822Sjhd	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
1085822Sjhd	RELEASE=`basename "$RELEASE"`
1095822Sjhd	CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
1105822Sjhd
1115822Sjhd	# Create the gnome archive
1125822Sjhd	#
1135822Sjhd	(
1144889Ssjelinek		# usr/share gnome stuff
1154889Ssjelinek		cd "$MINIROOT"
1164889Ssjelinek		find usr/share/GConf usr/share/application-registry \
1174889Ssjelinek		    usr/share/autostart usr/share/dbus-1 usr/share/dtds \
1184889Ssjelinek		    usr/share/emacs usr/share/gnome usr/share/gnome-2.0 \
1194889Ssjelinek		    usr/share/gnome-background-properties \
1204889Ssjelinek		    usr/share/gtk-engines usr/share/gui-install \
1214889Ssjelinek		    usr/share/icon-naming-utils usr/share/control-center \
1224889Ssjelinek		    usr/share/icons usr/share/locale usr/share/metacity \
1234889Ssjelinek		    usr/share/mime usr/share/mime-info usr/share/pixmaps \
1244889Ssjelinek		    usr/share/scrollkeeper usr/share/sgml usr/share/themes \
1254889Ssjelinek		    usr/share/xml \
1264889Ssjelinek		    -print > /tmp/gnome_share.$$ 2>/dev/null
1274889Ssjelinek
1284889Ssjelinek		if [ ! -f /tmp/gnome_share.$$ ] ; then
1294889Ssjelinek			echo "/tmp/gnome_share.$$ file list not found."
1305648Ssetje			return
1314889Ssjelinek		fi
1324889Ssjelinek
1334889Ssjelinek		# usr/lib gnome stuff
1344889Ssjelinek
1354889Ssjelinek		find usr/lib/libgnome*\.so\.* \
1364889Ssjelinek		    usr/lib/libgst*\.so\.* usr/lib/libgconf*\.so\.* \
1374889Ssjelinek		    usr/lib/libgdk*\.so\.* usr/lib/libgtk*\.so\.* \
1384889Ssjelinek		    usr/lib/libglade*\.so\.* usr/lib/libmetacity*\.so\.* \
1394889Ssjelinek		    usr/lib/libfontconfig*\.so\.* usr/lib/libgmodule*\.so\.* \
1404889Ssjelinek		    usr/lib/libgobject*\.so\.* usr/lib/libgthread*\.so\.* \
1414889Ssjelinek		    usr/lib/libpopt*\.so\.* usr/lib/libstartup*\.so\.* \
1424889Ssjelinek		    usr/lib/libexif*\.so\.* usr/lib/libtiff*\.so\.* \
1434889Ssjelinek		    usr/lib/libdbus*\.so\.* usr/lib/libstartup*\.so\.* \
1444889Ssjelinek		    usr/lib/libexif*\.so\.* usr/lib/libORBit*\.so\.* \
1454889Ssjelinek	 	    usr/lib/libmlib*\.so\.* usr/lib/libxsl*\.so\.* \
1464889Ssjelinek		    usr/lib/libpango*\.so\.* usr/lib/libpng*\.so\.* \
1474889Ssjelinek		    usr/lib/liboil*\.so\.* usr/lib/libbonobo*\.so\.* \
1484889Ssjelinek		    usr/lib/libart*\.so\.* usr/lib/libcairo*\.so\.* \
1494889Ssjelinek		    usr/lib/libjpeg*\.so\.* \
1504889Ssjelinek		    usr/lib/libpolkit*\.so\.* \
1514889Ssjelinek			-print | egrep -v '\.so\.[0]$' > \
1524889Ssjelinek		       /tmp/gnome_lib.$$ 2>/dev/null
1534889Ssjelinek
1544889Ssjelinek		find usr/lib/nautilus usr/lib/pango usr/lib/iconv \
1554889Ssjelinek		    usr/lib/metacity-dialog usr/lib/window-manager-settings \
1564889Ssjelinek		    usr/lib/bonobo-2.0 usr/lib/bononbo usr/lib/gtk-2.0 \
1574889Ssjelinek		    usr/lib/GConf usr/lib/bonobo-activation-server \
1584889Ssjelinek		    usr/lib/python2.4 usr/lib/gstreamer-0.10 \
1594889Ssjelinek		    usr/lib/gconf-sanity-check-2 usr/lib/gconfd \
1604889Ssjelinek		    usr/lib/gnome-vfs-2.0 usr/lib/dbus-daemon \
1614889Ssjelinek		    usr/lib/gnome-vfs-daemon usr/lib/gnome-settings-daemon \
1624889Ssjelinek		    usr/lib/gnome_segv2 usr/lib/orbit-2.0 \
1634889Ssjelinek		    usr/lib/libmlib \
1644889Ssjelinek		    print > /tmp/gnome_libdir.$$ 2>/dev/null
1654889Ssjelinek
1664889Ssjelinek		if [ ! -f /tmp/gnome_lib.$$  -a ! -f gnome_libdir.$$ ] ; then
1674889Ssjelinek			echo "/tmp/gnome_lib.$$ file list not found."
1684889Ssjelinek			return
1694889Ssjelinek		fi
1704889Ssjelinek
1714889Ssjelinek		# /usr/sfw gnome stuff
1724889Ssjelinek		find usr/sfw/bin usr/sfw/include usr/sfw/share usr/sfw/src \
1734889Ssjelinek		    -print > /tmp/gnome_sfw.$$ 2>/dev/null
1744889Ssjelinek
1754889Ssjelinek		if [ ! -f /tmp/gnome_sfw.$$ ] ; then
1764889Ssjelinek			echo "/tmp/gnome_sfw.$$ file list not found."
1774889Ssjelinek			return
1784889Ssjelinek		fi
1794889Ssjelinek
1804889Ssjelinek		# gnome app binaries usr/bin
1814889Ssjelinek		find usr/bin/gnome* usr/bin/gui-install usr/bin/bonobo* \
1824889Ssjelinek		    usr/bin/gtk-* usr/bin/fax* usr/bin/gdk* usr/bin/gif2tiff \
1834889Ssjelinek		    usr/bin/install-lan \
1844889Ssjelinek		    usr/bin/metacity* usr/bin/gst-* usr/bin/gconftool-2 \
1854889Ssjelinek		    usr/bin/pango* usr/bin/desktop* usr/bin/djpeg \
1864889Ssjelinek		    usr/bin/notify-send usr/bin/oil-bugreport \
1874889Ssjelinek		    usr/bin/bmp2tiff usr/bin/thembus-theme-applier \
1884889Ssjelinek		    usr/bin/thumbnail usr/lib/update-* \
1894889Ssjelinek		    usr/bin/ras2tiff usr/bin/raw2tiff usr/bin/rdjpgcom \
1904889Ssjelinek		    usr/bin/thumbnail usr/bin/dbus* \
1914889Ssjelinek		    usr/bin/tiff* usr/bin/rgb2ycbcr \
1924889Ssjelinek		    usr/bin/fc-cache usr/bin/fc-list \
1934889Ssjelinek			-print > /tmp/gnome_bin.$$ 2>/dev/null
1944889Ssjelinek
1954889Ssjelinek		if [ ! -f /tmp/gnome_bin.$$ ] ; then
1964889Ssjelinek			echo "/tmp/gnome_bin.$$ file list not found."
1975648Ssetje			return
1984889Ssjelinek		fi
1994889Ssjelinek
2004889Ssjelinek		# Cat all the files together and create the gnome archive
2014889Ssjelinek		#
2024889Ssjelinek
2034889Ssjelinek		cat /tmp/gnome_libdir.$$ /tmp/gnome_lib.$$ \
2044889Ssjelinek		     /tmp/gnome_share.$$ /tmp/gnome_sfw.$$ /tmp/gnome_bin.$$ \
2054889Ssjelinek		    > /tmp/gnome.$$
2064889Ssjelinek
2074889Ssjelinek		if [ ! -f /tmp/gnome.$$ ] ; then
2084889Ssjelinek			echo "/tmp/gnome.$$ file not found."
2094889Ssjelinek			return
2104889Ssjelinek		fi
2114889Ssjelinek		# Save off this file in the miniroot for use later
2124889Ssjelinek		# when unpacking. Clean up old cruft if there.
2134889Ssjelinek		#
2144889Ssjelinek
2154889Ssjelinek		if [ -f .tmp_proto/gnome_saved ]; then
2164889Ssjelinek			rm -f .tmp_proto/gnome_saved
2174889Ssjelinek		fi
2184889Ssjelinek
2194889Ssjelinek		cp /tmp/gnome.$$ .tmp_proto/gnome_saved
2204889Ssjelinek
2214889Ssjelinek		# Create gnome archive
2224889Ssjelinek		#
2234889Ssjelinek
2244889Ssjelinek		cpio -ocmPuB < /tmp/gnome.$$ 2>/dev/null | bzip2 > \
2254889Ssjelinek		    "$CPIO_DIR/gnome.cpio.bz2"
2264889Ssjelinek
2275648Ssetje		# Remove files from miniroot that are in archive.
2284889Ssjelinek		# Create symlinks for files in archive
2294889Ssjelinek
2304889Ssjelinek		rm -rf `cat /tmp/gnome_share.$$`
2314889Ssjelinek
2324889Ssjelinek		for i in `cat /tmp/gnome_share.$$`
2335648Ssetje		do
2344889Ssjelinek			ln -s /tmp/root/$i $i 2>/dev/null
2354889Ssjelinek		done
2364889Ssjelinek
2374889Ssjelinek		rm -rf `cat /tmp/gnome_lib.$$`
2384889Ssjelinek		for i in `cat /tmp/gnome_lib.$$`
2394889Ssjelinek		do
2404889Ssjelinek			ln -s /tmp/root/$i $i 2>/dev/null
2414889Ssjelinek		done
2424889Ssjelinek
2434889Ssjelinek		rm -rf `cat /tmp/gnome_libdir.$$`
2444889Ssjelinek		for i in `cat /tmp/gnome_libdir.$$`
2455648Ssetje		do
2464889Ssjelinek			ln -s /tmp/root/$i $i 2>/dev/null
2474889Ssjelinek		done
2484889Ssjelinek
2494889Ssjelinek		rm -rf `cat /tmp/gnome_sfw.$$`
2504889Ssjelinek		for i in `cat /tmp/gnome_sfw.$$`
2515648Ssetje		do
2524889Ssjelinek			ln -s /tmp/root/$i $i 2>/dev/null
2534889Ssjelinek		done
2544889Ssjelinek
2554889Ssjelinek		rm -rf `cat /tmp/gnome_bin.$$`
2564889Ssjelinek		for i in `cat /tmp/gnome_bin.$$`
2575648Ssetje		do
2584889Ssjelinek			ln -s /tmp/root/$i $i 2>/dev/null
2594889Ssjelinek		done
2604889Ssjelinek		rm -f /tmp/gnome_share.$$
2614889Ssjelinek		rm -f /tmp/gnome_lib.$$
2624889Ssjelinek		rm -f /tmp/gnome_libdir.$$
2634889Ssjelinek		rm -f /tmp/gnome_bin.$$
2644889Ssjelinek	)
2654889Ssjelinek}
2664889Ssjelinek
2674889Ssjelinekarchive_JavaGUI()
2684889Ssjelinek{
2694889Ssjelinek	MEDIA="$1"
2704889Ssjelinek	MINIROOT="$2"
2714889Ssjelinek
2724889Ssjelinek	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
2734889Ssjelinek	RELEASE=`basename "$RELEASE"`
2744889Ssjelinek
2755648Ssetje	CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
2764889Ssjelinek
2774889Ssjelinek	# Archive the java wizard components that are only used in the
2784889Ssjelinek	# non developer express path.
2794889Ssjelinek	#
2804889Ssjelinek	(
2814889Ssjelinek		# path is usr/lib/install/data
2824889Ssjelinek		cd "$MINIROOT"
2834889Ssjelinek		find usr/lib/install/data/wizards \
2844889Ssjelinek		    -print > /tmp/java_ui.$$ 2>/dev/null
2854889Ssjelinek
2864889Ssjelinek		if [ ! -f /tmp/java_ui.$$ ] ; then
2874889Ssjelinek			echo "/tmp/java_ui.$$ file list not found."
2885648Ssetje			return
2894889Ssjelinek		fi
2904889Ssjelinek
2914889Ssjelinek		cpio -ocmPuB < /tmp/java_ui.$$ 2>/dev/null | bzip2 > \
2924889Ssjelinek		    "$CPIO_DIR/javaui.cpio.bz2"
2934889Ssjelinek
2944889Ssjelinek		rm -rf `cat /tmp/java_ui.$$`
2955648Ssetje		ln -s /tmp/root/usr/lib/install/data/wizards \
2965648Ssetje		    usr/lib/install/data/wizards 2>/dev/null
2974889Ssjelinek
2984889Ssjelinek		rm -f /tmp/java_ui.$$
2994889Ssjelinek
3004889Ssjelinek	)
3014889Ssjelinek}
3024889Ssjelinek
3034889Ssjelinekarchive_Misc()
3044889Ssjelinek{
3054889Ssjelinek	MEDIA="$1"
3064889Ssjelinek	MINIROOT="$2"
3074889Ssjelinek
3084889Ssjelinek	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
3094889Ssjelinek	RELEASE=`basename "$RELEASE"`
3104889Ssjelinek
3115648Ssetje	CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
3124889Ssjelinek
3134889Ssjelinek	# Archive misc stuff that is needed by non devex installer
3144889Ssjelinek	#
3154889Ssjelinek	(
3164889Ssjelinek		# usr/lib stuff
3174889Ssjelinek		cd "$MINIROOT"
3184889Ssjelinek		find usr/lib/lp -print > /tmp/lp.$$ 2>/dev/null
3194889Ssjelinek		if [ ! -f /tmp/lp.$$ ] ; then
3204889Ssjelinek			echo "/tmp/lp.$$ file list not found."
3215648Ssetje			return
3224889Ssjelinek		fi
3234889Ssjelinek
3244889Ssjelinek		cpio -ocmPuB < /tmp/lp.$$ 2>/dev/null | bzip2 > \
3254889Ssjelinek		    "$CPIO_DIR/lpmisc.cpio.bz2"
3264889Ssjelinek
3274889Ssjelinek		rm -rf `cat /tmp/lp.$$`
3284889Ssjelinek		ln -s /tmp/root/usr/lib/lp usr/lib/lp 2>/dev/null
3294889Ssjelinek
3304889Ssjelinek		rm -f /tmp/lp.$$
3314889Ssjelinek	)
3324889Ssjelinek
3334889Ssjelinek}
3344889Ssjelinek
3354889Ssjelinekarchive_Perl()
3364889Ssjelinek{
3374889Ssjelinek	MEDIA="$1"
3384889Ssjelinek	MINIROOT="$2"
3394889Ssjelinek
3404889Ssjelinek	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
3414889Ssjelinek	RELEASE=`basename "$RELEASE"`
3424889Ssjelinek
3435648Ssetje	CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
3444889Ssjelinek
3454889Ssjelinek	# Archive perl, it is only needed by gnome gui.
3464889Ssjelinek	#
3474889Ssjelinek	(
3484889Ssjelinek		# in usr
3494889Ssjelinek		cd "$MINIROOT"
3504889Ssjelinek		find usr/perl5 -print > /tmp/perl.$$ 2>/dev/null
3514889Ssjelinek
3524889Ssjelinek		if [ ! -f /tmp/perl.$$ ] ; then
3534889Ssjelinek			echo "/tmp/perl.$$ file list not found."
3545648Ssetje			return
3554889Ssjelinek		fi
3564889Ssjelinek		cpio -ocmPuB < /tmp/perl.$$ 2>/dev/null | bzip2 > \
3574889Ssjelinek		    "$CPIO_DIR/perl.cpio.bz2"
3584889Ssjelinek
3594889Ssjelinek		rm -rf `cat /tmp/perl.$$` 2>/dev/null
3605571Ssjelinek		ln -s /tmp/root/usr/perl5 usr/perl5 2>/dev/null
3614889Ssjelinek
3624889Ssjelinek		rm -f /tmp/perl.$$
3634889Ssjelinek	)
3644889Ssjelinek}
3651777Ssetjearchive_X()
3660Sstevel@tonic-gate{
3671777Ssetje	MEDIA="$1"
3681777Ssetje	MINIROOT="$2"
3690Sstevel@tonic-gate
3701777Ssetje	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
3711777Ssetje	RELEASE=`basename "$RELEASE"`
3720Sstevel@tonic-gate
3735648Ssetje	CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
3740Sstevel@tonic-gate
3750Sstevel@tonic-gate	# create the graphics and non-graphics X archive
3760Sstevel@tonic-gate	#
3772851Sjongkis	(
3784889Ssjelinek		cd "$MINIROOT"
3794889Ssjelinek		find usr/openwin usr/dt usr/X11 -print 2> /dev/null |\
3802851Sjongkis		    cpio -ocmPuB 2> /dev/null | bzip2 > "$CPIO_DIR/X.cpio.bz2"
3810Sstevel@tonic-gate
3824889Ssjelinek		find usr/openwin/bin/mkfontdir \
3834889Ssjelinek		     usr/openwin/lib/installalias \
3844889Ssjelinek		     usr/openwin/server/lib/libfont.so.1 \
3854889Ssjelinek		     usr/openwin/server/lib/libtypesclr.so.0 \
3862851Sjongkis			 -print | cpio -ocmPuB 2> /dev/null | bzip2 > \
3872851Sjongkis			 "$CPIO_DIR/X_small.cpio.bz2"
3880Sstevel@tonic-gate
3894889Ssjelinek		rm -rf usr/dt usr/openwin usr/X11
3904889Ssjelinek		ln -s /tmp/root/usr/dt usr/dt
3914889Ssjelinek		ln -s /tmp/root/usr/openwin usr/openwin
3924889Ssjelinek		ln -s /tmp/root/usr/X11 usr/X11
3932851Sjongkis	)
3941777Ssetje}
3951777Ssetje
3965648Ssetjearchive_lu()
3975648Ssetje{
3985648Ssetje	MEDIA="$1"
3995648Ssetje	MINIROOT="$2"
4005648Ssetje
4015648Ssetje	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
4025648Ssetje	RELEASE=`basename "$RELEASE"`
4035648Ssetje
4045648Ssetje	CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
4055648Ssetje
4065648Ssetje	(
4075648Ssetje		cd "$MINIROOT"
4089931SSreedhar.Chalamalasetti@Sun.COM		find usr/lib/install usr/snadm usr/sbin usr/lib/locale \
4097563SPrasad.Singamsetty@Sun.COM		    boot/grub boot/solaris/bootenv.rc \
4107563SPrasad.Singamsetty@Sun.COM		    tmp/root/boot/grub tmp/root/boot/solaris/bootenv.rc \
4117563SPrasad.Singamsetty@Sun.COM		    2> /dev/null | cpio -ocmPuB 2> /dev/null | bzip2 \
4127563SPrasad.Singamsetty@Sun.COM		    > "$CPIO_DIR"/lu.cpio.bz2
4135648Ssetje		ls platform > "$CPIO_DIR/lu.platforms"
4145648Ssetje	)
4155648Ssetje}
4165648Ssetje
4177563SPrasad.Singamsetty@Sun.COMcleanout_pkgdata()
4187563SPrasad.Singamsetty@Sun.COM{
4197563SPrasad.Singamsetty@Sun.COM	rm -Rf tmp/root/var/sadm/install tmp/root/var/sadm/pkg
4207563SPrasad.Singamsetty@Sun.COM}
4217563SPrasad.Singamsetty@Sun.COM
4221777Ssetjepackmedia()
4231777Ssetje{
4241777Ssetje	MEDIA="$1"
4251777Ssetje	MINIROOT="$2"
4261777Ssetje
4271777Ssetje	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
4281777Ssetje	RELEASE=`basename "$RELEASE"`
4295822Sjhd	ARCHIVES="X X_small perl lpmisc javaui gnome"
4301777Ssetje
4311777Ssetje	mkdir -p "$MEDIA/$RELEASE/Tools/Boot"
4325648Ssetje
4335648Ssetje	if [ -d "$MINIROOT/platform/i86pc" ] ; then
4345648Ssetje		mkdir -p "$MEDIA/boot/amd64"
4355648Ssetje		mkdir -p "$MEDIA/boot/platform/i86pc/kernel"
4365648Ssetje		mkdir -p "$MEDIA/boot/platform/i86pc/kernel/amd64"
4375648Ssetje		mkdir -p "$MEDIA/boot/platform/i86xpv/kernel"
4385648Ssetje		mkdir -p "$MEDIA/boot/platform/i86xpv/kernel/amd64"
4395648Ssetje		cp "$MINIROOT/platform/i86pc/multiboot" "$MEDIA/boot"
4405648Ssetje		cp "$MINIROOT/platform/i86pc/kernel/unix" \
4415648Ssetje		    "$MEDIA/boot/platform/i86pc/kernel/unix"
4425648Ssetje		cp "$MINIROOT/platform/i86pc/kernel/amd64/unix" \
4435648Ssetje		    "$MEDIA/boot/platform/i86pc/kernel/amd64/unix"
4445648Ssetje		cp "$MINIROOT/platform/i86xpv/kernel/unix" \
4455648Ssetje		    "$MEDIA/boot/platform/i86xpv/kernel/unix"
4465648Ssetje		cp "$MINIROOT/platform/i86xpv/kernel/amd64/unix" \
4475648Ssetje		    "$MEDIA/boot/platform/i86xpv/kernel/amd64/unix"
4485648Ssetje		(
4495648Ssetje			cd "$MEDIA/$RELEASE/Tools/Boot"
4505648Ssetje			ln -sf ../../../boot/x86.miniroot
4515648Ssetje			ln -sf ../../../boot/multiboot
4525648Ssetje			ln -sf ../../../boot/platform/i86pc/kernel/unix
4535648Ssetje			ln -sf ../../../boot/platform/i86pc/kernel/amd64/unix
4545648Ssetje			ln -sf ../../../boot/platform/i86xpv/kernel/unix
4555648Ssetje			ln -sf ../../../boot/platform/i86xpv/kernel/amd64/unix
4565648Ssetje			ln -sf ../../../boot/grub/pxegrub
4575648Ssetje		)
4585648Ssetje	fi
4595648Ssetje
4605648Ssetje	if [ -d "$MINIROOT/platform/sun4u" ] ; then
4615648Ssetje		mkdir -p "$MEDIA/boot"
4626319Sjg		dd if="$MINIROOT/platform/sun4u/lib/fs/hsfs/bootblk" \
4635648Ssetje		    of="$MEDIA/boot/hsfs.bootblock" \
4645648Ssetje		    bs=1b oseek=1 count=15 conv=sync 2> /dev/null
4655648Ssetje	fi
4665648Ssetje
4675648Ssetje	for arch in sun4u sun4v ; do
4685648Ssetje		if [ -d "$MINIROOT/platform/$arch" ] ; then
4695648Ssetje			archdir="$MEDIA/$RELEASE/Tools/Boot/platform/$arch"
4705648Ssetje			mkdir -p $archdir
4715648Ssetje			ln -sf ../../../../../boot/sparc.miniroot \
4725648Ssetje			    "$archdir/boot_archive"
4735648Ssetje			cp "$MINIROOT/usr/platform/$arch/lib/fs/nfs/inetboot" \
4745648Ssetje			    "$archdir"
4755648Ssetje			cp "$MINIROOT/platform/$arch/wanboot" \
4765648Ssetje			    "$archdir"
4775648Ssetje			mkdir -p "$MEDIA/platform/$arch"
4785648Ssetje			ln -sf ../../boot/sparc.miniroot \
4795648Ssetje			    "$MEDIA/platform/$arch/boot_archive"
4808144SJerry.Gilliam@Sun.COM			ln -sf ../../$RELEASE/Tools/Boot/platform/$arch/wanboot \
4818144SJerry.Gilliam@Sun.COM			    "$MEDIA/platform/$arch/wanboot"
4825648Ssetje		fi
4835648Ssetje	done
4841777Ssetje
4851777Ssetje	# archive package databases to conserve memory
4861777Ssetje	#
4872851Sjongkis	(
4882851Sjongkis		cd "$MINIROOT"
4892851Sjongkis		find tmp/root/var/sadm/install tmp/root/var/sadm/pkg -print | \
4902851Sjongkis		    cpio -ocmPuB 2> /dev/null | bzip2 > \
4912851Sjongkis		    "$MEDIA/$RELEASE/Tools/Boot/pkg_db.cpio.bz2"
4921777Ssetje
4937563SPrasad.Singamsetty@Sun.COM		cleanout_pkgdata
4947563SPrasad.Singamsetty@Sun.COM	)
4957563SPrasad.Singamsetty@Sun.COM
4967563SPrasad.Singamsetty@Sun.COM	archive_lu "$MEDIA" "$MINIROOT"
4975648Ssetje
4982595Ssetje	archive_X "$MEDIA" "$MINIROOT"
4992595Ssetje
5004889Ssjelinek	# Take out the gnome and java parts of the installer from
5014889Ssjelinek	# the miniroot. These are not required to boot the system
5024889Ssjelinek	# and start the installers.
5034889Ssjelinek
5045648Ssetje	if [ -d "$MINIROOT/platform/i86pc" ] ; then
5055822Sjhd		preload_Gnome "$MEDIA" "$MINIROOT"
5065648Ssetje		archive_Gnome "$MEDIA" "$MINIROOT"
5075648Ssetje		archive_JavaGUI "$MEDIA" "$MINIROOT"
5085648Ssetje		archive_Misc "$MEDIA" "$MINIROOT"
5095648Ssetje		archive_Perl "$MEDIA" "$MINIROOT"
510*10159SJerry.Gilliam@Sun.COM		pack "$MEDIA/boot/amd64/x86.miniroot"
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"
5335648Ssetje	fi
5340Sstevel@tonic-gate
5351821Ssetje	# copy the install menu to menu.lst so we have a menu
5361821Ssetje	# on the install media
5371821Ssetje	#
5385648Ssetje	if [ -f "$MINIROOT/boot/grub/install_menu" ] ; then
5395648Ssetje		cp $MINIROOT/boot/grub/install_menu \
5405648Ssetje		    $MEDIA/boot/grub/menu.lst
5411821Ssetje	fi
5427204Sjg
5437204Sjg	#
5447204Sjg	# jumpstart utilities in usr/sbin/install.d
5457204Sjg	#
5467204Sjg	if [ -d "$MINIROOT/usr/sbin/install.d" ] ; then
5477204Sjg		(
5487204Sjg		cd ${MINIROOT}
5497204Sjg		find usr/sbin/install.d/chkprobe \
5507204Sjg		    -print | cpio -ocmPuB 2> /dev/null | bzip2 > \
5517204Sjg		    ${MEDIA}/${RELEASE}/Tools/Boot/usr_sbin_install_d.cpio.bz2
5527204Sjg		)
5537204Sjg	fi
5541777Ssetje}
5550Sstevel@tonic-gate
5561777Ssetjeunarchive_X()
5571777Ssetje{
5581777Ssetje	MEDIA="$1"
5591777Ssetje	UNPACKED_ROOT="$2"
5601777Ssetje
5611777Ssetje	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
5621777Ssetje	RELEASE=`basename "$RELEASE"`
5631777Ssetje
5645648Ssetje	CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
5651777Ssetje
5661777Ssetje	# unpack X
5671777Ssetje	#
5682851Sjongkis	(
5694889Ssjelinek		cd "$UNPACKED_ROOT"
5704889Ssjelinek		rm -rf usr/dt usr/openwin usr/X11
5712851Sjongkis		bzcat "$CPIO_DIR/X.cpio.bz2" | cpio -icdmu 2> /dev/null
5722851Sjongkis	)
5730Sstevel@tonic-gate}
5740Sstevel@tonic-gate
5750Sstevel@tonic-gateunpackmedia()
5761777Ssetje{
5771777Ssetje	MEDIA="$1"
5781777Ssetje	UNPACKED_ROOT="$2"
5790Sstevel@tonic-gate
5801777Ssetje	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
5811777Ssetje	RELEASE=`basename "$RELEASE"`
5821777Ssetje
5831777Ssetje	unarchive_X "$MEDIA" "$UNPACKED_ROOT"
5840Sstevel@tonic-gate
5850Sstevel@tonic-gate	# unpack package databases
5860Sstevel@tonic-gate	#
5872851Sjongkis	(
5882851Sjongkis		cd "$UNPACKED_ROOT"
5892851Sjongkis		bzcat "$MEDIA/$RELEASE/Tools/Boot/pkg_db.cpio.bz2" |
5902851Sjongkis		    cpio -icdmu 2> /dev/null
5914889Ssjelinek
5928715SJan.Kryl@Sun.COM		if [ -d "$MINIROOT/platform/i86pc" ] ; then
5938715SJan.Kryl@Sun.COM
5948715SJan.Kryl@Sun.COM			# unpack gnome, perl, java and misc
5958715SJan.Kryl@Sun.COM			# Remove symlinks left from unpacking x86.miniroot
5968715SJan.Kryl@Sun.COM			# so that unpacking subsequent archives will populate
5978715SJan.Kryl@Sun.COM			# appropriately.
5988715SJan.Kryl@Sun.COM			#
5998715SJan.Kryl@Sun.COM			rm -rf usr/perl5
6008715SJan.Kryl@Sun.COM			rm -rf usr/lib/install/data/wizards
6018715SJan.Kryl@Sun.COM			rm -rf usr/lib/lp
6024889Ssjelinek
6038715SJan.Kryl@Sun.COM			# Gnome list saved off from packmedia
6048715SJan.Kryl@Sun.COM			for i in `cat .tmp_proto/gnome_saved`
6058715SJan.Kryl@Sun.COM			do
6068715SJan.Kryl@Sun.COM				rm -rf $i
6078715SJan.Kryl@Sun.COM			done
6088715SJan.Kryl@Sun.COM
6098715SJan.Kryl@Sun.COM			bzcat "$MEDIA/$RELEASE/Tools/Boot/gnome.cpio.bz2" |
6108715SJan.Kryl@Sun.COM			    cpio -icdmu 2>/dev/null
6118715SJan.Kryl@Sun.COM			bzcat "$MEDIA/$RELEASE/Tools/Boot/javaui.cpio.bz2" |
6128715SJan.Kryl@Sun.COM			    cpio -icdmu 2>/dev/null
6138715SJan.Kryl@Sun.COM			bzcat "$MEDIA/$RELEASE/Tools/Boot/lpmisc.cpio.bz2" |
6148715SJan.Kryl@Sun.COM			    cpio -icdmu 2>/dev/null
6158715SJan.Kryl@Sun.COM			bzcat "$MEDIA/$RELEASE/Tools/Boot/perl.cpio.bz2" |
6168715SJan.Kryl@Sun.COM			    cpio -icdmu 2>/dev/null
6178715SJan.Kryl@Sun.COM		fi
6182851Sjongkis	)
6190Sstevel@tonic-gate}
6200Sstevel@tonic-gate
6210Sstevel@tonic-gatedo_unpack()
6220Sstevel@tonic-gate{
6232851Sjongkis	(
6242851Sjongkis		cd $MNT
6252851Sjongkis		find . -print | cpio -pdum "$UNPACKED_ROOT" 2> /dev/null
6262851Sjongkis	)
627*10159SJerry.Gilliam@Sun.COM	# increase the chances the unmount will succeed
628*10159SJerry.Gilliam@Sun.COM	umount -f $MNT
6290Sstevel@tonic-gate}
6300Sstevel@tonic-gate
6310Sstevel@tonic-gateunpack()
6320Sstevel@tonic-gate{
633*10159SJerry.Gilliam@Sun.COM	MR=$1
6341777Ssetje	if [ ! -f "$MR" ] ; then
635*10159SJerry.Gilliam@Sun.COM		printf "$MR: not found\n"
6360Sstevel@tonic-gate		usage
6370Sstevel@tonic-gate	fi
6380Sstevel@tonic-gate
6397563SPrasad.Singamsetty@Sun.COM	if [ `uname -i` = i86pc ] ; then
6405648Ssetje		gzcat "$MR" > $TMR
6415648Ssetje	else
6425648Ssetje		REALTHING=true ; export REALTHING
6435648Ssetje		TMR="$MR"
6445648Ssetje	fi
6450Sstevel@tonic-gate
6462334Ssetje	LOFIDEV=`/usr/sbin/lofiadm -a $TMR`
6470Sstevel@tonic-gate	if [ $? != 0 ] ; then
6480Sstevel@tonic-gate		echo lofi plumb failed
6490Sstevel@tonic-gate		exit 2
6500Sstevel@tonic-gate	fi
6510Sstevel@tonic-gate
6521777Ssetje	mkdir -p $MNT
6530Sstevel@tonic-gate
6542334Ssetje	FSTYP=`fstyp $LOFIDEV`
6550Sstevel@tonic-gate
6561777Ssetje	if [ "$FSTYP" = ufs ] ; then
6572334Ssetje		/usr/sbin/mount -o ro,nologging $LOFIDEV $MNT
6580Sstevel@tonic-gate		do_unpack
6591777Ssetje	elif [ "$FSTYP" = hsfs ] ; then
6602334Ssetje		/usr/sbin/mount -F hsfs -o ro $LOFIDEV $MNT
6610Sstevel@tonic-gate		do_unpack
6620Sstevel@tonic-gate	else
6630Sstevel@tonic-gate		printf "invalid root archive\n"
6640Sstevel@tonic-gate	fi
6650Sstevel@tonic-gate
6665648Ssetje
6670Sstevel@tonic-gate	rmdir $MNT
6682851Sjongkis	lofiadm -d $TMR ; LOFIDEV=
6695648Ssetje	if [ "$REALTHING" != true ] ; then
6705648Ssetje		rm $TMR
6715648Ssetje	fi
6725648Ssetje}
6735648Ssetje
6745648Ssetjecompress()
6755648Ssetje{
6765648Ssetje	SRC=$1
6775648Ssetje	DST=$2
6785648Ssetje
6795648Ssetje	(
6805648Ssetje		cd $SRC
6815648Ssetje		filelist=`find .`
6825648Ssetje
6835648Ssetje		for file in $filelist ; do
6845648Ssetje
6855648Ssetje			file=`echo $file | sed s#^./##`
6865648Ssetje
6875648Ssetje			# copy all files over to preserve hard links
6885648Ssetje			#
6895648Ssetje			echo $file | cpio -pdum $DST 2> /dev/null
6905648Ssetje
6915648Ssetje			if [ -f $file ] && [ -s $file ] && [ ! -h $file ] ; then
6925648Ssetje				fiocompress -mc $file $DST/$file &
6935648Ssetje			fi
6945648Ssetje
6955648Ssetje		done
6965648Ssetje
6977563SPrasad.Singamsetty@Sun.COM		wait `pgrep fiocompress`
6987563SPrasad.Singamsetty@Sun.COM
6995648Ssetje		# now re-copy a couple of uncompressed files
7005648Ssetje
7017563SPrasad.Singamsetty@Sun.COM		if [ -d "$SRC/platform/i86pc" ] ; then
7027563SPrasad.Singamsetty@Sun.COM			find `cat boot/solaris/filelist.ramdisk` -type file \
7037563SPrasad.Singamsetty@Sun.COM			    -print 2> /dev/null > /tmp/flist$$
7047563SPrasad.Singamsetty@Sun.COM			find usr/kernel -type file -print 2> /dev/null \
7057563SPrasad.Singamsetty@Sun.COM			    >> /tmp/flist$$
7067563SPrasad.Singamsetty@Sun.COM			# some of the files are replaced with links into
7077563SPrasad.Singamsetty@Sun.COM			# tmp/root on the miniroot, so find the backing files
7087563SPrasad.Singamsetty@Sun.COM			# from there as well and add them to the list ti
7097563SPrasad.Singamsetty@Sun.COM			# be copied uncompressed
7107563SPrasad.Singamsetty@Sun.COM			(
7117563SPrasad.Singamsetty@Sun.COM				cd $SRC/tmp/root
7127563SPrasad.Singamsetty@Sun.COM				find `cat ../../boot/solaris/filelist.ramdisk` \
7137563SPrasad.Singamsetty@Sun.COM				    -type file -print 2> /dev/null | \
7147563SPrasad.Singamsetty@Sun.COM				    sed 's#^#tmp/root/#' >> /tmp/flist$$
7157563SPrasad.Singamsetty@Sun.COM			)
7167563SPrasad.Singamsetty@Sun.COM			flist=`cat /tmp/flist$$`
7177563SPrasad.Singamsetty@Sun.COM			(
7187563SPrasad.Singamsetty@Sun.COM				cd $DST
7197563SPrasad.Singamsetty@Sun.COM				rm -f $flist
7207563SPrasad.Singamsetty@Sun.COM			)
7217563SPrasad.Singamsetty@Sun.COM			for file in $flist ; do
7227563SPrasad.Singamsetty@Sun.COM				echo $file | cpio -pdum $DST 2> /dev/null
7237563SPrasad.Singamsetty@Sun.COM			done
7247563SPrasad.Singamsetty@Sun.COM		else
7257563SPrasad.Singamsetty@Sun.COM			find kernel platform -name unix | \
7267563SPrasad.Singamsetty@Sun.COM			    cpio -pdum $DST 2> /dev/null
7277563SPrasad.Singamsetty@Sun.COM			find kernel platform -name genunix | cpio -pdum $DST \
7287563SPrasad.Singamsetty@Sun.COM			    2> /dev/null
7297563SPrasad.Singamsetty@Sun.COM			find kernel platform -name platmod | cpio -pdum $DST \
7307563SPrasad.Singamsetty@Sun.COM			    2> /dev/null
7317563SPrasad.Singamsetty@Sun.COM			find `find kernel platform -name cpu` | \
7327563SPrasad.Singamsetty@Sun.COM			    cpio -pdum $DST 2> /dev/null
7337563SPrasad.Singamsetty@Sun.COM			find `find kernel platform -name kmdb\*` | \
7347563SPrasad.Singamsetty@Sun.COM				cpio -pdum $DST 2> /dev/null
7357563SPrasad.Singamsetty@Sun.COM			find kernel/misc/sparcv9/ctf kernel/fs/sparcv9/dcfs \
7367563SPrasad.Singamsetty@Sun.COM			    kernel/misc/ctf kernel/fs/dcfs \
7377563SPrasad.Singamsetty@Sun.COM			    etc/system etc/name_to_major etc/path_to_inst \
7387563SPrasad.Singamsetty@Sun.COM			    etc/name_to_sysnum | cpio -pdum $DST 2> /dev/null
7397563SPrasad.Singamsetty@Sun.COM		fi
7405648Ssetje	)
7415648Ssetje}
7425648Ssetje
7435648Ssetjeroot_is_ramdisk()
7445648Ssetje{
7455648Ssetje	grep -v "set root_is_ramdisk=" "$UNPACKED_ROOT"/etc/system | \
7465648Ssetje	    grep -v "set ramdisk_size=" > /tmp/system.$$
7475648Ssetje	cat /tmp/system.$$ > "$UNPACKED_ROOT"/etc/system
7485648Ssetje	rm /tmp/system.$$
7495648Ssetje
7505648Ssetje	echo set root_is_ramdisk=1 >> "$UNPACKED_ROOT"/etc/system
7515648Ssetje	echo set ramdisk_size=$1 >> "$UNPACKED_ROOT"/etc/system
7520Sstevel@tonic-gate}
7530Sstevel@tonic-gate
7540Sstevel@tonic-gatepack()
7550Sstevel@tonic-gate{
756*10159SJerry.Gilliam@Sun.COM	MR="$1"
757*10159SJerry.Gilliam@Sun.COM	[ -d "$UNPACKED_ROOT" ] || usage
7580Sstevel@tonic-gate
7597563SPrasad.Singamsetty@Sun.COM	# always compress if fiocompress exists
7605648Ssetje	#
7617563SPrasad.Singamsetty@Sun.COM	if [ -x /usr/sbin/fiocompress ] ; then
7625648Ssetje		COMPRESS=true
7635648Ssetje	fi
7645648Ssetje
7652511Sjongkis	# Estimate image size and add %10 overhead for ufs stuff.
7662511Sjongkis	# Note, we can't use du here in case $UNPACKED_ROOT is on a filesystem,
7672511Sjongkis	# e.g. zfs, in which the disk usage is less than the sum of the file
7685648Ssetje	# sizes.  The nawk code
7692511Sjongkis	#
7702511Sjongkis	#	{t += ($7 % 1024) ? (int($7 / 1024) + 1) * 1024 : $7}
7712511Sjongkis	#
7722511Sjongkis	# below rounds up the size of a file/directory, in bytes, to the
7732511Sjongkis	# next multiple of 1024.  This mimics the behavior of ufs especially
7742511Sjongkis	# with directories.  This results in a total size that's slightly
7752511Sjongkis	# bigger than if du was called on a ufs directory.
7765648Ssetje	#
7775648Ssetje	# if the operation in turn is compressing the files the amount
7785648Ssetje	# of typical shrinkage is used to come up with a useful archive
7795648Ssetje	# size
7802511Sjongkis	size=$(find "$UNPACKED_ROOT" -ls | nawk '
7812511Sjongkis	    {t += ($7 % 1024) ? (int($7 / 1024) + 1) * 1024 : $7}
7822511Sjongkis	    END {print int(t * 1.10 / 1024)}')
7835648Ssetje	if [ "$COMPRESS" = true ] ; then
7847563SPrasad.Singamsetty@Sun.COM		size=`echo $size | nawk '{s = $1} END {print int(s * 0.6)}'`
7855648Ssetje	fi
7860Sstevel@tonic-gate
7872334Ssetje	/usr/sbin/mkfile ${size}k "$TMR"
7882334Ssetje
7892334Ssetje	LOFIDEV=`/usr/sbin/lofiadm -a "$TMR"`
7900Sstevel@tonic-gate	if [ $? != 0 ] ; then
7910Sstevel@tonic-gate		echo lofi plumb failed
7920Sstevel@tonic-gate		exit 2
7930Sstevel@tonic-gate	fi
7940Sstevel@tonic-gate
7952334Ssetje	RLOFIDEV=`echo $LOFIDEV | sed s/lofi/rlofi/`
7965648Ssetje	newfs $RLOFIDEV < /dev/null 2> /dev/null
7971777Ssetje	mkdir -p $MNT
7985648Ssetje	mount -o nologging $LOFIDEV $MNT
7991777Ssetje	rmdir $MNT/lost+found
8005648Ssetje
8015648Ssetje	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
8025648Ssetje		root_is_ramdisk $size
8035648Ssetje	fi
8045648Ssetje
8052851Sjongkis	(
8062851Sjongkis		cd "$UNPACKED_ROOT"
8075648Ssetje		if [ "$COMPRESS" = true ] ; then
8085648Ssetje			compress . $MNT
8095648Ssetje		else
8105648Ssetje			find . -print | cpio -pdum $MNT 2> /dev/null
8115648Ssetje		fi
8122851Sjongkis	)
8130Sstevel@tonic-gate	lockfs -f $MNT
8140Sstevel@tonic-gate	umount $MNT
8150Sstevel@tonic-gate	rmdir $MNT
8165648Ssetje
8175648Ssetje	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
8185648Ssetje		"$UNPACKED_ROOT/usr/sbin/installboot" \
8196319Sjg		    "$UNPACKED_ROOT/platform/sun4u/lib/fs/ufs/bootblk" \
8205648Ssetje		    $RLOFIDEV
8215648Ssetje	fi
8225648Ssetje
8232334Ssetje	lofiadm -d $LOFIDEV
8242851Sjongkis	LOFIDEV=
8250Sstevel@tonic-gate
8262334Ssetje	rm -f "$TMR.gz"
8275648Ssetje
8285648Ssetje	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
8295648Ssetje		mv "$TMR" "$MR"
8305648Ssetje	else
8315648Ssetje		gzip -f "$TMR"
8325648Ssetje		mv "$TMR.gz" "$MR"
8335648Ssetje	fi
8345648Ssetje
8351777Ssetje	chmod a+r "$MR"
8360Sstevel@tonic-gate}
8370Sstevel@tonic-gate
8385716Ssetjestrip_amd64()
8395716Ssetje{
8405716Ssetje	find "$UNPACKED_ROOT" -name amd64 -type directory | xargs rm -rf
8415716Ssetje}
8425716Ssetje
8430Sstevel@tonic-gate# main
8440Sstevel@tonic-gate#
8450Sstevel@tonic-gate
8462334SsetjeEXTRA_SPACE=0
8472851SjongkisSTRIP_AMD64=
8485648SsetjeCOMPRESS=
8492334Ssetje
8505648SsetjePATH=/usr/sbin:/usr/bin:/opt/sfw/bin ; export PATH
8515648Ssetje
8525648Ssetjewhile getopts s:6c opt ; do
8532334Ssetje	case $opt in
8542334Ssetje	s)	EXTRA_SPACE="$OPTARG"
8552334Ssetje		;;
8562334Ssetje	6)	STRIP_AMD64=false
8572334Ssetje		;;
8585648Ssetje	c)	COMPRESS=true
8595648Ssetje		;;
8602334Ssetje	*)	usage
8612334Ssetje		;;
8622334Ssetje	esac
8632334Ssetjedone
8642334Ssetjeshift `expr $OPTIND - 1`
8652334Ssetje
866*10159SJerry.Gilliam@Sun.COM[ $# == 3 ] || usage
8670Sstevel@tonic-gate
8681777SsetjeUNPACKED_ROOT="$3"
8691777SsetjeBASE="`pwd`"
8700Sstevel@tonic-gateMNT=/tmp/mnt$$
8712334SsetjeTMR=/tmp/mr$$
8722334SsetjeLOFIDEV=
8731777SsetjeMR="$2"
8740Sstevel@tonic-gate
875*10159SJerry.Gilliam@Sun.COM# sanity check
876*10159SJerry.Gilliam@Sun.COM[ "$UNPACKED_ROOT" != "/" ] || usage
877*10159SJerry.Gilliam@Sun.COM
8780Sstevel@tonic-gateif [ "`dirname $MR`" = . ] ; then
8791777Ssetje	MR="$BASE/$MR"
8800Sstevel@tonic-gatefi
8810Sstevel@tonic-gateif [ "`dirname $UNPACKED_ROOT`" = . ] ; then
8821777Ssetje	UNPACKED_ROOT="$BASE/$UNPACKED_ROOT"
8830Sstevel@tonic-gatefi
8840Sstevel@tonic-gate
8855648Ssetje
8865648SsetjeMEDIA="$MR"
8875648Ssetje
8882334Ssetjetrap cleanup EXIT
8892334Ssetje
890*10159SJerry.Gilliam@Sun.COM# always unpack into a fresh root
891*10159SJerry.Gilliam@Sun.COMcase $1 in
892*10159SJerry.Gilliam@Sun.COM	unpack|unpackmedia)
893*10159SJerry.Gilliam@Sun.COM		rm -rf "$UNPACKED_ROOT"
894*10159SJerry.Gilliam@Sun.COM		mkdir -p "$UNPACKED_ROOT"
895*10159SJerry.Gilliam@Sun.COM		;;
896*10159SJerry.Gilliam@Sun.COMesac
897*10159SJerry.Gilliam@Sun.COM[ -d "$UNPACKED_ROOT" ] || usage
898*10159SJerry.Gilliam@Sun.COM
8990Sstevel@tonic-gatecase $1 in
9000Sstevel@tonic-gate	packmedia)
901*10159SJerry.Gilliam@Sun.COM		packmedia "$MEDIA" "$UNPACKED_ROOT"
9021777Ssetje		if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
903*10159SJerry.Gilliam@Sun.COM			pack "$MEDIA/boot/sparc.miniroot"
9045648Ssetje		else
905*10159SJerry.Gilliam@Sun.COM			pack "$MEDIA/boot/x86.miniroot"
9065648Ssetje		fi
9075716Ssetje
9085648Ssetje		;;
9095648Ssetje	unpackmedia)
9105648Ssetje		if [ -f "$MEDIA/boot/sparc.miniroot" ] ; then
911*10159SJerry.Gilliam@Sun.COM			unpack "$MEDIA/boot/sparc.miniroot"
9121777Ssetje		else
913*10159SJerry.Gilliam@Sun.COM			unpack "$MEDIA/boot/x86.miniroot"
914*10159SJerry.Gilliam@Sun.COM			unpack "$MEDIA/boot/amd64/x86.miniroot"
9155648Ssetje		fi
9165648Ssetje		unpackmedia "$MEDIA" "$UNPACKED_ROOT"
9175648Ssetje		;;
918*10159SJerry.Gilliam@Sun.COM	pack)	pack "$MR"
9195648Ssetje		;;
920*10159SJerry.Gilliam@Sun.COM	unpack)	unpack "$MR"
9215648Ssetje		;;
9225648Ssetje	*)	usage
9235648Ssetje		;;
9240Sstevel@tonic-gateesac
925