# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 2004,2007 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
#*===========================================================================*/
#*                                                                           */
#* Module Name:  ctbrdefs                                                    */
#*                                                                           */
#* Description:                                                              */
#*      Common definitions for the ctbackup and ctrestore scripts;           */
#*      "sourced" by same.                                                   */
#*                                                                           */
#*===========================================================================*/
#*   @(#)56   1.2   src/rsct/utils/cmds/ctbrdefs.sh, common_utils, rsct_relgh, relghs001a 10/4/04 19:00:29

# Set path to known value
PATH=/usr/sbin/rsct/install/bin:/usr/sbin/rsct/bin:/usr/bin:/bin:/usr/sbin
export PATH

# define some function option values

FUNC_RETURN=0
FUNC_EXIT=1

CTBACKUPDIR=/var/ct.backup	# backup directory
BCFGDIR=${CTBACKUPDIR}/cfg	# backup configuration directory
CLUSTER_LIST=${CTBACKUPDIR}/cluster.list

CTROOTDIR=/var/ct			# root directory for all RSCT run-time data
CFGDIR=${CTROOTDIR}/cfg		# cluster independent configuration directory

# define list of files in /var/ct

VAR_CT_FILES="first_start"

# define list of RMC files in /var/ct/cfg

VAR_CT_CFG_RMC="mc.tunehb \
				mc.priority \
				ctrmc.acls \
				ctrmc.rpe \
				ctrmc.msgp \
				ctrmc.dmsgp \
				ctrmc.mntbl \
				ctrmc.ngntbl \
				ctrmc.mcptbl \
				ctrmc.isdd"

# define list of ctsec files in /var/ct/cfg

VAR_CT_CFG_SEC="ct_has.qkf \
				ct_has.pkf \
				ct_has.thl \
				ctsec_map.global \
				ctsec_map.local \
				ctcasd.cfg \
				ctsec.cfg \
				unix.map \
				ctsec.nodeinfo"

# define list of cluster definition files in /var/ct/cfg

VAR_CT_CFG_CLUSTER="default_cluster \
					current_cluster \
					clusters"

# define line of "autostart" files in /var/ct/cfg

VAR_CT_CFG_AUTOSTART="ConfigRM.autostart \
					  ConfigRM-online.autostart"

# define well-known files in /var/ct/cfg

VAR_CT_CFG_FILES="ct_node_id \
				  $VAR_CT_CFG_RMC \
				  $VAR_CT_CFG_SEC \
				  $VAR_CT_CFG_CLUSTER \
				  $VAR_CT_CFG_AUTOSTART"

# define well-know files in /var/ct/<cluster_id>/cfg

CLUSTER_CFG_FILES="nodedef.cfg \
				   rsct.params \
				   machine.lst \
				   cluster.info \
				   hats.info \
				   topology.info \
				   ctrmc.srcntbl"

# define miscellaneous directories, with their contents, to be saved.
# these directory paths are relative to $CTROOTDIR and MUST contain at
# least two directories, i.e. a/b, a/b/c is OK, a is not. The first directory
# in the path be a <cluster_name> or "cfg"

VAR_CT_MISC_DIRS="cfg/cimrm"

# define miscellaneous directories, with their contents, to be saved.
# these directory paths are relative to $CTROOTDIR/IW and MUST contain at
# least two directories, i.e. a/b, a/b/c is OK, a is not. The first directory
# in the path be a <cluster_name> or "cfg"

VAR_CT_IW_MISC_DIRS="cfg/rmdefs \
					 cfg/nls"


# define function to copy a file, with error checking
# The first arg is the file to copy, the second arg is the target directory
# The third arg indicates whether or not the function should exit or return
# to the caller.

function copy_file_to_dir {
	print "Copying file $1 to directory $2"
	if [[ -a $1 ]]
	then
		if ! cp -p $1 $2
		then
			print "Cannot copy file $1 to directory $2"
			if [[ $3 -eq $FUNC_RETURN ]]
			then
				return 1
			else
				exit 1
			fi
		fi
	fi

	return 0
}

# define function to make a directory and set its owner/group/perms
# The second arg indicates whether or not the function should exit or return
# to the caller.

function mkdir_and_set_ogp {
	print "Making directory $1"
	if [[ ! -a $1 ]]
	then
		if ! mkdir $1
		then
			print "Cannot make directory $1"
			if [[ $2 -eq $FUNC_RETURN ]]
			then
				return 1
			else
				exit 1
			fi
		fi
		chown bin $1
		chgrp bin $1
		chmod 775 $1
	fi

	return 0
}
