#
# Copyright (c) 2001-2005 Easysoft Ltd. All rights reserved.
#
# $Id: install_init 32 2005-03-02 17:59:57Z martin $
#
# This is the installation initialisation script.
#
# Calling format:
#
# install_init long_product_name
#
# returns
#
# 0 = success
# 1 = invalid command line
# 2 = environment variable not defined
# 3 = some other error
#
if [ "$ECHO" = "" ];then
  echo "error - ECHO not defined, expect it to be exported"
  exit 2
fi
if [ "$platform" = "" ]; then
  $ECHO "error - platform not defined, expect it to be exported"
  exit 2
fi
#
# Check command line
#
cmdline_error=""
if [ $# -ne 1 ];then
  cmdlinestr="incorrect number of parameters"
  cmdline_error="1"
else
  PRODUCTLONG="$1"
fi
#
# If command line error
#
if [ "$cmdline_error" = "1" ];then
  $ECHO "Invalid command line, $cmdlinestr"
  $ECHO "Usage:"
  $ECHO "install_init long_product_name"
  exit 1
fi
#
# If an OSname.txt file exists compare it with $platform and they
# should match or perhaps someone is installing distribution for x on y.
#
if [ -r "OSname.txt" ];then
  bdist=`cat OSname.txt`
  if [ "$bdist" != "" ];then
    if [ "$bdist" != "$platform" ];then
      cat <<EOF
This platform looks like "$platform" and this distribution appears to
be for "$bdist". Please check you have downloaded the correct distribution
for this platform. If you are you can continue.

EOF
      answer="hoho"
      while [ \( "$answer" != "y" \) -a \( "$answer" != "n" \) ]
      do
	$ECHO "Continue (y/n) [n]: \c"
	read answer
        if [ "$answer" = "" ];then
          answer="n"
        fi
        if [ "$answer" = "n" ];then
	  $ECHO "Installation aborted due to mismatched distribution and platform."
	  exit 1
        fi
      done
    fi
  fi
fi
#
# On AIX make sure and shared objects not in use are unloaded.
#
if [ "$platform" = "aix" ];then
  if [ -x /usr/sbin/slibclean ];then
    /usr/sbin/slibclean
  fi
fi
exit 0