#!/bin/sh

user=`id | sed -e 's/[^(]*(\([^)]*\).*/\1/'`

if [ "$user" != "root" ]
then
	echo
	echo "You must be superuser to run installpatch."
	echo
	exit 1
fi

prog_dir=`dirname $0`
first_char=`echo $prog_dir |  sed -e 's/^\(.\).*$/\1/'`

if [ "$first_char" != "/" ]
then
	prog_dir=`pwd`/$prog_dir
fi

if [ ! -f $prog_dir/patch_tarfile -o ! -f $prog_dir/components_list ]
then
	echo
	echo "$prog_dir does not have all the information to install the patch"
	echo
	exit 1
fi
echo
echo -n "Where is the SC3.0.1 installed? "
read SC_DIR_NAME

if [ ! -d $SC_DIR_NAME/SC3.0.1 ] 
then
	echo
	echo "SC3.0.1 not installed in $SC_DIR_NAME"
	echo
	exit 1
fi

cd $SC_DIR_NAME

echo
echo "Extracting the patch in $SC_DIR_NAME... will take few minutes."
echo

for i in `cat $prog_dir/components_list`
do
	if [ -f $i ]
	then
		rm -f $i  > /dev/null
	fi
done

tar xf $prog_dir/patch_tarfile
echo
echo "Patch installation done."
echo
exit 0
