#! /bin/bash
# COMPONENT_NAME: install
#
# FUNCTIONS: Installs APL2 service on Linux
#
# COPYRIGHT:
#
# Licensed Materials - Property of IBM
# (C) Copyright International Business Machines Corp. 2002
# All rights reserved.
#
# US Government Users Restricted Rights - Use, duplication or disclosure
# restricted by GSA ADP Schedule Contract with IBM Corp.
#

if [ "`/usr/bin/whoami`" != "root" ]
then
      echo ""
      echo "You must be root to execute the APL2 install script. "
      exit 1
fi

INSFILE=apl2ls10

APL2_SCRIPT=`which apl2`
if [ ! -z "$APL2_SCRIPT" ] ; then
   APL2=`grep APL2= $APL2_SCRIPT | cut -f2 -d'='`
fi

if [ -z "$APL2" ] ; then
   echo ""
   echo "This service requires that APL2 be already installed."
   echo "I cannot locate the APL2 installation directory."
   echo -n "Please enter the directory, or <ENTER> to quit:"
   read APL2
   if [ -z "$APL2" ] ; then
      echo "Cancelling service installation."
      exit 1
   fi
fi

if [ ! -d $APL2 ] ; then
   echo ""
   echo "$APL2 is not a valid directory."
   exit 1
fi
if [ ! -f $APL2/bin/apl2exe ] ; then
   echo ""
   echo "$APL2 does not contain the APL2 interpreter."
   exit 1
fi
if [ ! -d $APL2/runtime ] ; then
   echo ""
   echo "The APL2 system in $APL2 is not at the Version 2.0 level."
   exit 1
fi

cp $INSFILE.tgz  $APL2/$INSFILE.tgz
cd $APL2

gzip -d $INSFILE.tgz
tar -xovf $INSFILE.tar
rm $INSFILE.tar

if [ ! -x /usr/bin/apl2env ] ; then
   ln -s $APL2/bin/apl2env  /usr/bin/apl2env
fi

if [ "$APL2" != "/usr/APL2" ] ; then

ed $APL2/bin/apl2 <<ENDedit
/^APL2=\/usr\/APL2
d
i
APL2=${APL2}
.
w
q
ENDedit

ed $APL2/bin/apl2runt <<ENDedit
/^APL2=\/usr\/APL2
d
i
APL2=${APL2}
.
w
q
ENDedit

ed $APL2/bin/apl2env <<ENDedit
/^APL2=\/usr\/APL2
d
i
APL2=${APL2}
.
w
q
ENDedit

fi

echo " "
echo "APL2 service has been successfully installed.           "
echo " "
echo "For information on the changes and fixes in this        "
echo "service level, see file $APL2/README.                   "
echo " "
