#!/bin/ksh93
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/sa/tsmclient/sbin/cl_tsmBAclientstart.sh 1.1 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2010 
# 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 
# @(#)41	1.1  src/43haes/usr/sbin/cluster/sa/tsmclient/sbin/cl_tsmBAclientstart.sh, hacmp.assist, 61haes_r714 11/28/11 15:02:26
###############################################################################################
#
# NAME:
#	cl_tsmBAclientstart
#
# PURPOSE:
#       sart script of Smart Assist for TSM backup archive client
#
# ARGUMENTS:
# 	n/a
# RETURNS
#  0 on success
#  1 on Failure
#
#################################################################################################

[[ "VERBOSE_LOGGING" == "high" ]] && set -x
. /usr/es/sbin/cluster/sa/tsmclient/sbin/cl_tsmcliGlobals
KLIB_HACMPLOG_ENTRY=$KLIB_TSM_CLIENT_HACMPLOG_ENTRY

typeset app_name

while getopts a: opt
do
        case $opt in

                a) # client application name, which will be highly available
                        app_name=$OPTARG
                        ;;

        esac
done

sys_time=$(cat /tmp/tsmc_sys.temp|grep SYS_MOD_TIME|awk -F= '{ print $2 }' ) > /dev/null 2>&1
opt_time=$(cat /tmp/tsmc_opt.tmp|grep OPT_MOD_TIME|awk -F= '{ print $2 }' ) > /dev/null 2>&1
tsm_conf_dir=$(clodmget -q "name=TSM_CONF_DIR and application_id=$app_name" -f value -n HACMPsa_metadata)
tsm_conf_dir=$(echo $tsm_conf_dir|sed 's/^[ ]*//')
sys_time=$(echo $sys_time|sed 's/^[ ]*//')
opt_time=$(echo $opt_time|sed 's/^[ ]*//')

export DSM_CONFIG=$tsm_conf_dir/dsm.opt

TSM_BIN=""
lslpp -iq tivoli.tsm.client.ba.64bit.common > /dev/null 2>&1
if [[ $? == 0 ]];then
        TSM_BIN=$TSM_CLIENT_BA_BIN64
else
        TSM_BIN=$TSM_CLIENT_BA_BIN
fi

[[ -n $sys_time ]] || {
			[[ -f $TSM_BIN/dsm.sys ]] && {	
	                        sys_time=$(istat $TSM_BIN/dsm.sys|grep modified|cut -d: -f 2,3,4)
        	                sys_time=$(echo "$sys_time"|sed 's/^[ \t]*//'|sed 's/\\//g'|sed 's/ //g')
                	        claddsaapp -a $app_name DSM_SYS_MOD_TIME="$sys_time"
				echo "SYS_MOD_TIME=$sys_time" > /tmp/tsmc_sys.temp
				}
                        }

[[ -n $opt_time ]] || {
			[[ -f $tsm_conf_dir/dsm.opt ]] && {
	                        opt_time=$(istat $tsm_conf_dir/dsm.opt|grep modified|cut -d: -f 2,3,4)
        	                opt_time=$(echo "$opt_time"|sed 's/^[ \t]*//'|sed 's/\\//g'|sed 's/ //g')
                	        claddsaapp -a $app_name DSM_OPT_MOD_TIME="$opt_time"
				echo "OPT_MOD_TIME=$opt_time" > /tmp/tsmc_opt.tmp
				}
                        }

KLIB_SA_logmsg INFO 2 11 tsmclientsa.cat "starting BA client deamon dsmcad\n"

$TSM_BIN/dsmcad  > /dev/null 2>&1
[[ $? != 0 ]] && {
                 KLIB_SA_logmsg ERROR 2 12 tsmclientsa.cat "Failed while starting BA client deamon dsmcad\n"

		 exit 1
		}
exit 0
