#!/bin/ksh  
#
# ident "@(#)M15LDAP.ksh	1.21 01/11/29 SMI"
#
# Copyright (c) 2001 by Sun Microsystems, Inc.
# All rights reserved.
#

#
# MODULE NAME: LDAP 
# AUTHOR     :
# DESCRIPTION: LDAP client package is no longer required in 2.0 since it's
#	part of the Solaris release.
#
# 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.
#


#
# UninstallLDAPClient()
#
# Description:
#    Unistall LDAP library
#
# Parameters:
#    (none)
#
# Globals used:
#    G_ADMIN_FILE


UninstallLdapClient() {
  RemoveMsg "$LCL_PROD_NAME" "$LCL_VERSION"
  RemoveProduct $G_ADMIN_FILE $LCL_PKG_LIST

  return $?
}


#
# LCL_Preremove()
#
# Description:
#    Pre-remove procedure: ask whether LDAP has to be removed
#
# Parameters:
#    (none)
#
# Globals used:
#    (none)

LCL_Preremove() {

   _DO_REMOVE="no"

   if SunOSRelease 5.6 ; then

      if [[ $_SW_INSTALLED = "yes" ]]; then

         if YesOrNo "Remove $LCL_PROD_NAME $LCL_VERSION" "Y"; then
            _DO_REMOVE="yes"
            AddPostInitMessage "Remove\t [ $LCL_PROD_NAME $LCL_VERSION ]"
         fi
      fi
        
   fi

   return 0
}



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

#
# Module_Init()
#
Module_Init() {

  exit_no=0

#
# Check if LDAP client is already installed. 
# 
#
  if ProductInstalled $LCL_PKG_LIST; then
     
      _SW_INSTALLED="yes"

  fi

  if IsUninstallRequired; then
      LCL_Preremove
      exit_no=$?
  fi
   
#
# check to see if there is a M15LDAP preserved file.  If so, rename it
# to M10SunDS so that it can be converted to the SRDS format.
#
  if IsModuleDataPreserved; then
	DSTMOD=${G_UPGRADE_DIR}/preserve/M10SunDS
	if [[ -d $DSTMOD ]]; then
	   fmt <<-!
	Found conflicting preserved data from both ${_MODULE_NAME} and
	M10SunDS modules.  Please check your preserved tarfile!!
	!
	   return 2
	fi
	mv ${G_UPGRADE_DIR}/preserve/${_MODULE_NAME} \
		${G_UPGRADE_DIR}/preserve/M10SunDS
		# 2> /dev/null
  fi
  return $exit_no
}

#
# Module_Preserve()
#

Module_Preserve() {

  return 0

}

#
# Module_Remove()
#
# Description:  Remove the LDAP client library package.

Module_Remove() {

  if ! UninstallLdapClient ; then
      Note "$LCL_PROD_NAME not succesfully removed"
      return 1
  fi

  return 0 
}

#
# Module_Install()
#
# Description:  No longer needed for 2.0 since SUNWlldap is part of the
#	Solaris release.
#
#
# Parameters:
#   (none)
#
# Globals used: none
#

Module_Install() {

    return 0

}

#
# Module_Restore()
#

Module_Restore() {

 return 0

}

#
# Module_Abort()
#

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/upgrade_lib
. ${G_MEDIA_DIR}/support_lib/iu_lib
. ${G_MEDIA_DIR}/support_lib/module_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"

#
# BEGIN: Developers module variables definition here
#

export LCL_PROD_NAME="LDAP Client Libraries"
export LCL_VERSION="11.6.0"
export LCL_PKG_LIST="SUNWlldap"

#
# END
#

#
# FRAMEWORK CODE 
#

. ${G_MEDIA_DIR}/support_lib/framework_lib
