#!/bin/ksh -p
#
# ident "@(#)M30EngDocs.ksh	1.21 02/09/12 SMI"
#
# Copyright 2001-2002 Sun Microsystems, Inc.  All rights reserved.
#

#
# MODULE NAME: EngDocs
# AUTHOR     :
# DESCRIPTION: To install Sunray English documentation
#
# The following exported variables (initialized by the master task) are 
# available (read-only) for the module:
#
# G_PROGRAM_ID    : program name
# G_MEDIA_DIR     : pathname of the install directory on the media (CD,...)
# G_PRODUCT_DIR   : pathname of the bundles directory on the media (CD,...)
# G_ADMIN_FILE    : pathname of the admin file used by pkgadd. default provided.
# G_DEBUG         : debug on/off. Possible values "yes", "no"
# G_QUICK_INSTALL : used to force a quick install (no user inputs).
#                   possible values "yes", "no"
# G_TMP_DIR       : pathname of the temporary directory 
# G_UT_PROD_NAME  : product name
# G_UT_VERSION    : product version
# G_DAEMON_LOC    : location of OS daemon scripts
# G_LOGFILE       : pathname of the log file.
# G_PID           : PID of the master task
# G_SR_CURRENT_VERSION: the currently installed SR version
#

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

#
# EngDocsVersion()
#
# Description:
#    Check if version number of the Eng.docs currently installed matches the
#    version number required.
#
# Parameters:
#    $1 - version number
#
# Globals used:
#    (none)

EngDocsVersion() {

#
# take only the version number (i.e. 1.2 or 1.3) without the build number
# (usually, the format is 1.2_16.a,REV=xxxxx).
#
   case "$G_SR_CURRENT_VERSION" in
      $1) return 0;;
      *)  return 1;;
   esac
}

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

EngDoc_Preinstall() {

# check to see if the english doc package is available on the CD.
   if [[ -d ${UT_DOC_DIR}/en_US/SUNWeutdo ]]; then
      _DO_INSTALL="yes"
      _INSTALL_DOC="yes"
   fi

# check to see if the manpage package is available on the CD.
   if [[ -d ${UT_DOC_DIR}/en_US/SUNWutm ]]; then
      _DO_INSTALL="yes"
      _INSTALL_MANPAGE="yes"
   fi

#
# starting in 2.0, the doc for the locale that the Admin GUI supports is
# automatically installed.  Since we will always install the english version
# of the Admin GUI, the english doc will always be installed as well.
#


   if [[ $_SW_INSTALLED = "no" ]]; then
      if [[ $_INSTALL_DOC = "no" ]]; then
      	 AddPostInitMessage \
            "Skip\t [ $G_UT_PROD_NAME $G_UT_VERSION English documentation not available ]"
      else 
         AddPostInitMessage \
            "Install\t [ $G_UT_PROD_NAME $G_UT_VERSION English documentation ]"
      fi
   else
      _DO_REMOVE="yes"
      if [[ $_INSTALL_DOC = "no" ]]; then
      	 AddPostInitMessage \
            "Remove\t [ $G_UT_PROD_NAME $G_SR_CURRENT_VERSION English documentation ]"
      	 AddPostInitMessage \
            "Skip\t [ $G_UT_PROD_NAME $G_UT_VERSION English documentation no available ]"
      else
         AddPostInitMessage \
            "Upgrade\t [ $G_UT_PROD_NAME English documentation ${G_SR_CURRENT_VERSION} to ${G_UT_VERSION} ]"
      fi
   fi

   return 0
}

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

EngDoc_Preremove() {

   if AnyPackageInstalled $UT_EN_LIST ; then
      _DO_REMOVE="yes"
      AddPostInitMessage \
              "Remove\t [ $G_UT_PROD_NAME ${G_SR_CURRENT_VERSION} English documentation ]"
   fi
}

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

Module_Init() {

   return_code=0

#
# Check if the English documentation is already installed (and, of course,
# which version of it)
#
   if ProductInstalled $UT_EN_LIST && EngDocsVersion $G_UT_VERSION && \
      ! ProductPartiallyInstalled $UT_EN_LIST; then

      _SW_INSTALLED="yes"
      _SW_COMPATIBLE="yes"

   elif ProductInstalled $UT_EN_LIST && ! EngDocsVersion $G_UT_VERSION; then

      _SW_INSTALLED="yes"
      _SW_COMPATIBLE="no"

   fi

   if IsInstallRequired; then

      EngDoc_Preinstall
      return_code=$?

   elif IsUninstallRequired; then

      EngDoc_Preremove
      return_code=$?

   fi

   return $return_code
}

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

Module_Preserve() {

   return 0

}

#
# Module_Remove()
#
# Description:
#    Remove English 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} English 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

   RemoveProduct $G_ADMIN_FILE $UT_EN_LIST

#
# 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 English 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 manpage only
     MESSAGE="manpages"
     INSTALL_PKG="SUNWutm"
  elif [[ $_INSTALL_MANPAGE = "no" ]]; then
     # this means that we install the doc only
     MESSAGE="English Documentation"
     INSTALL_PKG="SUNWeutdo"
  else
     # this means that we install both the manpage and the doc
     MESSAGE="English manpage and Documentation"
     INSTALL_PKG="SUNWeutdo SUNWutm"
  fi
  InstallMsg "$G_UT_PROD_NAME" "$G_UT_VERSION $MESSAGE"

  # cleanup old instances
  RemoveProduct $G_ADMIN_FILE $UT_EN_LIST || \
    Error "failed to completely remove $G_UT_PROD_NAME English Documentation"

  pkgadd $vflag -a $G_ADMIN_FILE -d ${UT_DOC_DIR}/en_US $INSTALL_PKG

#
# check that packages have been installed correctly
#
  if ! ProductInstalled $UT_EN_LIST || \
       ProductPartiallyInstalled $UT_EN_LIST; then
     print -u2 \
             "$G_UT_PROD_NAME $MESSAGE not successfully installed"

     return 2
  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

}

#
# END
#

#
# MAIN STARTS HERE
#

trap "exit 2" HUP INT QUIT TERM

#
# include libraries
#

. ${G_MEDIA_DIR}/support_lib/iu_lib
. ${G_MEDIA_DIR}/support_lib/module_lib
. ${G_MEDIA_DIR}/support_lib/upgrade_lib

export _EVENT=$1
export _MODULE_NAME=$(basename $0)
export _VARS_LIST=""
export _EXIT_CODE=0
export _RETURN_VAL=0
export _VAR_STORAGE_FILE="${G_TMP_DIR}/.${G_PROGRAM_ID}.${_MODULE_NAME#???}"

DeclareModuleVar _DO_INSTALL="no"
DeclareModuleVar _DO_REMOVE="no"
DeclareModuleVar _SW_INSTALLED="no"
DeclareModuleVar _SW_COMPATIBLE="yes"
DeclareModuleVar _INSTALL_DOC="no"
DeclareModuleVar _INSTALL_MANPAGE="no"

#
# BEGIN: Developers module variables definition here
#

export UT_DOC_DIR="${G_PRODUCT_DIR}/Docs/Solaris_8+"
export UT_EN_LIST="SUNWutm SUNWeutdo"

export UT_LIB_LOCALE_DIR="/opt/SUNWut/lib/locale/en_US"

#
# END
#

#
# FRAMEWORK CODE 
#

. ${G_MEDIA_DIR}/support_lib/framework_lib
