#!/bin/sh
echo ''
echo 'PatchDiag Tool Setup script'
echo ''

if [ -f ./patchdiag ]
then
	echo ''
	echo 'I found another patchdiag script in this directory'
	echo 'Please remove or rename it and start the script again'
	exit
fi
echo ''
echo 'Please enter the directory location of the cross reference file (patchdiag.xref):'; 
echo 'Ex: if the patchdiag.xref file is in the directory /patchdiag/etc, then'
echo '    type "/patchdiag/etc".'
read xref 
while [ ! -d $xref ] || [ ! -r $xref ]
do
	echo ' '
	echo "I'm sorry. The location that you specified"
	echo "($xref) does not exist.";
	echo ' '
	echo 'Please enter the location of the cross reference file {patchdiag.xref}:'
	read xref
done

while [ ! -r $xref/patchdiag.xref ]
do
	echo ' '
	echo "I'm sorry. I could not find a patchdiag.xref file in the"
	echo "location that you specified:"
	echo "($xref)"
	echo ' '
	echo 'Please enter the location of the cross reference file.'
	read xref
done
#
echo ''
echo 'Creating the patchdiag script now...'
echo ''
echo '#!/bin/sh' > patchdiag
echo "XREF=\${XREF:=$xref}" >> patchdiag
BINDIR=`pwd`
echo 'ARCH=`uname -p`' >> patchdiag
echo 'export XREF' >> patchdiag
echo "$BINDIR/patchdiag.\$ARCH \$*" >> patchdiag
chmod 755 patchdiag
echo 'Done'

