#!/bin/sh
#<copyright>
# ----------------------------------------------------------
# Sun Proprietary/Confidential Code
# Copyright 2001, Sun Microsystems, Inc. All rights reserved.
# ----------------------------------------------------------
#</copyright>

# Remove the core file created when the perl test fails.
trap 'test -f /opt/SUNWstade/bin/core && rm -f /opt/SUNWstade/bin/core' 2 3 15

found=N
#/usr/perl5/5.00503/bin/perl
for p in "/var/opt/SUNWstade/storade_perl" "/usr/bin/perl" "/usr/perl5/5.6.1/bin/perl" "/usr/local/bin/perl" "/bin/perl"  "/opt/bin/perl" 
do
  if test $found = "N"; then
    if test -x $p; then
      perl=$p
      echo "Trying perl at: $perl"
      v=`$p -e '$x=$]; print $x*1000'`

      if test "0$v" -ge "05005" ; then
           rm -f /opt/SUNWstade/bin/perl
           ln -s $perl /opt/SUNWstade/bin/perl
           $perl /opt/SUNWstade/sbin/try_libraries
           if test "$?" = "0"; then
             echo "-> Perl $p will be used."
             found="Y"
           fi
      fi
    fi
  fi
done

if test $found = "N" ; then
  LOOP=Y
  echo " "
  echo " ******************* ERROR *************************************"
  echo " No supported version of perl could be found. "
  echo " ******************* HELP **************************************"
  echo " If only the Perl binaries need to be acquired, be sure to select"
  echo " the appropriate operating system."
  echo " The Perl source is generic for the individual operating system"
  echo " types and will have to be compiled."
  echo " The following URL can assist with getting a supported version. "
  echo " http://www.perl.com/pub/language/info/software.html"
  echo
  echo "If you have a supported version of perl in a different directory"
  echo "link it to /var/opt/SUNWstade/storade_perl and run this command again."
  echo " ***************************************************************"
  exit 1;
fi

rm -f /opt/SUNWstade/bin/perl /opt/SUNWstadh/bin/perl

ln -s $perl /opt/SUNWstade/bin/perl >/dev/null 2>&1
ln -s $perl /opt/SUNWstadh/bin/perl >/dev/null 2>&1

pkginfo SUNWstadh > /dev/null 2>&1

if [ $? -eq 0 ]
then
  cd /opt/SUNWstadh/dhbin
  $perl /opt/SUNWstadh/dhbin/ras_install.exe $*

elif test -d "/opt/SUNWstade/svebin"
then
  cd /opt/SUNWstade/svebin
  $perl /opt/SUNWstade/svebin/ras_install.exe $*

else
  $perl /opt/SUNWstade/bin/fix_perl_path $perl
  cd /opt/SUNWstade/bin
  $perl /opt/SUNWstade/bin/ras_install.exe $*
fi

# Remove the core file created when the perl test fails.
test -f /opt/SUNWstade/bin/core && rm -f /opt/SUNWstade/bin/core
