#!/ibin/sh
#       %Z% %M% %I% %E% %Q%
#
#	Copyright (C) 2001 The Santa Cruz Operation, Inc.
#		All Rights Reserved.
#	The information in this file is provided for the exclusive use of
#	the licensees of The Santa Cruz Operation, Inc.  Such users have the
#	right to use, modify, and incorporate this code into other products
#	for purposes authorized by the license agreement provided they include
#	this notice and the associated copyright notice with any such product.
#	The information in this file is provided "AS IS" without warranty.
#
#******************************************************************************
#                      Generic CCS script -- CHANGE THIS!!!
#-----------------------------------------------------------------------------
#  COMMENTS/DESCRIPTION
#-----------------------------------------------------------------------------
#
#       input:
#           $1 is the name of the step
#           $2 is the keyword list (e.g., INSTALL, UPGRADE, REMOVE)
#           $3 is the package list
#============================================================================

#====================================================================== INT ===
#  cleanup -- 
#   
#    cleanup exits the package script with the passed argument 
#
#------------------------------------------------------------------------------
cleanup()
{
	exit $1
}

#====================================================================== INT ===
#  do_save -- 
#   
#    do_save uses ccsUpgradeTool to save the RTS config files
#
#------------------------------------------------------------------------------
do_save()
{
	return # don't do anything here for now
}

#=================CUSTOM INSTALLATION STEP FUNCTIONS=================== INT ===
#
#====================================================================== INT ===
#  do_preload -- 
#   
#	If the keyword "UPGRADE" is specified, but the old version being
#	upgraded is not an SSO component, special action may be required
#	at this point. See guidelines 4.6.2 "How to Handle In-Place Upgrade".
#
#	Note that only the files in the "SharedControl" package of the
#	component have been loaded onto the target at this point.
#
#------------------------------------------------------------------------------
do_preload()
{
	# calls do_save to save config files for upgrade
	#

	do_save
}

#====================================================================== INT ===
#  do_postload -- 
#   
#	No work is defined
#
#------------------------------------------------------------------------------
do_postload()
{
	:
	# no work currently defined for here
}

#====================================================================== INT ===
#  do_preattach -- 
#
#	In this step, the ccs should make any necessary version-compatibility
#	checks. If, for some reason it is not valid to install the component
#	on the given client -- perhaps an inappropriate version of the
#	operating system is installed, for instance -- the ccs shoudl return
#	an exit code of $FAIL, causing teh installation to fail.
#
#	If the keyword "UPGRADE" is specified, but the old version being
#	upgraded is not an SSO component, special action is required at this
#	point. See guidelines 4.6.2 "How to Handle In-Place Upgrade".
#   
#------------------------------------------------------------------------------
do_preattach()
{
	#
	#	< FILL IN HERE >
	#
	# perform necessary version-compatibility checks. perform a 
	#	cleanup $FAIL
	# if something is not right after loggin the reasons.
	#

	# calls do_save to save config files for network client upgrade
	#

	do_save
}

#====================================================================== INT ===
#  do_postattach -- 
#
#	If the keyword "UPGRADE" is specified, this is the step in which the
#	ccs should merge the old configuration data into the appropriate files.
#
#	If the old version being upgraded was not an SSO component, the old
#	configuration data will have been saved in the CCS_PERSISTENT_STORAGE by
#	an earlier script phase.
#
#	After the saved data has been restored, any "query" parameters that
#	necessitate further self-configuration should be applied. Only files
#	wholly owned by this component -- i.e., those in the /var/opt area
#	-- can be modified.
#   
#------------------------------------------------------------------------------
do_postattach()
{
        case "$upgrade" in
	    nonSSOupgrade)
		# preserve any needed data from a 3.2v4 installation
		;;
	    SSOupgrade)
		# preserve any needed data from an OSr5 installation
                ;;
	esac
}

#====================================================================== INT ===
#  do_preregister -- 
#   
#	Here is where ScoAdmin OSAs that need to be available to other
#	components during those component's "configure" phase should be
#	installed. This implies some stringent restrictions on the
#	implementation of such OSA's: they must operate completely within
#	the boundries of their own component provided tools and data,
#	possibly relying as well on tools available in /ibin.
#
#------------------------------------------------------------------------------
do_preregister()
{
	:
	# No work defined yet
}

#====================================================================== INT ===
#  do_postregister -- 
#
#	No work is defined
#
#------------------------------------------------------------------------------
do_postregister()
{
	:
	# No work defined yet
}

#====================================================================== INT ===
#  do_preconfigure -- 
#   
#	The component should configure itself into any system service of which
#	it is a consumer. For instance, calls to "idinstall" should be made
#	here to add a drive into (or, in the case of a removal, to pull a
#	driver out of) the link kit.
#
#------------------------------------------------------------------------------
do_preconfigure()
{
	:
	#
	#	< FILL IN HERE >
	#
	# This is where things that need to register with OSA's should call
	# those OSAs.
}

#====================================================================== INT ===
#  do_postconfigure -- 
#
#	Any remaining configuration that relied on steps taken in the pre-
#	configurure and system steps should be completed here
#
#------------------------------------------------------------------------------
do_postconfigure()
{
	:
	#
	#	< FILL IN HERE >
	#
	# Continue anything started in do_preconfigure that needs finishing
	# up.
	#
}

#====================================================================== INT ===
#  do_preexport -- 
#   
#	No work defined here
#
#------------------------------------------------------------------------------
do_preexport()
{
	:
	# no work defined yet
}

#====================================================================== INT ===
#  do_postexport -- 
#   
#	In the final phase, all the remaining public interfaces are exported
#	to the system's public name space.
#
#------------------------------------------------------------------------------
do_postexport()
{
  	# Create the default php.ini
  	[ ! -f /usr/lib/php/php.ini ] && {
	  cp -f /usr/lib/php/php.ini-dist /usr/lib/php/php.ini > /dev/null 2>&1
	  chown bin /usr/lib/php/php.ini > /dev/null 2>&1
	  chgrp bin /usr/lib/php/php.ini > /dev/null 2>&1
	  chmod 644 /usr/lib/php/php.ini > /dev/null 2>&1
	}
}

#=================CUSTOM REMOVAL STEP FUNCTIONS-----=================== INT ===
#
#====================================================================== INT ===
#  do_preunexport -- 
#   
#	In the first phase, all the extra public interfaces are unexported
#	from the system's public name space.
#
#------------------------------------------------------------------------------
do_preunexport()
{
	:
	#
	#	< FILL IN HERE >
	#
	# This is the place that would be filled by all the other misc
	# functions performed by the removal script that were not covered by
	# the previous steps. Things like flushing buffers and the like.
}

#====================================================================== INT ===
#  do_postunexport -- 
#   
#	No work defined here
#
#------------------------------------------------------------------------------
do_postunexport()
{
	:
	# no work defined yet
}

#====================================================================== INT ===
#  do_preunconfigure -- 
#   
#	The component should unconfigure itself from any system service it is
#	a consumer of, using calls to the appropriate service interface. For
#	instance, kernel drivers should be removed by a call to the "idinstall"
#	utility.
#
#------------------------------------------------------------------------------
do_preunconfigure()
{
	:
	#
	#	< FILL IN HERE >
	#
	# This is where things that needed to register with OSA's should
	# remove themselves from those OSAs.
}

#====================================================================== INT ===
#  do_postunconfigure -- 
#
#	No work is defined
#
#------------------------------------------------------------------------------
do_postunconfigure()
{
	:
	# No work defined yet
}

#====================================================================== INT ===
#  do_preunregister -- 
#
#	For components which provide system services, any work which is
#	necessary prior to the removal of those services should be completed
#	in this step. Depending on the service, it may be appropriate to
#	inform all service consumers of the service's removal, using a
#	provider-defined interface. See the guidlines 3.4 "Responsibilies
#	involved with providing a system service."
#
#------------------------------------------------------------------------------
do_preunregister()
{
	:
	#
	#	< FILL IN HERE >
	#
	# This is where OSAs should call classconf & osaconf to remove
	# themselves from the osa registration database
	#
}

#====================================================================== INT ===
#  do_postunregister -- 
#
#	No work is defined
#
#------------------------------------------------------------------------------
do_postunregister()
{
	:
	# No work defined yet
}

#====================================================================== INT ===
#  do_preunattach -- 
#
#	No work is defined
#
#------------------------------------------------------------------------------
do_preunattach()
{
	:
	# No work defined yet
}

#====================================================================== INT ===
#  do_postunattach -- 
#
#	No work is defined
#
#------------------------------------------------------------------------------
do_postunattach()
{
	:
	# No work defined yet
}


#====================================================================== INT ===
#  do_preunload -- 
#
#	No work is defined
#
#------------------------------------------------------------------------------
do_preunload()
{
	:
	# No work defined yet
}

#====================================================================== INT ===
#  do_postunload -- 
#
#	No work is defined
#
#------------------------------------------------------------------------------
do_postunload()
{
	:
	# No work defined yet
}

#====================================================================== INT ===
#  main --
#   
#    Based on step specified, perform actions of the general form:
#       Global initialization
#       Loop to call each package script for package-specific actions
#       Global cleanup
#
#    NOTE: Currently, a number of steps exist for which no action needs to
#    be specified in this product.  This will probably be true for most
#    products in the near future.
#------------------------------------------------------------------------------

# NOTE: Do not "cd" around the place as the SSO_CLIENT_ROOT and related
#       variables are of relative path and your use of them will be damaged
#	if you change your location.

# set a trap so if the user dels out, a WARN exit value is passed
# to the calling program
trap 'cleanup $WARN' 1 2 3 15

# Process the arguments to this script and perform action
# for the step being executed currently
pkg_step=$1
pkg_keywords=$2
pkg_list=$3

# Source in the standard functions library
. ccsSetup.sh

# source in iqm file or SAVE_FILE if iqm file not found 
if [ -f "$IQM_FILE" ]; then
    . $IQM_FILE
elif [ -f "$SAVE_FILE" ]; then
    . $SAVE_FILE 
fi

export IQM_TIMEZONE

# determine action to perform, default is install
upgrade=
removal=
for word in $pkg_keywords
do
	case "$word" in
		OLD_CUSTOM_UPGRADE) upgrade=nonSSOupgrade
		;;
		UPGRADE) upgrade=SSOupgrade
		;;
	esac
done

# This first case details in which order an "installation" takes place in:
case "$pkg_step" in
	PRE_LOAD)
			do_preload
			;;
	POST_LOAD)
			do_postload
			;;
	PRE_ATTACH)
			do_preattach
			;;
	POST_ATTACH)
			do_postattach
			;;
	PRE_REGISTER)
			do_preregister
			;;
	POST_REGISTER)
			do_postregister
			;;
	PRE_CONFIGURE)
			do_preconfigure
			;;
	POST_CONFIGURE)
			do_postconfigure
			;;
	PRE_EXPORT)
			do_preexport
			;;
	POST_EXPORT)
			do_postexport
			;;
esac

# This first case details in which order an "removal" takes place in:
case "$pkg_step" in
	PRE_UNEXPORT)
			do_preunexport
			;;
	POST_UNEXPORT)
			do_postunexport
			;;
	PRE_UNCONFIGURE)
			do_preunconfigure
			;;
	POST_UNCONFIGURE)
			do_postunconfigure
			;;
	PRE_UNREGISTER)
			do_preunregister
			;;
	POST_UNREGISTER)
			do_postunregister
			;;
	PRE_UNATTACH)
			do_preunattach
			;;
	POST_UNATTACH)
			do_postunattach
			;;
	PRE_UNLOAD)
			do_preunload
			;;
	POST_UNLOAD)
			do_postunload
			;;
esac

cleanup $OK

