#!/bin/ksh -p
#
# ident "@(#)adminGUI.ksh	1.9 04/10/12 SMI"
#
# Copyright 2001-2002,2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

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

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

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

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 and Documentation"

   _DO_INSTALL="no"

   # check to see if the localized Admin GUI package is available on the CD.
   #
   if ls $UT_L10N_DIR/$L10N_GUI 1>/dev/null 2>&1; then
      _INSTALL_GUI="yes"
   fi

   # check to see if the localized doc package is available on the CD.
   #
   if ls $UT_DOC_DIR/$L10N_DOC 1>/dev/null 2>&1; then
      _INSTALL_DOC="yes"
   fi

   # if both L10N doc and GUI are not available, there is nothing to install.
   # Just remove the old packages.
   #
   if [[ ${_INSTALL_GUI} = "no" && ${_INSTALL_DOC} = "no" ]]; then # {
      if [[ $_SW_INSTALLED = "yes" || $_DOC_INSTALLED = "yes" ]]; then
         AddPostInitMessage "Remove\t [ $OVL $AGD ]"
         _DO_REMOVE="yes"
         fmt <<-!

		An installation of $OVL
		Admin GUI support and/or documentation has been detetected
		on this server.  Since the $G_SR_CURRENT_VERSION $SW_LOCALE
		Admin GUI and documentation are not currently available
		the $G_SR_CURRENT_VERSION $SW_LOCALE Admin GUI and
		documentation will be removed for now.  You can reinstall
		them in the future when they become available.

		!
      fi
      AddPostInitMessage "Skip\t [ $NVL $AGD are not available ]"
      return 0
   fi # }

   # 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 # {
      if [[ -z $G_SR_CURRENT_VERSION ]]; then # {
	 # this is a new install, we will only prompt the user.
	 #
	 if [[ $_INSTALL_GUI = "yes" ]]; then
	    print ""
	    if YesOrNo "Do you want to install $NVL Admin GUI" "N"; then
	        _DO_INSTALL="yes"
                AddPostInitMessage "Install\t [ $NVL Admin GUI ]"
	        if [[ $_INSTALL_DOC = "yes" ]]; then
            	    AddPostInitMessage "Install\t [ $NVL documentation ]"
	        else
            	    AddPostInitMessage \
		      "Skip\t [ $NVL documentation not available ]"
	        fi
	    fi
	 fi
      # }
      else # {
	# this is not a new install. This is an upgrade without the Admin GUI
	# support package installed.  We'll just remove the doc if it's
	# currently installed.
	# This can only happen when someone installed the docs manually in
	# 2.x.
	#
	if [[ $_DOC_INSTALLED = "yes" && $_DO_INSTALL = "no" ]]; then # {
	    _DO_REMOVE="yes"
	    AddPostInitMessage "Remove\t [ $OVL documentation ]"
	    fmt <<-!

		The $OVL
		documentation is currently installed on this server.  This
		document is now installed automatically when you install
		the $SW_LOCALE Admin GUI.  Since the $G_SR_CURRENT_VERSION
		$SW_LOCALE Admin GUI support is not currently installed on
		this system, the $G_UT_VERSION $SW_LOCALE Admin GUI will not
		be installed on this system and the $G_SR_CURRENT_VERSION
		$SW_LOCALE will be removed from this system.  If you wish to
		install the documentation only, please refer to the
		Installation documentation.

		!
	fi # }
      fi # }
   # }
   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"

      if [[ $_INSTALL_GUI = "yes" ]]; then
          _DO_INSTALL="yes"
          AddPostInitMessage \
            "Upgrade\t [ $OVL Admin GUI to ${G_UT_VERSION} ]"
      else
          AddPostInitMessage \
            "Skip\t [ $NVL Admin GUI support not available ]"
      fi

      if [[ $_INSTALL_DOC = "yes" ]]; then
         if [[ $_DO_INSTALL = "yes" ]]; then
            AddPostInitMessage \
	      "Upgrade\t [ $OVL documentation to $G_UT_VERSION ]"
	 else
            AddPostInitMessage "Remove\t [ $OVL documentation ]"
            fmt <<-!

		The $OVL
		documentation is currently installed on this server.  This
		document is now installed automatically when you install
		the $SW_LOCALE Admin GUI.  Since the $SW_LOCALE Admin GUI
		support is not currently available, the $G_UT_VERSION
		$SW_LOCALE Admin GUI will not be installed on this system and
		the $G_SR_CURRENT_VERSION $SW_LOCALE documentation will be
		removed from this system.  If you wish to install the
		documentation only, please refer to the Installation 
		documentation.

		!
         fi
      else
         AddPostInitMessage "Skip\t [ $NVL documentation not available ]"
      fi
   fi # }

   return 0
}

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

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 and documentation ]"
   fi
}

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

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 AnyPackageInstalled $L10N_DOC_NAME || \
	ProductPartiallyInstalled $L10N_DOC_NAME; then

      _DOC_INSTALLED="yes"
   fi

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

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

Module_Preserve() {

   return 0

}

#
# 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

Module_Remove() {

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

# 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
}

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

Module_Install() {

  vflag=""

  if [[ $G_DEBUG = "yes" ]]; then
     vflag="-v"
  fi
  typeset INSTALL_PKG=""
  typeset MESSAGE=""
  if [[ $_INSTALL_DOC = "no" ]]; then
     # this means that we install Admin GUI only
     MESSAGE="Admin GUI"
     INSTALL_PKG=$L10N_GUI
  elif [[ $_INSTALL_GUI = "no" ]]; then
     # this means that we install the documentation only
     MESSAGE="Documentation"
     INSTALL_PKG=$L10N_DOC
  else
     # this means that we install both the Admin GUI and the doc
     MESSAGE="Admin GUI and Documentation"
     INSTALL_PKG=$UT_ADMINGUI_INSTLIST
  fi
  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 and Documentation"
  fi

  Module_Specific_Install
  if [[ $_INSTALL_DOC = "yes" ]]; then
     if ! InstallProduct $G_ADMIN_FILE ${UT_DOC_DIR} $L10N_DOC; then
        print -u2 \
         "$G_UT_PROD_NAME $G_UT_VERSION $SW_LOCALE Documentation not successfully installed"
	return 1
     fi
  fi
  if [[ $_INSTALL_GUI = "yes" ]]; then
     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
  fi
  return 0
}

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

Module_Restore() {

   return 0

}

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

Module_Abort() {

   return 0

}

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

Module_Exit() {

   return 0

}
