#!/bin/sh
SRC=`pwd`
WIZ=$1
BOOTIMAGE=$2

if [ `/usr/ucb/whoami` != "root" ]; then
        echo "You Must be root."
        exit 1
fi

case $WIZ in
	cd0) ;;
	disk0) ;;
	*)  	echo 1st parameter must be cd0 or disk0;
		echo "Usage: install_wizards [wizard to use] [Solaris Boot Image]";
	    	exit 1
esac	
	
if [ ! "$BOOTIMAGE" -o "$1" = '-h' -o "$BOOTIMAGE" = '-help' ]; then
	echo "Usage: install_wizards [wizard to use] [Solaris Boot Image]"
        exit 1
fi

echo "	Installing Wizards and the needed components"

if [ $WIZ = disk0 ] ;then
   if [ ! -d  $BOOTIMAGE/webstart/wizards/app ];then

	echo "			Creating $BOOTIMAGE/webstart/wizards"
	mkdir -p $BOOTIMAGE/webstart/wizards/app
	mkdir -p $BOOTIMAGE/webstart/wizards/bin
   else 
	echo "			Removing $BOOTIMAGE/webstart/wizards"
	rm -r $BOOTIMAGE/webstart/wizards/*
	mkdir -p $BOOTIMAGE/webstart/wizards/app
	mkdir -p $BOOTIMAGE/webstart/wizards/bin
   fi
   cd $SRC/wizards/apps/proto
#   cp reboot.class $BOOTIMAGE/webstart/wizards/app/
#   cp insertcd.class $BOOTIMAGE/webstart/wizards/app/
   cp insertcd0.class $BOOTIMAGE/webstart/wizards/app/
   cp solaris.class $BOOTIMAGE/webstart/wizards/app/
   cp install.class $BOOTIMAGE/webstart/wizards/app/
   cp installfail.class $BOOTIMAGE/webstart/wizards/app/
   cp progress.class $BOOTIMAGE/webstart/wizards/app/
   cp sysid.class $BOOTIMAGE/webstart/wizards/app/
   cp launcher.class $BOOTIMAGE/webstart/wizards/app/
   cp postinstall.class $BOOTIMAGE/webstart/wizards/app/
#   cp insertnetscd.class $BOOTIMAGE/webstart/wizards/app/
   chmod 755 $BOOTIMAGE/webstart/wizards/app/*.class

   # copy over scripts for launcher and solaris wizard
   cd $SRC/wizards/apps/wizards/com/sun/launcher/bin
   cp getVold $BOOTIMAGE/webstart/wizards/bin
   cp runwebstart $BOOTIMAGE/webstart/wizards/bin
   cp s96webstart $BOOTIMAGE/webstart/wizards/bin
   cp setupRoot $BOOTIMAGE/webstart/wizards/bin
   cd $SRC/wizards/apps/install/com/sun/solarisinstall/bin
   cp writeLocaleFile $BOOTIMAGE/webstart/wizards/bin
   cp parsePackagesToBeAdded $BOOTIMAGE/webstart/wizards/bin
   cd $SRC/wizards/apps/install/com/sun/solarisinstall/solaris2/bin
   cp installer $BOOTIMAGE/webstart/wizards/bin
   chmod 755 $BOOTIMAGE/webstart/wizards/bin/*


else
   cd $SRC/wizards/$WIZ
   for i in `ls W*`
   do
         cp $i $BOOTIMAGE/webstart/wizards/$i
         chmod 755 $BOOTIMAGE/webstart/wizards/$i
   done
fi
