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

#
# MODULE NAME: UtSunmc
# AUTHOR     : Ronald Hixon
# DESCRIPTION: Used for installing / uninstalling Sun Ray module for SunMC
#	       Also used for Preserving/Restoring utsunmc data
#
# 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
#

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

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

Module_Init() {

  _SW_INSTALLED="no"

  case "$G_OS" in
    Linux) return 0;;
  esac

  if AnyPackageInstalled $UT_PKG_LIST || \
	ProductPartiallyInstalled $UT_PKG_LIST ; then
     _SW_INSTALLED="yes"
  fi

  if IsInstallRequired ; then
       _DO_INSTALL="yes"
       if [[ $_SW_INSTALLED = "yes" ]]; then
           _DO_REMOVE="yes"
	   _DO_RESTORE="yes"
	   AddPostInitMessage \
	   "Upgrade\t [ $G_UT_PROD_NAME utsunmc modules $G_SR_CURRENT_VERSION to $G_UT_VERSION ]"
       else
	   AddPostInitMessage "Install\t [ $G_UT_PROD_NAME $G_UT_VERSION modules for utsunmc ]"
       fi
  elif IsUninstallRequired && [[ ${_SW_INSTALLED} = "yes" ]]; then
       _DO_REMOVE="yes"
       AddPostInitMessage \
	"Remove\t [ $G_UT_PROD_NAME $G_SR_CURRENT_VERSION modules for utsunmc ]"
  fi

   return 0

}

#
# Module_Preserve()
#
# Description:
#   If installed build is earlier than 1.3_10.b do not preserve data.
#   The config file is not necessary since libutsmon will use
#   a dynamic version if a real one does not exist.
#
# Parameters:
#   (none)
#
# Globals used:
#

Module_Preserve() {

  return 0

}

#
# Module_Remove()
#
# Description:
#
# Parameters:
#   (none)
#
# Globals used:
#    G_UT_PROD_NAME
#    G_UT_VERSION
#    G_ADMIN_FILE
#

Module_Remove() {

   RemoveMsg "$G_UT_PROD_NAME" "$G_SR_CURRENT_VERSION module for SunMC"

   RemoveProduct $G_ADMIN_FILE $UT_PKG_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:
#
# 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

  InstallMsg "$G_UT_PROD_NAME" "$G_UT_VERSION module for SunMC"

  if ! InstallProduct $G_ADMIN_FILE ${UT_DIR} $UT_PKG_LIST; then
     print -u2 \
             "$G_UT_PROD_NAME module for SunMC 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 _DO_RESTORE="no"	# this is to force the framework to
					# invoke the Module_Restore

#
# BEGIN: Developers module variables definition here
#

export UT_ETC_DIR="/etc/opt/SUNWut"
export UT_VAR_DIR="/var/opt/SUNWut"

typeset -r UT_DIR=$(GetPackagePath ${G_SUNRAY_SERVER_DIR})

typeset -r UT_PKG_LIST="SUNWutesa"

#
# END
#

#
# FRAMEWORK CODE
#

. ${G_MEDIA_DIR}/support_lib/framework_lib
