#!/bin/ksh 

#
# Launch script for the Helmsman Unix client 4.4 B07
#

echo "Starting Helmsman Client 4.4 B07"

#
# Save the current working directory
#
originalPwd=$PWD

cd $HOME

#
# Verify the .helmsman4 directory
#
if [ ! -d ".helmsman4" ]
then
   mkdir .helmsman4
   if [ $? -ne 0 ]
   then
      echo "Error creating .helmsman4 directory"
      exit -1
   fi
fi

#
# .helmsman is a link to .helmsman4
#
rm -rf .helmsman 2>&1
ln -s .helmsman4 .helmsman

#
# Verify the plug_ins directory
#
if [ ! -d "plug_ins" ]
then
   mkdir plug_ins
   if [ $? -ne 0 ]
   then
      echo "Error creating plug_ins directory"
      exit -1
   fi
fi

#
# Verify the cache directory
#
cd .helmsman4
if [ ! -d "cache" ]
then
   mkdir cache
   if [ $? -ne 0 ]
   then
      echo "Error creating cache directory"
      exit -1
   fi
fi

#
# Verify the configuration file
#
if [ ! -f "config.dat" ]
then
   cp /helmsman/helmclient/config.dat .
   if [ $? -ne 0 ]
   then
      echo "Error copying config.dat file"
      exit -1
   fi
else
   # We have a config file, make sure exchange path and plug in are in sync
   cat  config.dat | grep -v ExchangePath | grep -v PdfPlugIn > config.dat.tmp
   grep ExchangePath /helmsman/helmclient/config.dat >> config.dat.tmp
   grep PdfPlugIn /helmsman/helmclient/config.dat >> config.dat.tmp
   mv config.dat config.dat.old
   mv config.dat.tmp config.dat
fi

plat=`uname -s`
if [ "$plat" = "HP-UX" ]
then
   PLATFORM="_hpux10"
   APIFILE="hp_helmiacsvr.api"
else
   PLATFORM="_solaris"
   APIFILE="solaris_helmiacsvr.api"
fi

cd ../plug_ins
#
# Verify the api file
#
if [ ! -f "$APIFILE" ]
then
   cp /helmsman/helmclient/$APIFILE .
   if [ $? -ne 0 ]
   then
      echo "Error copying the api file"
      exit -1
   fi
fi

cd ..

chmod -R 775 .helmsman4
chmod -R 775 plug_ins

export PATH=$PATH:/helmsman/helmclient/bin
export LD_LIBRARY_PATH=/usr/lib:/usr/dt/lib:/usr/openwin/lib:/helmsman/helmclient/verity/lib
export HHHOME=/helmsman/helmclient/hyperhelp

#
# Start the application from the .helmsman4 directory
#
cd .helmsman4
/helmsman/helmclient/bin/helm4/$PLATFORM/splash 2>/dev/null
/helmsman/helmclient/bin/helm4/$PLATFORM/helm4 2>/dev/null

#
# Go back to original directory
#
cd $originalPwd

exit 0
