#!/bin/sh
#
#	a shell script to automatically install the Cobol patch
#
#	this script is essentially a duplicate of the install instruction steps listed
#	in the accompanying README.  we've added some up-front checks and made the
#	sequence an executable script for convenience.  you may want to review the
#	sequence to ensure it's going to put things where you expect them to go.
#

if [ `whoami` != "root" ]; then
	echo 'You must be root to install the Cobol patch.'
	exit 1
fi
if [ ! -d $COBDIR ]; then
	echo 'COBDIR not set.  Please set the environment variable COBDIR to'
echo 'the directory where Cobol is installed and then rerun this script.'
	exit 1
fi

echo -n "is Cobol installed in $COBDIR? (y/n) "
export INSTALD; read INSTALD
if [ $INSTALD != 'y' ]; then
	echo 'Please set $COBDIR to the directory that holds Cobol 3.2'
	echo 'and rerun this script.'
	exit 1
fi
echo -n 'Please enter the directory where the Cobol patch is located: '
export PATCHD; read PATCHD
if [ ! -d $PATCHD/install ]; then
        echo "$PATCHD does not appear to hold the Cobol patch"
        echo "Please check the Cobol patch directory and rerun this script."
        exit 1
fi
echo "Installing the Cobol patch from $PATCHD to $COBDIR"

export PATH; PATH=$COBDIR/bin:$PATH

echo "This script will overwrite on top of the old version unless you back it up"
echo -n "Do you want to exit this script and backup the current version? (y/n) "
export QUIT; read QUIT
if [ $QUIT = 'y' ]; then
        echo 'Leaving the script'
        exit 1
fi

echo  "Installing the Cobol patch from $PATCHD to $COBDIR"
echo  "Please wait ..."
cd $PATCHD/install
cp cdr11* $COBDIR/cdr
cp cobver ncg.gnt rts32 $COBDIR
cp signals.1 $COBDIR/docs
cp libcobol.a libcobol.so.1.0  $COBDIR/coblib
cp libosx.a libosx.so.1.0 $COBDIR/coblib
ln $COBDIR/coblib/libcobol.so.1.0 $COBDIR/coblib/libcobol.so
ln $COBDIR/coblib/libosx.so.1.0 $COBDIR/coblib/libosx.so
cp toolboxver osxver ccitcp2 $COBDIR
cp cci.h $COBDIR/src
cp mkfs2 $COBDIR/src/fs

echo "Installation Complete"


echo "Read and apply the documentation changes contained in the file 'documentation'"
exit 0
