#!/bin/ksh 
#
# ident "@(#)M46Utslaunch.ksh	1.3 04/02/09 SMI"
#
# Copyright 2002,2004 Sun Microsystems, Inc.  All rights reserved.
#

#
# MODULE NAME: Utslaunch.ksh 
# AUTHOR     : 
# DESCRIPTION: Used for Preserving/Restoring utslaunch 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() {

  if IsUninstallRequired; then

     return 0

  fi

  GetCurrentSRVersion
  INSTALLED_VERSION=$_RETURN_VAL

  if [ -z "$INSTALLED_VERSION" ]; then
    _SW_INSTALLED="no"
  elif [ -f $UTSLAUNCH_DEFAULT_FILE ] || [ -f $UTSLAUNCH_MANDATORY_FILE ]; then
    _SW_INSTALLED="yes"
  else
    _SW_INSTALLED="no"
  fi

  if IsInstallRequired ; then
       _DO_INSTALL="yes"
       if [[ ${_SW_INSTALLED} = "yes" ]]; then
          AddPostInitMessage "Upgrade\t [ data for utslaunch ]"
       fi
       if [ ${_SW_INSTALLED} = "no" ]; then
	  AddPostInitMessage "Install\t [ data for utslaunch ]"
       fi
  elif IsPreserveRequired ; then
       if [[ ${_SW_INSTALLED} = "yes" ]]; then
          AddPostInitMessage "Preserve [ data for utslaunch ]"
       fi
  fi

  return 0
}

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

Module_Preserve() {

   SaveFiles $UTSLAUNCH_PRESERVE_FILES
   if [[ $? != 0 ]]; then
      return 2
   fi
   return 0

}

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

Module_Remove() {

   return 0

}

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

Module_Install() {

  return 0

}

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

Module_Restore() {
 typeset path
 typeset file

# merge with the preserved files
   if GetPreservedFilePath $UTSLAUNCH_DEFAULT_FILE; then
      path=${_RETURN_VAL}
      UpdateFields "$path" $UTSLAUNCH_DEFAULT_FILE
   fi   

   if GetPreservedFilePath $UTSLAUNCH_MANDATORY_FILE; then
      path=${_RETURN_VAL}
      cp -p "$path" $UTSLAUNCH_MANDATORY_FILE
   fi   

 echo "Restoration of Utslaunch data complete"

 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/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 UT_ETC_DIR="/etc/opt/SUNWut"

export UTSLAUNCH_PRESERVE_FILES="
                             ${UT_ETC_DIR}/utslaunch_defaults.properties \
                             ${UT_ETC_DIR}/utslaunch_mandatory.properties "			      
export UTSLAUNCH_DEFAULT_FILE="
                             ${UT_ETC_DIR}/utslaunch_defaults.properties"
export UTSLAUNCH_MANDATORY_FILE="
                             ${UT_ETC_DIR}/utslaunch_mandatory.properties "			      

typeset -r UT_PKG_LIST="SUNWuta SUNWuto SUNWutr SUNWutk SUNWutu"

#
# END
#

#
# FRAMEWORK CODE 
#

. ${G_MEDIA_DIR}/support_lib/framework_lib
