#! /usr/bin/ksh
#
# Solaris Electronic Software Distribution
# unwrap script
#


# Enter the names of the file segments here.
SEGMENTS="sol-9-beta-sparc_aa.zip sol-9-beta-sparc_ab.zip sol-9-beta-sparc_ac.zip sol-9-beta-sparc_ad.zip sol-9-beta-sparc_ae.zip sol-9-beta-sparc_af.zip"
UNZIPPED_SEGMENTS="sol-9-beta-sparc_aa sol-9-beta-sparc_ab sol-9-beta-sparc_ac sol-9-beta-sparc_ad sol-9-beta-sparc_ae sol-9-beta-sparc_af"

# Enter the free disk space here (in Kilobytes) that is needed to
# unpack the archive. This should be
# (2 x the size of the zip file) + the size of the unzipped CD image.
spaceReq=2749457




PATH=/usr/bin

echo ""
echo "Checking for complete distribution ...\c"
for i in $SEGMENTS; do
	if [[ ! -f $i ]] then
		echo " FAIL"
		echo "Missing file $i"
		exit 1
	fi
done

echo " done."

echo ""
echo "Checking available disk space ...\c"

spaceAvail=$(df -b . | sed -n '2p' | sed -e 's/^.*[ 	][ 	]*//')

if [[ $spaceAvail -lt $spaceReq ]] then
	echo " FAIL."
	echo "Not enough space (need $spaceReq KB free space)"
	exit 1
fi

echo " done."

echo ""
echo "Unwrapping Archive ...\c"
for i in $SEGMENTS; do
	/usr/bin/unzip $i
	zipstat=$?
	if [[ $zipstat != 0 ]] then
		echo " FAILED on unzip"
		exit 1
	fi
done
	
cat $UNZIPPED_SEGMENTS > sol-9-beta-sparc.cpio
if [[ $? != 0 ]] then
	echo " FAILED on concatenation of segments"
	exit 1
fi

echo " done."

rm $UNZIPPED_SEGMENTS

exit 0
