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
233446Smrj# Copyright 2007 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#
441777Ssetje# This utility is also used to pack parts (in essence the window system,
451777Ssetje# usr/dt and usr/openwin) of the non ramdisk SPARC
461777Ssetje# miniroot. (un)packmedia will recognize that they are being run a SPARC
471777Ssetje# 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
662851Sjongkis	rm -f "$TMR" "$TMR.gz"
672334Ssetje}
682334Ssetje
694889Ssjelinekarchive_Gnome()
704889Ssjelinek{
714889Ssjelinek	MEDIA="$1"
724889Ssjelinek	MINIROOT="$2"
734889Ssjelinek
744889Ssjelinek	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
754889Ssjelinek	RELEASE=`basename "$RELEASE"`
764889Ssjelinek
774889Ssjelinek	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
784889Ssjelinek		CPIO_DIR="$MEDIA/$RELEASE/Tools/miniroot_extra"
794889Ssjelinek		mkdir -p "$CPIO_DIR"
804889Ssjelinek	else
814889Ssjelinek		CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
824889Ssjelinek	fi
834889Ssjelinek
844889Ssjelinek
854889Ssjelinek	# Create the gnome archive
864889Ssjelinek	#
874889Ssjelinek	(
884889Ssjelinek		# Prepopulate the gconf database. This needs to be done and
894889Ssjelinek		# done first for several reasons. 1) Archiving out the gnome
904889Ssjelinek		# libraries and binaries causes the gconftool-2 to not run
914889Ssjelinek		# appropriately at boot time. 2) The binaries and libraries
924889Ssjelinek		# needed to run this are big and thus we want to archive
934889Ssjelinek		# them separately. 3) Having schemas prepopluated in the
944889Ssjelinek		# miniroot means faster boot times.
954889Ssjelinek		#
964889Ssjelinek
974889Ssjelinek		cd "$MINIROOT"
984889Ssjelinek		HOME="./tmp/root"
994889Ssjelinek		export HOME
1004889Ssjelinek		umask 0022
1014889Ssjelinek		GCONF_CONFIG_SOURCE="xml:merged:"$MINIROOT"/.tmp_proto/root/etc/gconf/gconf.xml.defaults"
1024889Ssjelinek		export GCONF_CONFIG_SOURCE
1034889Ssjelinek		SCHEMADIR="$MINIROOT/.tmp_proto/root/etc/gconf/schemas"
1044889Ssjelinek		export SCHEMADIR
1054889Ssjelinek		/usr/bin/gconftool-2 --makefile-install-rule $SCHEMADIR/*.schemas >/dev/null 2>&1
106*5571Ssjelinek		echo '
107*5571Ssjelinek		xml:readwrite:/tmp/root/.gconf
108*5571Ssjelinek		xml:readonly:/etc/gconf/gconf.xml.defaults
109*5571Ssjelinek		' > /"$MINIROOT"/.tmp_proto/root/etc/gconf/2/path
110*5571Ssjelinek
1114889Ssjelinek		# usr/share gnome stuff
1124889Ssjelinek		cd "$MINIROOT"
1134889Ssjelinek		find usr/share/GConf usr/share/application-registry \
1144889Ssjelinek		    usr/share/autostart usr/share/dbus-1 usr/share/dtds \
1154889Ssjelinek		    usr/share/emacs usr/share/gnome usr/share/gnome-2.0 \
1164889Ssjelinek		    usr/share/gnome-background-properties \
1174889Ssjelinek		    usr/share/gtk-engines usr/share/gui-install \
1184889Ssjelinek		    usr/share/icon-naming-utils usr/share/control-center \
1194889Ssjelinek		    usr/share/icons usr/share/locale usr/share/metacity \
1204889Ssjelinek		    usr/share/mime usr/share/mime-info usr/share/pixmaps \
1214889Ssjelinek		    usr/share/scrollkeeper usr/share/sgml usr/share/themes \
1224889Ssjelinek		    usr/share/xml \
1234889Ssjelinek		    -print > /tmp/gnome_share.$$ 2>/dev/null
1244889Ssjelinek
1254889Ssjelinek		if [ ! -f /tmp/gnome_share.$$ ] ; then
1264889Ssjelinek			echo "/tmp/gnome_share.$$ file list not found."
1274889Ssjelinek			return
1284889Ssjelinek		fi
1294889Ssjelinek
1304889Ssjelinek		# usr/lib gnome stuff
1314889Ssjelinek
1324889Ssjelinek		find usr/lib/libgnome*\.so\.* \
1334889Ssjelinek		    usr/lib/libgst*\.so\.* usr/lib/libgconf*\.so\.* \
1344889Ssjelinek		    usr/lib/libgdk*\.so\.* usr/lib/libgtk*\.so\.* \
1354889Ssjelinek		    usr/lib/libglade*\.so\.* usr/lib/libmetacity*\.so\.* \
1364889Ssjelinek		    usr/lib/libfontconfig*\.so\.* usr/lib/libgmodule*\.so\.* \
1374889Ssjelinek		    usr/lib/libgobject*\.so\.* usr/lib/libgthread*\.so\.* \
1384889Ssjelinek		    usr/lib/libpopt*\.so\.* usr/lib/libstartup*\.so\.* \
1394889Ssjelinek		    usr/lib/libexif*\.so\.* usr/lib/libtiff*\.so\.* \
1404889Ssjelinek		    usr/lib/libdbus*\.so\.* usr/lib/libstartup*\.so\.* \
1414889Ssjelinek		    usr/lib/libexif*\.so\.* usr/lib/libORBit*\.so\.* \
1424889Ssjelinek	 	    usr/lib/libmlib*\.so\.* usr/lib/libxsl*\.so\.* \
1434889Ssjelinek		    usr/lib/libpango*\.so\.* usr/lib/libpng*\.so\.* \
1444889Ssjelinek		    usr/lib/liboil*\.so\.* usr/lib/libbonobo*\.so\.* \
1454889Ssjelinek		    usr/lib/libart*\.so\.* usr/lib/libcairo*\.so\.* \
1464889Ssjelinek		    usr/lib/libjpeg*\.so\.* \
1474889Ssjelinek		    usr/lib/libpolkit*\.so\.* \
1484889Ssjelinek			-print | egrep -v '\.so\.[0]$' > \
1494889Ssjelinek		       /tmp/gnome_lib.$$ 2>/dev/null
1504889Ssjelinek
1514889Ssjelinek		find usr/lib/nautilus usr/lib/pango usr/lib/iconv \
1524889Ssjelinek		    usr/lib/metacity-dialog usr/lib/window-manager-settings \
1534889Ssjelinek		    usr/lib/bonobo-2.0 usr/lib/bononbo usr/lib/gtk-2.0 \
1544889Ssjelinek		    usr/lib/GConf usr/lib/bonobo-activation-server \
1554889Ssjelinek		    usr/lib/python2.4 usr/lib/gstreamer-0.10 \
1564889Ssjelinek		    usr/lib/gconf-sanity-check-2 usr/lib/gconfd \
1574889Ssjelinek		    usr/lib/gnome-vfs-2.0 usr/lib/dbus-daemon \
1584889Ssjelinek		    usr/lib/gnome-vfs-daemon usr/lib/gnome-settings-daemon \
1594889Ssjelinek		    usr/lib/gnome_segv2 usr/lib/orbit-2.0 \
1604889Ssjelinek		    usr/lib/libmlib \
1614889Ssjelinek		    print > /tmp/gnome_libdir.$$ 2>/dev/null
1624889Ssjelinek
1634889Ssjelinek		if [ ! -f /tmp/gnome_lib.$$  -a ! -f gnome_libdir.$$ ] ; then
1644889Ssjelinek			echo "/tmp/gnome_lib.$$ file list not found."
1654889Ssjelinek			return
1664889Ssjelinek		fi
1674889Ssjelinek
1684889Ssjelinek		# /usr/sfw gnome stuff
1694889Ssjelinek		find usr/sfw/bin usr/sfw/include usr/sfw/share usr/sfw/src \
1704889Ssjelinek		    -print > /tmp/gnome_sfw.$$ 2>/dev/null
1714889Ssjelinek
1724889Ssjelinek		if [ ! -f /tmp/gnome_sfw.$$ ] ; then
1734889Ssjelinek			echo "/tmp/gnome_sfw.$$ file list not found."
1744889Ssjelinek			return
1754889Ssjelinek		fi
1764889Ssjelinek
1774889Ssjelinek		# gnome app binaries usr/bin
1784889Ssjelinek		find usr/bin/gnome* usr/bin/gui-install usr/bin/bonobo* \
1794889Ssjelinek		    usr/bin/gtk-* usr/bin/fax* usr/bin/gdk* usr/bin/gif2tiff \
1804889Ssjelinek		    usr/bin/install-lan \
1814889Ssjelinek		    usr/bin/metacity* usr/bin/gst-* usr/bin/gconftool-2 \
1824889Ssjelinek		    usr/bin/pango* usr/bin/desktop* usr/bin/djpeg \
1834889Ssjelinek		    usr/bin/notify-send usr/bin/oil-bugreport \
1844889Ssjelinek		    usr/bin/bmp2tiff usr/bin/thembus-theme-applier \
1854889Ssjelinek		    usr/bin/thumbnail usr/lib/update-* \
1864889Ssjelinek		    usr/bin/ras2tiff usr/bin/raw2tiff usr/bin/rdjpgcom \
1874889Ssjelinek		    usr/bin/thumbnail usr/bin/dbus* \
1884889Ssjelinek		    usr/bin/tiff* usr/bin/rgb2ycbcr \
1894889Ssjelinek		    usr/bin/fc-cache usr/bin/fc-list \
1904889Ssjelinek			-print > /tmp/gnome_bin.$$ 2>/dev/null
1914889Ssjelinek
1924889Ssjelinek		if [ ! -f /tmp/gnome_bin.$$ ] ; then
1934889Ssjelinek			echo "/tmp/gnome_bin.$$ file list not found."
1944889Ssjelinek			return
1954889Ssjelinek		fi
1964889Ssjelinek
1974889Ssjelinek		# Cat all the files together and create the gnome archive
1984889Ssjelinek		#
1994889Ssjelinek
2004889Ssjelinek		cat /tmp/gnome_libdir.$$ /tmp/gnome_lib.$$ \
2014889Ssjelinek		     /tmp/gnome_share.$$ /tmp/gnome_sfw.$$ /tmp/gnome_bin.$$ \
2024889Ssjelinek		    > /tmp/gnome.$$
2034889Ssjelinek
2044889Ssjelinek		if [ ! -f /tmp/gnome.$$ ] ; then
2054889Ssjelinek			echo "/tmp/gnome.$$ file not found."
2064889Ssjelinek			return
2074889Ssjelinek		fi
2084889Ssjelinek		# Save off this file in the miniroot for use later
2094889Ssjelinek		# when unpacking. Clean up old cruft if there.
2104889Ssjelinek		#
2114889Ssjelinek
2124889Ssjelinek		if [ -f .tmp_proto/gnome_saved ]; then
2134889Ssjelinek			rm -f .tmp_proto/gnome_saved
2144889Ssjelinek		fi
2154889Ssjelinek
2164889Ssjelinek		cp /tmp/gnome.$$ .tmp_proto/gnome_saved
2174889Ssjelinek
2184889Ssjelinek		# Create gnome archive
2194889Ssjelinek		#
2204889Ssjelinek
2214889Ssjelinek		cpio -ocmPuB < /tmp/gnome.$$ 2>/dev/null | bzip2 > \
2224889Ssjelinek		    "$CPIO_DIR/gnome.cpio.bz2"
2234889Ssjelinek
2244889Ssjelinek		# Remove files from miniroot that are in archive.
2254889Ssjelinek		# Create symlinks for files in archive
2264889Ssjelinek
2274889Ssjelinek		rm -rf `cat /tmp/gnome_share.$$`
2284889Ssjelinek
2294889Ssjelinek		for i in `cat /tmp/gnome_share.$$`
2304889Ssjelinek		do
2314889Ssjelinek			ln -s /tmp/root/$i $i 2>/dev/null
2324889Ssjelinek		done
2334889Ssjelinek
2344889Ssjelinek		rm -rf `cat /tmp/gnome_lib.$$`
2354889Ssjelinek		for i in `cat /tmp/gnome_lib.$$`
2364889Ssjelinek		do
2374889Ssjelinek			ln -s /tmp/root/$i $i 2>/dev/null
2384889Ssjelinek		done
2394889Ssjelinek
2404889Ssjelinek		rm -rf `cat /tmp/gnome_libdir.$$`
2414889Ssjelinek		for i in `cat /tmp/gnome_libdir.$$`
2424889Ssjelinek		do
2434889Ssjelinek			ln -s /tmp/root/$i $i 2>/dev/null
2444889Ssjelinek		done
2454889Ssjelinek
2464889Ssjelinek		rm -rf `cat /tmp/gnome_sfw.$$`
2474889Ssjelinek		for i in `cat /tmp/gnome_sfw.$$`
2484889Ssjelinek		do
2494889Ssjelinek			ln -s /tmp/root/$i $i 2>/dev/null
2504889Ssjelinek		done
2514889Ssjelinek
2524889Ssjelinek		rm -rf `cat /tmp/gnome_bin.$$`
2534889Ssjelinek		for i in `cat /tmp/gnome_bin.$$`
2544889Ssjelinek		do
2554889Ssjelinek			ln -s /tmp/root/$i $i 2>/dev/null
2564889Ssjelinek		done
2574889Ssjelinek		rm -f /tmp/gnome_share.$$
2584889Ssjelinek		rm -f /tmp/gnome_lib.$$
2594889Ssjelinek		rm -f /tmp/gnome_libdir.$$
2604889Ssjelinek		rm -f /tmp/gnome_bin.$$
2614889Ssjelinek	)
2624889Ssjelinek}
2634889Ssjelinek
2644889Ssjelinekarchive_JavaGUI()
2654889Ssjelinek{
2664889Ssjelinek	MEDIA="$1"
2674889Ssjelinek	MINIROOT="$2"
2684889Ssjelinek
2694889Ssjelinek	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
2704889Ssjelinek	RELEASE=`basename "$RELEASE"`
2714889Ssjelinek
2724889Ssjelinek	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
2734889Ssjelinek		CPIO_DIR="$MEDIA/$RELEASE/Tools/miniroot_extra"
2744889Ssjelinek		mkdir -p "$CPIO_DIR"
2754889Ssjelinek	else
2764889Ssjelinek		CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
2774889Ssjelinek	fi
2784889Ssjelinek
2794889Ssjelinek	# Archive the java wizard components that are only used in the
2804889Ssjelinek	# non developer express path.
2814889Ssjelinek	#
2824889Ssjelinek	(
2834889Ssjelinek		# path is usr/lib/install/data
2844889Ssjelinek		cd "$MINIROOT"
2854889Ssjelinek		find usr/lib/install/data/wizards \
2864889Ssjelinek		    -print > /tmp/java_ui.$$ 2>/dev/null
2874889Ssjelinek
2884889Ssjelinek		if [ ! -f /tmp/java_ui.$$ ] ; then
2894889Ssjelinek			echo "/tmp/java_ui.$$ file list not found."
2904889Ssjelinek			return
2914889Ssjelinek		fi
2924889Ssjelinek
2934889Ssjelinek		cpio -ocmPuB < /tmp/java_ui.$$ 2>/dev/null | bzip2 > \
2944889Ssjelinek		    "$CPIO_DIR/javaui.cpio.bz2"
2954889Ssjelinek
2964889Ssjelinek		rm -rf `cat /tmp/java_ui.$$`
2974889Ssjelinek		ln -s /tmp/root/usr/lib/install/data/wizards usr/lib/install/data/wizards 2>/dev/null
2984889Ssjelinek
2994889Ssjelinek		rm -f /tmp/java_ui.$$
3004889Ssjelinek
3014889Ssjelinek	)
3024889Ssjelinek}
3034889Ssjelinek
3044889Ssjelinekarchive_Misc()
3054889Ssjelinek{
3064889Ssjelinek	MEDIA="$1"
3074889Ssjelinek	MINIROOT="$2"
3084889Ssjelinek
3094889Ssjelinek	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
3104889Ssjelinek	RELEASE=`basename "$RELEASE"`
3114889Ssjelinek
3124889Ssjelinek	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
3134889Ssjelinek		CPIO_DIR="$MEDIA/$RELEASE/Tools/miniroot_extra"
3144889Ssjelinek		mkdir -p "$CPIO_DIR"
3154889Ssjelinek	else
3164889Ssjelinek		CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
3174889Ssjelinek	fi
3184889Ssjelinek
3194889Ssjelinek	# Archive misc stuff that is needed by non devex installer
3204889Ssjelinek	#
3214889Ssjelinek	(
3224889Ssjelinek		# usr/lib stuff
3234889Ssjelinek		cd "$MINIROOT"
3244889Ssjelinek		find usr/lib/lp -print > /tmp/lp.$$ 2>/dev/null
3254889Ssjelinek		if [ ! -f /tmp/lp.$$ ] ; then
3264889Ssjelinek			echo "/tmp/lp.$$ file list not found."
3274889Ssjelinek			return
3284889Ssjelinek		fi
3294889Ssjelinek
3304889Ssjelinek		cpio -ocmPuB < /tmp/lp.$$ 2>/dev/null | bzip2 > \
3314889Ssjelinek		    "$CPIO_DIR/lpmisc.cpio.bz2"
3324889Ssjelinek
3334889Ssjelinek		rm -rf `cat /tmp/lp.$$`
3344889Ssjelinek		ln -s /tmp/root/usr/lib/lp usr/lib/lp 2>/dev/null
3354889Ssjelinek
3364889Ssjelinek		rm -f /tmp/lp.$$
3374889Ssjelinek	)
3384889Ssjelinek
3394889Ssjelinek}
3404889Ssjelinek
3414889Ssjelinekarchive_Perl()
3424889Ssjelinek{
3434889Ssjelinek	MEDIA="$1"
3444889Ssjelinek	MINIROOT="$2"
3454889Ssjelinek
3464889Ssjelinek	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
3474889Ssjelinek	RELEASE=`basename "$RELEASE"`
3484889Ssjelinek
3494889Ssjelinek	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
3504889Ssjelinek		CPIO_DIR="$MEDIA/$RELEASE/Tools/miniroot_extra"
3514889Ssjelinek		mkdir -p "$CPIO_DIR"
3524889Ssjelinek	else
3534889Ssjelinek		CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
3544889Ssjelinek	fi
3554889Ssjelinek
3564889Ssjelinek	# Archive perl, it is only needed by gnome gui.
3574889Ssjelinek	#
3584889Ssjelinek	(
3594889Ssjelinek		# in usr
3604889Ssjelinek		cd "$MINIROOT"
3614889Ssjelinek		find usr/perl5 -print > /tmp/perl.$$ 2>/dev/null
3624889Ssjelinek
3634889Ssjelinek		if [ ! -f /tmp/perl.$$ ] ; then
3644889Ssjelinek			echo "/tmp/perl.$$ file list not found."
3654889Ssjelinek			return
3664889Ssjelinek		fi
3674889Ssjelinek		cpio -ocmPuB < /tmp/perl.$$ 2>/dev/null | bzip2 > \
3684889Ssjelinek		    "$CPIO_DIR/perl.cpio.bz2"
3694889Ssjelinek
3704889Ssjelinek		rm -rf `cat /tmp/perl.$$` 2>/dev/null
371*5571Ssjelinek		ln -s /tmp/root/usr/perl5 usr/perl5 2>/dev/null
3724889Ssjelinek
3734889Ssjelinek		rm -f /tmp/perl.$$
3744889Ssjelinek	)
3754889Ssjelinek}
3761777Ssetjearchive_X()
3770Sstevel@tonic-gate{
3781777Ssetje	MEDIA="$1"
3791777Ssetje	MINIROOT="$2"
3800Sstevel@tonic-gate
3811777Ssetje	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
3821777Ssetje	RELEASE=`basename "$RELEASE"`
3830Sstevel@tonic-gate
3841777Ssetje	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
3851777Ssetje		CPIO_DIR="$MEDIA/$RELEASE/Tools/miniroot_extra"
3861777Ssetje		mkdir -p "$CPIO_DIR"
3871777Ssetje	else
3881777Ssetje		CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
3891777Ssetje	fi
3900Sstevel@tonic-gate
3910Sstevel@tonic-gate	# create the graphics and non-graphics X archive
3920Sstevel@tonic-gate	#
3932851Sjongkis	(
3944889Ssjelinek		cd "$MINIROOT"
3954889Ssjelinek		find usr/openwin usr/dt usr/X11 -print 2> /dev/null |\
3962851Sjongkis		    cpio -ocmPuB 2> /dev/null | bzip2 > "$CPIO_DIR/X.cpio.bz2"
3970Sstevel@tonic-gate
3984889Ssjelinek		find usr/openwin/bin/mkfontdir \
3994889Ssjelinek		     usr/openwin/lib/installalias \
4004889Ssjelinek		     usr/openwin/server/lib/libfont.so.1 \
4014889Ssjelinek		     usr/openwin/server/lib/libtypesclr.so.0 \
4022851Sjongkis			 -print | cpio -ocmPuB 2> /dev/null | bzip2 > \
4032851Sjongkis			 "$CPIO_DIR/X_small.cpio.bz2"
4040Sstevel@tonic-gate
4054889Ssjelinek		rm -rf usr/dt usr/openwin usr/X11
4064889Ssjelinek		ln -s /tmp/root/usr/dt usr/dt
4074889Ssjelinek		ln -s /tmp/root/usr/openwin usr/openwin
4084889Ssjelinek		ln -s /tmp/root/usr/X11 usr/X11
4092851Sjongkis	)
4101777Ssetje}
4111777Ssetje
4121777Ssetjepackmedia()
4131777Ssetje{
4141777Ssetje	MEDIA="$1"
4151777Ssetje	MINIROOT="$2"
4161777Ssetje
4171777Ssetje	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
4181777Ssetje	RELEASE=`basename "$RELEASE"`
4191777Ssetje
4201777Ssetje	mkdir -p "$MEDIA/$RELEASE/Tools/Boot"
4215084Sjohnlev	mkdir -p "$MEDIA/boot/amd64"
4223446Smrj	mkdir -p "$MEDIA/boot/platform/i86pc/kernel"
4235084Sjohnlev	mkdir -p "$MEDIA/boot/platform/i86pc/kernel/amd64"
4245084Sjohnlev	mkdir -p "$MEDIA/boot/platform/i86xpv/kernel"
4255084Sjohnlev	mkdir -p "$MEDIA/boot/platform/i86xpv/kernel/amd64"
4261777Ssetje
4271777Ssetje	# archive package databases to conserve memory
4281777Ssetje	#
4292851Sjongkis	(
4302851Sjongkis		cd "$MINIROOT"
4312851Sjongkis		find tmp/root/var/sadm/install tmp/root/var/sadm/pkg -print | \
4322851Sjongkis		    cpio -ocmPuB 2> /dev/null | bzip2 > \
4332851Sjongkis		    "$MEDIA/$RELEASE/Tools/Boot/pkg_db.cpio.bz2"
4342851Sjongkis	)
4351777Ssetje
4361777Ssetje	rm -rf "$MINIROOT/tmp/root/var/sadm/install"
4371777Ssetje	rm -rf "$MINIROOT/tmp/root/var/sadm/pkg"
4381777Ssetje
4392595Ssetje	archive_X "$MEDIA" "$MINIROOT"
4402595Ssetje
4414889Ssjelinek	# Take out the gnome and java parts of the installer from
4424889Ssjelinek	# the miniroot. These are not required to boot the system
4434889Ssjelinek	# and start the installers.
4444889Ssjelinek
4454889Ssjelinek	archive_Gnome "$MEDIA" "$MINIROOT"
4464889Ssjelinek	archive_JavaGUI "$MEDIA" "$MINIROOT"
4474889Ssjelinek	archive_Perl "$MEDIA" "$MINIROOT"
4484889Ssjelinek	archive_Misc "$MEDIA" "$MINIROOT"
4494889Ssjelinek
4501777Ssetje	cp "$MINIROOT/platform/i86pc/multiboot" "$MEDIA/boot"
4513446Smrj	cp "$MINIROOT/platform/i86pc/kernel/unix" \
4523446Smrj	    "$MEDIA/boot/platform/i86pc/kernel/unix"
4535084Sjohnlev	cp "$MINIROOT/platform/i86pc/kernel/amd64/unix" \
4545084Sjohnlev	    "$MEDIA/boot/platform/i86pc/kernel/amd64/unix"
4555084Sjohnlev	cp "$MINIROOT/platform/i86xpv/kernel/unix" \
4565084Sjohnlev	    "$MEDIA/boot/platform/i86xpv/kernel/unix"
4575084Sjohnlev	cp "$MINIROOT/platform/i86xpv/kernel/amd64/unix" \
4585084Sjohnlev	    "$MEDIA/boot/platform/i86xpv/kernel/amd64/unix"
4590Sstevel@tonic-gate
4601821Ssetje	# copy the install menu to menu.lst so we have a menu
4611821Ssetje	# on the install media
4621821Ssetje	#
4631821Ssetje	if [ -f "${MINIROOT}/boot/grub/install_menu" ] ; then
4641821Ssetje		cp ${MINIROOT}/boot/grub/install_menu \
4651821Ssetje		    ${MEDIA}/boot/grub/menu.lst
4661821Ssetje	fi
4671821Ssetje
4682851Sjongkis	(
4692851Sjongkis		cd "$MEDIA/$RELEASE/Tools/Boot"
4702851Sjongkis		ln -sf ../../../boot/x86.miniroot
4715084Sjohnlev		ln -sf ../../../boot/platform/i86pc/kernel/unix
4725084Sjohnlev		ln -sf ../../../boot/platform/i86pc/kernel/amd64/unix
4735084Sjohnlev		ln -sf ../../../boot/platform/i86xpv/kernel/unix
4745084Sjohnlev		ln -sf ../../../boot/platform/i86xpv/kernel/amd64/unix
4752851Sjongkis		ln -sf ../../../boot/multiboot
4762851Sjongkis		ln -sf ../../../boot/grub/pxegrub
4772851Sjongkis	)
4781777Ssetje}
4790Sstevel@tonic-gate
4801777Ssetjeunarchive_X()
4811777Ssetje{
4821777Ssetje	MEDIA="$1"
4831777Ssetje	UNPACKED_ROOT="$2"
4841777Ssetje
4851777Ssetje	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
4861777Ssetje	RELEASE=`basename "$RELEASE"`
4871777Ssetje
4881777Ssetje	if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
4891777Ssetje		CPIO_DIR="$MEDIA/$RELEASE/Tools/miniroot_extra"
4901777Ssetje	else
4911777Ssetje		CPIO_DIR="$MEDIA/$RELEASE/Tools/Boot"
4920Sstevel@tonic-gate	fi
4931777Ssetje
4941777Ssetje	# unpack X
4951777Ssetje	#
4962851Sjongkis	(
4974889Ssjelinek		cd "$UNPACKED_ROOT"
4984889Ssjelinek		rm -rf usr/dt usr/openwin usr/X11
4992851Sjongkis		bzcat "$CPIO_DIR/X.cpio.bz2" | cpio -icdmu 2> /dev/null
5002851Sjongkis	)
5010Sstevel@tonic-gate}
5020Sstevel@tonic-gate
5030Sstevel@tonic-gateunpackmedia()
5041777Ssetje{
5051777Ssetje	MEDIA="$1"
5061777Ssetje	UNPACKED_ROOT="$2"
5070Sstevel@tonic-gate
5081777Ssetje	RELEASE=`/bin/ls -d "$MEDIA/Solaris_"*`
5091777Ssetje	RELEASE=`basename "$RELEASE"`
5101777Ssetje
5111777Ssetje	unarchive_X "$MEDIA" "$UNPACKED_ROOT"
5120Sstevel@tonic-gate
5130Sstevel@tonic-gate	# unpack package databases
5140Sstevel@tonic-gate	#
5152851Sjongkis	(
5162851Sjongkis		cd "$UNPACKED_ROOT"
5172851Sjongkis		bzcat "$MEDIA/$RELEASE/Tools/Boot/pkg_db.cpio.bz2" |
5182851Sjongkis		    cpio -icdmu 2> /dev/null
5194889Ssjelinek
5204889Ssjelinek		# unpack gnome, perl, java and misc
5214889Ssjelinek		# Remove symlinks left from unpacking x86.miniroot so that
5224889Ssjelinek		# unpacking subsequent archives will populate appropriately.
5234889Ssjelinek		#
5244889Ssjelinek		rm -rf usr/perl5
5254889Ssjelinek		rm -rf usr/lib/install/data/wizards
5264889Ssjelinek		rm -rf usr/lib/lp
5274889Ssjelinek
5284889Ssjelinek		# Gnome list saved off from packmedia
5294889Ssjelinek		for i in `cat .tmp_proto/gnome_saved`
5304889Ssjelinek		do
5314889Ssjelinek			rm -rf $i
5324889Ssjelinek		done
5334889Ssjelinek
5344889Ssjelinek		bzcat "$MEDIA/$RELEASE/Tools/Boot/gnome.cpio.bz2" |
5354889Ssjelinek		    cpio -icdmu 2>/dev/null
5364889Ssjelinek		bzcat "$MEDIA/$RELEASE/Tools/Boot/javaui.cpio.bz2" |
5374889Ssjelinek		    cpio -icdmu 2>/dev/null
5384889Ssjelinek		bzcat "$MEDIA/$RELEASE/Tools/Boot/lpmisc.cpio.bz2" |
5394889Ssjelinek		    cpio -icdmu 2>/dev/null
5404889Ssjelinek		bzcat "$MEDIA/$RELEASE/Tools/Boot/perl.cpio.bz2" |
5414889Ssjelinek		    cpio -icdmu 2>/dev/null
5422851Sjongkis	)
5430Sstevel@tonic-gate}
5440Sstevel@tonic-gate
5450Sstevel@tonic-gatedo_unpack()
5460Sstevel@tonic-gate{
5471777Ssetje	rm -rf "$UNPACKED_ROOT"
5481777Ssetje	mkdir -p "$UNPACKED_ROOT"
5492851Sjongkis	(
5502851Sjongkis		cd $MNT
5512851Sjongkis		find . -print | cpio -pdum "$UNPACKED_ROOT" 2> /dev/null
5522851Sjongkis	)
5530Sstevel@tonic-gate	umount $MNT
5540Sstevel@tonic-gate}
5550Sstevel@tonic-gate
5560Sstevel@tonic-gateunpack()
5570Sstevel@tonic-gate{
5580Sstevel@tonic-gate
5591777Ssetje	if [ ! -f "$MR" ] ; then
5600Sstevel@tonic-gate		usage
5610Sstevel@tonic-gate		exit 1
5620Sstevel@tonic-gate	fi
5630Sstevel@tonic-gate
5641777Ssetje	gzcat "$MR" > $TMR
5650Sstevel@tonic-gate
5662334Ssetje	LOFIDEV=`/usr/sbin/lofiadm -a $TMR`
5670Sstevel@tonic-gate	if [ $? != 0 ] ; then
5680Sstevel@tonic-gate		echo lofi plumb failed
5690Sstevel@tonic-gate		exit 2
5700Sstevel@tonic-gate	fi
5710Sstevel@tonic-gate
5721777Ssetje	mkdir -p $MNT
5730Sstevel@tonic-gate
5742334Ssetje	FSTYP=`fstyp $LOFIDEV`
5750Sstevel@tonic-gate
5761777Ssetje	if [ "$FSTYP" = ufs ] ; then
5772334Ssetje		/usr/sbin/mount -o ro,nologging $LOFIDEV $MNT
5780Sstevel@tonic-gate		do_unpack
5791777Ssetje	elif [ "$FSTYP" = hsfs ] ; then
5802334Ssetje		/usr/sbin/mount -F hsfs -o ro $LOFIDEV $MNT
5810Sstevel@tonic-gate		do_unpack
5820Sstevel@tonic-gate	else
5830Sstevel@tonic-gate		printf "invalid root archive\n"
5840Sstevel@tonic-gate	fi
5850Sstevel@tonic-gate
5860Sstevel@tonic-gate	rmdir $MNT
5872851Sjongkis	lofiadm -d $TMR ; LOFIDEV=
5880Sstevel@tonic-gate	rm $TMR
5890Sstevel@tonic-gate}
5900Sstevel@tonic-gate
5910Sstevel@tonic-gatepack()
5920Sstevel@tonic-gate{
5931777Ssetje	if [ ! -d "$UNPACKED_ROOT" -o -z "$MR" ] ; then
5940Sstevel@tonic-gate		usage
5950Sstevel@tonic-gate		exit 1
5960Sstevel@tonic-gate	fi
5970Sstevel@tonic-gate
5982511Sjongkis	# Estimate image size and add %10 overhead for ufs stuff.
5992511Sjongkis	# Note, we can't use du here in case $UNPACKED_ROOT is on a filesystem,
6002511Sjongkis	# e.g. zfs, in which the disk usage is less than the sum of the file
6012511Sjongkis	# sizes.  The nawk code
6022511Sjongkis	#
6032511Sjongkis	#	{t += ($7 % 1024) ? (int($7 / 1024) + 1) * 1024 : $7}
6042511Sjongkis	#
6052511Sjongkis	# below rounds up the size of a file/directory, in bytes, to the
6062511Sjongkis	# next multiple of 1024.  This mimics the behavior of ufs especially
6072511Sjongkis	# with directories.  This results in a total size that's slightly
6082511Sjongkis	# bigger than if du was called on a ufs directory.
6092511Sjongkis	size=$(find "$UNPACKED_ROOT" -ls | nawk '
6102511Sjongkis	    {t += ($7 % 1024) ? (int($7 / 1024) + 1) * 1024 : $7}
6112511Sjongkis	    END {print int(t * 1.10 / 1024)}')
6120Sstevel@tonic-gate
6132334Ssetje	/usr/sbin/mkfile ${size}k "$TMR"
6142334Ssetje
6152334Ssetje	LOFIDEV=`/usr/sbin/lofiadm -a "$TMR"`
6160Sstevel@tonic-gate	if [ $? != 0 ] ; then
6170Sstevel@tonic-gate		echo lofi plumb failed
6180Sstevel@tonic-gate		exit 2
6190Sstevel@tonic-gate	fi
6200Sstevel@tonic-gate
6212334Ssetje	RLOFIDEV=`echo $LOFIDEV | sed s/lofi/rlofi/`
6222334Ssetje	newfs $RLOFIDEV < /dev/null 2> /dev/null
6231777Ssetje	mkdir -p $MNT
6242334Ssetje	mount -o nologging $LOFIDEV $MNT
6251777Ssetje	rmdir $MNT/lost+found
6262851Sjongkis	(
6272851Sjongkis		cd "$UNPACKED_ROOT"
6282851Sjongkis		find . -print | cpio -pdum $MNT 2> /dev/null
6292851Sjongkis	)
6300Sstevel@tonic-gate	lockfs -f $MNT
6310Sstevel@tonic-gate	umount $MNT
6320Sstevel@tonic-gate	rmdir $MNT
6332334Ssetje	lofiadm -d $LOFIDEV
6342851Sjongkis	LOFIDEV=
6350Sstevel@tonic-gate
6362334Ssetje	rm -f "$TMR.gz"
6372334Ssetje	gzip -f "$TMR"
6382334Ssetje	mv "$TMR.gz" "$MR"
6391777Ssetje	chmod a+r "$MR"
6400Sstevel@tonic-gate}
6410Sstevel@tonic-gate
6420Sstevel@tonic-gate# main
6430Sstevel@tonic-gate#
6440Sstevel@tonic-gate
6452334SsetjeEXTRA_SPACE=0
6462851SjongkisSTRIP_AMD64=
6472334Ssetje
6482334Ssetjewhile getopts s:6 opt ; do
6492334Ssetje	case $opt in
6502334Ssetje	s)	EXTRA_SPACE="$OPTARG"
6512334Ssetje		;;
6522334Ssetje	6)	STRIP_AMD64=false
6532334Ssetje		;;
6542334Ssetje	*)	usage
6552334Ssetje		exit 1
6562334Ssetje		;;
6572334Ssetje	esac
6582334Ssetjedone
6592334Ssetjeshift `expr $OPTIND - 1`
6602334Ssetje
6610Sstevel@tonic-gateif [ $# != 3 ] ; then
6620Sstevel@tonic-gate	usage
6630Sstevel@tonic-gate	exit 1
6640Sstevel@tonic-gatefi
6650Sstevel@tonic-gate
6661777SsetjeUNPACKED_ROOT="$3"
6671777SsetjeBASE="`pwd`"
6680Sstevel@tonic-gateMNT=/tmp/mnt$$
6692334SsetjeTMR=/tmp/mr$$
6702334SsetjeLOFIDEV=
6711777SsetjeMR="$2"
6720Sstevel@tonic-gate
6730Sstevel@tonic-gateif [ "`dirname $MR`" = . ] ; then
6741777Ssetje	MR="$BASE/$MR"
6750Sstevel@tonic-gatefi
6760Sstevel@tonic-gateif [ "`dirname $UNPACKED_ROOT`" = . ] ; then
6771777Ssetje	UNPACKED_ROOT="$BASE/$UNPACKED_ROOT"
6780Sstevel@tonic-gatefi
6790Sstevel@tonic-gate
6802334Ssetjetrap cleanup EXIT
6812334Ssetje
6820Sstevel@tonic-gatecase $1 in
6830Sstevel@tonic-gate	packmedia)
6841777Ssetje		MEDIA="$MR"
6855084Sjohnlev		MR="$MEDIA/boot/x86.miniroot"
6861777Ssetje
6871777Ssetje		if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
6881777Ssetje			archive_X "$MEDIA" "$UNPACKED_ROOT"
6891777Ssetje		else
6901777Ssetje			packmedia "$MEDIA" "$UNPACKED_ROOT"
6915084Sjohnlev
6925084Sjohnlev			# create the 64-bit miniroot
6935084Sjohnlev			# if the -6 option was passed, don't strip
6945084Sjohnlev			# the 64-bit modules from the 32-bit miniroot
6955084Sjohnlev			MR="$MEDIA/boot/amd64/x86.miniroot"
6961777Ssetje			pack
6975084Sjohnlev
6985084Sjohnlev			if [ "$STRIP_AMD64" = false ] ; then
6995084Sjohnlev				ln $MR $MEDIA/boot/x86.miniroot
7005084Sjohnlev			else
7015084Sjohnlev				# create the 32-bit miniroot
7025084Sjohnlev				MR="$MEDIA/boot/x86.miniroot"
7035084Sjohnlev				find "$UNPACKED_ROOT" -name amd64 \
7045084Sjohnlev				    -type directory | xargs rm -rf
7055084Sjohnlev				pack
7065084Sjohnlev			fi
7071777Ssetje		fi ;;
7080Sstevel@tonic-gate	unpackmedia)
7091777Ssetje		MEDIA="$MR"
7101777Ssetje		MR="$MR/boot/x86.miniroot"
7111777Ssetje
7121777Ssetje		if [ -d "$UNPACKED_ROOT/kernel/drv/sparcv9" ] ; then
7131777Ssetje			unarchive_X "$MEDIA" "$UNPACKED_ROOT"
7141777Ssetje		else
7151777Ssetje			unpack
7161777Ssetje			unpackmedia "$MEDIA" "$UNPACKED_ROOT"
7171777Ssetje		fi ;;
7180Sstevel@tonic-gate	pack)	pack ;;
7190Sstevel@tonic-gate	unpack)	unpack ;;
7200Sstevel@tonic-gate	*)	usage ;;
7210Sstevel@tonic-gateesac
722