#!/bin/ksh -x
# Usage:	install_cd0 <boot image absolute path>
# parameters:	$1 = boot image directory (Ex: /export2/s26_sparc)

BOOTIMAGE=$1

SRC=`pwd`
FILES=$SRC/files
if [ -f $BOOTIMAGE/etc/bootrc ];then
	ARCH=i386
else
	ARCH=sparc
fi

if [ $ARCH = i386 ];then
        ZIP=/home/mattw/info-zip/zip22_x86/zip
else
        ZIP=/opt/info-zip/zip22/zip
fi

if [ `/usr/ucb/whoami` != "root" ]; then 
	echo "You Must be root."
	exit 1
fi
if [ ! "$BOOTIMAGE" -o "$1" = '-h' -o "$BOOTIMAGE" = '-help' ]; then
	echo "Usage: install_cd0 [Solaris boot image absolute path]."
	exit 1
fi

echo "		Installing files"

#mkdir -p $MINI_CD0/bin

if [ -d $BOOTIMAGE/platform/i86pc ];then
	ARCH=i386
else 
	ARCH=sparc
fi

#Copy the new cd0 mini-root files to the current mini-root
cp  $FILES/rcS.sh		$BOOTIMAGE/sbin/rcS
chmod 744 $BOOTIMAGE/sbin/rcS
cp  $FILES/startup		$BOOTIMAGE/sbin/startup
chmod 555 $BOOTIMAGE/sbin/startup
cp  $FILES/getLocale	$BOOTIMAGE/sbin/getLocale
chmod 555 $BOOTIMAGE/sbin/getLocale
cp $FILES/setupRoot	$BOOTIMAGE/sbin/setupRoot
chmod 555 $BOOTIMAGE/sbin/setupRoot
cp $FILES/cd0_install.sh 	$BOOTIMAGE/sbin/cd0_install
chmod 755 $BOOTIMAGE/sbin/cd0_install
cp $FILES/bin/getpart.$ARCH	$BOOTIMAGE/usr/sbin/install.d/getpart
chmod 555 $BOOTIMAGE/usr/sbin/install.d/getpart
cp $FILES/bin/find_device.$ARCH $BOOTIMAGE/usr/sbin/install.d/find_device
chmod 555 $BOOTIMAGE/usr/sbin/install.d/find_device
cp $FILES/bin/fastfs.$ARCH $BOOTIMAGE/usr/sbin/install.d/fastfs
chmod 755 $BOOTIMAGE/usr/sbin/install.d/fastfs
if [ ! -f $BOOTIMAGE/etc/dumpadm.conf ];then
  cd $BOOTIMAGE/etc
  ln -s ../tmp/root/etc/dumpadm.conf dumpadm.conf
  cd $SRC
fi

if [ $ARCH = "i386" ];then
	cp $FILES/bin/mdboot  $BOOTIMAGE/usr/sbin/install.d/mdboot
	chmod 555 $BOOTIMAGE/usr/sbin/install.d/mdboot
	cp $FILES/bin/mkfs.$ARCH $BOOTIMAGE/usr/lib/fs/pcfs/mkfs
	chmod 555 $BOOTIMAGE/usr/lib/fs/pcfs/mkfs
	cp $FILES/bin/strap.com $BOOTIMAGE/usr/sbin/install.d/strap.com
	chmod 555 $BOOTIMAGE/usr/sbin/install.d/strap.com
        cp $FILES/bootrc.cd0 $BOOTIMAGE/etc/bootrc
	chmod 755 $BOOTIMAGE/etc/bootrc
	cd $FILES/x86_boot
	mkdir $BOOTIMAGE/webstart/boot/.boot
	find . -name SCCS -prune -o -print | cpio -dump $BOOTIMAGE/webstart/boot/.boot
fi
