#!/bin/sh
# $Id: install,v 1.1.2.1 2005/03/14 15:08:05 jb122832 Exp $
# install - scs install wrapper

BASEDIR="`dirname $0`/.."
INSTDIR=$BASEDIR/install
LICENSE=$INSTDIR/license_agreement
INSTALLER="$INSTDIR/installercore"
INSTALLLOGFILE="/var/log/scs-install.log"

TRUE="true"
FALSE="false"

#
# Get command-line switches if they exist
#
# The FACTORY_INST flag is used to figure out if we are
# attempting to install an appliance at the Sun factory. 
# If at the factory, there are special things we want to 
# do at first startup instead of in the postinstall.
#
# The FORCE_INSTALL flag indicates that the installation process
# should install over the top of an existing SCS installation.  This
# bypasses a check in the preinstall script.
#
FACTORY_INST="$FALSE"
FORCE_INSTALL="$FALSE"
for arg in $*
do
  case $arg in 
    -factoryinstall )   FACTORY_INST="$TRUE"; shift;;
    -forceinstall   )   FORCE_INSTALL="$TRUE"; shift;;
    --              )   shift; break;;
  esac
done
export FACTORY_INST
export FORCE_INSTALL



#
# Display the license agreement
#
# Note: skip the legal agreement if we are doing a factory install
#
if [ "$FACTORY_INST" = "$FALSE" ] ; then
  echo
  more $LICENSE
  while [ 1 ]
  do
    #echo -n "[a/d] "
    echo -n "Accept (A) / Decline (D)? "
    read AGREEMENT
    case "$AGREEMENT" in
      # [Yy]|[Yy]es|YES ) break;;
      # [Nn]|[Nn]o|NO ) exit 0 ;;
      [aA]|[aA]ccept|ACCEPT ) break;;
      [dD]|[dD]ecline|DECLINE ) exit 0 ;;
      [Qq]|[Qq]uit|QUIT ) echo "Quiting." ; exit 0 ;;
    esac
  done
fi

# dispatch to the main installer script, logging all output to $INSTALLLOGFILE

exec 3>&1
EXITCODE=`( ( /bin/sh "$INSTALLER" "$@" 2>&1 3>&- 4>&- ; echo $? >&4 ) | tee -a "$INSTALLLOGFILE" >&3 4>&- ) 4>&1`
exit $EXITCODE
