#!/bin/ksh -p
#
# ident "@(#)adminGUI.ksh	1.15	12/12/11 Oracle"
#
# Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
#

#
# The common routines for the M31AdminGUI<locale> modules.
# This script should be sourced by the M31AdminGUI* modules only.
#

#
# Module developers to provide the following functions:
# Module_Init, Module_Preserve, Module_Remove, Module_Install, Module_Restore
# Module_Abort, Module_Exit
#

#
# function AdminGUI_Preinstall
#
# Description:
#    Pre-install procedure
#
# Parameters:
#    (none)
#
# Globals used:
#    G_UT_PROD_NAME
#    G_UT_VERSION

function AdminGUI_Preinstall {
   typeset OVL="$G_UT_PROD_NAME $G_SR_CURRENT_VERSION $SW_LOCALE"
   typeset NVL="$G_UT_PROD_NAME $G_UT_VERSION $SW_LOCALE"
   typeset AGD="Admin GUI"

   _DO_INSTALL="yes"
   _DO_REMOVE="no"

   # got this far because L10N GUI and/or docs are available on the CD.
   #
   # NOTE: we overloaded the _SW_INSTALLED variable.  When set to "yes",
   # it can mean either the SRSS is installed (for 1.x cases) or the
   # locale package is installed (for 2.x cases).  When set to "no",
   # it means the locale package is not installed.
   #
   if [[ $_SW_INSTALLED = "no" ]]; then # {
      # this is a new install, we will only prompt the user.
      #
      AddPostInitMessage "Install\t [ $NVL Admin GUI ]"
   # }
   else # {
      # if SRSS software is installed (meaning upgrade), do the following:
      # - upgrading from 1.x (_SW_COMPATIBLE=="no"), install GUI and doc.
      # - upgrading from 2.0 (_SW_COMPATIBLE=="yes"), install GUI and doc.
      #
      _DO_REMOVE="yes"
      AddPostInitMessage "Upgrade\t [ $OVL Admin GUI to ${G_UT_VERSION} ]"
   fi # }

   return 0
}

#
# function AdminGUI_Preremove
#
# Description:
#    Pre-remove procedure
#
# Parameters:
#    (none)
#
# Globals used:
#    G_UT_PROD_NAME
#    G_UT_VERSION

function AdminGUI_Preremove {

   if AnyPackageInstalled $UT_ADMINGUI_NAMELIST; then
      _DO_REMOVE="yes"
      AddPostInitMessage \
             "Remove\t [ $G_UT_PROD_NAME $G_SR_CURRENT_VERSION $SW_LOCALE Admin GUI ]"
   fi
}

#
# function Module_Init
#
# Description:
#   initialization of the module for installation, uninstallation
#
# Parameters:
#   (none)
#
# Globals used:
#

function Module_Init {

   return_code=0
   _DO_INSTALL="no"
   _DO_REMOVE="no"

   if [[ -n $G_SR_CURRENT_VERSION ]] && [[ $G_SR_CURRENT_VERSION < "2.0" ]]; then
#
# special handling for 1.x upgrade.  We mark the package as installed but
# incompatible.
#
      _SW_INSTALLED="yes"
      _SW_COMPATIBLE="no"

   elif AnyPackageInstalled $L10N_GUI_NAME || \
	ProductPartiallyInstalled $L10N_GUI_NAME; then
#
# Check if the localized Admin GUI is already installed.
#
      _SW_COMPATIBLE="yes"
      _SW_INSTALLED="yes"

   fi

   if IsInstallRequired; then
	AdminGUI_Preinstall
	return_code=$?
   elif IsUninstallRequired; then
	AdminGUI_Preremove
	return_code=$?
   fi
   return $return_code
}

#
# function Module_Preserve
#
# Description:
#   
#
# Parameters:
#   (none)
#
# Globals used:
#

function Module_Preserve {

   return 0

}

#
# function Module_Remove
#
# Description:
#    Remove Japanese documentation
#    Note that this function can be used to uninstall older version of
#    the product (up to now the package list is the same).
#
# Parameters:
#   (none)
#
# Globals used:
#   G_UT_PROD_NAME
#   G_ADMIN_FILE

function Module_Remove {

   RemoveMsg "$G_UT_PROD_NAME" "$G_SR_CURRENT_VERSION $SW_LOCALE Admin GUI"

# remove the docdir links.  This is to support the older SR releases.
# In 2.0, the docdir link is installed as part of the package.  So, no
# need to removing it manually in the future.
   if [[ -L ${UT_LIB_LOCALE_DIR}/docdir ]]; then
	rm ${UT_LIB_LOCALE_DIR}/docdir
   fi
   Module_Specific_Remove
   RemoveProduct $G_ADMIN_FILE $UT_ADMINGUI_NAMELIST

#
# if the removal didn't succeed, we exit with 1 so to keep the procedure
# going...
#
   if [[ $? != 0 ]]; then
      return 1
   fi

   return 0
}

#
# function Module_Install
#
# Description:
#    To install Japanese docs
#
# Parameters:
#   (none)
#
# Globals used:
#    G_DEBUG
#    G_UT_PROD_NAME
#    G_UT_VERSION
#    G_ADMIN_FILE

function Module_Install {

  vflag=""

  if [[ $G_DEBUG = "yes" ]]; then
     vflag="-v"
  fi

  typeset MESSAGE="Admin GUI"
  typeset INSTALL_PKG=$UT_ADMINGUI_INSTLIST

  InstallMsg "$G_UT_PROD_NAME" "$G_UT_VERSION $SW_LOCALE $MESSAGE"

  # cleanup old instances
  RemoveProduct $G_ADMIN_FILE $UT_ADMINGUI_NAMELIST

  if [[ $? != 0 ]]; then
	Error "failed to completely remove $G_UT_PROD_NAME $SW_LOCALE Admin GUI"
  fi

  Module_Specific_Install

  if ! InstallProduct $G_ADMIN_FILE ${UT_L10N_DIR} $L10N_GUI; then
     print -u2 \
        "$G_UT_PROD_NAME $G_UT_VERSION $SW_LOCALE Admin GUI not successfully installed"
     return 1
  fi

  return 0
}

#
# function Module_Restore
#
# Description:
#    Restore saved configuration data
#
# Parameters:
#   (none)
#
# Globals used:
#

function Module_Restore {

   return 0

}

#
# function Module_Abort
#
# Description:
#    Abort procedure
#
# Parameters:
#   (none)
#
# Globals used:
#

function Module_Abort {

   return 0

}

#
# function Module_Exit
#
# Description:
#    Exit procedure (normal termination)
#
# Parameters:
#   (none)
#
# Globals used:
#

function Module_Exit {

   return 0

}
