#!/bin/sh
# Install on a Unix system in a manner that permits version upgrades.
# Thu Dec 22 12:14:18 EST 2005

# *****
# Important: Edit the VERSIONLABEL file prior to running this script.
# *****

# The "version" string is specified in the file VERSIONLABEL, which should
# contain one line of version label, and optionally may have comment lines.
VERSION=`grep -v '^#' VERSIONLABEL | tr -d '\n' `
echo installing cintpos with version label $VERSION

# cinters and cintpos are installed under a common directory.
BASELIB=/usr/local/lib/cint

# The cintpos files go here, and cinterp goes in in $BASELIB/cinterp.
LIBDIR=$BASELIB/cintpos

# Files will be copied here
VERSIONDIR=$LIBDIR/$VERSION

# User executables go here. Normally this will already be in $PATH.
EXEDIR=/usr/local/bin

# These files and directories will be copied.
FILES="b bc bcb bcl bs bsb bsl setenv compall README \
INSTALL xrefdata xreffuns records s t tests helpfiles \
ENDERBIG ENDERLIT g bin cin com doc"

# Create target directories if needed.
if ! test -d $BASELIB
then
  mkdir $BASELIB
fi
if ! test -d $LIBDIR
then
  mkdir $LIBDIR
fi

# If the version directory already exists, clean it out.
if test -d $VERSIONDIR
then
  rm -rf $VERSIONDIR/*
else
  mkdir $VERSIONDIR
fi

# Copy the files.
tar cf - $FILES | (cd $VERSIONDIR; tar xf - )
echo installed runtime files in $VERSIONDIR

# These are used in the scripts in /usr/local/bin.
CINTPOSROOT=$VERSIONDIR
POSPATH=$CINTPOSROOT/cin
POSHDRS=$CINTPOSROOT/g

# Install a script to run the current cinpos version.
CINTPOS=$EXEDIR/cintpos

cat << EOF_CINTPOS_SCRIPT > $CINTPOS
#!/bin/sh
export CINTPOSROOT=$CINTPOSROOT
export POSPATH=$POSPATH
export POSHDRS=$POSHDRS
$VERSIONDIR/bin/cintpos \$*
EOF_CINTPOS_SCRIPT
chmod +x $CINTPOS

echo cintpos is $CINTPOS

