#!/bin/sh

# Copyright  2004 Sun Microsystems, Inc. All rights reserved. 
# 
# Sun Microsystems, Inc. has intellectual property rights relating to
# technology embodied in the product that is described in this document.
# In particular, and without limitation, these intellectual property rights
# may include one or more of the U.S. patents listed at
# http://www.sun.com/patents and one or more additional patents or pending
# patent applications in the U.S. and in other countries.
# 
# U.S. Government Rights - Commercial software. Government users are subject
# to the Sun Microsystems, Inc. standard license agreement and applicable
# provisions of the FAR and its supplements.
# 
# Use is subject to license terms. 
# 
# This distribution may include materials developed by third parties. Sun,
# Sun Microsystems, the Sun logo, Java and Sun[tm] ONE are trademarks or
# registered trademarks of Sun Microsystems, Inc. in the U.S. and other
# countries. 
# 
# Copyright  2004 Sun Microsystems, Inc. Tous droits rservs. Sun
# Microsystems, Inc. dtient les droits de proprit intellectuels relatifs
#  la technologie incorpore dans le produit qui est dcrit dans ce document.
# En particulier, et ce sans limitation, ces droits de proprit
# intellectuelle peuvent inclure un ou plus des brevets amricains lists
#  l'adresse http://www.sun.com/patents et un ou les brevets supplmentaires
# ou les applications de brevet en attente aux Etats - Unis et dans les
# autres pays.
# 
# L'utilisation est soumise aux termes du contrat de licence.
# 
# Cette distribution peut comprendre des composants dvelopps par des
# tierces parties.
# 
# Sun, Sun Microsystems, le logo Sun, Java et Sun[tm] ONE sont des marques
# de fabrique ou des marques dposes de Sun Microsystems, Inc. aux
# Etats-Unis et dans d'autres pays.


containerConfig()
{
  if [ "$WEB_CONTAINER" = "WS6" ]; then
    WC_CONFIG=./amws61config
  elif [ "$WEB_CONTAINER" = "WL6" ]; then
    WC_CONFIG=./amwl61config
  elif [ "$WEB_CONTAINER" = "WL8" ]; then
    WC_CONFIG=./amwl81config
  elif [ "$WEB_CONTAINER" = "WAS5" ]; then
    WC_CONFIG=./amwas51config
  elif [ "$WEB_CONTAINER" = "AS7" ]; then
    WC_CONFIG=./amas70config
  fi
}

###########################################################
# Finds amutils and sources it. This function is identical
# in all scripts. Any changes made here need to made in
# other scripts too.
source_amutils()
{
	# Try to guess the location of amutils
	if [ "$BASEDIR" != "" -a "$PRODUCT_DIR" != "" -a -f $BASEDIR/$PRODUCT_DIR/bin/amutils ]; then
		AMUTILS=$BASEDIR/$PRODUCT_DIR/bin/amutils
	elif [ "$BASEDIR" != "" -a "$PRODUCT_DIR" != "" -a -f $BASEDIR/$PRODUCT_DIR/share/bin/amutils ]; then
		AMUTILS=$BASEDIR/$PRODUCT_DIR/share/bin/amutils
	elif [ -f ./amutils ]; then
		AMUTILS=./amutils
	elif [ -f `dirname $0`/amutils ]; then
		AMUTILS=`dirname $0`/amutils
	elif [ -f /opt/SUNWam/bin/amutils ]; then
		AMUTILS=/opt/SUNWam/bin/amutils
	elif [ -f /opt/SUNWam/share/bin/amutils ]; then
		AMUTILS=/opt/SUNWam/share/bin/amutils ]
	elif [ -f /opt/sun/identity/bin/amutils ]; then
		AMUTILS=/opt/sun/identity/bin/amutils
	elif [ -f /opt/sun/identity/share/bin/amutils ]; then
		AMUTILS=/opt/sun/identity/share/bin/amutils ]
	else
		echo "$0: FATAL: Could not find amutils. Exiting."
		exit 1
	fi

	# Source it!
	echo "$0: Sourcing $AMUTILS"
	. $AMUTILS
}

if [ $# -eq 0 ]; then
	INSTALL_FILE_NOT_REQUIRED=true
	source_amutils
	do_interactive
	set -- -s $IS_SILENT_INSTALL_FILE
	INSTALL_FILE_NOT_REQUIRED=false
fi

case $1 in
   "--help") echo help
   ;;
   "--silent" | "-s" ) echo silent install
   if [ ! -f "$2" ]; then
      echo File not found: $2
   fi
   IS_SILENT_INSTALL_FILE=$2
   export IS_SILENT_INSTALL_FILE
   ;;
   *)
   echo "Usage: amconfig -s <silent>"
   ;;
esac

source_amutils

check_root_user
check_os

#change all the files' ownership
change_ownership

#get the container specific script
containerConfig

case $DEPLOY_LEVEL in
  1)
      echo full install
      ./amdsconfig $1 $2
      ./amsvcconfig $1 $2
      $WC_CONFIG $1 $2
      link_amconfig
      unjar_docs
      tag_swap_samples
      ;;
  2)
      echo console only
      ./amsdkconfig $1 $2
      $WC_CONFIG $1 $2
      link_amconfig
      unjar_docs
      tag_swap_samples
      ;;
  3)
      echo SDK only
      ./amsdkconfig $1 $2
      link_amconfig
      unjar_docs
      tag_swap_samples
      ;;
  4)
      echo SDK only with container config
      ./amsdkconfig $1 $2
      $WC_CONFIG $1 $2
      link_amconfig
      unjar_docs
      tag_swap_samples
      ;;
  5)
      echo federation only
      $WC_CONFIG $1 $2
      link_amconfig
      ;;
  6)
      echo server only install
      ./amdsconfig $1 $2
      ./amsvcconfig $1 $2
      $WC_CONFIG $1 $2
      link_amconfig
      unjar_docs
      tag_swap_samples
      ;;
  11)
      echo full uninstall
      $WC_CONFIG $1 $2
      ;;
  12)
      echo console only uninstall
      $WC_CONFIG $1 $2
      ;;
  13)
      echo sdk uninstall
      ;;
  14)
      echo uninstall SDK only with container config
      $WC_CONFIG $1 $2
      ;;
  15)
      echo federation uninstall
      $WC_CONFIG $1 $2
      ;;
  16)
      echo server only uninstall
      $WC_CONFIG $1 $2
      ;;
  21)
      echo full reinstall
      ./amdsconfig $1 $2
      ./amsvcconfig $1 $2
      $WC_CONFIG $1 $2
      ;;
  26)
      echo server reinstall
      ./amdsconfig $1 $2
      ./amsvcconfig $1 $2
      $WC_CONFIG $1 $2
      ;;
  31)
      echo sdk reinstall
      ./amsdkconfig $1 $2
      $WC_CONFIG $1 $2
      ;;
  32)
      echo console reinstall
      ./amsdkconfig $1 $2
      $WC_CONFIG $1 $2
      ;;
  33)
      echo console sdk reinstall
      ./amsdkconfig $1 $2
      $WC_CONFIG $1 $2
      ;;
  35)
      echo liberty reinstall
      $WC_CONFIG $1 $2
      ;;
  *) echo no such config option
      ;;
  esac

exit 0

