#!/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 License Software installed? "
read SC_DIR_NAME

if [ ! -d $SC_DIR_NAME/SunTech_License ] 
then
	echo
	echo "License Software not installed in $SC_DIR_NAME (subdir SunTech_License not found)."
	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

if [ -d /etc/opt/licenses ] 
then
	cd /etc/opt/licenses
	for i in `cat $prog_dir/components_list`
	do
		if [ -f $i ]
		then
			rm -f $i  > /dev/null
			ln -s $SC_DIR_NAME/$i .
		fi
	done
fi


echo
echo "Patch installation done."
echo "Please take down the License Manager and then restart it."
echo
exit 0
