#!/bin/sh

##### WARNING #######
# Changed by Marc Guenther <yoda@leo.org> to use gzip instead of compress (saves about 6Mbytes)
# original skript is unbundle.sh
#####################

INSTALLPATH="."
CURRENTDIR=`pwd`

LISTPKGS="101242-10.cpio.bin.gz 101923-08.cpio.bin.gz 103073-01.cpio.bin.gz 103246-03.cpio.bin.gz SUNWOosUc.cpio.bin.gz SUNWOosUd.cpio.bin.gz SUNWOosUe.cpio.bin.gz SUNWOosUh.cpio.bin.gz SUNWOosUp.cpio.bin.gz SUNWOosUs.cpio.bin.gz SUNWOosUt.cpio.bin.gz SUNWOosUv.cpio.bin.gz SUNWOosUw.cpio.bin.gz SUNWOosUx.cpio.bin.gz SUNWOosUy.cpio.bin.gz SUNWxwinc.cpio.bin.gz SUNWxwmod.cpio.bin.gz SUNWxwplt.cpio.bin.gz SUNWxwslb.cpio.bin.gz"

CORELISTPKGS="SUNWOosUc.cpio.bin.gz SUNWOosUd.cpio.bin.gz SUNWOosUh.cpio.bin.gz SUNWOosUs.cpio.bin.gz SUNWOosUv.cpio.bin.gz SUNWOosUw.cpio.bin.gz"

TEST="OK"

USAGE="$0 [-h] [-l path]"

while getopts l:h opt
do
	case "$opt" in
		l) INSTALLPATH="$OPTARG";;
		s) SBUILDNUMBER="$OPTARG";;
		h) cat << EOF_HELP
Usage: $USAGE

-h		- this help message
-l path		- specify the path you wish to install

EOF_HELP
		exit 0;;
		\?) echo "Usage: $USAGE" 1>&2
		exit 1;;
	esac
done

shift `expr $OPTIND - 1`

for LISTCORE in $CORELISTPKGS
do
	if [ ! -f $LISTCORE ]
	then
		echo "Your are missing the following core package: $LISTCORE"
		TEST="MISSING"
	fi
done

if [ "$TEST" = "MISSING" ]
then
	echo ""
	echo "Please download them and then rerun this script"
	exit 1
fi

for LIST in $LISTPKGS
do
	if [ -f $CURRENTDIR/$LIST ]
	then
		NAMEIS=`echo $LIST | sed -e 's/\.cpio\.bin\.gz//'`
		if [ ! -d $INSTALLPATH/solaris_openstep/$NAMEIS ] &&
		   [ ! -d $INSTALLPATH/solaris_openstep/openwin-3.4_packages/$NAMEIS ] &&
		   [ ! -d $INSTALLPATH/solaris_openstep/openwin_patches/$NAMEIS ] &&
		   [ ! -d $INSTALLPATH/solaris_openstep/solaris_patches/$NAMEIS ]
		then
			echo "Unbundling $LIST from $CURRENTDIR to $CURRENTDIR/$INSTALLPATH"
			(cd $INSTALLPATH; gzcat $CURRENTDIR/$LIST | cpio -icdm)
		else
		   echo "$NAMEIS is already unbundled"
		fi	
	fi
done
